summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Cherry <tomcherry@google.com>2019-09-04 19:30:02 -0700
committerandroid-build-merger <android-build-merger@google.com>2019-09-04 19:30:02 -0700
commit4375597f95476d6e88c7bfdeae5fab84c5375476 (patch)
tree5ab3466fd92adb6c3ae1b33f9097bdd53b293a77
parent2378575dac467fbda73e2e50dc9fc3140864eeed (diff)
parent8412deda5189c9f24f5fbe350a8bc75aab74c64e (diff)
downloadcore-temp_140451723.tar.gz
Merge "liblog: run liblog#enoent only as root"temp_140451723
am: 8412deda51 Change-Id: I5b179babe5324bcd63a5303f65a72e9e4bb6e9c2
-rw-r--r--liblog/tests/liblog_test.cpp38
1 files changed, 10 insertions, 28 deletions
diff --git a/liblog/tests/liblog_test.cpp b/liblog/tests/liblog_test.cpp
index 45a9bc90b..5a73dc06e 100644
--- a/liblog/tests/liblog_test.cpp
+++ b/liblog/tests/liblog_test.cpp
@@ -1747,22 +1747,21 @@ static int count_matching_ts(log_time ts) {
return count;
}
-
-// meant to be handed to ASSERT_TRUE / EXPECT_TRUE only to expand the message
-static testing::AssertionResult IsOk(bool ok, std::string& message) {
- return ok ? testing::AssertionSuccess()
- : (testing::AssertionFailure() << message);
-}
#endif // TEST_PREFIX
TEST(liblog, enoent) {
#ifdef TEST_PREFIX
+ if (getuid() != 0) {
+ GTEST_SKIP() << "Skipping test, must be run as root.";
+ return;
+ }
+
TEST_PREFIX
log_time ts(CLOCK_MONOTONIC);
EXPECT_LT(0, __android_log_btwrite(0, EVENT_TYPE_LONG, &ts, sizeof(ts)));
EXPECT_EQ(SUPPORTS_END_TO_END, count_matching_ts(ts));
- // This call will fail if we are setuid(AID_SYSTEM), beware of any
+ // This call will fail unless we are root, beware of any
// test prior to this one playing with setuid and causing interference.
// We need to run before these tests so that they do not interfere with
// this test.
@@ -1774,20 +1773,7 @@ TEST(liblog, enoent) {
// liblog.android_logger_get_ is one of those tests that has no recourse
// and that would be adversely affected by emptying the log if it was run
// right after this test.
- if (getuid() != AID_ROOT) {
- fprintf(
- stderr,
- "WARNING: test conditions request being run as root and not AID=%d\n",
- getuid());
- if (!__android_log_is_debuggable()) {
- fprintf(
- stderr,
- "WARNING: can not run test on a \"user\" build, bypassing test\n");
- return;
- }
- }
-
- system((getuid() == AID_ROOT) ? "stop logd" : "su 0 stop logd");
+ system("stop logd");
usleep(1000000);
// A clean stop like we are testing returns -ENOENT, but in the _real_
@@ -1799,19 +1785,15 @@ TEST(liblog, enoent) {
std::string content = android::base::StringPrintf(
"__android_log_btwrite(0, EVENT_TYPE_LONG, &ts, sizeof(ts)) = %d %s\n",
ret, (ret <= 0) ? strerror(-ret) : "(content sent)");
- EXPECT_TRUE(
- IsOk((ret == -ENOENT) || (ret == -ENOTCONN) || (ret == -ECONNREFUSED),
- content));
+ EXPECT_TRUE(ret == -ENOENT || ret == -ENOTCONN || ret == -ECONNREFUSED) << content;
ret = __android_log_btwrite(0, EVENT_TYPE_LONG, &ts, sizeof(ts));
content = android::base::StringPrintf(
"__android_log_btwrite(0, EVENT_TYPE_LONG, &ts, sizeof(ts)) = %d %s\n",
ret, (ret <= 0) ? strerror(-ret) : "(content sent)");
- EXPECT_TRUE(
- IsOk((ret == -ENOENT) || (ret == -ENOTCONN) || (ret == -ECONNREFUSED),
- content));
+ EXPECT_TRUE(ret == -ENOENT || ret == -ENOTCONN || ret == -ECONNREFUSED) << content;
EXPECT_EQ(0, count_matching_ts(ts));
- system((getuid() == AID_ROOT) ? "start logd" : "su 0 start logd");
+ system("start logd");
usleep(1000000);
EXPECT_EQ(0, count_matching_ts(ts));