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