From 93c24d7e652b555bb9241883f2d39d09168d0d4b Mon Sep 17 00:00:00 2001 From: Jooyung Han Date: Tue, 6 Sep 2022 09:58:47 +0900 Subject: [PATCH] Only run Service::Start() under root Tests using Service::Start() should run under root. Otherwise tests fail to start services from the test binary due to lack of permission. Bug: 244748231 Test: CtsInitTestCases Change-Id: Ia4eb8457cfad7d44da6b171e44f64238e08af9f7 --- init/init_test.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/init/init_test.cpp b/init/init_test.cpp index 05cf3fd4c..8362390cc 100644 --- a/init/init_test.cpp +++ b/init/init_test.cpp @@ -280,6 +280,10 @@ void TestApexServicesInit(const std::vector& apex_services, } TEST(init, StopServiceByApexName) { + if (getuid() != 0) { + GTEST_SKIP() << "Must be run as root."; + return; + } std::string_view script_template = R"init( service apex_test_service /system/bin/yes user shell @@ -291,6 +295,10 @@ service apex_test_service /system/bin/yes } TEST(init, StopMultipleServicesByApexName) { + if (getuid() != 0) { + GTEST_SKIP() << "Must be run as root."; + return; + } std::string_view script_template = R"init( service apex_test_service_multiple_a /system/bin/yes user shell @@ -307,6 +315,10 @@ service apex_test_service_multiple_b /system/bin/id } TEST(init, StopServicesFromMultipleApexes) { + if (getuid() != 0) { + GTEST_SKIP() << "Must be run as root."; + return; + } std::string_view apex_script_template = R"init( service apex_test_service_multi_apex_a /system/bin/yes user shell @@ -332,6 +344,10 @@ service apex_test_service_multi_apex_c /system/bin/yes } TEST(init, StopServicesFromApexAndNonApex) { + if (getuid() != 0) { + GTEST_SKIP() << "Must be run as root."; + return; + } std::string_view apex_script_template = R"init( service apex_test_service_apex_a /system/bin/yes user shell @@ -357,6 +373,10 @@ service apex_test_service_non_apex /system/bin/yes } TEST(init, StopServicesFromApexMixed) { + if (getuid() != 0) { + GTEST_SKIP() << "Must be run as root."; + return; + } std::string_view script_template = R"init( service apex_test_service_mixed_a /system/bin/yes user shell