From fb3e64ab42da59dbf09a9505b616e29d822ad38e Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Thu, 30 Nov 2023 09:58:31 -0800 Subject: [PATCH] service_test: Only run the ServiceStopTest as root Despite 'require_root: true' in Android.bp for CtsInitTestCases, it can happen that this test is run without root privileges. If that happens, skip the ServiceStopTest. Bug: 313551148 Change-Id: I45f29369915a1f61e08ffd9bf5601a83a147597c Signed-off-by: Bart Van Assche --- init/service_test.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/init/service_test.cpp b/init/service_test.cpp index c81b0077f..a3590b536 100644 --- a/init/service_test.cpp +++ b/init/service_test.cpp @@ -236,6 +236,11 @@ class ServiceStopTest : public testing::TestWithParam {}; // Service::Stop() if their uid_%d/pid_%d cgroup directory got removed. This test, if run with the // parameter set to 'true', verifies that such services are stopped. TEST_P(ServiceStopTest, stop) { + if (getuid() != 0) { + GTEST_SKIP() << "Must be run as root."; + return; + } + static constexpr std::string_view kServiceName = "ServiceA"; static constexpr std::string_view kScriptTemplate = R"init( service $name /system/bin/yes