aboutsummaryrefslogtreecommitdiffstats
path: root/emulator/opengl/host/tools/emugen/tests/run-tests.sh
diff options
context:
space:
mode:
authorDavid 'Digit' Turner <digit@google.com>2014-10-30 15:09:17 +0100
committerDavid 'Digit' Turner <digit@google.com>2014-10-30 15:39:18 +0100
commit6d4468efe84bf50fb8e43aab011059fb7d019c1b (patch)
tree97c94f079366add2a311b8eec619dc8625fac0e9 /emulator/opengl/host/tools/emugen/tests/run-tests.sh
parentcf7e8c7948b3b811a6693ac871d2578a2bdf0a46 (diff)
downloadsdk-6d4468efe84bf50fb8e43aab011059fb7d019c1b.zip
sdk-6d4468efe84bf50fb8e43aab011059fb7d019c1b.tar.gz
sdk-6d4468efe84bf50fb8e43aab011059fb7d019c1b.tar.bz2
emulator/opengl: Add emugen test suite.
This adds a small test suite to check the output of the 'emugen' program. This serves two purposes: 1) To more easily check that modifications to 'emugen' do not break stuff liberally. 2) To better document how the changes in the generator actually modify the output. To run it, simply call the 'run-tests.sh' script with 'emugen' in your path, or use --emugen=<program> otherwise. See --help for more details. NOTE: The test suite currently doesn't check that the generated sources compile properly, or that they even work as expected. See the following external/qemu patch to call run-tests.sh during each android-rebuild.sh run: https://android-review.googlesource.com/112541 Change-Id: I9abc3f9ae63b0bb753f0f8e07c1b3f0b11a3252f
Diffstat (limited to 'emulator/opengl/host/tools/emugen/tests/run-tests.sh')
-rwxr-xr-xemulator/opengl/host/tools/emugen/tests/run-tests.sh129
1 files changed, 129 insertions, 0 deletions
diff --git a/emulator/opengl/host/tools/emugen/tests/run-tests.sh b/emulator/opengl/host/tools/emugen/tests/run-tests.sh
new file mode 100755
index 0000000..67409ed
--- /dev/null
+++ b/emulator/opengl/host/tools/emugen/tests/run-tests.sh
@@ -0,0 +1,129 @@
+#!/bin/sh
+
+# Copyright 2014 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+set -e
+
+export LANG=C
+export LC_ALL=C
+
+PROGDIR=$(dirname "$0")
+PROGNAME=$(basename "$0")
+
+fatal () {
+ echo "ERROR: $@"
+ exit 1
+}
+
+OPT_EMUGEN=
+OPT_HELP=
+OPT_OUT_DIR=
+OPT_TOOL=
+
+for OPT; do
+ OPTARG=$(expr "x$OPT" : "x[^=]*=\\(.*\\)" || true)
+ case $OPT in
+ --help|-h|-?)
+ OPT_HELP=true
+ ;;
+ --emugen=*)
+ OPT_EMUGEN=$OPTARG
+ ;;
+ --out-dir=*)
+ OPT_OUT_DIR=$OPTARG
+ ;;
+ --tool=*)
+ OPT_TOOL=$OPTARG
+ ;;
+ -*)
+ fatal "Invalid option '$OPT', see --help."
+ ;;
+ *)
+ fatal "This script doesn't take arguments, see --help."
+ ;;
+ esac
+done
+
+if [ "$OPT_HELP" ]; then
+ cat <<EOF
+Usage: $PROGNAME [options]
+
+Run the emugen test suite. This scripts looks for sub-directories
+named t.<number>/input, and uses them as input to 'emugen'. It then
+compares the output to t.<number>/expected/ content.
+
+Valid options:
+ --help|-h|-? Print this help.
+ --out-dir=<dir> Generate outputs into <dir>.
+ --emugen=<program> Emugen program path, if not in path.
+ --tool=<tool> Launch visual diff tool in case of differences.
+EOF
+ exit 0
+fi
+
+# Find emugen program
+EMUGEN=
+if [ "$OPT_EMUGEN" ]; then
+ EMUGEN=$OPT_EMUGEN
+else
+ EMUGEN=$(which emugen 2>/dev/null || true)
+ if [ -z "$EMUGEN" ]; then
+ fatal "Cannot find 'emugen' program in PATH, use --emugen=<program> option."
+ fi
+ echo "Auto-config: --emugen=$EMUGEN"
+fi
+if [ ! -f "$EMUGEN" ]; then
+ fatal "Emugen program doesn't exist: $EMUGEN"
+fi
+
+# Create output directory.
+OUT_DIR=
+if [ "$OPT_OUT_DIR" ]; then
+ OUT_DIR=$OPT_OUT_DIR
+else
+ OUT_DIR=/tmp/$USER-emugen-testing
+ echo "Auto-config: --out-dir=$OUT_DIR"
+fi
+mkdir -p "$OUT_DIR" && rm -rf "$OUT_DIR/emugen"
+
+OUT_DIR=$OUT_DIR/emugen
+
+# Find test directories
+TEST_DIRS=$(cd "$PROGDIR" && find . -name "t.*" | sed -e 's|^\./||')
+for TEST_DIR in $TEST_DIRS; do
+ IN=$PROGDIR/$TEST_DIR/input
+ PREFIXES=$(cd $IN && find . -name "*.in" | sed -e 's|^\./||g' -e 's|\.in$||g')
+ OUT=$OUT_DIR/$TEST_DIR
+ mkdir -p "$OUT/encoder"
+ mkdir -p "$OUT/decoder"
+ mkdir -p "$OUT/wrapper"
+ for PREFIX in $PREFIXES; do
+ echo "Processing $IN/foo.*"
+ $EMUGEN -i "$PROGDIR/$TEST_DIR/input" -D "$OUT/decoder" -E "$OUT/encoder" -W "$OUT/wrapper" $PREFIX
+ done
+ if ! diff -qr "$PROGDIR/$TEST_DIR/expected" "$OUT"; then
+ if [ "$OPT_TOOL" ]; then
+ $OPT_TOOL "$PROGDIR/$TEST_DIR/expected" "$OUT"
+ else
+ echo "ERROR: Invalid differences between actual and expected output!"
+ diff -burN "$PROGDIR/$TEST_DIR/expected" "$OUT"
+ exit 1
+ fi
+ fi
+done
+
+echo "All good!"
+exit 0