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

Commit 2bd06f28 authored by Mark Salyzyn's avatar Mark Salyzyn
Browse files

logd: CTS test

Utilize logd-unit-tests as a CTS test

Goal is to check if the kernel logger is enabled.

Test: run cts tests
Bug: 31772697
Change-Id: I6d80350f3e40aff095f81b6600c40dd7d376bd74
parent 483d2f9a
Loading
Loading
Loading
Loading
+35 −0
Original line number Original line Diff line number Diff line
@@ -49,3 +49,38 @@ LOCAL_CFLAGS += $(test_c_flags)
LOCAL_SHARED_LIBRARIES := libbase libcutils liblog libselinux
LOCAL_SHARED_LIBRARIES := libbase libcutils liblog libselinux
LOCAL_SRC_FILES := $(test_src_files)
LOCAL_SRC_FILES := $(test_src_files)
include $(BUILD_NATIVE_TEST)
include $(BUILD_NATIVE_TEST)

cts_executable := CtsLogdTestCases

include $(CLEAR_VARS)
LOCAL_MODULE := $(cts_executable)
LOCAL_MODULE_TAGS := tests
LOCAL_CFLAGS += $(test_c_flags)
LOCAL_SRC_FILES := $(test_src_files)
LOCAL_MODULE_PATH := $(TARGET_OUT_DATA)/nativetest
LOCAL_MULTILIB := both
LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32
LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
LOCAL_SHARED_LIBRARIES := libbase libcutils liblog libselinux
LOCAL_STATIC_LIBRARIES := libgtest libgtest_main
LOCAL_COMPATIBILITY_SUITE := cts
LOCAL_CTS_TEST_PACKAGE := android.core.logd
include $(BUILD_CTS_EXECUTABLE)

ifeq ($(HOST_OS)-$(HOST_ARCH),$(filter $(HOST_OS)-$(HOST_ARCH),linux-x86 linux-x86_64))

include $(CLEAR_VARS)
LOCAL_MODULE := $(cts_executable)_list
LOCAL_MODULE_TAGS := optional
LOCAL_CFLAGS := $(test_c_flags) -DHOST
LOCAL_C_INCLUDES := external/gtest/include
LOCAL_SRC_FILES := $(test_src_files)
LOCAL_MULTILIB := both
LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)
LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
LOCAL_CXX_STL := libc++
LOCAL_SHARED_LIBRARIES := libbase libcutils liblog
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
include $(BUILD_HOST_NATIVE_TEST)

endif  # ifeq ($(HOST_OS)-$(HOST_ARCH),$(filter $(HOST_OS)-$(HOST_ARCH),linux-x86 linux-x86_64))
+27 −0
Original line number Original line Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2016 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<configuration description="Config for CTS Logging Daemon test cases">
    <target_preparer class="com.android.compatibility.common.tradefed.targetprep.FilePusher">
        <option name="cleanup" value="true" />
        <option name="push" value="CtsLogdTestCases->/data/local/tmp/CtsLogdTestCases" />
        <option name="append-bitness" value="true" />
    </target_preparer>
    <test class="com.android.tradefed.testtype.GTest" >
        <option name="native-test-device-path" value="/data/local/tmp" />
        <option name="module-name" value="CtsLogdTestCases" />
        <option name="runtime-hint" value="65s" />
    </test>
</configuration>
+34 −0
Original line number Original line Diff line number Diff line
@@ -39,6 +39,7 @@
#include "../LogReader.h"  // pickup LOGD_SNDTIMEO
#include "../LogReader.h"  // pickup LOGD_SNDTIMEO
#include "../libaudit.h"   // pickup AUDIT_RATE_LIMIT_*
#include "../libaudit.h"   // pickup AUDIT_RATE_LIMIT_*


#ifdef __ANDROID__
static void send_to_control(char* buf, size_t len) {
static void send_to_control(char* buf, size_t len) {
    int sock = socket_local_client("logd", ANDROID_SOCKET_NAMESPACE_RESERVED,
    int sock = socket_local_client("logd", ANDROID_SOCKET_NAMESPACE_RESERVED,
                                   SOCK_STREAM);
                                   SOCK_STREAM);
@@ -157,8 +158,10 @@ static char* find_benchmark_spam(char* cp) {
    } while (*cp);
    } while (*cp);
    return benchmark;
    return benchmark;
}
}
#endif


TEST(logd, statistics) {
TEST(logd, statistics) {
#ifdef __ANDROID__
    size_t len;
    size_t len;
    char* buf;
    char* buf;


@@ -204,8 +207,12 @@ TEST(logd, statistics) {
    EXPECT_TRUE(NULL != events_logs);
    EXPECT_TRUE(NULL != events_logs);


    delete[] buf;
    delete[] buf;
#else
    GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif
}
}


#ifdef __ANDROID__
static void caught_signal(int /* signum */) {
static void caught_signal(int /* signum */) {
}
}


@@ -315,8 +322,10 @@ static void dump_log_msg(const char* prefix, log_msg* msg, unsigned int version,
    fprintf(stderr, "}\n");
    fprintf(stderr, "}\n");
    fflush(stderr);
    fflush(stderr);
}
}
#endif


