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