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
diff --git a/liblog/Android.bp b/liblog/Android.bp
index 747fcc8..cd67845 100644
--- a/liblog/Android.bp
+++ b/liblog/Android.bp
@@ -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 @@
"config_read.c",
"log_time.cpp",
"properties.c",
- "logprint.c",
"pmsg_reader.c",
"pmsg_writer.c",
"logd_reader.c",
diff --git a/liblog/fake_log_device.c b/liblog/fake_log_device.c
index 957129e..1d7a157 100644
--- a/liblog/fake_log_device.c
+++ b/liblog/fake_log_device.c
@@ -612,7 +612,12 @@
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;
diff --git a/liblog/fake_writer.c b/liblog/fake_writer.c
index dab8bc5..2350673 100644
--- a/liblog/fake_writer.c
+++ b/liblog/fake_writer.c
@@ -46,9 +46,19 @@
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 @@
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;
diff --git a/liblog/include/log/log_radio.h b/liblog/include/log/log_radio.h
index 30a73f2..430e522 100644
--- a/liblog/include/log/log_radio.h
+++ b/liblog/include/log/log_radio.h
@@ -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.
*/
diff --git a/liblog/include/log/log_read.h b/liblog/include/log/log_read.h
index 5b5eebc..6a44b56 100644
--- a/liblog/include/log/log_read.h
+++ b/liblog/include/log/log_read.h
@@ -251,7 +251,11 @@
#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 */
diff --git a/liblog/include/log/log_system.h b/liblog/include/log/log_system.h
index 8c1ec96..394a106 100644
--- a/liblog/include/log/log_system.h
+++ b/liblog/include/log/log_system.h
@@ -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.
*/
diff --git a/liblog/logprint.c b/liblog/logprint.c
index 18af9de..e61850d 100644
--- a/liblog/logprint.c
+++ b/liblog/logprint.c
@@ -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 @@
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 @@
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 @@
}
free(cp);
}
+#endif
return format;
}
@@ -411,7 +428,7 @@
/*
* 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 @@
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 @@
* Assumes single threaded execution
*
*/
-
LIBLOG_ABI_PUBLIC int android_log_addFilterString(
AndroidLogFormat *p_format,
const char *filterString)
@@ -728,6 +765,7 @@
}
}
}
+ outCount = 0;
lval = 0;
switch (type) {
case EVENT_TYPE_INT:
@@ -953,7 +991,7 @@
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 @@
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 @@
*/
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 @@
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 @@
result->tv_nsec = entry->tv_nsec;
subTimespec(result, result, &convert);
}
+#endif
/**
* Formats a log message into a buffer
@@ -1529,6 +1572,7 @@
*/
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 @@
nsec = time.tv_nsec;
}
}
+#endif
if (now < 0) {
nsec = NS_PER_SEC - nsec;
}
@@ -1591,13 +1636,18 @@
* 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);
}
diff --git a/liblog/tests/Android.mk b/liblog/tests/Android.mk
index 097befc..7343412 100644
--- a/liblog/tests/Android.mk
+++ b/liblog/tests/Android.mk
@@ -111,6 +111,7 @@
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))
diff --git a/liblog/tests/liblog_test.cpp b/liblog/tests/liblog_test.cpp
index 379fe47..346314c 100644
--- a/liblog/tests/liblog_test.cpp
+++ b/liblog/tests/liblog_test.cpp
@@ -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 @@
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 @@
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 @@
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 @@
}
#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 @@
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 @@
&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 @@
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 @@
&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 @@
return NULL;
}
-int start_thread()
+static int start_thread()
{
sem_init(&thread_trigger, 0, 0);
@@ -1022,7 +1035,11 @@
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 @@
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, 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 @@
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 @@
#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 @@
}
#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 @@
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 @@
sleep(2);
- count = 0;
-
for (;;) {
log_msg log_msg;
if (android_logger_list_read(logger_list, &log_msg) <= 0) {
@@ -1909,7 +1939,7 @@
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 @@
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 @@
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 @@
sleep(2);
- count = 0;
-
for (;;) {
log_msg log_msg;
if (android_logger_list_read(logger_list, &log_msg) <= 0) {
@@ -2081,7 +2111,7 @@
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 @@
#endif
}
-#ifdef __ANDROID__
static int is_real_element(int type) {
return ((type == EVENT_TYPE_INT) ||
(type == EVENT_TYPE_LONG) ||
@@ -2122,8 +2151,8 @@
(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 @@
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 @@
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 @@
&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_overflow) {
-#ifdef __ANDROID__
android_log_context ctx;
EXPECT_TRUE(NULL != (ctx = create_android_logger(1005)));
@@ -2716,13 +2754,9 @@
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 @@
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 @@
}
#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);
diff --git a/liblog/tests/log_id_test.cpp b/liblog/tests/log_id_test.cpp
index 3241534..b8223f1 100644
--- a/liblog/tests/log_id_test.cpp
+++ b/liblog/tests/log_id_test.cpp
@@ -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 @@
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__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__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 @@
}
}
ASSERT_LT(0, ret);
-#else
- GTEST_LOG_(INFO) << "This test does nothing.\n";
-#endif
}
diff --git a/liblog/tests/log_radio_test.cpp b/liblog/tests/log_radio_test.cpp
index 591748a..ecba777 100644
--- a/liblog/tests/log_radio_test.cpp
+++ b/liblog/tests/log_radio_test.cpp
@@ -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 @@
usleep(100000);
RLOGE_IF(false, content_false);
+#ifdef __ANDROID__
// give time for content to long-path through logger
sleep(1);
@@ -112,6 +112,6 @@
#endif
#else
- GTEST_LOG_(INFO) << "This test does nothing.\n";
+ GTEST_LOG_(INFO) << "This test does not test end-to-end.\n";
#endif
}
diff --git a/liblog/tests/log_system_test.cpp b/liblog/tests/log_system_test.cpp
index b62832e..40e3a63 100644
--- a/liblog/tests/log_system_test.cpp
+++ b/liblog/tests/log_system_test.cpp
@@ -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 @@
usleep(100000);
SLOGE_IF(false, content_false);
+#ifdef __ANDROID__
// give time for content to long-path through logger
sleep(1);
@@ -112,6 +112,6 @@
#endif
#else
- GTEST_LOG_(INFO) << "This test does nothing.\n";
+ GTEST_LOG_(INFO) << "This test does not test end-to-end.\n";
#endif
}
diff --git a/liblog/tests/log_time_test.cpp b/liblog/tests/log_time_test.cpp
index f2601b6..59655ba 100644
--- a/liblog/tests/log_time_test.cpp
+++ b/liblog/tests/log_time_test.cpp
@@ -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 @@
EXPECT_EQ(tl, ts);
EXPECT_GE(tl, ts);
EXPECT_LE(tl, ts);
-
-#else
- GTEST_LOG_(INFO) << "This test does nothing.\n";
-#endif
}