Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f37948d6 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge changes I6145bae8,Ia9452b3e

* changes:
  logcat: unit test produces log stutter
  liblog: test failures due to permission issues
parents 491c3871 a46326a5
Loading
Loading
Loading
Loading
+71 −37
Original line number Diff line number Diff line
@@ -214,6 +214,8 @@ static bool isLogdwActive() {
    }
    return false;
}

bool tested__android_log_close;
#endif

TEST(liblog, __android_log_btwrite__android_logger_list_read) {
@@ -228,22 +230,33 @@ TEST(liblog, __android_log_btwrite__android_logger_list_read) {
    // Check that we can close and reopen the logger
    log_time ts(CLOCK_MONOTONIC);
    ASSERT_LT(0, __android_log_btwrite(0, EVENT_TYPE_LONG, &ts, sizeof(ts)));
    bool pmsgActiveAfter__android_log_btwrite = isPmsgActive();
    bool logdwActiveAfter__android_log_btwrite = isLogdwActive();
    bool pmsgActiveAfter__android_log_btwrite;
    bool logdwActiveAfter__android_log_btwrite;
    if (getuid() == AID_ROOT) {
        tested__android_log_close = true;
        pmsgActiveAfter__android_log_btwrite = isPmsgActive();
        logdwActiveAfter__android_log_btwrite = isLogdwActive();
        EXPECT_TRUE(pmsgActiveAfter__android_log_btwrite);
        EXPECT_TRUE(logdwActiveAfter__android_log_btwrite);
    } else if (!tested__android_log_close) {
        fprintf(stderr, "WARNING: can not test __android_log_close()\n");
    }
    __android_log_close();
    if (getuid() == AID_ROOT) {
        bool pmsgActiveAfter__android_log_close = isPmsgActive();
        bool logdwActiveAfter__android_log_close = isLogdwActive();
        EXPECT_FALSE(pmsgActiveAfter__android_log_close);
        EXPECT_FALSE(logdwActiveAfter__android_log_close);
    }

    log_time ts1(CLOCK_MONOTONIC);
    ASSERT_LT(0, __android_log_btwrite(0, EVENT_TYPE_LONG, &ts1, sizeof(ts1)));
    if (getuid() == AID_ROOT) {
        pmsgActiveAfter__android_log_btwrite = isPmsgActive();
        logdwActiveAfter__android_log_btwrite = isLogdwActive();
        EXPECT_TRUE(pmsgActiveAfter__android_log_btwrite);
        EXPECT_TRUE(logdwActiveAfter__android_log_btwrite);
    }
    usleep(1000000);

    int count = 0;
@@ -539,7 +552,6 @@ TEST(liblog, __security_buffer) {
    bool set_persist = false;
    bool allow_security = false;

    setuid(AID_SYSTEM); // only one that can read security buffer
    if (__android_log_security()) {
        allow_security = true;
    } else {
@@ -612,6 +624,8 @@ TEST(liblog, __security_buffer) {
        return;
    }

    setuid(AID_SYSTEM); // only one that can read security buffer

    pid_t pid = getpid();

    ASSERT_TRUE(NULL != (logger_list = android_logger_list_open(
@@ -2662,10 +2676,15 @@ static const char __pmsg_file[] =
TEST(liblog, __android_log_pmsg_file_write) {
#ifdef __ANDROID__
    __android_log_close();
    if (getuid() == AID_ROOT) {
        tested__android_log_close = true;
        bool pmsgActiveAfter__android_log_close = isPmsgActive();
        bool logdwActiveAfter__android_log_close = isLogdwActive();
        EXPECT_FALSE(pmsgActiveAfter__android_log_close);
        EXPECT_FALSE(logdwActiveAfter__android_log_close);
    } else if (!tested__android_log_close) {
        fprintf(stderr, "WARNING: can not test __android_log_close()\n");
    }
    int return__android_log_pmsg_file_write = __android_log_pmsg_file_write(
            LOG_ID_CRASH, ANDROID_LOG_VERBOSE,
            __pmsg_file, max_payload_buf, sizeof(max_payload_buf));
@@ -2679,24 +2698,32 @@ TEST(liblog, __android_log_pmsg_file_write) {
                        "with liblog.__android_log_msg_file_read test\n",
                        __pmsg_file);
    }
    bool pmsgActiveAfter__android_pmsg_file_write = isPmsgActive();
    bool logdwActiveAfter__android_pmsg_file_write = isLogdwActive();
    bool pmsgActiveAfter__android_pmsg_file_write;
    bool logdwActiveAfter__android_pmsg_file_write;
    if (getuid() == AID_ROOT) {
        pmsgActiveAfter__android_pmsg_file_write = isPmsgActive();
        logdwActiveAfter__android_pmsg_file_write = isLogdwActive();
        EXPECT_FALSE(pmsgActiveAfter__android_pmsg_file_write);
        EXPECT_FALSE(logdwActiveAfter__android_pmsg_file_write);
    }
    EXPECT_LT(0, __android_log_buf_print(LOG_ID_MAIN, ANDROID_LOG_INFO,
                                         "TEST__android_log_pmsg_file_write",
                                         "main"));
    if (getuid() == AID_ROOT) {
        bool pmsgActiveAfter__android_log_buf_print = isPmsgActive();
        bool logdwActiveAfter__android_log_buf_print = isLogdwActive();
        EXPECT_TRUE(pmsgActiveAfter__android_log_buf_print);
        EXPECT_TRUE(logdwActiveAfter__android_log_buf_print);
    }
    EXPECT_LT(0, __android_log_pmsg_file_write(
            LOG_ID_CRASH, ANDROID_LOG_VERBOSE,
            __pmsg_file, max_payload_buf, sizeof(max_payload_buf)));
    if (getuid() == AID_ROOT) {
        pmsgActiveAfter__android_pmsg_file_write = isPmsgActive();
        logdwActiveAfter__android_pmsg_file_write = isLogdwActive();
        EXPECT_TRUE(pmsgActiveAfter__android_pmsg_file_write);
        EXPECT_TRUE(logdwActiveAfter__android_pmsg_file_write);
    }
#else
    GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif
@@ -2731,19 +2758,26 @@ TEST(liblog, __android_log_pmsg_file_read) {
    signaled = 0;

    __android_log_close();
    if (getuid() == AID_ROOT) {
        tested__android_log_close = true;
        bool pmsgActiveAfter__android_log_close = isPmsgActive();
        bool logdwActiveAfter__android_log_close = isLogdwActive();
        EXPECT_FALSE(pmsgActiveAfter__android_log_close);
        EXPECT_FALSE(logdwActiveAfter__android_log_close);
    } else if (!tested__android_log_close) {
        fprintf(stderr, "WARNING: can not test __android_log_close()\n");
    }

    ssize_t ret = __android_log_pmsg_file_read(
            LOG_ID_CRASH, ANDROID_LOG_VERBOSE,
            __pmsg_file, __pmsg_fn, NULL);

    if (getuid() == AID_ROOT) {
        bool pmsgActiveAfter__android_log_pmsg_file_read = isPmsgActive();
        bool logdwActiveAfter__android_log_pmsg_file_read = isLogdwActive();
        EXPECT_FALSE(pmsgActiveAfter__android_log_pmsg_file_read);
        EXPECT_FALSE(logdwActiveAfter__android_log_pmsg_file_read);
    }

    if (ret == -ENOENT) {
        fprintf(stderr,
+6 −3
Original line number Diff line number Diff line
@@ -451,11 +451,12 @@ TEST(logcat, bad_buffer) {
      "logcat -v brief -b radio,events,bogo,system,main -g 2>/dev/null"));
}

static void caught_blocking(int /*signum*/)
static void caught_blocking(int signum)
{
    unsigned long long v = 0xDEADBEEFA55A0000ULL;

    v += getpid() & 0xFFFF;
    if (signum == 0) ++v;

    LOG_FAILURE_RETRY(__android_log_btwrite(0, EVENT_TYPE_LONG, &v, sizeof(v)));
}
@@ -520,11 +521,12 @@ TEST(logcat, blocking) {
    EXPECT_EQ(1, signals);
}

static void caught_blocking_tail(int /*signum*/)
static void caught_blocking_tail(int signum)
{
    unsigned long long v = 0xA55ADEADBEEF0000ULL;

    v += getpid() & 0xFFFF;
    if (signum == 0) ++v;

    LOG_FAILURE_RETRY(__android_log_btwrite(0, EVENT_TYPE_LONG, &v, sizeof(v)));
}
@@ -955,10 +957,11 @@ TEST(logcat, logrotate_nodir) {
                     " -n 256 -r 1024"));
}

static void caught_blocking_clear(int /*signum*/) {
static void caught_blocking_clear(int signum) {
    unsigned long long v = 0xDEADBEEFA55C0000ULL;

    v += getpid() & 0xFFFF;
    if (signum == 0) ++v;

    LOG_FAILURE_RETRY(__android_log_btwrite(0, EVENT_TYPE_LONG, &v, sizeof(v)));
}