blob: edc45d7923bb980d65321475b23e69b8307aba75 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
#!/usr/bin/env sh
# test-abstraction-ssp-roundtrip.sh
#
# Reads each reference .ssp back into the abstraction and emits it again,
# and requires the result to be byte identical to the file it read.
#
# What that proves: the reader (sisudoc.ocda.abstraction.ssp_in) restores
# every field the writer emits. The check is made against the writer itself,
# since both go through template sspObjectRecord, so there is no second
# description of the format that could drift from the first.
#
# It needs no sample documents and no output directory: the committed
# reference set is the input. Run test-abstraction-ssp.sh first if you want
# to know that the reference set is itself current.
#
# Usage:
# ./test/test-abstraction-ssp-roundtrip.sh # uses result/bin/spine
# ./test/test-abstraction-ssp-roundtrip.sh ./bin/spine-ldc # specify binary
#
# Exit codes:
# 0 every reference .ssp round trips byte identically
# 1 one or more do not (the first differences are printed)
# 2 set-up problem (no binary, no reference set)
set -e
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
SPINE_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
REF_DIR="$SCRIPT_DIR/reference/abstraction"
SPINE_BIN="${1:-}"
if [ -z "$SPINE_BIN" ]; then
if [ -x "$SPINE_DIR/result/bin/spine" ]; then SPINE_BIN="$SPINE_DIR/result/bin/spine"
elif [ -x "$SPINE_DIR/bin/spine-ldc" ]; then SPINE_BIN="$SPINE_DIR/bin/spine-ldc"
elif [ -x "$SPINE_DIR/bin/spine" ]; then SPINE_BIN="$SPINE_DIR/bin/spine"
else
echo "ERROR: spine binary not found. Specify path as argument." >&2
exit 2
fi
fi
if [ ! -d "$REF_DIR" ] || [ -z "$(ls "$REF_DIR"/*.ssp 2>/dev/null)" ]; then
echo "ERROR: no reference files found at $REF_DIR" >&2
echo "Run ./test/test-abstraction-ssp.sh --generate first." >&2
exit 2
fi
TMP="$SCRIPT_DIR/current-roundtrip"
rm -rf "$TMP"
mkdir -p "$TMP"
echo "spine binary: $SPINE_BIN"
echo "reference: $REF_DIR"
echo "Reading each .ssp back and emitting it again ..."
COUNT=0
FAILURES=0
for ref in "$REF_DIR"/*.ssp; do
base=$(basename "$ref")
COUNT=$((COUNT + 1))
if ! $SPINE_BIN --ssp-round-trip="$ref" > "$TMP/$base" 2> "$TMP/$base.err"; then
echo "ERROR: $base (spine exited non-zero)"
head -3 "$TMP/$base.err"
FAILURES=$((FAILURES + 1))
continue
fi
if ! cmp -s "$ref" "$TMP/$base"; then
echo "DIFFERS: $base ($(diff "$ref" "$TMP/$base" | grep -c '^[<>]') lines)"
diff --unified=1 "$ref" "$TMP/$base" | head -12
echo " ..."
FAILURES=$((FAILURES + 1))
fi
done
rm -rf "$TMP"
if [ "$FAILURES" -eq 0 ]; then
echo "PASS: all $COUNT .ssp files read back and re-emit byte identically"
exit 0
else
echo "FAIL: $FAILURES of $COUNT do not round trip"
exit 1
fi
|