summaryrefslogtreecommitdiff
path: root/libmodprobe/libmodprobe_test.cpp
diff options
context:
space:
mode:
authorWill McVicker <willmcvicker@google.com>2021-03-12 11:11:37 -0800
committerWill McVicker <willmcvicker@google.com>2021-03-31 09:34:47 -0700
commit87b2ef0edfab63e0482c3adc58332a9fcb865fc5 (patch)
treeadd61c8f330c3bf580fc7213283c336757a60856 /libmodprobe/libmodprobe_test.cpp
parent007d7941c82563f27decf2f0a951c1c402f31433 (diff)
libmodprobe: refactor blocklist functionality
Remove the function EnableBlocklist() and add a constructor argument to enable/disable the use of modules.blocklist. In all cases, the enabling/disabling of the blocklist happens immediately after creating the Modprobe object. So this simplies libmodprobe. Additionally, the use of the blocklist by libmodprobe should be enabled by default unless explicitly disabled during creation of the Modprobe object. Currently, only modprobe(8) defaults to not using the blocklist and includes the argument -b BLOCKLIST for enabling it. That functionality remains. This refactor allows us to use the blocklist during first stage init. However, additional logic is needed to not return an error for the blocked non-aliased modules during first stage init; otherwise, the error would result in an init crash leading to a device reboot. So fixup LoadListedModules() to allow blocking modules without returning an error. Bug: 182582036 Test: boot test on pixel 5 with a module in modules.blocklist Change-Id: I394b5aa98fa98821011982cfe693749010c381f7
Diffstat (limited to 'libmodprobe/libmodprobe_test.cpp')
-rw-r--r--libmodprobe/libmodprobe_test.cpp30
1 files changed, 28 insertions, 2 deletions
diff --git a/libmodprobe/libmodprobe_test.cpp b/libmodprobe/libmodprobe_test.cpp
index d50c10d8f..f960b6139 100644
--- a/libmodprobe/libmodprobe_test.cpp
+++ b/libmodprobe/libmodprobe_test.cpp
@@ -78,6 +78,18 @@ TEST(libmodprobe, Test) {
"/test13.ko",
};
+ std::vector<std::string> expected_modules_blocklist_enabled = {
+ "/test1.ko option1=50 option2=60",
+ "/test6.ko",
+ "/test2.ko",
+ "/test5.ko option1=",
+ "/test8.ko",
+ "/test7.ko param1=4",
+ "/test12.ko",
+ "/test11.ko",
+ "/test13.ko",
+ };
+
const std::string modules_dep =
"test1.ko:\n"
"test2.ko:\n"
@@ -146,7 +158,7 @@ TEST(libmodprobe, Test) {
*i = dir.path + *i;
}
- Modprobe m({dir.path});
+ Modprobe m({dir.path}, "modules.load", false);
EXPECT_TRUE(m.LoadListedModules());
GTEST_LOG_(INFO) << "Expected modules loaded (in order):";
@@ -176,8 +188,22 @@ TEST(libmodprobe, Test) {
EXPECT_TRUE(modules_loaded == expected_after_remove);
- m.EnableBlocklist(true);
+ m = Modprobe({dir.path});
EXPECT_FALSE(m.LoadWithAliases("test4", true));
+ while (modules_loaded.size() > 0) EXPECT_TRUE(m.Remove(modules_loaded.front()));
+ EXPECT_TRUE(m.LoadListedModules());
+
+ GTEST_LOG_(INFO) << "Expected modules loaded after enabling blocklist (in order):";
+ for (auto i = expected_modules_blocklist_enabled.begin();
+ i != expected_modules_blocklist_enabled.end(); ++i) {
+ *i = dir.path + *i;
+ GTEST_LOG_(INFO) << "\"" << *i << "\"";
+ }
+ GTEST_LOG_(INFO) << "Actual modules loaded with blocklist enabled (in order):";
+ for (auto i = modules_loaded.begin(); i != modules_loaded.end(); ++i) {
+ GTEST_LOG_(INFO) << "\"" << *i << "\"";
+ }
+ EXPECT_TRUE(modules_loaded == expected_modules_blocklist_enabled);
}
TEST(libmodprobe, ModuleDepLineWithoutColonIsSkipped) {