From 2ef572be30e511e951f267958eda81e0d9901c22 Mon Sep 17 00:00:00 2001 From: Tom Cherry Date: Wed, 19 Jul 2017 14:54:21 -0700 Subject: [PATCH] ueventd: fixup ueventd_test.cpp Use ASSERT_EQ() instead of EXPECT_EQ() to prevent segfaults after failed API calls. Do not run setfscreatecon_IsPerThread unless we're in permissive mode as it will not pass otherwise. Test: init unit tests Change-Id: I70525d438e89f1ec036255890169a50b5007b4c4 --- init/ueventd_test.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/init/ueventd_test.cpp b/init/ueventd_test.cpp index 86d7055c7..4d9a1fa59 100644 --- a/init/ueventd_test.cpp +++ b/init/ueventd_test.cpp @@ -63,7 +63,10 @@ void WriteFromMultipleThreads(std::vector>& files_and_ } TEST(ueventd, setegid_IsPerThread) { - if (getuid() != 0) return; + if (getuid() != 0) { + GTEST_LOG_(INFO) << "Skipping test, must be run as root."; + return; + } TemporaryDir dir; @@ -78,13 +81,20 @@ TEST(ueventd, setegid_IsPerThread) { for (const auto& [file, expected_gid] : files_and_gids) { struct stat info; - EXPECT_EQ(0, stat(file.c_str(), &info)); + ASSERT_EQ(0, stat(file.c_str(), &info)); EXPECT_EQ(expected_gid, info.st_gid); } } TEST(ueventd, setfscreatecon_IsPerThread) { - if (getuid() != 0) return; + if (getuid() != 0) { + GTEST_LOG_(INFO) << "Skipping test, must be run as root."; + return; + } + if (!is_selinux_enabled() || security_getenforce() == 1) { + GTEST_LOG_(INFO) << "Skipping test, SELinux must be enabled and in permissive mode."; + return; + } const char* const contexts[] = { "u:object_r:audio_device:s0", @@ -105,7 +115,7 @@ TEST(ueventd, setfscreatecon_IsPerThread) { for (const auto& [file, expected_context] : files_and_contexts) { char* file_context; - EXPECT_GT(getfilecon(file.c_str(), &file_context), 0); + ASSERT_GT(getfilecon(file.c_str(), &file_context), 0); EXPECT_EQ(expected_context, file_context); freecon(file_context); }