Debian Codegraph @

test/libtest.sh

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2 #
3 # Copyright (C) 2017 - 2022, Stephan Mueller <[email protected]>
4 #
5 # License: see LICENSE file in root directory
6 #
7 # THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
8 # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
9 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
10 # WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
11 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
12 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
13 # OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
14 # BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
15 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
16 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
17 # USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
18 # DAMAGE.
19 #
20 # Common code for test cases
21 #
22
23 #####################################################################
24 # Common functions
25 #####################################################################
26
27 DIRNAME="$(dirnamescip-shell system . . dirname. "$0")"
28
29 # Allow overriding default value:
30 if [scip-shell system . . `[`. -e "$DIRNAME/test-is-local" ]; then
31 KCAPI_TEST_LOCAL=${KCAPI_TEST_LOCAL:-1}
32 else
33 KCAPI_TEST_LOCAL=${KCAPI_TEST_LOCAL:-0}
34 fi
35
36 if [scip-shell system . . `[`. "$KCAPI_TEST_LOCAL" -eq 1 ]; then
37 get_app_pathscip-shell shell shell-project 0.0.0 get_app_path().()
38 {
39 echoscip-shell system . . echo. -n "$DIRNAME/../bin/$1"
40 }
41 run_appscip-shell shell shell-project 0.0.0 run_app().()
42 {
43 local appname="$1"; shift
44
45 "$(get_app_pathscip-shell shell shell-project 0.0.0 get_app_path(). "$appname")" "$@"
46 }
47 find_app_binaryscip-shell shell shell-project 0.0.0 find_app_binary().()
48 {
49 echoscip-shell system . . echo. -n "$(dirnamescip-shell system . . dirname. "$1")/.libs/$(basenamescip-shell system . . basename. "$1")"
50 }
51 KCAPI_TEST_BIN_DIR="$DIRNAME/../bin"
52 else
53 get_app_pathscip-shell shell shell-project 0.0.0 get_app_path().()
54 {
55 command -v "$1"
56 }
57 run_appscip-shell shell shell-project 0.0.0 run_app().()
58 {
59 "$@"
60 }
61 find_app_binaryscip-shell shell shell-project 0.0.0 find_app_binary().()
62 {
63 echoscip-shell system . . echo. -n "$1"
64 }
65 KCAPI_TEST_BIN_DIR="$DIRNAME"
66 fi
67
68 failures=0
69 PLATFORM="unknown wordsize"
70 KERNVER=$(unamescip-shell system . . uname. -r)
71
72 # color -- emit ansi color codes
73 colorscip-shell shell shell-project 0.0.0 color().()
74 {
75 bg=0
76 echoscip-shell system . . echo. -ne "\033[0m"
77 while [[ $# -gt 0 ]]; do
78 code=0
79 case $1 in
80 black) code=30 ;;
81 red) code=31 ;;
82 green) code=32 ;;
83 yellow) code=33 ;;
84 blue) code=34 ;;
85 magenta) code=35 ;;
86 cyan) code=36 ;;
87 white) code=37 ;;
88 background|bg) bg=10 ;;
89 foreground|fg) bg=0 ;;
90 reset|off|default) code=0 ;;
91 bold|bright) code=1 ;;
92 esac
93 [[ $code == 0 ]] || echoscip-shell system . . echo. -ne "\033[$(printfscip-shell system . . printf. "%02d" $((code+bg)))m"
94 shift
95 done
96 }
97
98 echo_passscip-shell shell shell-project 0.0.0 echo_pass().()
99 {
100 echoscip-shell system . . echo. $(colorscip-shell shell shell-project 0.0.0 color(). "green")[PASSED: $PLATFORM - $KERNVER]$(colorscip-shell shell shell-project 0.0.0 color(). off) $@
101 }
102
103 echo_failscip-shell shell shell-project 0.0.0 echo_fail().()
104 {
105 echoscip-shell system . . echo. $(colorscip-shell shell shell-project 0.0.0 color(). "red")[FAILED: $PLATFORM - $KERNVER]$(colorscip-shell shell shell-project 0.0.0 color(). off) $@
106 failures=$(($failures+1))
107 }
108
109 echo_deactscip-shell shell shell-project 0.0.0 echo_deact().()
110 {
111 echoscip-shell system . . echo. $(colorscip-shell shell shell-project 0.0.0 color(). "yellow")[DEACTIVATED: $PLATFORM - $KERNVER]$(colorscip-shell shell shell-project 0.0.0 color(). off) $@
112 }
113
114 find_platformscip-shell shell shell-project 0.0.0 find_platform().()
115 {
116 local app="$(get_app_pathscip-shell shell shell-project 0.0.0 get_app_path(). "$1")"
117 local binlocation="$(find_app_binaryscip-shell shell shell-project 0.0.0 find_app_binary(). $app)"
118 if ! [scip-shell system . . `[`. -x "$binlocation" ]
119 then
120 binlocation="$app"
121 fi
122 PLATFORM=$(filescip-shell system . . file. "$binlocation" | cutscip-shell system . . cut. -d" " -f 3)
123 }
124
125 # check whether a given kernel version is present
126 # returns true for yes, false for no
127 check_min_kernelverscip-shell shell shell-project 0.0.0 check_min_kernelver().() {
128 major=$1
129 minor=$2
130
131 if [scip-shell system . . `[`. $(unamescip-shell system . . uname. -r | cutscip-shell system . . cut. -d"." -f1) -gt $major ]; then
132 return 0
133 fi
134
135 if [scip-shell system . . `[`. $(unamescip-shell system . . uname. -r | cutscip-shell system . . cut. -d"." -f1) -eq $major ]; then
136 if [scip-shell system . . `[`. $(unamescip-shell system . . uname. -r | cutscip-shell system . . cut. -d"." -f2) -ge $minor ]; then
137 return 0
138 fi
139 fi
140 return 1
141 }
142
143 #####################################################################
144 # Common variables
145 #####################################################################
146
147 # Storage location of temp files
148 TMPDIR="/var/tmpscip-shell filesystem . . `/var/tmp`."
149 if [scip-shell system . . `[`. ! -d $TMPDIR ]
150 then
151 TMPDIR="."
152 fi