Check for required executables before starting tests.
[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=../libdcp-test-private
10 work=build/test
11 dcpinfo=build/tools/dcpinfo
12
13 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:build/src:build/asdcplib/src
14
15 for c in xmlsec1 xmldiff; 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 else
27     $work/tests $private $*
28 fi
29
30 # Check a MXF written by the unit tests
31 diff $work/baz/video1.mxf $work/baz/video2.mxf
32 if [ "$?" != "0" ]; then
33     echo "FAIL: MXFs from recovery incorrect"
34     exit 1
35 fi
36
37 # Check the first DCP written by the unit tests
38 diff -ur test/ref/DCP/dcp_test1 $work/DCP/dcp_test1
39 if [ "$?" != "0" ]; then
40     echo "FAIL: files differ"
41     exit 1
42 fi
43
44 # Check the second DCP written by the unit tests
45 diff -ur test/ref/DCP/bar $work/DCP/bar
46 if [ "$?" != "0" ]; then
47     echo "FAIL: files differ"
48     exit 1
49 fi
50     
51 # Everything beyond this point needs $private to exist
52 if [ ! -e "$private/info.log" ]; then
53     echo ""
54     echo "Private data not found: some tests will not run."
55     exit 1
56 fi
57
58 # Run dcpinfo on all the DCPs in private/metadata, writing $work/info.log
59 rm -f $work/info.log
60 for d in `find $private/metadata -mindepth 1 -maxdepth 1 -type d | sort -f -d`; do
61     if [ `basename $d` != ".git" ]; then
62         $dcpinfo --ignore-missing-assets -k -s $d 2> /dev/null >> $work/info.log
63         if [ "$?" != "0" ]; then
64             echo "FAIL: dcpinfo failed for $d"
65             exit 1
66         fi
67     fi
68 done
69
70 # Check info.log is what it should be
71 diff -q $work/info.log $private/info.log
72 if [ "$?" != "0" ]; then
73     echo "FAIL: dcpinfo output incorrect"
74     exit 1
75 fi
76
77 # Copy test/private into build/ then re-write the subtitles of every DCP using 
78 # $work/rewrite_subs.  This tests round-trip of subtitle reading/writing.
79 rm -f $work/info2.log
80 rm -rf $work/private
81 mkdir $work/private
82 cp -r $private/* $work/private
83 for d in `find $work/private/metadata -mindepth 1 -maxdepth 1 -type d | sort -f -d`; do
84     if [ `basename $d` != ".git" ]; then
85         $work/rewrite_subs $d
86         $dcpinfo --ignore-missing-assets -k -s $d >> $work/info2.log
87     fi
88 done
89
90 # Fudge the output
91 sed -i "s/DCP: build\/test/DCP: test/g" $work/info2.log
92
93 # And check it
94 diff -q $work/info2.log $private/info2.log
95 if [ "$?" != "0" ]; then
96     echo "FAIL: dcpinfo output from rewrite incorrect"
97     exit 1
98 fi
99
100 # Dump the subs of JourneyToJah... (which has MXF-wrapped subtitles)
101 # and check that they are right
102 $dcpinfo -s $private/data/JourneyToJah_TLR-1_F_EN-DE-FR_CH_51_2K_LOK_20140225_DGL_SMPTE_OV >> $work/jah.log
103
104 echo "PASS"