3 # Copyright 2014 The Android Open Source Project
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
23 PROGDIR=$(dirname "$0")
24 PROGNAME=$(basename "$0")
37 OPTARG=$(expr "x$OPT" : "x[^=]*=\\(.*\\)" || true)
52 fatal "Invalid option '$OPT', see --help."
55 fatal "This script doesn't take arguments, see --help."
60 if [ "$OPT_HELP" ]; then
62 Usage: $PROGNAME [options]
64 Run the emugen test suite. This scripts looks for sub-directories
65 named t.<number>/input, and uses them as input to 'emugen'. It then
66 compares the output to t.<number>/expected/ content.
69 --help|-h|-? Print this help.
70 --out-dir=<dir> Generate outputs into <dir>.
71 --emugen=<program> Emugen program path, if not in path.
72 --tool=<tool> Launch visual diff tool in case of differences.
79 if [ "$OPT_EMUGEN" ]; then
82 EMUGEN=$(which emugen 2>/dev/null || true)
83 if [ -z "$EMUGEN" ]; then
84 fatal "Cannot find 'emugen' program in PATH, use --emugen=<program> option."
86 echo "Auto-config: --emugen=$EMUGEN"
88 if [ ! -f "$EMUGEN" ]; then
89 fatal "Emugen program doesn't exist: $EMUGEN"
92 # Create output directory.
94 if [ "$OPT_OUT_DIR" ]; then
97 OUT_DIR=/tmp/$USER-emugen-testing
98 echo "Auto-config: --out-dir=$OUT_DIR"
100 mkdir -p "$OUT_DIR" && rm -rf "$OUT_DIR/emugen"
102 OUT_DIR=$OUT_DIR/emugen
104 # Find test directories
105 TEST_DIRS=$(cd "$PROGDIR" && find . -name "t.*" | sed -e 's|^\./||')
106 for TEST_DIR in $TEST_DIRS; do
107 IN=$PROGDIR/$TEST_DIR/input
108 PREFIXES=$(cd $IN && find . -name "*.in" | sed -e 's|^\./||g' -e 's|\.in$||g')
109 OUT=$OUT_DIR/$TEST_DIR
110 mkdir -p "$OUT/encoder"
111 mkdir -p "$OUT/decoder"
112 mkdir -p "$OUT/wrapper"
113 for PREFIX in $PREFIXES; do
114 echo "Processing $IN/foo.*"
115 $EMUGEN -i "$PROGDIR/$TEST_DIR/input" -D "$OUT/decoder" -E "$OUT/encoder" -W "$OUT/wrapper" $PREFIX
117 if ! diff -qr "$PROGDIR/$TEST_DIR/expected" "$OUT"; then
118 if [ "$OPT_TOOL" ]; then
119 $OPT_TOOL "$PROGDIR/$TEST_DIR/expected" "$OUT"
121 echo "ERROR: Invalid differences between actual and expected output!"
122 diff -burN "$PROGDIR/$TEST_DIR/expected" "$OUT"