sysctl.sh 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780
  1. #!/bin/bash
  2. # Copyright (C) 2017 Luis R. Rodriguez <mcgrof@kernel.org>
  3. #
  4. # This program is free software; you can redistribute it and/or modify it
  5. # under the terms of the GNU General Public License as published by the Free
  6. # Software Foundation; either version 2 of the License, or at your option any
  7. # later version; or, when distributed separately from the Linux kernel or
  8. # when incorporated into other software packages, subject to the following
  9. # license:
  10. #
  11. # This program is free software; you can redistribute it and/or modify it
  12. # under the terms of copyleft-next (version 0.3.1 or later) as published
  13. # at http://copyleft-next.org/.
  14. # This performs a series tests against the proc sysctl interface.
  15. # Kselftest framework requirement - SKIP code is 4.
  16. ksft_skip=4
  17. TEST_NAME="sysctl"
  18. TEST_DRIVER="test_${TEST_NAME}"
  19. TEST_DIR=$(dirname $0)
  20. TEST_FILE=$(mktemp)
  21. # This represents
  22. #
  23. # TEST_ID:TEST_COUNT:ENABLED
  24. #
  25. # TEST_ID: is the test id number
  26. # TEST_COUNT: number of times we should run the test
  27. # ENABLED: 1 if enabled, 0 otherwise
  28. #
  29. # Once these are enabled please leave them as-is. Write your own test,
  30. # we have tons of space.
  31. ALL_TESTS="0001:1:1"
  32. ALL_TESTS="$ALL_TESTS 0002:1:1"
  33. ALL_TESTS="$ALL_TESTS 0003:1:1"
  34. ALL_TESTS="$ALL_TESTS 0004:1:1"
  35. ALL_TESTS="$ALL_TESTS 0005:3:1"
  36. test_modprobe()
  37. {
  38. if [ ! -d $DIR ]; then
  39. echo "$0: $DIR not present" >&2
  40. echo "You must have the following enabled in your kernel:" >&2
  41. cat $TEST_DIR/config >&2
  42. exit $ksft_skip
  43. fi
  44. }
  45. function allow_user_defaults()
  46. {
  47. if [ -z $DIR ]; then
  48. DIR="/sys/module/test_sysctl/"
  49. fi
  50. if [ -z $DEFAULT_NUM_TESTS ]; then
  51. DEFAULT_NUM_TESTS=50
  52. fi
  53. if [ -z $SYSCTL ]; then
  54. SYSCTL="/proc/sys/debug/test_sysctl"
  55. fi
  56. if [ -z $PROD_SYSCTL ]; then
  57. PROD_SYSCTL="/proc/sys"
  58. fi
  59. if [ -z $WRITES_STRICT ]; then
  60. WRITES_STRICT="${PROD_SYSCTL}/kernel/sysctl_writes_strict"
  61. fi
  62. }
  63. function check_production_sysctl_writes_strict()
  64. {
  65. echo -n "Checking production write strict setting ... "
  66. if [ ! -e ${WRITES_STRICT} ]; then
  67. echo "FAIL, but skip in case of old kernel" >&2
  68. else
  69. old_strict=$(cat ${WRITES_STRICT})
  70. if [ "$old_strict" = "1" ]; then
  71. echo "ok"
  72. else
  73. echo "FAIL, strict value is 0 but force to 1 to continue" >&2
  74. echo "1" > ${WRITES_STRICT}
  75. fi
  76. fi
  77. if [ -z $PAGE_SIZE ]; then
  78. PAGE_SIZE=$(getconf PAGESIZE)
  79. fi
  80. if [ -z $MAX_DIGITS ]; then
  81. MAX_DIGITS=$(($PAGE_SIZE/8))
  82. fi
  83. if [ -z $INT_MAX ]; then
  84. INT_MAX=$(getconf INT_MAX)
  85. fi
  86. if [ -z $UINT_MAX ]; then
  87. UINT_MAX=$(getconf UINT_MAX)
  88. fi
  89. }
  90. test_reqs()
  91. {
  92. uid=$(id -u)
  93. if [ $uid -ne 0 ]; then
  94. echo $msg must be run as root >&2
  95. exit $ksft_skip
  96. fi
  97. if ! which perl 2> /dev/null > /dev/null; then
  98. echo "$0: You need perl installed"
  99. exit $ksft_skip
  100. fi
  101. if ! which getconf 2> /dev/null > /dev/null; then
  102. echo "$0: You need getconf installed"
  103. exit $ksft_skip
  104. fi
  105. if ! which diff 2> /dev/null > /dev/null; then
  106. echo "$0: You need diff installed"
  107. exit $ksft_skip
  108. fi
  109. }
  110. function load_req_mod()
  111. {
  112. if [ ! -d $DIR ]; then
  113. if ! modprobe -q -n $TEST_DRIVER; then
  114. echo "$0: module $TEST_DRIVER not found [SKIP]"
  115. exit $ksft_skip
  116. fi
  117. modprobe $TEST_DRIVER
  118. if [ $? -ne 0 ]; then
  119. exit
  120. fi
  121. fi
  122. }
  123. reset_vals()
  124. {
  125. VAL=""
  126. TRIGGER=$(basename ${TARGET})
  127. case "$TRIGGER" in
  128. int_0001)
  129. VAL="60"
  130. ;;
  131. int_0002)
  132. VAL="1"
  133. ;;
  134. uint_0001)
  135. VAL="314"
  136. ;;
  137. string_0001)
  138. VAL="(none)"
  139. ;;
  140. *)
  141. ;;
  142. esac
  143. echo -n $VAL > $TARGET
  144. }
  145. set_orig()
  146. {
  147. if [ ! -z $TARGET ]; then
  148. echo "${ORIG}" > "${TARGET}"
  149. fi
  150. }
  151. set_test()
  152. {
  153. echo "${TEST_STR}" > "${TARGET}"
  154. }
  155. verify()
  156. {
  157. local seen
  158. seen=$(cat "$1")
  159. if [ "${seen}" != "${TEST_STR}" ]; then
  160. return 1
  161. fi
  162. return 0
  163. }
  164. verify_diff_w()
  165. {
  166. echo "$TEST_STR" | diff -q -w -u - $1
  167. return $?
  168. }
  169. test_rc()
  170. {
  171. if [[ $rc != 0 ]]; then
  172. echo "Failed test, return value: $rc" >&2
  173. exit $rc
  174. fi
  175. }
  176. test_finish()
  177. {
  178. set_orig
  179. rm -f "${TEST_FILE}"
  180. if [ ! -z ${old_strict} ]; then
  181. echo ${old_strict} > ${WRITES_STRICT}
  182. fi
  183. exit $rc
  184. }
  185. run_numerictests()
  186. {
  187. echo "== Testing sysctl behavior against ${TARGET} =="
  188. rc=0
  189. echo -n "Writing test file ... "
  190. echo "${TEST_STR}" > "${TEST_FILE}"
  191. if ! verify "${TEST_FILE}"; then
  192. echo "FAIL" >&2
  193. exit 1
  194. else
  195. echo "ok"
  196. fi
  197. echo -n "Checking sysctl is not set to test value ... "
  198. if verify "${TARGET}"; then
  199. echo "FAIL" >&2
  200. exit 1
  201. else
  202. echo "ok"
  203. fi
  204. echo -n "Writing sysctl from shell ... "
  205. set_test
  206. if ! verify "${TARGET}"; then
  207. echo "FAIL" >&2
  208. exit 1
  209. else
  210. echo "ok"
  211. fi
  212. echo -n "Resetting sysctl to original value ... "
  213. set_orig
  214. if verify "${TARGET}"; then
  215. echo "FAIL" >&2
  216. exit 1
  217. else
  218. echo "ok"
  219. fi
  220. # Now that we've validated the sanity of "set_test" and "set_orig",
  221. # we can use those functions to set starting states before running
  222. # specific behavioral tests.
  223. echo -n "Writing entire sysctl in single write ... "
  224. set_orig
  225. dd if="${TEST_FILE}" of="${TARGET}" bs=4096 2>/dev/null
  226. if ! verify "${TARGET}"; then
  227. echo "FAIL" >&2
  228. rc=1
  229. else
  230. echo "ok"
  231. fi
  232. echo -n "Writing middle of sysctl after synchronized seek ... "
  233. set_test
  234. dd if="${TEST_FILE}" of="${TARGET}" bs=1 seek=1 skip=1 2>/dev/null
  235. if ! verify "${TARGET}"; then
  236. echo "FAIL" >&2
  237. rc=1
  238. else
  239. echo "ok"
  240. fi
  241. echo -n "Writing beyond end of sysctl ... "
  242. set_orig
  243. dd if="${TEST_FILE}" of="${TARGET}" bs=20 seek=2 2>/dev/null
  244. if verify "${TARGET}"; then
  245. echo "FAIL" >&2
  246. rc=1
  247. else
  248. echo "ok"
  249. fi
  250. echo -n "Writing sysctl with multiple long writes ... "
  251. set_orig
  252. (perl -e 'print "A" x 50;'; echo "${TEST_STR}") | \
  253. dd of="${TARGET}" bs=50 2>/dev/null
  254. if verify "${TARGET}"; then
  255. echo "FAIL" >&2
  256. rc=1
  257. else
  258. echo "ok"
  259. fi
  260. test_rc
  261. }
  262. # Your test must accept digits 3 and 4 to use this
  263. run_limit_digit()
  264. {
  265. echo -n "Checking ignoring spaces up to PAGE_SIZE works on write ..."
  266. reset_vals
  267. LIMIT=$((MAX_DIGITS -1))
  268. TEST_STR="3"
  269. (perl -e 'print " " x '$LIMIT';'; echo "${TEST_STR}") | \
  270. dd of="${TARGET}" 2>/dev/null
  271. if ! verify "${TARGET}"; then
  272. echo "FAIL" >&2
  273. rc=1
  274. else
  275. echo "ok"
  276. fi
  277. test_rc
  278. echo -n "Checking passing PAGE_SIZE of spaces fails on write ..."
  279. reset_vals
  280. LIMIT=$((MAX_DIGITS))
  281. TEST_STR="4"
  282. (perl -e 'print " " x '$LIMIT';'; echo "${TEST_STR}") | \
  283. dd of="${TARGET}" 2>/dev/null
  284. if verify "${TARGET}"; then
  285. echo "FAIL" >&2
  286. rc=1
  287. else
  288. echo "ok"
  289. fi
  290. test_rc
  291. }
  292. # You are using an int
  293. run_limit_digit_int()
  294. {
  295. echo -n "Testing INT_MAX works ..."
  296. reset_vals
  297. TEST_STR="$INT_MAX"
  298. echo -n $TEST_STR > $TARGET
  299. if ! verify "${TARGET}"; then
  300. echo "FAIL" >&2
  301. rc=1
  302. else
  303. echo "ok"
  304. fi
  305. test_rc
  306. echo -n "Testing INT_MAX + 1 will fail as expected..."
  307. reset_vals
  308. let TEST_STR=$INT_MAX+1
  309. echo -n $TEST_STR > $TARGET 2> /dev/null
  310. if verify "${TARGET}"; then
  311. echo "FAIL" >&2
  312. rc=1
  313. else
  314. echo "ok"
  315. fi
  316. test_rc
  317. echo -n "Testing negative values will work as expected..."
  318. reset_vals
  319. TEST_STR="-3"
  320. echo -n $TEST_STR > $TARGET 2> /dev/null
  321. if ! verify "${TARGET}"; then
  322. echo "FAIL" >&2
  323. rc=1
  324. else
  325. echo "ok"
  326. fi
  327. test_rc
  328. }
  329. # You used an int array
  330. run_limit_digit_int_array()
  331. {
  332. echo -n "Testing array works as expected ... "
  333. TEST_STR="4 3 2 1"
  334. echo -n $TEST_STR > $TARGET
  335. if ! verify_diff_w "${TARGET}"; then
  336. echo "FAIL" >&2
  337. rc=1
  338. else
  339. echo "ok"
  340. fi
  341. test_rc
  342. echo -n "Testing skipping trailing array elements works ... "
  343. # Do not reset_vals, carry on the values from the last test.
  344. # If we only echo in two digits the last two are left intact
  345. TEST_STR="100 101"
  346. echo -n $TEST_STR > $TARGET
  347. # After we echo in, to help diff we need to set on TEST_STR what
  348. # we expect the result to be.
  349. TEST_STR="100 101 2 1"
  350. if ! verify_diff_w "${TARGET}"; then
  351. echo "FAIL" >&2
  352. rc=1
  353. else
  354. echo "ok"
  355. fi
  356. test_rc
  357. echo -n "Testing PAGE_SIZE limit on array works ... "
  358. # Do not reset_vals, carry on the values from the last test.
  359. # Even if you use an int array, you are still restricted to
  360. # MAX_DIGITS, this is a known limitation. Test limit works.
  361. LIMIT=$((MAX_DIGITS -1))
  362. TEST_STR="9"
  363. (perl -e 'print " " x '$LIMIT';'; echo "${TEST_STR}") | \
  364. dd of="${TARGET}" 2>/dev/null
  365. TEST_STR="9 101 2 1"
  366. if ! verify_diff_w "${TARGET}"; then
  367. echo "FAIL" >&2
  368. rc=1
  369. else
  370. echo "ok"
  371. fi
  372. test_rc
  373. echo -n "Testing exceeding PAGE_SIZE limit fails as expected ... "
  374. # Do not reset_vals, carry on the values from the last test.
  375. # Now go over limit.
  376. LIMIT=$((MAX_DIGITS))
  377. TEST_STR="7"
  378. (perl -e 'print " " x '$LIMIT';'; echo "${TEST_STR}") | \
  379. dd of="${TARGET}" 2>/dev/null
  380. TEST_STR="7 101 2 1"
  381. if verify_diff_w "${TARGET}"; then
  382. echo "FAIL" >&2
  383. rc=1
  384. else
  385. echo "ok"
  386. fi
  387. test_rc
  388. }
  389. # You are using an unsigned int
  390. run_limit_digit_uint()
  391. {
  392. echo -n "Testing UINT_MAX works ..."
  393. reset_vals
  394. TEST_STR="$UINT_MAX"
  395. echo -n $TEST_STR > $TARGET
  396. if ! verify "${TARGET}"; then
  397. echo "FAIL" >&2
  398. rc=1
  399. else
  400. echo "ok"
  401. fi
  402. test_rc
  403. echo -n "Testing UINT_MAX + 1 will fail as expected..."
  404. reset_vals
  405. TEST_STR=$(($UINT_MAX+1))
  406. echo -n $TEST_STR > $TARGET 2> /dev/null
  407. if verify "${TARGET}"; then
  408. echo "FAIL" >&2
  409. rc=1
  410. else
  411. echo "ok"
  412. fi
  413. test_rc
  414. echo -n "Testing negative values will not work as expected ..."
  415. reset_vals
  416. TEST_STR="-3"
  417. echo -n $TEST_STR > $TARGET 2> /dev/null
  418. if verify "${TARGET}"; then
  419. echo "FAIL" >&2
  420. rc=1
  421. else
  422. echo "ok"
  423. fi
  424. test_rc
  425. }
  426. run_stringtests()
  427. {
  428. echo -n "Writing entire sysctl in short writes ... "
  429. set_orig
  430. dd if="${TEST_FILE}" of="${TARGET}" bs=1 2>/dev/null
  431. if ! verify "${TARGET}"; then
  432. echo "FAIL" >&2
  433. rc=1
  434. else
  435. echo "ok"
  436. fi
  437. echo -n "Writing middle of sysctl after unsynchronized seek ... "
  438. set_test
  439. dd if="${TEST_FILE}" of="${TARGET}" bs=1 seek=1 2>/dev/null
  440. if verify "${TARGET}"; then
  441. echo "FAIL" >&2
  442. rc=1
  443. else
  444. echo "ok"
  445. fi
  446. echo -n "Checking sysctl maxlen is at least $MAXLEN ... "
  447. set_orig
  448. perl -e 'print "A" x ('"${MAXLEN}"'-2), "B";' | \
  449. dd of="${TARGET}" bs="${MAXLEN}" 2>/dev/null
  450. if ! grep -q B "${TARGET}"; then
  451. echo "FAIL" >&2
  452. rc=1
  453. else
  454. echo "ok"
  455. fi
  456. echo -n "Checking sysctl keeps original string on overflow append ... "
  457. set_orig
  458. perl -e 'print "A" x ('"${MAXLEN}"'-1), "B";' | \
  459. dd of="${TARGET}" bs=$(( MAXLEN - 1 )) 2>/dev/null
  460. if grep -q B "${TARGET}"; then
  461. echo "FAIL" >&2
  462. rc=1
  463. else
  464. echo "ok"
  465. fi
  466. echo -n "Checking sysctl stays NULL terminated on write ... "
  467. set_orig
  468. perl -e 'print "A" x ('"${MAXLEN}"'-1), "B";' | \
  469. dd of="${TARGET}" bs="${MAXLEN}" 2>/dev/null
  470. if grep -q B "${TARGET}"; then
  471. echo "FAIL" >&2
  472. rc=1
  473. else
  474. echo "ok"
  475. fi
  476. echo -n "Checking sysctl stays NULL terminated on overwrite ... "
  477. set_orig
  478. perl -e 'print "A" x ('"${MAXLEN}"'-1), "BB";' | \
  479. dd of="${TARGET}" bs=$(( $MAXLEN + 1 )) 2>/dev/null
  480. if grep -q B "${TARGET}"; then
  481. echo "FAIL" >&2
  482. rc=1
  483. else
  484. echo "ok"
  485. fi
  486. test_rc
  487. }
  488. sysctl_test_0001()
  489. {
  490. TARGET="${SYSCTL}/int_0001"
  491. reset_vals
  492. ORIG=$(cat "${TARGET}")
  493. TEST_STR=$(( $ORIG + 1 ))
  494. run_numerictests
  495. run_limit_digit
  496. }
  497. sysctl_test_0002()
  498. {
  499. TARGET="${SYSCTL}/string_0001"
  500. reset_vals
  501. ORIG=$(cat "${TARGET}")
  502. TEST_STR="Testing sysctl"
  503. # Only string sysctls support seeking/appending.
  504. MAXLEN=65
  505. run_numerictests
  506. run_stringtests
  507. }
  508. sysctl_test_0003()
  509. {
  510. TARGET="${SYSCTL}/int_0002"
  511. reset_vals
  512. ORIG=$(cat "${TARGET}")
  513. TEST_STR=$(( $ORIG + 1 ))
  514. run_numerictests
  515. run_limit_digit
  516. run_limit_digit_int
  517. }
  518. sysctl_test_0004()
  519. {
  520. TARGET="${SYSCTL}/uint_0001"
  521. reset_vals
  522. ORIG=$(cat "${TARGET}")
  523. TEST_STR=$(( $ORIG + 1 ))
  524. run_numerictests
  525. run_limit_digit
  526. run_limit_digit_uint
  527. }
  528. sysctl_test_0005()
  529. {
  530. TARGET="${SYSCTL}/int_0003"
  531. reset_vals
  532. ORIG=$(cat "${TARGET}")
  533. run_limit_digit_int_array
  534. }
  535. list_tests()
  536. {
  537. echo "Test ID list:"
  538. echo
  539. echo "TEST_ID x NUM_TEST"
  540. echo "TEST_ID: Test ID"
  541. echo "NUM_TESTS: Number of recommended times to run the test"
  542. echo
  543. echo "0001 x $(get_test_count 0001) - tests proc_dointvec_minmax()"
  544. echo "0002 x $(get_test_count 0002) - tests proc_dostring()"
  545. echo "0003 x $(get_test_count 0003) - tests proc_dointvec()"
  546. echo "0004 x $(get_test_count 0004) - tests proc_douintvec()"
  547. echo "0005 x $(get_test_count 0005) - tests proc_douintvec() array"
  548. }
  549. test_reqs
  550. usage()
  551. {
  552. NUM_TESTS=$(grep -o ' ' <<<"$ALL_TESTS" | grep -c .)
  553. let NUM_TESTS=$NUM_TESTS+1
  554. MAX_TEST=$(printf "%04d\n" $NUM_TESTS)
  555. echo "Usage: $0 [ -t <4-number-digit> ] | [ -w <4-number-digit> ] |"
  556. echo " [ -s <4-number-digit> ] | [ -c <4-number-digit> <test- count>"
  557. echo " [ all ] [ -h | --help ] [ -l ]"
  558. echo ""
  559. echo "Valid tests: 0001-$MAX_TEST"
  560. echo ""
  561. echo " all Runs all tests (default)"
  562. echo " -t Run test ID the number amount of times is recommended"
  563. echo " -w Watch test ID run until it runs into an error"
  564. echo " -c Run test ID once"
  565. echo " -s Run test ID x test-count number of times"
  566. echo " -l List all test ID list"
  567. echo " -h|--help Help"
  568. echo
  569. echo "If an error every occurs execution will immediately terminate."
  570. echo "If you are adding a new test try using -w <test-ID> first to"
  571. echo "make sure the test passes a series of tests."
  572. echo
  573. echo Example uses:
  574. echo
  575. echo "$TEST_NAME.sh -- executes all tests"
  576. echo "$TEST_NAME.sh -t 0002 -- Executes test ID 0002 number of times is recomended"
  577. echo "$TEST_NAME.sh -w 0002 -- Watch test ID 0002 run until an error occurs"
  578. echo "$TEST_NAME.sh -s 0002 -- Run test ID 0002 once"
  579. echo "$TEST_NAME.sh -c 0002 3 -- Run test ID 0002 three times"
  580. echo
  581. list_tests
  582. exit 1
  583. }
  584. function test_num()
  585. {
  586. re='^[0-9]+$'
  587. if ! [[ $1 =~ $re ]]; then
  588. usage
  589. fi
  590. }
  591. function get_test_count()
  592. {
  593. test_num $1
  594. TEST_DATA=$(echo $ALL_TESTS | awk '{print $'$1'}')
  595. LAST_TWO=${TEST_DATA#*:*}
  596. echo ${LAST_TWO%:*}
  597. }
  598. function get_test_enabled()
  599. {
  600. test_num $1
  601. TEST_DATA=$(echo $ALL_TESTS | awk '{print $'$1'}')
  602. echo ${TEST_DATA#*:*:}
  603. }
  604. function run_all_tests()
  605. {
  606. for i in $ALL_TESTS ; do
  607. TEST_ID=${i%:*:*}
  608. ENABLED=$(get_test_enabled $TEST_ID)
  609. TEST_COUNT=$(get_test_count $TEST_ID)
  610. if [[ $ENABLED -eq "1" ]]; then
  611. test_case $TEST_ID $TEST_COUNT
  612. fi
  613. done
  614. }
  615. function watch_log()
  616. {
  617. if [ $# -ne 3 ]; then
  618. clear
  619. fi
  620. date
  621. echo "Running test: $2 - run #$1"
  622. }
  623. function watch_case()
  624. {
  625. i=0
  626. while [ 1 ]; do
  627. if [ $# -eq 1 ]; then
  628. test_num $1
  629. watch_log $i ${TEST_NAME}_test_$1
  630. ${TEST_NAME}_test_$1
  631. else
  632. watch_log $i all
  633. run_all_tests
  634. fi
  635. let i=$i+1
  636. done
  637. }
  638. function test_case()
  639. {
  640. NUM_TESTS=$DEFAULT_NUM_TESTS
  641. if [ $# -eq 2 ]; then
  642. NUM_TESTS=$2
  643. fi
  644. i=0
  645. while [ $i -lt $NUM_TESTS ]; do
  646. test_num $1
  647. watch_log $i ${TEST_NAME}_test_$1 noclear
  648. RUN_TEST=${TEST_NAME}_test_$1
  649. $RUN_TEST
  650. let i=$i+1
  651. done
  652. }
  653. function parse_args()
  654. {
  655. if [ $# -eq 0 ]; then
  656. run_all_tests
  657. else
  658. if [[ "$1" = "all" ]]; then
  659. run_all_tests
  660. elif [[ "$1" = "-w" ]]; then
  661. shift
  662. watch_case $@
  663. elif [[ "$1" = "-t" ]]; then
  664. shift
  665. test_num $1
  666. test_case $1 $(get_test_count $1)
  667. elif [[ "$1" = "-c" ]]; then
  668. shift
  669. test_num $1
  670. test_num $2
  671. test_case $1 $2
  672. elif [[ "$1" = "-s" ]]; then
  673. shift
  674. test_case $1 1
  675. elif [[ "$1" = "-l" ]]; then
  676. list_tests
  677. elif [[ "$1" = "-h" || "$1" = "--help" ]]; then
  678. usage
  679. else
  680. usage
  681. fi
  682. fi
  683. }
  684. test_reqs
  685. allow_user_defaults
  686. check_production_sysctl_writes_strict
  687. test_modprobe
  688. load_req_mod
  689. trap "test_finish" EXIT
  690. parse_args $@
  691. exit 0