forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/tools/testing/selftests/kmod/kmod.sh
....@@ -28,7 +28,7 @@
2828 # override by exporting to your environment prior running this script.
2929 # For instance this script assumes you do not have xfs loaded upon boot.
3030 # If this is false, export DEFAULT_KMOD_FS="ext4" prior to running this
31
-# script if the filesyste module you don't have loaded upon bootup
31
+# script if the filesystem module you don't have loaded upon bootup
3232 # is ext4 instead. Refer to allow_user_defaults() for a list of user
3333 # override variables possible.
3434 #
....@@ -61,6 +61,10 @@
6161 ALL_TESTS="$ALL_TESTS 0007:5:1"
6262 ALL_TESTS="$ALL_TESTS 0008:150:1"
6363 ALL_TESTS="$ALL_TESTS 0009:150:1"
64
+ALL_TESTS="$ALL_TESTS 0010:1:1"
65
+ALL_TESTS="$ALL_TESTS 0011:1:1"
66
+ALL_TESTS="$ALL_TESTS 0012:1:1"
67
+ALL_TESTS="$ALL_TESTS 0013:1:1"
6468
6569 # Kselftest framework requirement - SKIP code is 4.
6670 ksft_skip=4
....@@ -126,7 +130,7 @@
126130 if [[ $KMOD_VERSION -le 19 ]]; then
127131 echo "$0: You need at least kmod 20" >&2
128132 echo "kmod <= 19 is buggy, for details see:" >&2
129
- echo "http://git.kernel.org/cgit/utils/kernel/kmod/kmod.git/commit/libkmod/libkmod-module.c?id=fd44a98ae2eb5eb32161088954ab21e58e19dfc4" >&2
133
+ echo "https://git.kernel.org/cgit/utils/kernel/kmod/kmod.git/commit/libkmod/libkmod-module.c?id=fd44a98ae2eb5eb32161088954ab21e58e19dfc4" >&2
130134 exit $ksft_skip
131135 fi
132136
....@@ -149,6 +153,7 @@
149153
150154 test_finish()
151155 {
156
+ echo "$MODPROBE" > /proc/sys/kernel/modprobe
152157 echo "Test completed"
153158 }
154159
....@@ -263,7 +268,7 @@
263268 config_reset()
264269 {
265270 if ! echo -n "1" >"$DIR"/reset; then
266
- echo "$0: reset shuld have worked" >&2
271
+ echo "$0: reset should have worked" >&2
267272 exit 1
268273 fi
269274 }
....@@ -338,7 +343,7 @@
338343
339344 kmod_defaults_driver
340345 config_num_threads 1
341
- printf '\000' >"$DIR"/config_test_driver
346
+ printf $NAME >"$DIR"/config_test_driver
342347 config_trigger ${FUNCNAME[0]}
343348 config_expect_result ${FUNCNAME[0]} MODULE_NOT_FOUND
344349 }
....@@ -349,7 +354,7 @@
349354
350355 kmod_defaults_fs
351356 config_num_threads 1
352
- printf '\000' >"$DIR"/config_test_fs
357
+ printf $NAME >"$DIR"/config_test_fs
353358 config_trigger ${FUNCNAME[0]}
354359 config_expect_result ${FUNCNAME[0]} -EINVAL
355360 }
....@@ -443,6 +448,62 @@
443448 config_expect_result ${FUNCNAME[0]} SUCCESS
444449 }
445450
451
+kmod_test_0010()
452
+{
453
+ kmod_defaults_driver
454
+ config_num_threads 1
455
+ echo "/KMOD_TEST_NONEXISTENT" > /proc/sys/kernel/modprobe
456
+ config_trigger ${FUNCNAME[0]}
457
+ config_expect_result ${FUNCNAME[0]} -ENOENT
458
+ echo "$MODPROBE" > /proc/sys/kernel/modprobe
459
+}
460
+
461
+kmod_test_0011()
462
+{
463
+ kmod_defaults_driver
464
+ config_num_threads 1
465
+ # This causes the kernel to not even try executing modprobe. The error
466
+ # code is still -ENOENT like when modprobe doesn't exist, so we can't
467
+ # easily test for the exact difference. But this still is a useful test
468
+ # since there was a bug where request_module() returned 0 in this case.
469
+ echo > /proc/sys/kernel/modprobe
470
+ config_trigger ${FUNCNAME[0]}
471
+ config_expect_result ${FUNCNAME[0]} -ENOENT
472
+ echo "$MODPROBE" > /proc/sys/kernel/modprobe
473
+}
474
+
475
+kmod_check_visibility()
476
+{
477
+ local name="$1"
478
+ local cmd="$2"
479
+
480
+ modprobe $DEFAULT_KMOD_DRIVER
481
+
482
+ local priv=$(eval $cmd)
483
+ local unpriv=$(capsh --drop=CAP_SYSLOG -- -c "$cmd")
484
+
485
+ if [ "$priv" = "$unpriv" ] || \
486
+ [ "${priv:0:3}" = "0x0" ] || \
487
+ [ "${unpriv:0:3}" != "0x0" ] ; then
488
+ echo "${FUNCNAME[0]}: FAIL, $name visible to unpriv: '$priv' vs '$unpriv'" >&2
489
+ exit 1
490
+ else
491
+ echo "${FUNCNAME[0]}: OK!"
492
+ fi
493
+}
494
+
495
+kmod_test_0012()
496
+{
497
+ kmod_check_visibility /proc/modules \
498
+ "grep '^${DEFAULT_KMOD_DRIVER}\b' /proc/modules | awk '{print \$NF}'"
499
+}
500
+
501
+kmod_test_0013()
502
+{
503
+ kmod_check_visibility '/sys/module/*/sections/*' \
504
+ "cat /sys/module/${DEFAULT_KMOD_DRIVER}/sections/.*text | head -n1"
505
+}
506
+
446507 list_tests()
447508 {
448509 echo "Test ID list:"
....@@ -460,6 +521,10 @@
460521 echo "0007 x $(get_test_count 0007) - multithreaded tests with default setup test request_module() and get_fs_type()"
461522 echo "0008 x $(get_test_count 0008) - multithreaded - push kmod_concurrent over max_modprobes for request_module()"
462523 echo "0009 x $(get_test_count 0009) - multithreaded - push kmod_concurrent over max_modprobes for get_fs_type()"
524
+ echo "0010 x $(get_test_count 0010) - test nonexistent modprobe path"
525
+ echo "0011 x $(get_test_count 0011) - test completely disabling module autoloading"
526
+ echo "0012 x $(get_test_count 0012) - test /proc/modules address visibility under CAP_SYSLOG"
527
+ echo "0013 x $(get_test_count 0013) - test /sys/module/*/sections/* visibility under CAP_SYSLOG"
463528 }
464529
465530 usage()
....@@ -488,7 +553,7 @@
488553 echo Example uses:
489554 echo
490555 echo "${TEST_NAME}.sh -- executes all tests"
491
- echo "${TEST_NAME}.sh -t 0008 -- Executes test ID 0008 number of times is recomended"
556
+ echo "${TEST_NAME}.sh -t 0008 -- Executes test ID 0008 number of times is recommended"
492557 echo "${TEST_NAME}.sh -w 0008 -- Watch test ID 0008 run until an error occurs"
493558 echo "${TEST_NAME}.sh -s 0008 -- Run test ID 0008 once"
494559 echo "${TEST_NAME}.sh -c 0008 3 -- Run test ID 0008 three times"
....@@ -616,6 +681,7 @@
616681 allow_user_defaults
617682 load_req_mod
618683
684
+MODPROBE=$(</proc/sys/kernel/modprobe)
619685 trap "test_finish" EXIT
620686
621687 parse_args $@