TEST(logd, both) {
TEST(logd, both) {
#ifdef __ANDROID__
    log_msg msg;
    log_msg msg;


    // check if we can read any logs from logd
    // check if we can read any logs from logd
@@ -390,8 +399,12 @@ TEST(logd, both) {
    EXPECT_EQ(0, !user_logger_available && !kernel_logger_available);
    EXPECT_EQ(0, !user_logger_available && !kernel_logger_available);
    EXPECT_EQ(0, user_logger_content && kernel_logger_content);
    EXPECT_EQ(0, user_logger_content && kernel_logger_content);
    EXPECT_EQ(0, !user_logger_content && !kernel_logger_content);
    EXPECT_EQ(0, !user_logger_content && !kernel_logger_content);
#else
    GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif
}
}


#ifdef __ANDROID__
// BAD ROBOT
// BAD ROBOT
//   Benchmark threshold are generally considered bad form unless there is
//   Benchmark threshold are generally considered bad form unless there is
//   is some human love applied to the continued maintenance and whether the
//   is some human love applied to the continued maintenance and whether the
@@ -560,9 +573,11 @@ TEST(logd, benchmark) {
    // 50% threshold for SPAM filter (<20% typical, lots of engineering margin)
    // 50% threshold for SPAM filter (<20% typical, lots of engineering margin)
    ASSERT_GT(totalSize, nowSpamSize * 2);
    ASSERT_GT(totalSize, nowSpamSize * 2);
}
}
#endif


// b/26447386 confirm fixed
// b/26447386 confirm fixed
void timeout_negative(const char* command) {
void timeout_negative(const char* command) {
#ifdef __ANDROID__
    log_msg msg_wrap, msg_timeout;
    log_msg msg_wrap, msg_timeout;
    bool content_wrap = false, content_timeout = false, written = false;
    bool content_wrap = false, content_timeout = false, written = false;
    unsigned int alarm_wrap = 0, alarm_timeout = 0;
    unsigned int alarm_wrap = 0, alarm_timeout = 0;
@@ -632,6 +647,10 @@ void timeout_negative(const char* command) {
    EXPECT_NE(0U, alarm_wrap);
    EXPECT_NE(0U, alarm_wrap);
    EXPECT_TRUE(content_timeout);
    EXPECT_TRUE(content_timeout);
    EXPECT_NE(0U, alarm_timeout);
    EXPECT_NE(0U, alarm_timeout);
#else
    command = NULL;
    GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif
}
}


TEST(logd, timeout_no_start) {
TEST(logd, timeout_no_start) {
@@ -645,6 +664,7 @@ TEST(logd, timeout_start_epoch) {


// b/26447386 refined behavior
// b/26447386 refined behavior
TEST(logd, timeout) {
TEST(logd, timeout) {
#ifdef __ANDROID__
    // b/33962045 This test interferes with other log reader tests that
    // b/33962045 This test interferes with other log reader tests that
    // follow because of file descriptor socket persistence in the same
    // follow because of file descriptor socket persistence in the same
    // process.  So let's fork it to isolate it from giving us pain.
    // process.  So let's fork it to isolate it from giving us pain.
@@ -768,10 +788,14 @@ TEST(logd, timeout) {


    _exit(!written + content_wrap + alarm_wrap + !content_timeout +
    _exit(!written + content_wrap + alarm_wrap + !content_timeout +
          !alarm_timeout);
          !alarm_timeout);
#else
    GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif
}
}


// b/27242723 confirmed fixed
// b/27242723 confirmed fixed
TEST(logd, SNDTIMEO) {
TEST(logd, SNDTIMEO) {
#ifdef __ANDROID__
    static const unsigned sndtimeo =
    static const unsigned sndtimeo =
        LOGD_SNDTIMEO;  // <sigh> it has to be done!
        LOGD_SNDTIMEO;  // <sigh> it has to be done!
    static const unsigned sleep_time = sndtimeo + 3;
    static const unsigned sleep_time = sndtimeo + 3;
@@ -822,6 +846,9 @@ TEST(logd, SNDTIMEO) {
    EXPECT_EQ(0, save_errno);
    EXPECT_EQ(0, save_errno);


    close(fd);
    close(fd);
#else
    GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif
}
}


TEST(logd, getEventTag_list) {
TEST(logd, getEventTag_list) {
@@ -879,11 +906,14 @@ TEST(logd, getEventTag_newentry) {
#endif
#endif
}
}


#ifdef __ANDROID__
static inline int32_t get4LE(const char* src) {
static inline int32_t get4LE(const char* src) {
    return src[0] | (src[1] << 8) | (src[2] << 16) | (src[3] << 24);
    return src[0] | (src[1] << 8) | (src[2] << 16) | (src[3] << 24);
}
}
#endif


void __android_log_btwrite_multiple__helper(int count) {
void __android_log_btwrite_multiple__helper(int count) {
#ifdef __ANDROID__
    log_time ts(CLOCK_MONOTONIC);
    log_time ts(CLOCK_MONOTONIC);


    log_time ts1(CLOCK_MONOTONIC);
    log_time ts1(CLOCK_MONOTONIC);
@@ -976,6 +1006,10 @@ void __android_log_btwrite_multiple__helper(int count) {
    EXPECT_EQ(expected_chatty_count, chatty_count);
    EXPECT_EQ(expected_chatty_count, chatty_count);
    EXPECT_EQ(expected_identical_count, identical_count);
    EXPECT_EQ(expected_identical_count, identical_count);
    EXPECT_EQ(expected_expire_count, expire_count);
    EXPECT_EQ(expected_expire_count, expire_count);
#else
    count = 0;
    GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif
}
}


TEST(logd, multiple_test_1) {
TEST(logd, multiple_test_1) {