comparison test/test-layer-exports.sh @ 2438:a5ec35798c9e spectrogram-export

Add regression tests for layer export
author Chris Cannam
date Tue, 07 Jan 2020 14:36:27 +0000
parents
children 882848f168e8
comparison
equal deleted inserted replaced
2437:32dbc311c6d4 2438:a5ec35798c9e
1 #!/bin/bash
2 #
3 # Regression tests for layer export to CSV
4 # Must be run from directory that contains this script
5
6 # NB hardcoded assumptions here about the contents of the session
7 # file, so the session file (all.sv) is also hardcoded. The session is
8 # expected to consist of:
9 #
10 # - pane 1 with 3 layers (ruler, waveform, instants)
11 # - pane 2 with 3 layers (ruler, waveform, values)
12 # - pane 3 with 3 layers (ruler, image, regions)
13 # - pane 4 with 3 layers (ruler, text, notes)
14 # - pane 5 with 2 layers (ruler, 3d plot)
15 # - pane 6 with 3 layers (ruler, spectrogram, boxes)
16 # - pane 7 with 2 layers (ruler, peak frequency spectrogram)
17
18 set -e
19
20 if [ -n "$1" ]; then
21 echo "Usage: $0" 1>&2
22 exit 2
23 fi
24
25 set -u
26
27 sv="../sonic-visualiser"
28 if [ ! -f "$sv" -o ! -x "$sv" ]; then
29 echo "This script must be run from the sonic-visualiser/test directory" 1>&2
30 exit 1
31 fi
32
33 version=$("$sv" -v 2>&1)
34 adequate=no
35 case "$version" in
36 [012].*) ;;
37 3.[012]) ;;
38 3.[012].*) ;;
39 [1-9]*) adequate=yes ;;
40 *) echo "Failed to query Sonic Visualiser version" 1>&2
41 exit 1 ;;
42 esac
43 if [ "$adequate" = "no" ]; then
44 echo "Sonic Visualiser version must be at least 3.3 (supporting --osc-script option)" 1>&2
45 exit 1
46 fi
47
48 session="all.sv"
49
50 if [ ! -f "$session" ]; then
51 echo "Session file $session not found" 1>&2
52 exit 1
53 fi
54
55 tmpdir=$(mktemp -d)
56 trap "rm -rf $tmpdir" 0
57
58 input="$tmpdir/input.sv"
59
60 cp "$session" "$input"
61
62 cat > "$tmpdir/script" <<EOF
63 /open "$input"
64 /setcurrent 1 3
65 /exportlayer "$tmpdir/instants.csv"
66 /setcurrent 2 3
67 /exportlayer "$tmpdir/values.csv"
68 /setcurrent 3 2
69 /exportlayer "$tmpdir/image.csv"
70 /setcurrent 3 3
71 /exportlayer "$tmpdir/regions.csv"
72 /setcurrent 4 2
73 /exportlayer "$tmpdir/text.csv"
74 /setcurrent 4 3
75 /exportlayer "$tmpdir/notes.csv"
76 /setcurrent 5 2
77 /exportlayer "$tmpdir/3dplot.csv"
78 /setcurrent 6 2
79 /exportlayer "$tmpdir/spectrogram.csv"
80 /setcurrent 6 3
81 /exportlayer "$tmpdir/boxes.csv"
82 /setcurrent 7 2
83 /exportlayer "$tmpdir/peakfreq.csv"
84 /quit
85 EOF
86
87 "$sv" --no-splash --osc-script "$tmpdir/script"
88
89 for type in instants values image regions text notes 3dplot spectrogram boxes peakfreq ; do
90 actual="$tmpdir/$type.csv"
91 expected="layers-expected/$type.csv"
92 if ! cmp -s "$actual" "$expected" ; then
93 echo
94 echo "Test failed for layer type \"$type\"!"
95 echo
96 echo "Actual:"
97 ls -l "$actual"
98 echo "Expected"
99 ls -l "$expected"
100 echo
101 echo "Diff begins:"
102 diff -u1 "$actual" "$expected" | head
103 echo
104 fi
105 done
106
107