~pmdj/ubuntu/trusty/qemu/2.9+applesmc+fadtv3

« back to all changes in this revision

Viewing changes to roms/skiboot/external/test/test.sh

  • Committer: Phil Dennis-Jordan
  • Date: 2017-07-21 08:03:43 UTC
  • mfrom: (1.1.1)
  • Revision ID: phil@philjordan.eu-20170721080343-2yr2vdj7713czahv
New upstream release 2.9.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/sh
 
2
 
 
3
# Copyright 2013-2014 IBM Corp.
 
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
 
14
# implied.
 
15
# See the License for the specific language governing permissions and
 
16
# limitations under the License.
 
17
#
 
18
 
 
19
run_binary() {
 
20
        if [ -x "$1" ] ; then
 
21
                $VALGRIND "$1" $2 2>> $STDERR_OUT 1>> $STDOUT_OUT
 
22
        else
 
23
                echo "Fatal error, cannot execute binary '$1'. Did you make?";
 
24
                exit 1;
 
25
        fi
 
26
}
 
27
 
 
28
fail_test() {
 
29
        rm -rf "$STDERR_OUT";
 
30
        rm -rf "$STDOUT_OUT";
 
31
        echo "$0 ($CUR_TEST): test failed";
 
32
        exit ${1:-1};
 
33
}
 
34
 
 
35
pass_test() {
 
36
        /bin/true;
 
37
}
 
38
 
 
39
strip_version_from_result() {
 
40
        VERSION=$(./make_version.sh $1)
 
41
        sed -i "s/${VERSION}/VERSION/" $STDERR_OUT
 
42
        sed -i "s/${VERSION}/VERSION/" $STDOUT_OUT
 
43
}
 
44
 
 
45
diff_with_result() {
 
46
        # Explicitly diff a file with an arbitrary result file
 
47
        if [ "$#" -eq 1 ] ; then
 
48
                if ! diff -u "$RESULT" "$1" ; then
 
49
                        fail_test;
 
50
                fi
 
51
        # Otherwise just diff result.out with stdout and result.err with stderr
 
52
        else
 
53
                if ! diff -u "${RESULT}.out" "$STDOUT_OUT" ; then
 
54
                        fail_test;
 
55
                fi
 
56
                if ! diff -u "${RESULT}.err" "$STDERR_OUT" ; then
 
57
                        fail_test;
 
58
                fi
 
59
        fi
 
60
}
 
61
 
 
62
run_tests() {
 
63
        if [ $# -ne 2 ] ; then
 
64
                echo "Usage run_tests test_dir result_dir";
 
65
                exit 1;
 
66
        fi
 
67
 
 
68
        all_tests="$1";
 
69
        res_path="$2";
 
70
 
 
71
        if [ ! -d "$res_path" ] ; then
 
72
                echo "Result path isn't a valid directory";
 
73
                exit 1;
 
74
        fi
 
75
 
 
76
        export STDERR_OUT=$(mktemp --tmpdir external-test-stderr.XXXXXX);
 
77
        export STDOUT_OUT=$(mktemp --tmpdir external-test-stdout.XXXXXX);
 
78
 
 
79
 
 
80
        for the_test in $all_tests; do
 
81
                export CUR_TEST=$(basename $the_test)
 
82
                export RESULT="$res_path/$CUR_TEST"
 
83
 
 
84
                . "$the_test";
 
85
                R="$?"
 
86
                if [ "$R" -ne 0 ] ; then
 
87
                        fail_test "$R";
 
88
                fi
 
89
        #reset for next test
 
90
        > "$STDERR_OUT";
 
91
        > "$STDOUT_OUT";
 
92
        done
 
93
 
 
94
        rm -rf $STDERR_OUT;
 
95
        rm -rf $STDOUT_OUT;
 
96
 
 
97
        echo "$0 tests passed"
 
98
 
 
99
        exit 0;
 
100
}
 
101