summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCyril Bur <cyril.bur@au1.ibm.com>2015-10-14 10:06:30 +1100
committerStewart Smith <stewart@linux.vnet.ibm.com>2015-10-14 14:39:04 +1100
commit5dcab537f91cd8c66ae2244c6916d32cd92c8723 (patch)
tree0ddd4beeef78c68fd01b82227bc1f38be4bc5e14
parent3ed44fa2ccab0010252f2d212d2aab27c019ca33 (diff)
downloadtalos-skiboot-5dcab537f91cd8c66ae2244c6916d32cd92c8723.tar.gz
talos-skiboot-5dcab537f91cd8c66ae2244c6916d32cd92c8723.zip
external/test: Create an external test harness
Unlike skiboot where individual functions can be tested, the external/ binaries can sometimes only be fully tested by observing the output of the full binary as such this little framework designed to grab stdout and stderr and compare to provided output files should prove useful. Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
-rwxr-xr-xexternal/test/test.sh95
1 files changed, 95 insertions, 0 deletions
diff --git a/external/test/test.sh b/external/test/test.sh
new file mode 100755
index 00000000..50406330
--- /dev/null
+++ b/external/test/test.sh
@@ -0,0 +1,95 @@
+#! /bin/sh
+
+# Copyright 2013-2014 IBM Corp.
+#
+# 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.
+#
+
+run_binary() {
+ if [ -x "$1" ] ; then
+ $VALGRIND "$1" $2 2>> $STDERR_OUT 1>> $STDOUT_OUT
+ else
+ echo "Fatal error, cannot execute binary '$1'. Did you make?";
+ exit 1;
+ fi
+}
+
+fail_test() {
+ rm -rf "$STDERR_OUT";
+ rm -rf "$STDOUT_OUT";
+ echo "$0 ($CUR_TEST): test failed";
+ exit ${1:-1};
+}
+
+pass_test() {
+ /bin/true;
+}
+
+diff_with_result() {
+ # Explicitly diff a file with an arbitary result file
+ if [ "$#" -eq 1 ] ; then
+ if ! diff -u "$RESULT" "$1" ; then
+ fail_test;
+ fi
+ # Otherwise just diff result.out with stdout and result.err with stderr
+ else
+ if ! diff -u "${RESULT}.out" "$STDOUT_OUT" ; then
+ fail_test;
+ fi
+ if ! diff -u "${RESULT}.err" "$STDERR_OUT" ; then
+ fail_test;
+ fi
+ fi
+}
+
+run_tests() {
+ if [ $# -ne 2 ] ; then
+ echo "Usage run_tests test_dir result_dir";
+ exit 1;
+ fi
+
+ all_tests="$1";
+ res_path="$2";
+
+ if [ ! -d "$res_path" ] ; then
+ echo "Result path isn't a valid directory";
+ exit 1;
+ fi
+
+ export STDERR_OUT=$(mktemp --tmpdir external-test-stderr.XXXXXX);
+ export STDOUT_OUT=$(mktemp --tmpdir external-test-stdout.XXXXXX);
+
+
+ for the_test in $all_tests; do
+ export CUR_TEST=$(basename $the_test)
+ export RESULT="$res_path/$CUR_TEST"
+
+ . "$the_test";
+ R="$?"
+ if [ "$R" -ne 0 ] ; then
+ fail_test "$R";
+ fi
+ #reset for next test
+ > "$STDERR_OUT";
+ > "$STDOUT_OUT";
+ done
+
+ rm -rf $STDERR_OUT;
+ rm -rf $STDOUT_OUT;
+
+ echo "$0 tests passed"
+
+ exit 0;
+}
+
OpenPOWER on IntegriCloud