summaryrefslogtreecommitdiffstats
path: root/init/init_test.cpp
diff options
context:
space:
mode:
authorSteven Moreland <smoreland@google.com>2017-11-13 15:31:54 -0800
committerSteven Moreland <smoreland@google.com>2017-11-15 10:39:29 -0800
commit6f5333a4a94becb7ef74a5b54d0c28a3738881fd (patch)
treefa1045f06bc9300a2d51e70b568ed5282c325498 /init/init_test.cpp
parent5e1bea30b924661878c6fac4ec14b18e5ba17773 (diff)
downloadsystem_core-6f5333a4a94becb7ef74a5b54d0c28a3738881fd.tar.gz
system_core-6f5333a4a94becb7ef74a5b54d0c28a3738881fd.tar.bz2
system_core-6f5333a4a94becb7ef74a5b54d0c28a3738881fd.zip
Allow a service to override another.
For instance, on vendor.img: service foo /vendor/bin/nfc ... And then on odm.img: service foo /odm/bin/super-nfc override Allows a service on ODM to override a HAL on vendor. Bug: 69050941 Test: boot, init_tests Change-Id: I4e908fb66e89fc6e021799fe1fa6603d3072d62a
Diffstat (limited to 'init/init_test.cpp')
-rw-r--r--init/init_test.cpp40
1 files changed, 34 insertions, 6 deletions
diff --git a/init/init_test.cpp b/init/init_test.cpp
index 29a65abb9..268873c12 100644
--- a/init/init_test.cpp
+++ b/init/init_test.cpp
@@ -25,6 +25,7 @@
#include "import_parser.h"
#include "keyword_map.h"
#include "parser.h"
+#include "service.h"
#include "test_function_map.h"
#include "util.h"
@@ -34,12 +35,13 @@ namespace init {
using ActionManagerCommand = std::function<void(ActionManager&)>;
void TestInit(const std::string& init_script_file, const TestFunctionMap& test_function_map,
- const std::vector<ActionManagerCommand>& commands) {
+ const std::vector<ActionManagerCommand>& commands, ServiceList* service_list) {
ActionManager am;
Action::set_function_map(&test_function_map);
Parser parser;
+ parser.AddSectionParser("service", std::make_unique<ServiceParser>(service_list, nullptr));
parser.AddSectionParser("on", std::make_unique<ActionParser>(&am, nullptr));
parser.AddSectionParser("import", std::make_unique<ImportParser>(&parser));
@@ -55,11 +57,11 @@ void TestInit(const std::string& init_script_file, const TestFunctionMap& test_f
}
void TestInitText(const std::string& init_script, const TestFunctionMap& test_function_map,
- const std::vector<ActionManagerCommand>& commands) {
+ const std::vector<ActionManagerCommand>& commands, ServiceList* service_list) {
TemporaryFile tf;
ASSERT_TRUE(tf.fd != -1);
ASSERT_TRUE(android::base::WriteStringToFd(init_script, tf.fd));
- TestInit(tf.path, test_function_map, commands);
+ TestInit(tf.path, test_function_map, commands, service_list);
}
TEST(init, SimpleEventTrigger) {
@@ -76,7 +78,8 @@ pass_test
ActionManagerCommand trigger_boot = [](ActionManager& am) { am.QueueEventTrigger("boot"); };
std::vector<ActionManagerCommand> commands{trigger_boot};
- TestInitText(init_script, test_function_map, commands);
+ ServiceList service_list;
+ TestInitText(init_script, test_function_map, commands, &service_list);
EXPECT_TRUE(expect_true);
}
@@ -104,7 +107,30 @@ execute_third
ActionManagerCommand trigger_boot = [](ActionManager& am) { am.QueueEventTrigger("boot"); };
std::vector<ActionManagerCommand> commands{trigger_boot};
- TestInitText(init_script, test_function_map, commands);
+ ServiceList service_list;
+ TestInitText(init_script, test_function_map, commands, &service_list);
+}
+
+TEST(init, OverrideService) {
+ std::string init_script = R"init(
+service A something
+ class first
+
+service A something
+ class second
+ override
+
+)init";
+
+ ServiceList service_list;
+ TestInitText(init_script, TestFunctionMap(), {}, &service_list);
+ ASSERT_EQ(1, std::distance(service_list.begin(), service_list.end()));
+
+ auto service = service_list.begin()->get();
+ ASSERT_NE(nullptr, service);
+ EXPECT_EQ(std::set<std::string>({"second"}), service->classnames());
+ EXPECT_EQ("A", service->name());
+ EXPECT_TRUE(service->is_override());
}
TEST(init, EventTriggerOrderMultipleFiles) {
@@ -162,7 +188,9 @@ TEST(init, EventTriggerOrderMultipleFiles) {
ActionManagerCommand trigger_boot = [](ActionManager& am) { am.QueueEventTrigger("boot"); };
std::vector<ActionManagerCommand> commands{trigger_boot};
- TestInit(start.path, test_function_map, commands);
+ ServiceList service_list;
+
+ TestInit(start.path, test_function_map, commands, &service_list);
EXPECT_EQ(6, num_executed);
}