Merge branch 'master' into 1.0
[libdcp.git] / run / tests
1 #!/bin/bash -e
2 #
3 # Run our test suite, which (amongst other things)
4 # builds a couple of DCPs.
5 # The outputs are compared against the ones
6 # in test/ref/DCP, and an error is given
7 # if anything is different.
8
9 private=test/private
10 work=build/test
11
12 export LD_LIBRARY_PATH=build/src:build/asdcplib/src
13
14 # Run the unit tests in test/
15 if [ "$1" == "--debug" ]; then
16     shift
17     gdb --args $work/tests
18 elif [ "$1" == "--valgrind" ]; then
19     shift
20     valgrind --tool="memcheck" $work/tests
21 else
22     $work/tests $*
23 fi
24
25 if [ ! -e "test/private/info.log" ]; then
26     echo "Private data not found: some tests will not run"
27 fi
28
29 # Check the first DCP written by the unit tests
30 diff -ur test/ref/DCP/foo $work/DCP/foo
31 if [ "$?" != "0" ]; then
32     echo "FAIL: files differ"
33     exit 1
34 fi
35
36 # Check the second DCP written by the unit tests
37 diff -ur test/ref/DCP/bar $work/DCP/bar
38 if [ "$?" != "0" ]; then
39     echo "FAIL: files differ"
40     exit 1
41 fi
42
43 # Run dcpinfo on all the DCPs in private/metadata, writing $work/info.log
44 rm -f $work/info.log
45 for d in `find $private/metadata -mindepth 1 -maxdepth 1 -type d | sort`; do
46     if [ `basename $d` != ".git" ]; then
47         build/tools/dcpinfo -s $d >> $work/info.log
48         if [ "$?" != "0" ]; then
49             echo "FAIL: dcpinfo failed for $d"
50             exit 1
51         fi
52     fi
53 done
54
55 # Check info.log is what it should be
56 diff -q $work/info.log $private/info.log
57 if [ "$?" != "0" ]; then
58     echo "FAIL: dcpinfo output incorrect"
59     exit 1
60 fi
61
62 # Copy test/private into build/ then re-write the subtitles of every DCP using 
63 # $work/rewrite_subs.  This tests round-trip of subtitle reading/writing.
64 rm -f $work/info2.log
65 rm -rf $work/private
66 cp -r $private $work
67 for d in `find $work/private/metadata -mindepth 1 -maxdepth 1 -type d | sort`; do
68     if [ `basename $d` != ".git" ]; then
69         $work/rewrite_subs $d
70         build/tools/dcpinfo -s $d >> $work/info2.log
71     fi
72 done
73
74 # Fudge the output
75 sed -i "s/DCP: build\/test/DCP: test/g" $work/info2.log
76
77 # And check it
78 diff -q $work/info2.log $private/info.log
79 if [ "$?" != "0" ]; then
80     echo "FAIL: dcpinfo output from rewrite incorrect"
81     exit 1
82 fi
83
84 # Dump the subs of JourneyToJah... (which has MXF-wrapped subtitles)
85 # and check that they are right
86 build/tools/dcpinfo -s $private/JourneyToJah_TLR-1_F_EN-DE-FR_CH_51_2K_LOK_20140225_DGL_SMPTE_OV >> $work/jah.log
87
88 # Check a MXF written by the unit tests
89 diff $work/baz/video1.mxf $work/baz/video2.mxf
90 if [ "$?" != "0" ]; then
91     echo "FAIL: MXFs from recovery incorrect"
92     exit 1
93 fi
94     
95 echo "PASS"