4b87588109decf3442328313e9a365ff2d4bb883
[libdcp.git] / run / tests
1 #!/bin/bash
2 #
3 # Run our test suite.
4
5 # Private test data; this is stuff that is non-distributable
6 private=../libdcp-test-private
7 # Work directory
8 work=build/test
9 # Path to tools
10 dcpinfo=build/tools/dcpinfo
11 dcpverify=build/tools/dcpverify
12
13 export LD_LIBRARY_PATH=build/src:/home/c.hetherington/lib:$LD_LIBRARY_PATH
14 export LIBDCP_SHARE_PREFIX=.
15
16 # Make sure we have the required tools
17 for c in xmlsec1 xmldiff xmllint; do
18   hash $c 2>/dev/null || { echo >&2 "$c required but not found; aborting"; exit 1; }
19 done
20
21 echo "Running in $(pwd")
22 ls 
23 ls ..
24 echo "--- Unit tests"
25
26 # Run the unit tests in test/
27 if [ "$1" == "--debug" ]; then
28     shift
29     gdb --args $work/tests $private $*
30 elif [ "$1" == "--valgrind" ]; then
31     shift
32     valgrind --tool="memcheck" $work/tests $private $*
33 elif [ "$1" == "--callgrind" ]; then
34     shift
35     valgrind --tool="callgrind" $work/tests $private $*
36 else
37     $work/tests $* -- $private
38     if [ "$?" != "0" ]; then
39         echo "FAIL: unit tests"
40         exit 1
41     fi
42 fi
43
44 if [ "$*" != "" ]; then
45     echo "Skipping post-test checks as not all unit tests were run."
46     exit 0
47 fi
48
49 echo "--- Other tests"
50
51 # Check a MXF written by the unit tests
52 diff $work/baz/video1.mxf $work/baz/video2.mxf
53 if [ "$?" != "0" ]; then
54     echo "FAIL: MXFs from recovery incorrect"
55     exit 1
56 fi
57
58 # Check the DCP written by dcp_test1
59 diff -ur test/ref/DCP/dcp_test1 $work/DCP/dcp_test1
60 if [ "$?" != "0" ]; then
61     echo "FAIL: files differ"
62     exit 1
63 fi
64
65 # Check the DCP written by dcp_test2
66 diff -ur test/ref/DCP/dcp_test2 $work/DCP/dcp_test2
67 if [ "$?" != "0" ]; then
68     echo "FAIL: files differ"
69     exit 1
70 fi
71
72 # Check the DCP written by dcp_test5
73 diff -ur test/ref/DCP/dcp_test5 $work/DCP/dcp_test5
74 if [ "$?" != "0" ]; then
75     echo "FAIL: files differ"
76     exit 1
77 fi
78
79 # Check the DCP written by dcp_test7
80 diff -ur test/ref/DCP/dcp_test7 $work/DCP/dcp_test7
81 if [ "$?" != "0" ]; then
82     echo "FAIL: files differ"
83     exit 1
84 fi
85
86 # Check the DCP written by encryption_test
87 diff -ur test/ref/DCP/encryption_test $work/DCP/encryption_test
88 if [ "$?" != "0" ]; then
89     echo "FAIL: files differ"
90     exit 1
91 fi
92
93 # Everything beyond this point needs $private to exist
94 if [ ! -e "$private/info.log" ]; then
95     echo ""
96     echo "Private data not found: some tests will not run."
97     exit 1
98 fi
99
100 # Run dcpinfo on all the DCPs in private/metadata, writing $work/info.log
101 # This writes details of the CPLs and all subtitle details, so it checks
102 # if the code is reading subtitle files correctly.
103 rm -f $work/info.log
104 for d in `find $private/metadata -mindepth 1 -maxdepth 1 -type d | sort -f -d`; do
105     if [ `basename $d` != ".git" ]; then
106         $dcpinfo --ignore-missing-assets -s $d >> $work/info.log
107         if [ "$?" != "0" ]; then
108             echo "FAIL: dcpinfo failed for $d"
109             exit 1
110         fi
111     fi
112 done
113
114 # Run dcpverify on all the DCPs in private/metadata
115 for d in `find $private/metadata -mindepth 1 -maxdepth 1 -type d | sort -f -d`; do
116     if [ `basename $d` != ".git" ]; then
117         $dcpverify --ignore-missing-assets -q $d
118         if [ "$?" != "0" ]; then
119             echo "FAIL: dcpverify failed for $d"
120             exit 1
121         fi
122     fi
123 done
124
125 # Check info.log is what it should be
126 diff -q $work/info.log $private/info.log
127 if [ "$?" != "0" ]; then
128     echo "FAIL: dcpinfo output incorrect"
129     exit 1
130 fi
131
132 # Copy $private/metadata into build/metadata then re-write the subtitles
133 # of every DCP using $work/rewrite_subs.  This tests round-trip of
134 # subtitle reading/writing.
135 rm -f $work/info2.log
136 rm -rf $work/private
137 mkdir $work/private
138 cp -r $private/metadata $work/private/
139 for d in `find $work/private/metadata -mindepth 1 -maxdepth 1 -type d | sort -f -d`; do
140     if [ `basename $d` != ".git" ]; then
141         $work/rewrite_subs $d
142         $dcpinfo --ignore-missing-assets -s $d >> $work/info2.log
143     fi
144 done
145
146 # Fudge the output
147 sed -i "s/DCP: build\/test/DCP: test/g" $work/info2.log
148
149 # And check it
150 diff -q $work/info2.log $private/info2.log
151 if [ "$?" != "0" ]; then
152     echo "FAIL: dcpinfo output from rewrite incorrect"
153     exit 1
154 fi
155
156 # Dump the subs of JourneyToJah... (which has MXF-wrapped SMPTE subtitles)
157 # and check that they are right
158 $dcpinfo -s $private/data/JourneyToJah_TLR-1_F_EN-DE-FR_CH_51_2K_LOK_20140225_DGL_SMPTE_OV >> $work/jah.log
159
160 # Parse some problematic subs and check that we get it right
161 run/test/subs_in_out $private/TunaBoat_Icelandic_Reel1_V1_8sec.xml > $work/tuna.xml
162 diff -q $private/TunaBoat_Icelandic_Reel1_V1_8sec.parsed.xml $work/tuna.xml
163 if [ "$?" != "0" ]; then
164     echo "FAIL: output of parse check 1 invalid"
165     exit 1
166 fi
167
168 echo "PASS"