sysctl.sh 15 KB

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