Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / tools / testing / selftests / net / forwarding / lib_sh_test.sh
blobff2accccaf4d438e51c0ab77cdf12bda0636beeb
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
4 # This tests the operation of lib.sh itself.
6 ALL_TESTS="
7 test_ret
8 test_exit_status
10 NUM_NETIFS=0
11 source lib.sh
13 # Simulated checks.
15 do_test()
17 local msg=$1; shift
19 "$@"
20 check_err $? "$msg"
23 tpass()
25 do_test "tpass" true
28 tfail()
30 do_test "tfail" false
33 txfail()
35 FAIL_TO_XFAIL=yes do_test "txfail" false
38 # Simulated tests.
40 pass()
42 RET=0
43 do_test "true" true
44 log_test "true"
47 fail()
49 RET=0
50 do_test "false" false
51 log_test "false"
54 xfail()
56 RET=0
57 FAIL_TO_XFAIL=yes do_test "xfalse" false
58 log_test "xfalse"
61 skip()
63 RET=0
64 log_test_skip "skip"
67 slow_xfail()
69 RET=0
70 xfail_on_slow do_test "slow_false" false
71 log_test "slow_false"
74 # lib.sh tests.
76 ret_tests_run()
78 local t
80 RET=0
81 retmsg=
82 for t in "$@"; do
84 done
85 echo "$retmsg"
86 return $RET
89 ret_subtest()
91 local expect_ret=$1; shift
92 local expect_retmsg=$1; shift
93 local -a tests=( "$@" )
95 local status_names=(pass fail xfail xpass skip)
96 local ret
97 local out
99 RET=0
101 # Run this in a subshell, so that our environment is intact.
102 out=$(ret_tests_run "${tests[@]}")
103 ret=$?
105 (( ret == expect_ret ))
106 check_err $? "RET=$ret expected $expect_ret"
108 [[ $out == $expect_retmsg ]]
109 check_err $? "retmsg=$out expected $expect_retmsg"
111 log_test "RET $(echo ${tests[@]}) -> ${status_names[$ret]}"
114 test_ret()
116 ret_subtest $ksft_pass ""
118 ret_subtest $ksft_pass "" tpass
119 ret_subtest $ksft_fail "tfail" tfail
120 ret_subtest $ksft_xfail "txfail" txfail
122 ret_subtest $ksft_pass "" tpass tpass
123 ret_subtest $ksft_fail "tfail" tpass tfail
124 ret_subtest $ksft_xfail "txfail" tpass txfail
126 ret_subtest $ksft_fail "tfail" tfail tpass
127 ret_subtest $ksft_xfail "txfail" txfail tpass
129 ret_subtest $ksft_fail "tfail" tfail tfail
130 ret_subtest $ksft_fail "tfail" tfail txfail
132 ret_subtest $ksft_fail "tfail" txfail tfail
134 ret_subtest $ksft_xfail "txfail" txfail txfail
137 exit_status_tests_run()
139 EXIT_STATUS=0
140 tests_run > /dev/null
141 return $EXIT_STATUS
144 exit_status_subtest()
146 local expect_exit_status=$1; shift
147 local tests=$1; shift
148 local what=$1; shift
150 local status_names=(pass fail xfail xpass skip)
151 local exit_status
152 local out
154 RET=0
156 # Run this in a subshell, so that our environment is intact.
157 out=$(TESTS="$tests" exit_status_tests_run)
158 exit_status=$?
160 (( exit_status == expect_exit_status ))
161 check_err $? "EXIT_STATUS=$exit_status, expected $expect_exit_status"
163 log_test "EXIT_STATUS $tests$what -> ${status_names[$exit_status]}"
166 test_exit_status()
168 exit_status_subtest $ksft_pass ":"
170 exit_status_subtest $ksft_pass "pass"
171 exit_status_subtest $ksft_fail "fail"
172 exit_status_subtest $ksft_pass "xfail"
173 exit_status_subtest $ksft_skip "skip"
175 exit_status_subtest $ksft_pass "pass pass"
176 exit_status_subtest $ksft_fail "pass fail"
177 exit_status_subtest $ksft_pass "pass xfail"
178 exit_status_subtest $ksft_skip "pass skip"
180 exit_status_subtest $ksft_fail "fail pass"
181 exit_status_subtest $ksft_pass "xfail pass"
182 exit_status_subtest $ksft_skip "skip pass"
184 exit_status_subtest $ksft_fail "fail fail"
185 exit_status_subtest $ksft_fail "fail xfail"
186 exit_status_subtest $ksft_fail "fail skip"
188 exit_status_subtest $ksft_fail "xfail fail"
189 exit_status_subtest $ksft_fail "skip fail"
191 exit_status_subtest $ksft_pass "xfail xfail"
192 exit_status_subtest $ksft_skip "xfail skip"
193 exit_status_subtest $ksft_skip "skip xfail"
195 exit_status_subtest $ksft_skip "skip skip"
197 KSFT_MACHINE_SLOW=yes \
198 exit_status_subtest $ksft_pass "slow_xfail" ": slow"
200 KSFT_MACHINE_SLOW=no \
201 exit_status_subtest $ksft_fail "slow_xfail" ": fast"
204 trap pre_cleanup EXIT
206 tests_run
208 exit $EXIT_STATUS