67409edcc2353f64787b6b88e47db8255b2a70f6
[iec.git] / src / type3_AndroidCloud / anbox-master / external / android-emugl / host / tools / emugen / tests / run-tests.sh
1 #!/bin/sh
2
3 # Copyright 2014 The Android Open Source Project
4 #
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
8 #
9 #      http://www.apache.org/licenses/LICENSE-2.0
10 #
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.
16 #
17
18 set -e
19
20 export LANG=C
21 export LC_ALL=C
22
23 PROGDIR=$(dirname "$0")
24 PROGNAME=$(basename "$0")
25
26 fatal () {
27     echo "ERROR: $@"
28     exit 1
29 }
30
31 OPT_EMUGEN=
32 OPT_HELP=
33 OPT_OUT_DIR=
34 OPT_TOOL=
35
36 for OPT; do
37     OPTARG=$(expr "x$OPT" : "x[^=]*=\\(.*\\)" || true)
38     case $OPT in
39     --help|-h|-?)
40         OPT_HELP=true
41         ;;
42     --emugen=*)
43         OPT_EMUGEN=$OPTARG
44         ;;
45     --out-dir=*)
46         OPT_OUT_DIR=$OPTARG
47         ;;
48     --tool=*)
49         OPT_TOOL=$OPTARG
50         ;;
51     -*)
52         fatal "Invalid option '$OPT', see --help."
53         ;;
54     *)
55         fatal "This script doesn't take arguments, see --help."
56         ;;
57     esac
58 done
59
60 if [ "$OPT_HELP" ]; then
61     cat <<EOF
62 Usage: $PROGNAME [options]
63
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.
67
68 Valid options:
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.
73 EOF
74     exit 0
75 fi
76
77 # Find emugen program
78 EMUGEN=
79 if [ "$OPT_EMUGEN" ]; then
80     EMUGEN=$OPT_EMUGEN
81 else
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."
85     fi
86     echo "Auto-config: --emugen=$EMUGEN"
87 fi
88 if [ ! -f "$EMUGEN" ]; then
89     fatal "Emugen program doesn't exist: $EMUGEN"
90 fi
91
92 # Create output directory.
93 OUT_DIR=
94 if [ "$OPT_OUT_DIR" ]; then
95     OUT_DIR=$OPT_OUT_DIR
96 else
97     OUT_DIR=/tmp/$USER-emugen-testing
98     echo "Auto-config: --out-dir=$OUT_DIR"
99 fi
100 mkdir -p "$OUT_DIR" && rm -rf "$OUT_DIR/emugen"
101
102 OUT_DIR=$OUT_DIR/emugen
103
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
116     done
117     if ! diff -qr "$PROGDIR/$TEST_DIR/expected" "$OUT"; then
118         if [ "$OPT_TOOL" ]; then
119             $OPT_TOOL "$PROGDIR/$TEST_DIR/expected" "$OUT"
120         else
121             echo "ERROR: Invalid differences between actual and expected output!"
122             diff -burN "$PROGDIR/$TEST_DIR/expected" "$OUT"
123             exit 1
124         fi
125     fi
126 done
127
128 echo "All good!"
129 exit 0