Skip to content

Commit b3cf21f

Browse files
mcgrofgregkh
authored andcommitted
test_firmware: test three firmware kernel configs using a proc knob
Since we now have knobs to twiddle what used to be set on kernel configurations we can build one base kernel configuration and modify behaviour to mimic such kernel configurations to test them. Provided you build a kernel with: CONFIG_TEST_FIRMWARE=y CONFIG_FW_LOADER=y CONFIG_FW_LOADER_USER_HELPER=y CONFIG_IKCONFIG=y CONFIG_IKCONFIG_PROC=y We should now be able test all possible kernel configurations when FW_LOADER=y. Note that when FW_LOADER=m we just don't provide the built-in functionality of the built-in firmware. If you're on an old kernel and either don't have /proc/config.gz (CONFIG_IKCONFIG_PROC) or haven't enabled CONFIG_FW_LOADER_USER_HELPER we cannot run these dynamic tests, so just run both scripts just as we used to before making blunt assumptions about your setup and requirements exactly as we did before. Acked-by: Kees Cook <keescook@chromium.org> Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent f5a6145 commit b3cf21f

3 files changed

Lines changed: 122 additions & 1 deletion

File tree

‎tools/testing/selftests/firmware/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# No binaries, but make sure arg-less "make" doesn't trigger "run_tests"
44
all:
55

6-
TEST_PROGS := fw_filesystem.sh fw_fallback.sh
6+
TEST_PROGS := fw_run_tests.sh
77

88
include ../lib.mk
99

‎tools/testing/selftests/firmware/fw_lib.sh‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,34 @@ check_setup()
4747
{
4848
HAS_FW_LOADER_USER_HELPER="$(kconfig_has CONFIG_FW_LOADER_USER_HELPER=y)"
4949
HAS_FW_LOADER_USER_HELPER_FALLBACK="$(kconfig_has CONFIG_FW_LOADER_USER_HELPER_FALLBACK=y)"
50+
PROC_FW_IGNORE_SYSFS_FALLBACK="0"
51+
PROC_FW_FORCE_SYSFS_FALLBACK="0"
52+
53+
if [ -z $PROC_SYS_DIR ]; then
54+
PROC_SYS_DIR="/proc/sys/kernel"
55+
fi
56+
57+
FW_PROC="${PROC_SYS_DIR}/firmware_config"
58+
FW_FORCE_SYSFS_FALLBACK="$FW_PROC/force_sysfs_fallback"
59+
FW_IGNORE_SYSFS_FALLBACK="$FW_PROC/ignore_sysfs_fallback"
60+
61+
if [ -f $FW_FORCE_SYSFS_FALLBACK ]; then
62+
PROC_FW_FORCE_SYSFS_FALLBACK="$(cat $FW_FORCE_SYSFS_FALLBACK)"
63+
fi
64+
65+
if [ -f $FW_IGNORE_SYSFS_FALLBACK ]; then
66+
PROC_FW_IGNORE_SYSFS_FALLBACK="$(cat $FW_IGNORE_SYSFS_FALLBACK)"
67+
fi
68+
69+
if [ "$PROC_FW_FORCE_SYSFS_FALLBACK" = "1" ]; then
70+
HAS_FW_LOADER_USER_HELPER="yes"
71+
HAS_FW_LOADER_USER_HELPER_FALLBACK="yes"
72+
fi
73+
74+
if [ "$PROC_FW_IGNORE_SYSFS_FALLBACK" = "1" ]; then
75+
HAS_FW_LOADER_USER_HELPER_FALLBACK="no"
76+
HAS_FW_LOADER_USER_HELPER="no"
77+
fi
5078

5179
if [ "$HAS_FW_LOADER_USER_HELPER" = "yes" ]; then
5280
OLD_TIMEOUT="$(cat /sys/class/firmware/timeout)"
@@ -76,6 +104,28 @@ setup_tmp_file()
76104
fi
77105
}
78106

107+
proc_set_force_sysfs_fallback()
108+
{
109+
if [ -f $FW_FORCE_SYSFS_FALLBACK ]; then
110+
echo -n $1 > $FW_FORCE_SYSFS_FALLBACK
111+
check_setup
112+
fi
113+
}
114+
115+
proc_set_ignore_sysfs_fallback()
116+
{
117+
if [ -f $FW_IGNORE_SYSFS_FALLBACK ]; then
118+
echo -n $1 > $FW_IGNORE_SYSFS_FALLBACK
119+
check_setup
120+
fi
121+
}
122+
123+
proc_restore_defaults()
124+
{
125+
proc_set_force_sysfs_fallback 0
126+
proc_set_ignore_sysfs_fallback 0
127+
}
128+
79129
test_finish()
80130
{
81131
if [ "$HAS_FW_LOADER_USER_HELPER" = "yes" ]; then
@@ -93,6 +143,7 @@ test_finish()
93143
if [ -d $FWPATH ]; then
94144
rm -rf "$FWPATH"
95145
fi
146+
proc_restore_defaults
96147
}
97148

98149
kconfig_has()
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
4+
# This runs all known tests across all known possible configurations we could
5+
# emulate in one run.
6+
7+
set -e
8+
9+
TEST_DIR=$(dirname $0)
10+
source $TEST_DIR/fw_lib.sh
11+
12+
export HAS_FW_LOADER_USER_HELPER=""
13+
export HAS_FW_LOADER_USER_HELPER_FALLBACK=""
14+
15+
run_tests()
16+
{
17+
proc_set_force_sysfs_fallback $1
18+
proc_set_ignore_sysfs_fallback $2
19+
$TEST_DIR/fw_filesystem.sh
20+
21+
proc_set_force_sysfs_fallback $1
22+
proc_set_ignore_sysfs_fallback $2
23+
$TEST_DIR/fw_fallback.sh
24+
}
25+
26+
run_test_config_0001()
27+
{
28+
echo "-----------------------------------------------------"
29+
echo "Running kernel configuration test 1 -- rare"
30+
echo "Emulates:"
31+
echo "CONFIG_FW_LOADER=y"
32+
echo "CONFIG_FW_LOADER_USER_HELPER=n"
33+
echo "CONFIG_FW_LOADER_USER_HELPER_FALLBACK=n"
34+
run_tests 0 1
35+
}
36+
37+
run_test_config_0002()
38+
{
39+
echo "-----------------------------------------------------"
40+
echo "Running kernel configuration test 2 -- distro"
41+
echo "Emulates:"
42+
echo "CONFIG_FW_LOADER=y"
43+
echo "CONFIG_FW_LOADER_USER_HELPER=y"
44+
echo "CONFIG_FW_LOADER_USER_HELPER_FALLBACK=n"
45+
proc_set_ignore_sysfs_fallback 0
46+
run_tests 0 0
47+
}
48+
49+
run_test_config_0003()
50+
{
51+
echo "-----------------------------------------------------"
52+
echo "Running kernel configuration test 3 -- android"
53+
echo "Emulates:"
54+
echo "CONFIG_FW_LOADER=y"
55+
echo "CONFIG_FW_LOADER_USER_HELPER=y"
56+
echo "CONFIG_FW_LOADER_USER_HELPER_FALLBACK=y"
57+
run_tests 1 0
58+
}
59+
60+
check_mods
61+
check_setup
62+
63+
if [ -f $FW_FORCE_SYSFS_FALLBACK ]; then
64+
run_test_config_0001
65+
run_test_config_0002
66+
run_test_config_0003
67+
else
68+
echo "Running basic kernel configuration, working with your config"
69+
run_test
70+
fi

0 commit comments

Comments
 (0)