~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/net/forwarding/lib_sh_test.sh

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #!/bin/bash
  2 # SPDX-License-Identifier: GPL-2.0
  3 
  4 # This tests the operation of lib.sh itself.
  5 
  6 ALL_TESTS="
  7         test_ret
  8         test_exit_status
  9 "
 10 NUM_NETIFS=0
 11 source lib.sh
 12 
 13 # Simulated checks.
 14 
 15 do_test()
 16 {
 17         local msg=$1; shift
 18 
 19         "$@"
 20         check_err $? "$msg"
 21 }
 22 
 23 tpass()
 24 {
 25         do_test "tpass" true
 26 }
 27 
 28 tfail()
 29 {
 30         do_test "tfail" false
 31 }
 32 
 33 txfail()
 34 {
 35         FAIL_TO_XFAIL=yes do_test "txfail" false
 36 }
 37 
 38 # Simulated tests.
 39 
 40 pass()
 41 {
 42         RET=0
 43         do_test "true" true
 44         log_test "true"
 45 }
 46 
 47 fail()
 48 {
 49         RET=0
 50         do_test "false" false
 51         log_test "false"
 52 }
 53 
 54 xfail()
 55 {
 56         RET=0
 57         FAIL_TO_XFAIL=yes do_test "xfalse" false
 58         log_test "xfalse"
 59 }
 60 
 61 skip()
 62 {
 63         RET=0
 64         log_test_skip "skip"
 65 }
 66 
 67 slow_xfail()
 68 {
 69         RET=0
 70         xfail_on_slow do_test "slow_false" false
 71         log_test "slow_false"
 72 }
 73 
 74 # lib.sh tests.
 75 
 76 ret_tests_run()
 77 {
 78         local t
 79 
 80         RET=0
 81         retmsg=
 82         for t in "$@"; do
 83                 $t
 84         done
 85         echo "$retmsg"
 86         return $RET
 87 }
 88 
 89 ret_subtest()
 90 {
 91         local expect_ret=$1; shift
 92         local expect_retmsg=$1; shift
 93         local -a tests=( "$@" )
 94 
 95         local status_names=(pass fail xfail xpass skip)
 96         local ret
 97         local out
 98 
 99         RET=0
100 
101         # Run this in a subshell, so that our environment is intact.
102         out=$(ret_tests_run "${tests[@]}")
103         ret=$?
104 
105         (( ret == expect_ret ))
106         check_err $? "RET=$ret expected $expect_ret"
107 
108         [[ $out == $expect_retmsg ]]
109         check_err $? "retmsg=$out expected $expect_retmsg"
110 
111         log_test "RET $(echo ${tests[@]}) -> ${status_names[$ret]}"
112 }
113 
114 test_ret()
115 {
116         ret_subtest $ksft_pass ""
117 
118         ret_subtest $ksft_pass "" tpass
119         ret_subtest $ksft_fail "tfail" tfail
120         ret_subtest $ksft_xfail "txfail" txfail
121 
122         ret_subtest $ksft_pass "" tpass tpass
123         ret_subtest $ksft_fail "tfail" tpass tfail
124         ret_subtest $ksft_xfail "txfail" tpass txfail
125 
126         ret_subtest $ksft_fail "tfail" tfail tpass
127         ret_subtest $ksft_xfail "txfail" txfail tpass
128 
129         ret_subtest $ksft_fail "tfail" tfail tfail
130         ret_subtest $ksft_fail "tfail" tfail txfail
131 
132         ret_subtest $ksft_fail "tfail" txfail tfail
133 
134         ret_subtest $ksft_xfail "txfail" txfail txfail
135 }
136 
137 exit_status_tests_run()
138 {
139         EXIT_STATUS=0
140         tests_run > /dev/null
141         return $EXIT_STATUS
142 }
143 
144 exit_status_subtest()
145 {
146         local expect_exit_status=$1; shift
147         local tests=$1; shift
148         local what=$1; shift
149 
150         local status_names=(pass fail xfail xpass skip)
151         local exit_status
152         local out
153 
154         RET=0
155 
156         # Run this in a subshell, so that our environment is intact.
157         out=$(TESTS="$tests" exit_status_tests_run)
158         exit_status=$?
159 
160         (( exit_status == expect_exit_status ))
161         check_err $? "EXIT_STATUS=$exit_status, expected $expect_exit_status"
162 
163         log_test "EXIT_STATUS $tests$what -> ${status_names[$exit_status]}"
164 }
165 
166 test_exit_status()
167 {
168         exit_status_subtest $ksft_pass ":"
169 
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"
174 
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"
179 
180         exit_status_subtest $ksft_fail "fail pass"
181         exit_status_subtest $ksft_pass "xfail pass"
182         exit_status_subtest $ksft_skip "skip pass"
183 
184         exit_status_subtest $ksft_fail "fail fail"
185         exit_status_subtest $ksft_fail "fail xfail"
186         exit_status_subtest $ksft_fail "fail skip"
187 
188         exit_status_subtest $ksft_fail "xfail fail"
189         exit_status_subtest $ksft_fail "skip fail"
190 
191         exit_status_subtest $ksft_pass "xfail xfail"
192         exit_status_subtest $ksft_skip "xfail skip"
193         exit_status_subtest $ksft_skip "skip xfail"
194 
195         exit_status_subtest $ksft_skip "skip skip"
196 
197         KSFT_MACHINE_SLOW=yes \
198                 exit_status_subtest $ksft_pass "slow_xfail" ": slow"
199 
200         KSFT_MACHINE_SLOW=no \
201                 exit_status_subtest $ksft_fail "slow_xfail" ": fast"
202 }
203 
204 trap pre_cleanup EXIT
205 
206 tests_run
207 
208 exit $EXIT_STATUS

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php