Merge branch '1.0' of ssh://main.carlh.net/home/carl/git/libdcp into 1.0
[libdcp.git] / run / tests
1 #!/bin/bash -e
2 #
3 # Run our test suite.
4
5 # Private test data; this is stuff that is non-distributable
6 private=../libdcp1-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:build/asdcplib/src:$LD_LIBRARY_PATH
13
14 # Make sure we have the required tools
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 DCP written by dcp_test1
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 DCP written by dcp_test2
45 diff -ur test/ref/DCP/dcp_test2 $work/DCP/dcp_test2
46 if [ "$?" != "0" ]; then
47     echo "FAIL: files differ"
48     exit 1
49 fi
50
51 # Check the DCP written by encryption_test
52 diff -ur test/ref/DCP/encryption_test $work/DCP/encryption_test
53 if [ "$?" != "0" ]; then
54     echo "FAIL: files differ"
55     exit 1
56 fi
57     
58 # Everything beyond this point needs $private to exist
59 if [ ! -e "$private/info.log" ]; then
60     echo ""
61     echo "Private data not found: some tests will not run."
62     exit 1
63 fi
64
65 # Run dcpinfo on all the DCPs in private/metadata, writing $work/info.log
66 # This writes details of the CPLs and all subtitle details, so it checks
67 # if the code is reading subtitle files correctly.
68 rm -f $work/info.log
69 for d in `find $private/metadata -mindepth 1 -maxdepth 1 -type d | sort -f -d`; do
70     if [ `basename $d` != ".git" ]; then
71         $dcpinfo --ignore-missing-assets -k -s $d 2> /dev/null >> $work/info.log
72         if [ "$?" != "0" ]; then
73             echo "FAIL: dcpinfo failed for $d"
74             exit 1
75         fi
76     fi
77 done
78
79 # Check info.log is what it should be
80 diff -q $work/info.log $private/info.log
81 if [ "$?" != "0" ]; then
82     echo "FAIL: dcpinfo output incorrect"
83     exit 1
84 fi
85
86 # Copy $private into build/ then re-write the subtitles of every DCP using 
87 # $work/rewrite_subs.  This tests round-trip of subtitle reading/writing.
88 # Note that all the subs in $private/metadata are Interop.
89 rm -f $work/info2.log
90 rm -rf $work/private
91 mkdir $work/private
92 cp -r $private/* $work/private
93 for d in `find $work/private/metadata -mindepth 1 -maxdepth 1 -type d | sort -f -d`; do
94     if [ `basename $d` != ".git" ]; then
95         $work/rewrite_subs $d
96         $dcpinfo --ignore-missing-assets -k -s $d >> $work/info2.log
97     fi
98 done
99
100 # Fudge the output
101 sed -i "s/DCP: build\/test/DCP: test/g" $work/info2.log
102
103 # And check it
104 diff -q $work/info2.log $private/info2.log
105 if [ "$?" != "0" ]; then
106     echo "FAIL: dcpinfo output from rewrite incorrect"
107     exit 1
108 fi
109
110 # Dump the subs of JourneyToJah... (which has MXF-wrapped SMPTE subtitles)
111 # and check that they are right
112 $dcpinfo -s $private/data/JourneyToJah_TLR-1_F_EN-DE-FR_CH_51_2K_LOK_20140225_DGL_SMPTE_OV >> $work/jah.log
113
114 echo "PASS"