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