Skip to content

Commit 31a07ec

Browse files
committed
common/rc: introduce _load_module()
When a test case requires specific modules for testing, it loads and uses the modules. To maintain a clean environment, it is desired that the test case unloads after execution. The modules should be unloaded only when the module was not loaded before the test case run. However, writing logic to determine the module load status and unload accordingly can be cumbersome. To simplify and standardize such module unload control, introduce the helper function _load_module(). It attempts to load the specified module and records it to the global array MODULES_TO_UNLOAD only when the module was not already loaded. Modules listed in MODULES_TO_UNLOAD are unloaded by _unload_modules() after each test case run. Reviewed-by: Daniel Wagner <[email protected]> Signed-off-by: Shin'ichiro Kawasaki <[email protected]>
1 parent 756d18d commit 31a07ec

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

common/rc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,18 @@ _have_driver()
6969
return 0
7070
}
7171

72+
# Load the specified module. Record the module to MODULES_TO_UNLOAD so that they
73+
# will be unloaded by _unload_modules() after each test case run.
74+
_load_module() {
75+
local modname="${1/-/_}"
76+
77+
if ! modprobe --quiet --first-time "${modname}"; then
78+
return 1
79+
fi
80+
81+
MODULES_TO_UNLOAD+=("${modname}")
82+
}
83+
7284
# Check that the specified crypto algorithm is present, regardless of whether
7385
# it's built-in or as module.
7486
_have_crypto_algorithm()

0 commit comments

Comments
 (0)