liblog: add logprint to host build
- cleanup of some style issues - resolve a few minor bugs - add -lrt for host so that clock_gettime can be issued - enable write-only logging, logprint and event list handling tests for host consumption. NB: CtsLiblogTestCases_list is only outlet for host testing of the interfaces, but it is not part of any automated testing Test: gTest liblog-unit-tests, liblog-benchmarks and CtsLiblogTestCases_list && build mmma system/core/liblog Bug: 27405083 Change-Id: I13db1f45f67569407587a5a909248de33809b8cf
This commit is contained in:
parent
8f2492f582
commit
62d0d2d683
|
@ -15,13 +15,14 @@
|
|||
//
|
||||
|
||||
liblog_sources = [
|
||||
"config_write.c",
|
||||
"log_event_list.c",
|
||||
"log_event_write.c",
|
||||
"logger_write.c",
|
||||
"config_write.c",
|
||||
"logger_name.c",
|
||||
"logger_lock.c",
|
||||
"log_ratelimit.cpp",
|
||||
"logger_lock.c",
|
||||
"logger_name.c",
|
||||
"logger_write.c",
|
||||
"logprint.c",
|
||||
]
|
||||
liblog_host_sources = [
|
||||
"fake_log_device.c",
|
||||
|
@ -32,7 +33,6 @@ liblog_target_sources = [
|
|||
"config_read.c",
|
||||
"log_time.cpp",
|
||||
"properties.c",
|
||||
"logprint.c",
|
||||
"pmsg_reader.c",
|
||||
"pmsg_writer.c",
|
||||
"logd_reader.c",
|
||||
|
|
|
@ -612,7 +612,12 @@ static ssize_t logWritev(int fd, const struct iovec* vector, int count)
|
|||
|
||||
bail:
|
||||
unlock();
|
||||
return vector[0].iov_len + vector[1].iov_len + vector[2].iov_len;
|
||||
int len = 0;
|
||||
for (i = 0; i < count; ++i) {
|
||||
len += vector[i].iov_len;
|
||||
}
|
||||
return len;
|
||||
|
||||
error:
|
||||
unlock();
|
||||
return -1;
|
||||
|
|
|
@ -46,9 +46,19 @@ static int fakeOpen() {
|
|||
int i;
|
||||
|
||||
for (i = 0; i < LOG_ID_MAX; i++) {
|
||||
char buf[sizeof("/dev/log_security")];
|
||||
/*
|
||||
* Known maximum size string, plus an 8 character margin to deal with
|
||||
* possible independent changes to android_log_id_to_name().
|
||||
*/
|
||||
char buf[sizeof("/dev/log_security") + 8];
|
||||
if (logFds[i] >= 0) {
|
||||
continue;
|
||||
}
|
||||
snprintf(buf, sizeof(buf), "/dev/log_%s", android_log_id_to_name(i));
|
||||
logFds[i] = fakeLogOpen(buf, O_WRONLY);
|
||||
if (logFds[i] < 0) {
|
||||
fprintf(stderr, "fakeLogOpen(%s, O_WRONLY) failed\n", buf);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -66,16 +76,28 @@ static int fakeWrite(log_id_t log_id, struct timespec *ts __unused,
|
|||
struct iovec *vec, size_t nr)
|
||||
{
|
||||
ssize_t ret;
|
||||
int logFd;
|
||||
size_t i;
|
||||
int logFd, len;
|
||||
|
||||
if (/*(int)log_id >= 0 &&*/ (int)log_id >= (int)LOG_ID_MAX) {
|
||||
return -EBADF;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
len = 0;
|
||||
for (i = 0; i < nr; ++i) {
|
||||
len += vec[i].iov_len;
|
||||
}
|
||||
|
||||
if (len > LOGGER_ENTRY_MAX_PAYLOAD) {
|
||||
len = LOGGER_ENTRY_MAX_PAYLOAD;
|
||||
}
|
||||
|
||||
logFd = logFds[(int)log_id];
|
||||
ret = TEMP_FAILURE_RETRY(fakeLogWritev(logFd, vec, nr));
|
||||
if (ret < 0) {
|
||||
ret = -errno;
|
||||
} else if (ret > len) {
|
||||
ret = len;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -38,6 +38,10 @@
|
|||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
#ifndef __predict_false
|
||||
#define __predict_false(exp) __builtin_expect((exp) != 0, 0)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Simplified macro to send a verbose radio log message using current LOG_TAG.
|
||||
*/
|
||||
|
|
|
@ -251,7 +251,11 @@ int android_logger_set_prune_list(struct logger_list* logger_list,
|
|||
#define ANDROID_LOG_WRONLY O_WRONLY
|
||||
#define ANDROID_LOG_RDWR O_RDWR
|
||||
#define ANDROID_LOG_ACCMODE O_ACCMODE
|
||||
#ifndef O_NONBLOCK
|
||||
#define ANDROID_LOG_NONBLOCK 0x00000800
|
||||
#else
|
||||
#define ANDROID_LOG_NONBLOCK O_NONBLOCK
|
||||
#endif
|
||||
#if __ANDROID_USE_LIBLOG_READER_INTERFACE > 2
|
||||
#define ANDROID_LOG_WRAP 0x40000000 /* Block until buffer about to wrap */
|
||||
#define ANDROID_LOG_WRAP_DEFAULT_TIMEOUT 7200 /* 2 hour default */
|
||||
|
|
|
@ -36,6 +36,10 @@
|
|||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef __predict_false
|
||||
#define __predict_false(exp) __builtin_expect((exp) != 0, 0)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Simplified macro to send a verbose system log message using current LOG_TAG.
|
||||
*/
|
||||
|
|
|
@ -16,13 +16,20 @@
|
|||
*/
|
||||
|
||||
#define _GNU_SOURCE /* for asprintf */
|
||||
#ifndef __MINGW32__
|
||||
#define HAVE_STRSEP
|
||||
#endif
|
||||
|
||||
#include <arpa/inet.h>
|
||||
//#ifndef __MINGW32__
|
||||
//#include <arpa/inet.h>
|
||||
//#endif
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#ifndef __MINGW32__
|
||||
#include <pwd.h>
|
||||
#endif
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
@ -40,6 +47,10 @@
|
|||
#define MS_PER_NSEC 1000000
|
||||
#define US_PER_NSEC 1000
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
typedef struct FilterInfo_t {
|
||||
char *mTag;
|
||||
android_LogPriority mPri;
|
||||
|
@ -216,7 +227,11 @@ LIBLOG_ABI_PUBLIC AndroidLogFormat *android_log_format_new()
|
|||
p_ret->year_output = false;
|
||||
p_ret->zone_output = false;
|
||||
p_ret->epoch_output = false;
|
||||
#ifdef __ANDROID__
|
||||
p_ret->monotonic_output = android_log_clockid() == CLOCK_MONOTONIC;
|
||||
#else
|
||||
p_ret->monotonic_output = false;
|
||||
#endif
|
||||
p_ret->uid_output = false;
|
||||
p_ret->descriptive_output = false;
|
||||
descriptive_output = false;
|
||||
|
@ -322,6 +337,7 @@ LIBLOG_ABI_PUBLIC AndroidLogPrintFormat android_log_formatFromString(
|
|||
else if (strcmp(formatString, "monotonic") == 0) format = FORMAT_MODIFIER_MONOTONIC;
|
||||
else if (strcmp(formatString, "uid") == 0) format = FORMAT_MODIFIER_UID;
|
||||
else if (strcmp(formatString, "descriptive") == 0) format = FORMAT_MODIFIER_DESCRIPT;
|
||||
#ifndef __MINGW32__
|
||||
else {
|
||||
extern char *tzname[2];
|
||||
static const char gmt[] = "GMT";
|
||||
|
@ -353,6 +369,7 @@ LIBLOG_ABI_PUBLIC AndroidLogPrintFormat android_log_formatFromString(
|
|||
}
|
||||
free(cp);
|
||||
}
|
||||
#endif
|
||||
|
||||
return format;
|
||||
}
|
||||
|
@ -411,7 +428,7 @@ LIBLOG_ABI_PUBLIC int android_log_addFilterRule(
|
|||
|
||||
/*
|
||||
* Presently HAVE_STRNDUP is never defined, so the second case is always taken
|
||||
* Darwin doesn't have strnup, everything else does
|
||||
* Darwin doesn't have strndup, everything else does
|
||||
*/
|
||||
#ifdef HAVE_STRNDUP
|
||||
tagName = strndup(filterExpression, tagNameLength);
|
||||
|
@ -433,6 +450,27 @@ error:
|
|||
return -1;
|
||||
}
|
||||
|
||||
#ifndef HAVE_STRSEP
|
||||
/* KISS replacement helper for below */
|
||||
static char* strsep(char** stringp, const char* delim)
|
||||
{
|
||||
char* token;
|
||||
char* ret = *stringp;
|
||||
|
||||
if (!ret || !*ret) {
|
||||
return NULL;
|
||||
}
|
||||
token = strpbrk(ret, delim);
|
||||
if (token) {
|
||||
*token = '\0';
|
||||
++token;
|
||||
} else {
|
||||
token = ret + strlen(ret);
|
||||
}
|
||||
*stringp = token;
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* filterString: a comma/whitespace-separated set of filter expressions
|
||||
|
@ -444,7 +482,6 @@ error:
|
|||
* Assumes single threaded execution
|
||||
*
|
||||
*/
|
||||
|
||||
LIBLOG_ABI_PUBLIC int android_log_addFilterString(
|
||||
AndroidLogFormat *p_format,
|
||||
const char *filterString)
|
||||
|
@ -728,6 +765,7 @@ static int android_log_printBinaryEvent(const unsigned char** pEventData,
|
|||
}
|
||||
}
|
||||
}
|
||||
outCount = 0;
|
||||
lval = 0;
|
||||
switch (type) {
|
||||
case EVENT_TYPE_INT:
|
||||
|
@ -953,7 +991,7 @@ no_room:
|
|||
LIBLOG_ABI_PUBLIC int android_log_processBinaryLogBuffer(
|
||||
struct logger_entry *buf,
|
||||
AndroidLogEntry *entry,
|
||||
const EventTagMap *map,
|
||||
const EventTagMap *map __unused,
|
||||
char *messageBuf, int messageBufLen)
|
||||
{
|
||||
size_t inCount;
|
||||
|
@ -995,11 +1033,12 @@ LIBLOG_ABI_PUBLIC int android_log_processBinaryLogBuffer(
|
|||
inCount -= 4;
|
||||
|
||||
entry->tagLen = 0;
|
||||
entry->tag = NULL;
|
||||
#ifdef __ANDROID__
|
||||
if (map != NULL) {
|
||||
entry->tag = android_lookupEventTag_len(map, &entry->tagLen, tagIndex);
|
||||
} else {
|
||||
entry->tag = NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* If we don't have a map, or didn't find the tag number in the map,
|
||||
|
@ -1024,9 +1063,11 @@ LIBLOG_ABI_PUBLIC int android_log_processBinaryLogBuffer(
|
|||
*/
|
||||
const char* fmtStr = NULL;
|
||||
size_t fmtLen = 0;
|
||||
#ifdef __ANDROID__
|
||||
if (descriptive_output && map) {
|
||||
fmtStr = android_lookupEventFormat_len(map, &fmtLen, tagIndex);
|
||||
}
|
||||
#endif
|
||||
|
||||
char* outBuf = messageBuf;
|
||||
size_t outRemaining = messageBufLen - 1; /* leave one for nul byte */
|
||||
|
@ -1250,6 +1291,7 @@ static long long nsecTimespec(struct timespec *now)
|
|||
return (long long)now->tv_sec * NS_PER_SEC + now->tv_nsec;
|
||||
}
|
||||
|
||||
#ifdef __ANDROID__
|
||||
static void convertMonotonic(struct timespec *result,
|
||||
const AndroidLogEntry *entry)
|
||||
{
|
||||
|
@ -1482,6 +1524,7 @@ static void convertMonotonic(struct timespec *result,
|
|||
result->tv_nsec = entry->tv_nsec;
|
||||
subTimespec(result, result, &convert);
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Formats a log message into a buffer
|
||||
|
@ -1529,6 +1572,7 @@ LIBLOG_ABI_PUBLIC char *android_log_formatLogLine (
|
|||
*/
|
||||
now = entry->tv_sec;
|
||||
nsec = entry->tv_nsec;
|
||||
#if __ANDROID__
|
||||
if (p_format->monotonic_output) {
|
||||
// prevent convertMonotonic from being called if logd is monotonic
|
||||
if (android_log_clockid() != CLOCK_MONOTONIC) {
|
||||
|
@ -1538,6 +1582,7 @@ LIBLOG_ABI_PUBLIC char *android_log_formatLogLine (
|
|||
nsec = time.tv_nsec;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (now < 0) {
|
||||
nsec = NS_PER_SEC - nsec;
|
||||
}
|
||||
|
@ -1591,13 +1636,18 @@ LIBLOG_ABI_PUBLIC char *android_log_formatLogLine (
|
|||
* This code is Android specific, bionic guarantees that
|
||||
* calls to non-reentrant getpwuid() are thread safe.
|
||||
*/
|
||||
#if !defined(__MINGW32__)
|
||||
#if (FAKE_LOG_DEVICE == 0)
|
||||
#ifndef __BIONIC__
|
||||
#warning "This code assumes that getpwuid is thread safe, only true with Bionic!"
|
||||
#endif
|
||||
#endif
|
||||
struct passwd* pwd = getpwuid(entry->uid);
|
||||
if (pwd && (strlen(pwd->pw_name) <= 5)) {
|
||||
snprintf(uid, sizeof(uid), "%5s:", pwd->pw_name);
|
||||
} else {
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
// Not worth parsing package list, names all longer than 5
|
||||
snprintf(uid, sizeof(uid), "%5d:", entry->uid);
|
||||
}
|
||||
|
|
|
@ -111,6 +111,7 @@ LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
|
|||
LOCAL_CXX_STL := libc++
|
||||
LOCAL_SHARED_LIBRARIES := liblog libcutils libbase
|
||||
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
|
||||
LOCAL_LDLIBS_linux := -lrt
|
||||
include $(BUILD_HOST_NATIVE_TEST)
|
||||
|
||||
endif # ifeq ($(HOST_OS)-$(HOST_ARCH),$(filter $(HOST_OS)-$(HOST_ARCH),linux-x86 linux-x86_64))
|
||||
|
|
|
@ -57,7 +57,6 @@
|
|||
_rc; })
|
||||
|
||||
TEST(liblog, __android_log_btwrite) {
|
||||
#ifdef __ANDROID__
|
||||
int intBuf = 0xDEADBEEF;
|
||||
EXPECT_LT(0, __android_log_btwrite(0,
|
||||
EVENT_TYPE_INT,
|
||||
|
@ -72,13 +71,10 @@ TEST(liblog, __android_log_btwrite) {
|
|||
EVENT_TYPE_STRING,
|
||||
Buf, sizeof(Buf) - 1));
|
||||
usleep(1000);
|
||||
#else
|
||||
GTEST_LOG_(INFO) << "This test does nothing.\n";
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef __ANDROID__
|
||||
std::string popenToString(std::string command) {
|
||||
static std::string popenToString(std::string command) {
|
||||
std::string ret;
|
||||
|
||||
FILE* fp = popen(command.c_str(), "r");
|
||||
|
@ -142,7 +138,7 @@ static bool isLogdwActive() {
|
|||
return false;
|
||||
}
|
||||
|
||||
bool tested__android_log_close;
|
||||
static bool tested__android_log_close;
|
||||
#endif
|
||||
|
||||
TEST(liblog, __android_log_btwrite__android_logger_list_read) {
|
||||
|
@ -154,9 +150,9 @@ TEST(liblog, __android_log_btwrite__android_logger_list_read) {
|
|||
ASSERT_TRUE(NULL != (logger_list = android_logger_list_open(
|
||||
LOG_ID_EVENTS, ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK, 1000, pid)));
|
||||
|
||||
// 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)));
|
||||
// Check that we can close and reopen the logger
|
||||
bool pmsgActiveAfter__android_log_btwrite;
|
||||
bool logdwActiveAfter__android_log_btwrite;
|
||||
if (getuid() == AID_ROOT) {
|
||||
|
@ -296,10 +292,13 @@ TEST(liblog, android_set_log_frontend) {
|
|||
}
|
||||
|
||||
#ifdef __ANDROID__
|
||||
static inline int32_t get4LE(const char* src)
|
||||
{
|
||||
static inline uint32_t get4LE(const uint8_t* src) {
|
||||
return src[0] | (src[1] << 8) | (src[2] << 16) | (src[3] << 24);
|
||||
}
|
||||
|
||||
static inline uint32_t get4LE(const char* src) {
|
||||
return get4LE(reinterpret_cast<const uint8_t*>(src));
|
||||
}
|
||||
#endif
|
||||
|
||||
static void bswrite_test(const char *message) {
|
||||
|
@ -311,7 +310,11 @@ static void bswrite_test(const char *message) {
|
|||
ASSERT_TRUE(NULL != (logger_list = android_logger_list_open(
|
||||
LOG_ID_EVENTS, ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK, 1000, pid)));
|
||||
|
||||
#ifdef __ANDROID__
|
||||
log_time ts(android_log_clockid());
|
||||
#else
|
||||
log_time ts(CLOCK_REALTIME);
|
||||
#endif
|
||||
|
||||
ASSERT_LT(0, __android_log_bswrite(0, message));
|
||||
size_t num_lines = 1, size = 0, length = 0, total = 0;
|
||||
|
@ -377,8 +380,11 @@ static void bswrite_test(const char *message) {
|
|||
&log_msg.entry_v1, &entry, NULL, msgBuf, sizeof(msgBuf));
|
||||
EXPECT_EQ((length == total) ? 0 : -1, processBinaryLogBuffer);
|
||||
if (processBinaryLogBuffer == 0) {
|
||||
size_t line_overhead = 20;
|
||||
if (pid > 99999) ++line_overhead;
|
||||
if (pid > 999999) ++line_overhead;
|
||||
fflush(stderr);
|
||||
EXPECT_EQ((int)((20 * num_lines) + size),
|
||||
EXPECT_EQ((int)((line_overhead * num_lines) + size),
|
||||
android_log_printLogLine(logformat, fileno(stderr), &entry));
|
||||
}
|
||||
android_log_format_free(logformat);
|
||||
|
@ -424,7 +430,11 @@ static void buf_write_test(const char *message) {
|
|||
LOG_ID_MAIN, ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK, 1000, pid)));
|
||||
|
||||
static const char tag[] = "TEST__android_log_buf_write";
|
||||
#ifdef __ANDROID__
|
||||
log_time ts(android_log_clockid());
|
||||
#else
|
||||
log_time ts(CLOCK_REALTIME);
|
||||
#endif
|
||||
|
||||
EXPECT_LT(0, __android_log_buf_write(LOG_ID_MAIN, ANDROID_LOG_INFO,
|
||||
tag, message));
|
||||
|
@ -472,8 +482,11 @@ static void buf_write_test(const char *message) {
|
|||
&entry);
|
||||
EXPECT_EQ(0, processLogBuffer);
|
||||
if (processLogBuffer == 0) {
|
||||
size_t line_overhead = 11;
|
||||
if (pid > 99999) ++line_overhead;
|
||||
if (pid > 999999) ++line_overhead;
|
||||
fflush(stderr);
|
||||
EXPECT_EQ((int)(((11 + sizeof(tag)) * num_lines) + size),
|
||||
EXPECT_EQ((int)(((line_overhead + sizeof(tag)) * num_lines) + size),
|
||||
android_log_printLogLine(logformat, fileno(stderr), &entry));
|
||||
}
|
||||
android_log_format_free(logformat);
|
||||
|
@ -688,7 +701,7 @@ static void *running_thread(void *) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int start_thread()
|
||||
static int start_thread()
|
||||
{
|
||||
sem_init(&thread_trigger, 0, 0);
|
||||
|
||||
|
@ -1022,7 +1035,11 @@ TEST(liblog, __android_log_buf_print__maxtag) {
|
|||
ASSERT_TRUE(NULL != (logger_list = android_logger_list_open(
|
||||
LOG_ID_MAIN, ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK, 1000, pid)));
|
||||
|
||||
#ifdef __ANDROID__
|
||||
log_time ts(android_log_clockid());
|
||||
#else
|
||||
log_time ts(CLOCK_REALTIME);
|
||||
#endif
|
||||
|
||||
EXPECT_LT(0, __android_log_buf_print(LOG_ID_MAIN, ANDROID_LOG_INFO,
|
||||
max_payload_buf, max_payload_buf));
|
||||
|
@ -1128,6 +1145,12 @@ TEST(liblog, too_big_payload) {
|
|||
EXPECT_LE(LOGGER_ENTRY_MAX_PAYLOAD - sizeof(big_payload_tag),
|
||||
static_cast<size_t>(max_len));
|
||||
|
||||
// SLOP: Allow the underlying interface to optionally place a
|
||||
// terminating nul at the LOGGER_ENTRY_MAX_PAYLOAD's last byte
|
||||
// or not.
|
||||
if (ret == (max_len + static_cast<ssize_t>(sizeof(big_payload_tag)) - 1)) {
|
||||
--max_len;
|
||||
}
|
||||
EXPECT_EQ(ret, max_len + static_cast<ssize_t>(sizeof(big_payload_tag)));
|
||||
#else
|
||||
GTEST_LOG_(INFO) << "This test does nothing.\n";
|
||||
|
@ -1136,16 +1159,26 @@ TEST(liblog, too_big_payload) {
|
|||
|
||||
TEST(liblog, dual_reader) {
|
||||
#ifdef __ANDROID__
|
||||
struct logger_list *logger_list1;
|
||||
static const int num = 25;
|
||||
|
||||
// >25 messages due to liblog.__android_log_buf_print__concurrentXX above.
|
||||
for (int i = 25; i > 0; --i) {
|
||||
static const char fmt[] = "dual_reader %02d";
|
||||
char buffer[sizeof(fmt) + 8];
|
||||
snprintf(buffer, sizeof(buffer), fmt, i);
|
||||
LOG_FAILURE_RETRY(__android_log_buf_write(LOG_ID_MAIN,
|
||||
ANDROID_LOG_INFO,
|
||||
"liblog", buffer));
|
||||
}
|
||||
usleep(1000000);
|
||||
|
||||
struct logger_list *logger_list1;
|
||||
ASSERT_TRUE(NULL != (logger_list1 = android_logger_list_open(
|
||||
LOG_ID_MAIN, ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK, 25, 0)));
|
||||
LOG_ID_MAIN, ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK, num, 0)));
|
||||
|
||||
struct logger_list *logger_list2;
|
||||
|
||||
if (NULL == (logger_list2 = android_logger_list_open(
|
||||
LOG_ID_MAIN, ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK, 15, 0))) {
|
||||
LOG_ID_MAIN, ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK, num - 10, 0))) {
|
||||
android_logger_list_close(logger_list1);
|
||||
ASSERT_TRUE(NULL != logger_list2);
|
||||
}
|
||||
|
@ -1178,22 +1211,19 @@ TEST(liblog, dual_reader) {
|
|||
android_logger_list_close(logger_list1);
|
||||
android_logger_list_close(logger_list2);
|
||||
|
||||
EXPECT_EQ(25, count1);
|
||||
EXPECT_EQ(15, count2);
|
||||
EXPECT_EQ(num, count1);
|
||||
EXPECT_EQ(num - 10, count2);
|
||||
#else
|
||||
GTEST_LOG_(INFO) << "This test does nothing.\n";
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef __ANDROID__
|
||||
static bool checkPriForTag(AndroidLogFormat *p_format, const char *tag, android_LogPriority pri) {
|
||||
return android_log_shouldPrintLine(p_format, tag, pri)
|
||||
&& !android_log_shouldPrintLine(p_format, tag, (android_LogPriority)(pri - 1));
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST(liblog, filterRule) {
|
||||
#ifdef __ANDROID__
|
||||
static const char tag[] = "random";
|
||||
|
||||
AndroidLogFormat *p_format = android_log_format_new();
|
||||
|
@ -1255,9 +1285,6 @@ TEST(liblog, filterRule) {
|
|||
#endif
|
||||
|
||||
android_log_format_free(p_format);
|
||||
#else
|
||||
GTEST_LOG_(INFO) << "This test does nothing.\n";
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(liblog, is_loggable) {
|
||||
|
@ -1560,6 +1587,9 @@ TEST(liblog, is_loggable) {
|
|||
}
|
||||
|
||||
#ifdef __ANDROID__
|
||||
// Following tests the specific issues surrounding error handling wrt logd.
|
||||
// Kills logd and toss all collected data, equivalent to logcat -b all -c,
|
||||
// except we also return errors to the logging callers.
|
||||
// helper to liblog.enoent to count end-to-end matching logging messages.
|
||||
static int count_matching_ts(log_time ts) {
|
||||
usleep(1000000);
|
||||
|
@ -1855,6 +1885,8 @@ static void android_errorWriteWithInfoLog_helper(int TAG, const char* SUBTAG,
|
|||
|
||||
pid_t pid = getpid();
|
||||
|
||||
count = 0;
|
||||
|
||||
ASSERT_TRUE(NULL != (logger_list = android_logger_list_open(
|
||||
LOG_ID_EVENTS, ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK, 1000, pid)));
|
||||
|
||||
|
@ -1868,8 +1900,6 @@ static void android_errorWriteWithInfoLog_helper(int TAG, const char* SUBTAG,
|
|||
|
||||
sleep(2);
|
||||
|
||||
count = 0;
|
||||
|
||||
for (;;) {
|
||||
log_msg log_msg;
|
||||
if (android_logger_list_read(logger_list, &log_msg) <= 0) {
|
||||
|
@ -1909,7 +1939,7 @@ static void android_errorWriteWithInfoLog_helper(int TAG, const char* SUBTAG,
|
|||
ASSERT_EQ(EVENT_TYPE_STRING, eventData[0]);
|
||||
eventData++;
|
||||
|
||||
int subtag_len = strlen(SUBTAG);
|
||||
unsigned subtag_len = strlen(SUBTAG);
|
||||
if (subtag_len > 32) subtag_len = 32;
|
||||
ASSERT_EQ(subtag_len, get4LE(eventData));
|
||||
eventData += 4;
|
||||
|
@ -1923,7 +1953,7 @@ static void android_errorWriteWithInfoLog_helper(int TAG, const char* SUBTAG,
|
|||
ASSERT_EQ(EVENT_TYPE_INT, eventData[0]);
|
||||
eventData++;
|
||||
|
||||
ASSERT_EQ(UID, get4LE(eventData));
|
||||
ASSERT_EQ(UID, (int)get4LE(eventData));
|
||||
eventData += 4;
|
||||
|
||||
// Element #3: string type for data
|
||||
|
@ -2030,6 +2060,8 @@ static void android_errorWriteLog_helper(int TAG, const char *SUBTAG, int& count
|
|||
|
||||
pid_t pid = getpid();
|
||||
|
||||
count = 0;
|
||||
|
||||
ASSERT_TRUE(NULL != (logger_list = android_logger_list_open(
|
||||
LOG_ID_EVENTS, ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK, 1000, pid)));
|
||||
|
||||
|
@ -2042,8 +2074,6 @@ static void android_errorWriteLog_helper(int TAG, const char *SUBTAG, int& count
|
|||
|
||||
sleep(2);
|
||||
|
||||
count = 0;
|
||||
|
||||
for (;;) {
|
||||
log_msg log_msg;
|
||||
if (android_logger_list_read(logger_list, &log_msg) <= 0) {
|
||||
|
@ -2081,7 +2111,7 @@ static void android_errorWriteLog_helper(int TAG, const char *SUBTAG, int& count
|
|||
ASSERT_EQ(EVENT_TYPE_STRING, eventData[0]);
|
||||
eventData++;
|
||||
|
||||
ASSERT_EQ((int) strlen(SUBTAG), get4LE(eventData));
|
||||
ASSERT_EQ(strlen(SUBTAG), get4LE(eventData));
|
||||
eventData +=4;
|
||||
|
||||
if (memcmp(SUBTAG, eventData, strlen(SUBTAG))) {
|
||||
|
@ -2114,7 +2144,6 @@ TEST(liblog, android_errorWriteLog__android_logger_list_read__null_subtag) {
|
|||
#endif
|
||||
}
|
||||
|
||||
#ifdef __ANDROID__
|
||||
static int is_real_element(int type) {
|
||||
return ((type == EVENT_TYPE_INT) ||
|
||||
(type == EVENT_TYPE_LONG) ||
|
||||
|
@ -2122,8 +2151,8 @@ static int is_real_element(int type) {
|
|||
(type == EVENT_TYPE_FLOAT));
|
||||
}
|
||||
|
||||
int android_log_buffer_to_string(const char *msg, size_t len,
|
||||
char *strOut, size_t strOutLen) {
|
||||
static int android_log_buffer_to_string(const char *msg, size_t len,
|
||||
char *strOut, size_t strOutLen) {
|
||||
android_log_context context = create_android_log_parser(msg, len);
|
||||
android_log_list_element elem;
|
||||
bool overflow = false;
|
||||
|
@ -2274,6 +2303,7 @@ int android_log_buffer_to_string(const char *msg, size_t len,
|
|||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __ANDROID__
|
||||
static const char *event_test_int32(uint32_t tag, size_t &expected_len) {
|
||||
android_log_context ctx;
|
||||
|
||||
|
@ -2536,7 +2566,11 @@ static void create_android_logger(const char *(*fn)(uint32_t tag, size_t &expect
|
|||
ASSERT_TRUE(NULL != (logger_list = android_logger_list_open(
|
||||
LOG_ID_EVENTS, ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK, 1000, pid)));
|
||||
|
||||
#ifdef __ANDROID__
|
||||
log_time ts(android_log_clockid());
|
||||
#else
|
||||
log_time ts(CLOCK_REALTIME);
|
||||
#endif
|
||||
|
||||
size_t expected_len;
|
||||
const char *expected_string = (*fn)(1005, expected_len);
|
||||
|
@ -2577,18 +2611,23 @@ static void create_android_logger(const char *(*fn)(uint32_t tag, size_t &expect
|
|||
&log_msg.entry_v1, &entry, NULL, msgBuf, sizeof(msgBuf));
|
||||
EXPECT_EQ(0, processBinaryLogBuffer);
|
||||
if (processBinaryLogBuffer == 0) {
|
||||
int line_overhead = 20;
|
||||
if (pid > 99999) ++line_overhead;
|
||||
if (pid > 999999) ++line_overhead;
|
||||
print_barrier();
|
||||
int printLogLine = android_log_printLogLine(
|
||||
logformat, fileno(stderr), &entry);
|
||||
print_barrier();
|
||||
EXPECT_EQ(20 + (int)strlen(expected_string), printLogLine);
|
||||
EXPECT_EQ(line_overhead + (int)strlen(expected_string),
|
||||
printLogLine);
|
||||
}
|
||||
android_log_format_free(logformat);
|
||||
|
||||
// test buffer reading API
|
||||
int buffer_to_string = -1;
|
||||
if (eventData) {
|
||||
snprintf(msgBuf, sizeof(msgBuf), "I/[%d]", get4LE(eventData));
|
||||
snprintf(msgBuf, sizeof(msgBuf),
|
||||
"I/[%" PRIu32 "]", get4LE(eventData));
|
||||
print_barrier();
|
||||
fprintf(stderr, "%-10s(%5u): ", msgBuf, pid);
|
||||
memset(msgBuf, 0, sizeof(msgBuf));
|
||||
|
@ -2691,7 +2730,6 @@ TEST(liblog, create_android_logger_android_log_error_write_null) {
|
|||
}
|
||||
|
||||
TEST(liblog, create_android_logger_overflow) {
|
||||
#ifdef __ANDROID__
|
||||
android_log_context ctx;
|
||||
|
||||
EXPECT_TRUE(NULL != (ctx = create_android_logger(1005)));
|
||||
|
@ -2716,13 +2754,9 @@ TEST(liblog, create_android_logger_overflow) {
|
|||
EXPECT_GT(0, android_log_write_list_begin(ctx));
|
||||
EXPECT_LE(0, android_log_destroy(&ctx));
|
||||
ASSERT_TRUE(NULL == ctx);
|
||||
#else
|
||||
GTEST_LOG_(INFO) << "This test does nothing.\n";
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(liblog, android_log_write_list_buffer) {
|
||||
#ifdef __ANDROID__
|
||||
__android_log_event_list ctx(1005);
|
||||
ctx << 1005 << "tag_def" << "(tag|1),(name|3),(format|3)";
|
||||
std::string buffer(ctx);
|
||||
|
@ -2733,9 +2767,6 @@ TEST(liblog, android_log_write_list_buffer) {
|
|||
EXPECT_EQ(android_log_buffer_to_string(buffer.data(), buffer.length(),
|
||||
msgBuf, sizeof(msgBuf)), 0);
|
||||
EXPECT_STREQ(msgBuf, "[1005,tag_def,(tag|1),(name|3),(format|3)]");
|
||||
#else
|
||||
GTEST_LOG_(INFO) << "This test does nothing.\n";
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef __ANDROID__
|
||||
|
@ -2800,8 +2831,8 @@ TEST(liblog, __android_log_pmsg_file_write) {
|
|||
}
|
||||
|
||||
#ifdef __ANDROID__
|
||||
ssize_t __pmsg_fn(log_id_t logId, char prio, const char *filename,
|
||||
const char *buf, size_t len, void *arg) {
|
||||
static ssize_t __pmsg_fn(log_id_t logId, char prio, const char *filename,
|
||||
const char *buf, size_t len, void *arg) {
|
||||
EXPECT_TRUE(NULL == arg);
|
||||
EXPECT_EQ(LOG_ID_CRASH, logId);
|
||||
EXPECT_EQ(ANDROID_LOG_VERBOSE, prio);
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
#endif
|
||||
|
||||
TEST(liblog, log_id) {
|
||||
#ifdef __ANDROID__
|
||||
int count = 0;
|
||||
|
||||
for(int i = LOG_ID_MIN; i < LOG_ID_MAX; ++i) {
|
||||
|
@ -44,13 +43,9 @@ TEST(liblog, log_id) {
|
|||
fprintf(stderr, "log buffer %s\r", name);
|
||||
}
|
||||
ASSERT_EQ(LOG_ID_MAX, count);
|
||||
#else
|
||||
GTEST_LOG_(INFO) << "This test does nothing.\n";
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(liblog, __android_log_buf_print) {
|
||||
#ifdef __ANDROID__
|
||||
EXPECT_LT(0, __android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_INFO,
|
||||
"TEST__android_log_buf_print",
|
||||
"radio"));
|
||||
|
@ -63,13 +58,9 @@ TEST(liblog, __android_log_buf_print) {
|
|||
"TEST__android_log_buf_print",
|
||||
"main"));
|
||||
usleep(1000);
|
||||
#else
|
||||
GTEST_LOG_(INFO) << "This test does nothing.\n";
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(liblog, __android_log_buf_write) {
|
||||
#ifdef __ANDROID__
|
||||
EXPECT_LT(0, __android_log_buf_write(LOG_ID_RADIO, ANDROID_LOG_INFO,
|
||||
"TEST__android_log_buf_write",
|
||||
"radio"));
|
||||
|
@ -82,26 +73,20 @@ TEST(liblog, __android_log_buf_write) {
|
|||
"TEST__android_log_buf_write",
|
||||
"main"));
|
||||
usleep(1000);
|
||||
#else
|
||||
GTEST_LOG_(INFO) << "This test does nothing.\n";
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef __ANDROID__
|
||||
static void* ConcurrentPrintFn(void *arg) {
|
||||
int ret = __android_log_buf_print(LOG_ID_MAIN, ANDROID_LOG_INFO,
|
||||
"TEST__android_log_print", "Concurrent %" PRIuPTR,
|
||||
reinterpret_cast<uintptr_t>(arg));
|
||||
return reinterpret_cast<void*>(ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
#define NUM_CONCURRENT 64
|
||||
#define _concurrent_name(a,n) a##__concurrent##n
|
||||
#define concurrent_name(a,n) _concurrent_name(a,n)
|
||||
|
||||
TEST(liblog, concurrent_name(__android_log_buf_print, NUM_CONCURRENT)) {
|
||||
#ifdef __ANDROID__
|
||||
pthread_t t[NUM_CONCURRENT];
|
||||
int i;
|
||||
for (i=0; i < NUM_CONCURRENT; i++) {
|
||||
|
@ -119,7 +104,4 @@ TEST(liblog, concurrent_name(__android_log_buf_print, NUM_CONCURRENT)) {
|
|||
}
|
||||
}
|
||||
ASSERT_LT(0, ret);
|
||||
#else
|
||||
GTEST_LOG_(INFO) << "This test does nothing.\n";
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
#include <log/log_radio.h>
|
||||
|
||||
TEST(liblog, RLOG) {
|
||||
#ifdef __ANDROID__
|
||||
static const char content[] = "log_radio.h";
|
||||
static const char content_false[] = "log_radio.h false";
|
||||
|
||||
|
@ -84,6 +83,7 @@ TEST(liblog, RLOG) {
|
|||
usleep(100000);
|
||||
RLOGE_IF(false, content_false);
|
||||
|
||||
#ifdef __ANDROID__
|
||||
// give time for content to long-path through logger
|
||||
sleep(1);
|
||||
|
||||
|
@ -112,6 +112,6 @@ TEST(liblog, RLOG) {
|
|||
#endif
|
||||
|
||||
#else
|
||||
GTEST_LOG_(INFO) << "This test does nothing.\n";
|
||||
GTEST_LOG_(INFO) << "This test does not test end-to-end.\n";
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
#include <log/log_system.h>
|
||||
|
||||
TEST(liblog, SLOG) {
|
||||
#ifdef __ANDROID__
|
||||
static const char content[] = "log_system.h";
|
||||
static const char content_false[] = "log_system.h false";
|
||||
|
||||
|
@ -84,6 +83,7 @@ TEST(liblog, SLOG) {
|
|||
usleep(100000);
|
||||
SLOGE_IF(false, content_false);
|
||||
|
||||
#ifdef __ANDROID__
|
||||
// give time for content to long-path through logger
|
||||
sleep(1);
|
||||
|
||||
|
@ -112,6 +112,6 @@ TEST(liblog, SLOG) {
|
|||
#endif
|
||||
|
||||
#else
|
||||
GTEST_LOG_(INFO) << "This test does nothing.\n";
|
||||
GTEST_LOG_(INFO) << "This test does not test end-to-end.\n";
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -21,8 +21,6 @@
|
|||
#include <log/log_time.h>
|
||||
|
||||
TEST(liblog, log_time) {
|
||||
#ifdef __ANDROID__
|
||||
|
||||
#ifdef _SYSTEM_CORE_INCLUDE_PRIVATE_ANDROID_LOGGER_H_
|
||||
log_time(CLOCK_MONOTONIC);
|
||||
|
||||
|
@ -36,8 +34,4 @@ TEST(liblog, log_time) {
|
|||
EXPECT_EQ(tl, ts);
|
||||
EXPECT_GE(tl, ts);
|
||||
EXPECT_LE(tl, ts);
|
||||
|
||||
#else
|
||||
GTEST_LOG_(INFO) << "This test does nothing.\n";
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue