Merge changes Ieea7af39,Ic3755d1c,Ifad24b27,I3b33f2b8
* changes:
liblog: remove endianness functions
liblog: remove unused test #defines and transport code
liblog: remove stderr logger
liblog: add -Wall,-Wextra and do related clean-up.
diff --git a/liblog/Android.bp b/liblog/Android.bp
index c38d8cd..8a63007 100644
--- a/liblog/Android.bp
+++ b/liblog/Android.bp
@@ -23,7 +23,6 @@
"logger_read.cpp",
"logger_write.cpp",
"logprint.cpp",
- "stderr_write.cpp",
]
liblog_host_sources = [
"fake_log_device.cpp",
@@ -108,7 +107,9 @@
},
cflags: [
+ "-Wall",
"-Werror",
+ "-Wextra",
// This is what we want to do:
// liblog_cflags := $(shell \
// sed -n \
diff --git a/liblog/config_write.cpp b/liblog/config_write.cpp
index d454379..6ed893d 100644
--- a/liblog/config_write.cpp
+++ b/liblog/config_write.cpp
@@ -66,27 +66,6 @@
__android_log_add_transport(&__android_log_transport_write, &fakeLoggerWrite);
#endif
}
-
- if (__android_log_transport & LOGGER_STDERR) {
- extern struct android_log_transport_write stderrLoggerWrite;
-
- /*
- * stderr logger should be primary if we can be the only one, or if
- * already in the primary list. Otherwise land in the persist list.
- * Remember we can be called here if we are already initialized.
- */
- if (list_empty(&__android_log_transport_write)) {
- __android_log_add_transport(&__android_log_transport_write, &stderrLoggerWrite);
- } else {
- struct android_log_transport_write* transp;
- write_transport_for_each(transp, &__android_log_transport_write) {
- if (transp == &stderrLoggerWrite) {
- return;
- }
- }
- __android_log_add_transport(&__android_log_persist_write, &stderrLoggerWrite);
- }
- }
}
void __android_log_config_write_close() {
diff --git a/liblog/include/log/log_transport.h b/liblog/include/log/log_transport.h
index b48761a..bda7c25 100644
--- a/liblog/include/log/log_transport.h
+++ b/liblog/include/log/log_transport.h
@@ -22,7 +22,7 @@
#define LOGGER_KERNEL 0x02 /* Reserved/Deprecated */
#define LOGGER_NULL 0x04 /* Does not release resources of other selections */
#define LOGGER_RESERVED 0x08 /* Reserved, previously for logging to local memory */
-#define LOGGER_STDERR 0x10 /* logs sent to stderr */
+#define LOGGER_RESERVED2 0x10 /* Reserved, previously for logs sent to stderr */
/* clang-format on */
/* Both return the selected transport flag mask, or negative errno */
diff --git a/liblog/log_event_list.cpp b/liblog/log_event_list.cpp
index b1b527c..f148ef3 100644
--- a/liblog/log_event_list.cpp
+++ b/liblog/log_event_list.cpp
@@ -88,7 +88,6 @@
android_log_context create_android_log_parser(const char* msg, size_t len) {
android_log_context_internal* context;
- size_t i;
context =
static_cast<android_log_context_internal*>(calloc(1, sizeof(android_log_context_internal)));
@@ -401,22 +400,6 @@
}
/*
- * Extract a 4-byte value from a byte stream.
- */
-static inline uint32_t get4LE(const uint8_t* src) {
- return src[0] | (src[1] << 8) | (src[2] << 16) | (src[3] << 24);
-}
-
-/*
- * Extract an 8-byte value from a byte stream.
- */
-static inline uint64_t get8LE(const uint8_t* src) {
- uint32_t low = src[0] | (src[1] << 8) | (src[2] << 16) | (src[3] << 24);
- uint32_t high = src[4] | (src[5] << 8) | (src[6] << 16) | (src[7] << 24);
- return ((uint64_t)high << 32) | (uint64_t)low;
-}
-
-/*
* Gets the next element. Parsing errors result in an EVENT_TYPE_UNKNOWN type.
* If there is nothing to process, the complete field is set to non-zero. If
* an EVENT_TYPE_UNKNOWN type is returned once, and the caller does not check
@@ -489,7 +472,7 @@
elem.type = EVENT_TYPE_UNKNOWN;
return elem;
}
- elem.data.int32 = get4LE(&context->storage[pos]);
+ elem.data.int32 = *reinterpret_cast<int32_t*>(&context->storage[pos]);
/* common tangeable object suffix */
pos += elem.len;
elem.complete = !context->list_nest_depth && !context->count[0];
@@ -508,7 +491,7 @@
elem.type = EVENT_TYPE_UNKNOWN;
return elem;
}
- elem.data.int64 = get8LE(&context->storage[pos]);
+ elem.data.int64 = *reinterpret_cast<int64_t*>(&context->storage[pos]);
/* common tangeable object suffix */
pos += elem.len;
elem.complete = !context->list_nest_depth && !context->count[0];
@@ -527,7 +510,7 @@
elem.complete = true;
return elem;
}
- elem.len = get4LE(&context->storage[pos]);
+ elem.len = *reinterpret_cast<int32_t*>(&context->storage[pos]);
pos += sizeof(int32_t);
if ((pos + elem.len) > context->len) {
elem.len = context->len - pos; /* truncate string */
diff --git a/liblog/logd_reader.cpp b/liblog/logd_reader.cpp
index eba305f..d5bf844 100644
--- a/liblog/logd_reader.cpp
+++ b/liblog/logd_reader.cpp
@@ -14,7 +14,6 @@
* limitations under the License.
*/
-#include <endian.h>
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
diff --git a/liblog/logd_writer.cpp b/liblog/logd_writer.cpp
index c3f72f4..2c64b0b 100644
--- a/liblog/logd_writer.cpp
+++ b/liblog/logd_writer.cpp
@@ -14,7 +14,6 @@
* limitations under the License.
*/
-#include <endian.h>
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
@@ -184,9 +183,9 @@
android_log_event_int_t buffer;
header.id = LOG_ID_SECURITY;
- buffer.header.tag = htole32(LIBLOG_LOG_TAG);
+ buffer.header.tag = LIBLOG_LOG_TAG;
buffer.payload.type = EVENT_TYPE_INT;
- buffer.payload.data = htole32(snapshot);
+ buffer.payload.data = snapshot;
newVec[headerLength].iov_base = &buffer;
newVec[headerLength].iov_len = sizeof(buffer);
@@ -202,9 +201,9 @@
android_log_event_int_t buffer;
header.id = LOG_ID_EVENTS;
- buffer.header.tag = htole32(LIBLOG_LOG_TAG);
+ buffer.header.tag = LIBLOG_LOG_TAG;
buffer.payload.type = EVENT_TYPE_INT;
- buffer.payload.data = htole32(snapshot);
+ buffer.payload.data = snapshot;
newVec[headerLength].iov_base = &buffer;
newVec[headerLength].iov_len = sizeof(buffer);
diff --git a/liblog/logger_write.cpp b/liblog/logger_write.cpp
index 4fbab4b..7fc8747 100644
--- a/liblog/logger_write.cpp
+++ b/liblog/logger_write.cpp
@@ -39,13 +39,6 @@
static int __write_to_log_init(log_id_t, struct iovec* vec, size_t nr);
static int (*write_to_log)(log_id_t, struct iovec* vec, size_t nr) = __write_to_log_init;
-/*
- * This is used by the C++ code to decide if it should write logs through
- * the C code. Basically, if /dev/socket/logd is available, we're running in
- * the simulator rather than a desktop tool and want to use the device.
- */
-static enum { kLogUninitialized, kLogNotAvailable, kLogAvailable } g_log_status = kLogUninitialized;
-
static int check_log_uid_permissions() {
#if defined(__ANDROID__)
uid_t uid = __android_log_uid();
@@ -104,22 +97,6 @@
}
}
-extern "C" int __android_log_dev_available() {
- struct android_log_transport_write* node;
-
- if (list_empty(&__android_log_transport_write)) {
- return kLogUninitialized;
- }
-
- write_transport_for_each(node, &__android_log_transport_write) {
- __android_log_cache_available(node);
- if (node->logMask) {
- return kLogAvailable;
- }
- }
- return kLogNotAvailable;
-}
-
#if defined(__ANDROID__)
static atomic_uintptr_t tagMap;
#endif
@@ -228,13 +205,6 @@
return ret;
}
-/*
- * Extract a 4-byte value from a byte stream. le32toh open coded
- */
-static inline uint32_t get4LE(const uint8_t* src) {
- return src[0] | (src[1] << 8) | (src[2] << 16) | (src[3] << 24);
-}
-
static int __write_to_log_daemon(log_id_t log_id, struct iovec* vec, size_t nr) {
struct android_log_transport_write* node;
int ret, save_errno;
@@ -302,7 +272,7 @@
}
}
if (m && (m != (EventTagMap*)(uintptr_t)-1LL)) {
- tag = android_lookupEventTag_len(m, &len, get4LE(static_cast<uint8_t*>(vec[0].iov_base)));
+ tag = android_lookupEventTag_len(m, &len, *static_cast<uint32_t*>(vec[0].iov_base));
}
ret = __android_log_is_loggable_len(ANDROID_LOG_INFO, tag, len, ANDROID_LOG_VERBOSE);
if (f) { /* local copy marked for close */
@@ -616,9 +586,9 @@
return retval;
}
- __android_log_transport &= LOGGER_LOGD | LOGGER_STDERR;
+ __android_log_transport &= LOGGER_LOGD;
- transport_flag &= LOGGER_LOGD | LOGGER_STDERR;
+ transport_flag &= LOGGER_LOGD;
if (__android_log_transport != transport_flag) {
__android_log_transport = transport_flag;
@@ -644,7 +614,7 @@
if (write_to_log == __write_to_log_null) {
ret = LOGGER_NULL;
} else {
- __android_log_transport &= LOGGER_LOGD | LOGGER_STDERR;
+ __android_log_transport &= LOGGER_LOGD;
ret = __android_log_transport;
if ((write_to_log != __write_to_log_init) && (write_to_log != __write_to_log_daemon)) {
ret = -EINVAL;
diff --git a/liblog/logprint.cpp b/liblog/logprint.cpp
index 3a54445..dd2c797 100644
--- a/liblog/logprint.cpp
+++ b/liblog/logprint.cpp
@@ -291,8 +291,10 @@
return 1;
}
+#ifndef __MINGW32__
static const char tz[] = "TZ";
static const char utc[] = "UTC";
+#endif
/**
* Returns FORMAT_OFF on invalid string
@@ -580,24 +582,6 @@
return 0;
}
-/*
- * Extract a 4-byte value from a byte stream.
- */
-static inline uint32_t get4LE(const uint8_t* src) {
- return src[0] | (src[1] << 8) | (src[2] << 16) | (src[3] << 24);
-}
-
-/*
- * Extract an 8-byte value from a byte stream.
- */
-static inline uint64_t get8LE(const uint8_t* src) {
- uint32_t low, high;
-
- low = src[0] | (src[1] << 8) | (src[2] << 16) | (src[3] << 24);
- high = src[4] | (src[5] << 8) | (src[6] << 16) | (src[7] << 24);
- return ((uint64_t)high << 32) | (uint64_t)low;
-}
-
static bool findChar(const char** cp, size_t* len, int c) {
while ((*len) && isspace(*(*cp))) {
++(*cp);
@@ -744,7 +728,7 @@
int32_t ival;
if (eventDataLen < 4) return -1;
- ival = get4LE(eventData);
+ ival = *reinterpret_cast<const int32_t*>(eventData);
eventData += 4;
eventDataLen -= 4;
@@ -754,7 +738,7 @@
case EVENT_TYPE_LONG:
/* 64-bit signed long */
if (eventDataLen < 8) return -1;
- lval = get8LE(eventData);
+ lval = *reinterpret_cast<const int64_t*>(eventData);
eventData += 8;
eventDataLen -= 8;
pr_lval:
@@ -774,7 +758,7 @@
float fval;
if (eventDataLen < 4) return -1;
- ival = get4LE(eventData);
+ ival = *reinterpret_cast<const uint32_t*>(eventData);
fval = *(float*)&ival;
eventData += 4;
eventDataLen -= 4;
@@ -795,7 +779,7 @@
unsigned int strLen;
if (eventDataLen < 4) return -1;
- strLen = get4LE(eventData);
+ strLen = *reinterpret_cast<const uint32_t*>(eventData);
eventData += 4;
eventDataLen -= 4;
@@ -1034,7 +1018,7 @@
}
inCount = buf->len;
if (inCount < 4) return -1;
- tagIndex = get4LE(eventData);
+ tagIndex = *reinterpret_cast<const uint32_t*>(eventData);
eventData += 4;
inCount -= 4;
@@ -1189,6 +1173,7 @@
return p - begin;
}
+#ifdef __ANDROID__
static char* readSeconds(char* e, struct timespec* t) {
unsigned long multiplier;
char* p;
@@ -1229,7 +1214,6 @@
return (long long)now->tv_sec * NS_PER_SEC + now->tv_nsec;
}
-#ifdef __ANDROID__
static void convertMonotonic(struct timespec* result, const AndroidLogEntry* entry) {
struct listnode* node;
struct conversionList {
diff --git a/liblog/pmsg_reader.cpp b/liblog/pmsg_reader.cpp
index 81563bc..005fec8 100644
--- a/liblog/pmsg_reader.cpp
+++ b/liblog/pmsg_reader.cpp
@@ -130,7 +130,6 @@
ssize_t ret;
off_t current, next;
uid_t uid;
- struct android_log_logger* logger;
struct __attribute__((__packed__)) {
android_pmsg_log_header_t p;
android_log_header_t l;
diff --git a/liblog/pmsg_writer.cpp b/liblog/pmsg_writer.cpp
index 4632b32..69720ed 100644
--- a/liblog/pmsg_writer.cpp
+++ b/liblog/pmsg_writer.cpp
@@ -87,13 +87,6 @@
return 1;
}
-/*
- * Extract a 4-byte value from a byte stream.
- */
-static inline uint32_t get4LE(const uint8_t* src) {
- return src[0] | (src[1] << 8) | (src[2] << 16) | (src[3] << 24);
-}
-
static int pmsgWrite(log_id_t logId, struct timespec* ts, struct iovec* vec, size_t nr) {
static const unsigned headerLength = 2;
struct iovec newVec[nr + headerLength];
@@ -107,7 +100,7 @@
return -EINVAL;
}
- if (SNET_EVENT_LOG_TAG != get4LE(static_cast<uint8_t*>(vec[0].iov_base))) {
+ if (SNET_EVENT_LOG_TAG != *static_cast<uint8_t*>(vec[0].iov_base)) {
return -EPERM;
}
}
diff --git a/liblog/stderr_write.cpp b/liblog/stderr_write.cpp
deleted file mode 100644
index e76673f..0000000
--- a/liblog/stderr_write.cpp
+++ /dev/null
@@ -1,209 +0,0 @@
-/*
- * Copyright (C) 2017 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.
- */
-
-/*
- * stderr write handler. Output is logcat-like, and responds to
- * logcat's environment variables ANDROID_PRINTF_LOG and
- * ANDROID_LOG_TAGS to filter output.
- *
- * This transport only provides a writer, that means that it does not
- * provide an End-To-End capability as the logs are effectively _lost_
- * to the stderr file stream. The purpose of this transport is to
- * supply a means for command line tools to report their logging
- * to the stderr stream, in line with all other activities.
- */
-
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#include <log/event_tag_map.h>
-#include <log/log.h>
-#include <log/logprint.h>
-
-#include "log_portability.h"
-#include "logger.h"
-#include "uio.h"
-
-static int stderrOpen();
-static void stderrClose();
-static int stderrAvailable(log_id_t logId);
-static int stderrWrite(log_id_t logId, struct timespec* ts, struct iovec* vec, size_t nr);
-
-struct stderrContext {
- AndroidLogFormat* logformat;
-#if defined(__ANDROID__)
- EventTagMap* eventTagMap;
-#endif
-};
-
-struct android_log_transport_write stderrLoggerWrite = {
- .node = {&stderrLoggerWrite.node, &stderrLoggerWrite.node},
- .context.priv = NULL,
- .name = "stderr",
- .available = stderrAvailable,
- .open = stderrOpen,
- .close = stderrClose,
- .write = stderrWrite,
-};
-
-static int stderrOpen() {
- struct stderrContext* ctx;
- const char* envStr;
- bool setFormat;
-
- if (!stderr || (fileno(stderr) < 0)) {
- return -EBADF;
- }
-
- if (stderrLoggerWrite.context.priv) {
- return fileno(stderr);
- }
-
- ctx = static_cast<stderrContext*>(calloc(1, sizeof(stderrContext)));
- if (!ctx) {
- return -ENOMEM;
- }
-
- ctx->logformat = android_log_format_new();
- if (!ctx->logformat) {
- free(ctx);
- return -ENOMEM;
- }
-
- envStr = getenv("ANDROID_PRINTF_LOG");
- setFormat = false;
-
- if (envStr) {
- char* formats = strdup(envStr);
- char* sv = NULL;
- char* arg = formats;
- while (!!(arg = strtok_r(arg, ",:; \t\n\r\f", &sv))) {
- AndroidLogPrintFormat format = android_log_formatFromString(arg);
- arg = NULL;
- if (format == FORMAT_OFF) {
- continue;
- }
- if (android_log_setPrintFormat(ctx->logformat, format) <= 0) {
- continue;
- }
- setFormat = true;
- }
- free(formats);
- }
- if (!setFormat) {
- AndroidLogPrintFormat format = android_log_formatFromString("threadtime");
- android_log_setPrintFormat(ctx->logformat, format);
- }
- envStr = getenv("ANDROID_LOG_TAGS");
- if (envStr) {
- android_log_addFilterString(ctx->logformat, envStr);
- }
- stderrLoggerWrite.context.priv = ctx;
-
- return fileno(stderr);
-}
-
-static void stderrClose() {
- stderrContext* ctx = static_cast<stderrContext*>(stderrLoggerWrite.context.priv);
-
- if (ctx) {
- stderrLoggerWrite.context.priv = NULL;
- if (ctx->logformat) {
- android_log_format_free(ctx->logformat);
- ctx->logformat = NULL;
- }
-#if defined(__ANDROID__)
- if (ctx->eventTagMap) {
- android_closeEventTagMap(ctx->eventTagMap);
- ctx->eventTagMap = NULL;
- }
-#endif
- }
-}
-
-static int stderrAvailable(log_id_t logId) {
- if ((logId >= LOG_ID_MAX) || (logId == LOG_ID_KERNEL)) {
- return -EINVAL;
- }
- return 1;
-}
-
-static int stderrWrite(log_id_t logId, struct timespec* ts, struct iovec* vec, size_t nr) {
- struct log_msg log_msg;
- AndroidLogEntry entry;
- char binaryMsgBuf[1024];
- int err;
- size_t i;
- stderrContext* ctx = static_cast<stderrContext*>(stderrLoggerWrite.context.priv);
-
- if (!ctx) return -EBADF;
- if (!vec || !nr) return -EINVAL;
-
- log_msg.entry.len = 0;
- log_msg.entry.hdr_size = sizeof(log_msg.entry);
- log_msg.entry.pid = getpid();
-#ifdef __BIONIC__
- log_msg.entry.tid = gettid();
-#else
- log_msg.entry.tid = getpid();
-#endif
- log_msg.entry.sec = ts->tv_sec;
- log_msg.entry.nsec = ts->tv_nsec;
- log_msg.entry.lid = logId;
- log_msg.entry.uid = __android_log_uid();
-
- for (i = 0; i < nr; ++i) {
- size_t len = vec[i].iov_len;
- if ((log_msg.entry.len + len) > LOGGER_ENTRY_MAX_PAYLOAD) {
- len = LOGGER_ENTRY_MAX_PAYLOAD - log_msg.entry.len;
- }
- if (!len) continue;
- memcpy(log_msg.entry.msg + log_msg.entry.len, vec[i].iov_base, len);
- log_msg.entry.len += len;
- }
-
- if ((logId == LOG_ID_EVENTS) || (logId == LOG_ID_SECURITY)) {
-#if defined(__ANDROID__)
- if (!ctx->eventTagMap) {
- ctx->eventTagMap = android_openEventTagMap(NULL);
- }
-#endif
- err = android_log_processBinaryLogBuffer(&log_msg.entry_v1, &entry,
-#if defined(__ANDROID__)
- ctx->eventTagMap,
-#else
- NULL,
-#endif
- binaryMsgBuf, sizeof(binaryMsgBuf));
- } else {
- err = android_log_processLogBuffer(&log_msg.entry_v1, &entry);
- }
-
- /* print known truncated data, in essence logcat --debug */
- if ((err < 0) && !entry.message) return -EINVAL;
-
- if (!android_log_shouldPrintLine(ctx->logformat, entry.tag, entry.priority)) {
- return log_msg.entry.len;
- }
-
- err = android_log_printLogLine(ctx->logformat, fileno(stderr), &entry);
- if (err < 0) return errno ? -errno : -EINVAL;
- return log_msg.entry.len;
-}
diff --git a/liblog/tests/Android.bp b/liblog/tests/Android.bp
index d9d1a21..45f09f2 100644
--- a/liblog/tests/Android.bp
+++ b/liblog/tests/Android.bp
@@ -54,8 +54,7 @@
],
srcs: [
"libc_test.cpp",
- "liblog_test_default.cpp",
- "liblog_test_stderr.cpp",
+ "liblog_test.cpp",
"log_id_test.cpp",
"log_radio_test.cpp",
"log_read_test.cpp",
diff --git a/liblog/tests/liblog_benchmark.cpp b/liblog/tests/liblog_benchmark.cpp
index 21d12a1..7163743 100644
--- a/liblog/tests/liblog_benchmark.cpp
+++ b/liblog/tests/liblog_benchmark.cpp
@@ -17,7 +17,6 @@
#include <fcntl.h>
#include <inttypes.h>
#include <poll.h>
-#include <sys/endian.h>
#include <sys/socket.h>
#include <sys/syscall.h>
#include <sys/types.h>
@@ -227,14 +226,14 @@
buffer.header.tag = 0;
buffer.payload.type = EVENT_TYPE_INT;
uint32_t snapshot = 0;
- buffer.payload.data = htole32(snapshot);
+ buffer.payload.data = snapshot;
newVec[2].iov_base = &buffer;
newVec[2].iov_len = sizeof(buffer);
while (state.KeepRunning()) {
++snapshot;
- buffer.payload.data = htole32(snapshot);
+ buffer.payload.data = snapshot;
writev(pstore_fd, newVec, nr);
}
state.PauseTiming();
@@ -303,11 +302,11 @@
buffer->payload.header.tag = 0;
buffer->payload.payload.type = EVENT_TYPE_INT;
uint32_t snapshot = 0;
- buffer->payload.payload.data = htole32(snapshot);
+ buffer->payload.payload.data = snapshot;
while (state.KeepRunning()) {
++snapshot;
- buffer->payload.payload.data = htole32(snapshot);
+ buffer->payload.payload.data = snapshot;
write(pstore_fd, &buffer->pmsg_header,
sizeof(android_pmsg_log_header_t) + sizeof(android_log_header_t) +
sizeof(android_log_event_int_t));
@@ -378,11 +377,11 @@
buffer->payload.header.tag = 0;
buffer->payload.payload.type = EVENT_TYPE_INT;
uint32_t snapshot = 0;
- buffer->payload.payload.data = htole32(snapshot);
+ buffer->payload.payload.data = snapshot;
while (state.KeepRunning()) {
++snapshot;
- buffer->payload.payload.data = htole32(snapshot);
+ buffer->payload.payload.data = snapshot;
write(pstore_fd, &buffer->pmsg_header,
sizeof(android_pmsg_log_header_t) + sizeof(android_log_header_t) +
sizeof(android_log_event_int_t));
@@ -453,11 +452,11 @@
buffer->payload.header.tag = 0;
buffer->payload.payload.type = EVENT_TYPE_INT;
uint32_t snapshot = 0;
- buffer->payload.payload.data = htole32(snapshot);
+ buffer->payload.payload.data = snapshot;
while (state.KeepRunning()) {
++snapshot;
- buffer->payload.payload.data = htole32(snapshot);
+ buffer->payload.payload.data = snapshot;
write(pstore_fd, &buffer->pmsg_header, LOGGER_ENTRY_MAX_PAYLOAD);
}
state.PauseTiming();
@@ -526,11 +525,11 @@
buffer->payload.header.tag = 0;
buffer->payload.payload.type = EVENT_TYPE_INT;
uint32_t snapshot = 0;
- buffer->payload.payload.data = htole32(snapshot);
+ buffer->payload.payload.data = snapshot;
while (state.KeepRunning()) {
++snapshot;
- buffer->payload.payload.data = htole32(snapshot);
+ buffer->payload.payload.data = snapshot;
write(pstore_fd, &buffer->pmsg_header, LOGGER_ENTRY_MAX_PAYLOAD);
}
state.PauseTiming();
diff --git a/liblog/tests/liblog_test.cpp b/liblog/tests/liblog_test.cpp
index 5a73dc0..34fb909 100644
--- a/liblog/tests/liblog_test.cpp
+++ b/liblog/tests/liblog_test.cpp
@@ -38,26 +38,10 @@
#include <gtest/gtest.h>
#include <log/log_event_list.h>
#include <log/log_properties.h>
-#include <log/log_transport.h>
#include <log/logprint.h>
#include <private/android_filesystem_config.h>
#include <private/android_logger.h>
-#ifndef TEST_PREFIX
-#ifdef TEST_LOGGER
-#define TEST_PREFIX android_set_log_transport(TEST_LOGGER);
-// make sure we always run code despite overrides if compiled for android
-#elif defined(__ANDROID__)
-#define TEST_PREFIX
-#endif
-#endif
-
-#ifdef USING_LOGGER_STDERR
-#define SUPPORTS_END_TO_END 0
-#else
-#define SUPPORTS_END_TO_END 1
-#endif
-
// enhanced version of LOG_FAILURE_RETRY to add support for EAGAIN and
// non-syscall libs. Since we are only using this in the emergency of
// a signal to stuff a terminating code into the logs, we will spin rather
@@ -73,9 +57,6 @@
})
TEST(liblog, __android_log_btwrite) {
-#ifdef TEST_PREFIX
- TEST_PREFIX
-#endif
int intBuf = 0xDEADBEEF;
EXPECT_LT(0,
__android_log_btwrite(0, EVENT_TYPE_INT, &intBuf, sizeof(intBuf)));
@@ -89,7 +70,7 @@
usleep(1000);
}
-#if (defined(__ANDROID__) && defined(USING_LOGGER_DEFAULT))
+#if defined(__ANDROID__)
static std::string popenToString(const std::string& command) {
std::string ret;
@@ -160,9 +141,6 @@
TEST(liblog, __android_log_btwrite__android_logger_list_read) {
#ifdef __ANDROID__
-#ifdef TEST_PREFIX
- TEST_PREFIX
-#endif
struct logger_list* logger_list;
pid_t pid = getpid();
@@ -174,7 +152,6 @@
log_time ts(CLOCK_MONOTONIC);
EXPECT_LT(0, __android_log_btwrite(0, EVENT_TYPE_LONG, &ts, sizeof(ts)));
-#ifdef USING_LOGGER_DEFAULT
// Check that we can close and reopen the logger
bool logdwActiveAfter__android_log_btwrite;
if (getuid() == AID_ROOT) {
@@ -197,11 +174,9 @@
bool logdwActiveAfter__android_log_close = isLogdwActive();
EXPECT_FALSE(logdwActiveAfter__android_log_close);
}
-#endif
log_time ts1(CLOCK_MONOTONIC);
EXPECT_LT(0, __android_log_btwrite(0, EVENT_TYPE_LONG, &ts1, sizeof(ts1)));
-#ifdef USING_LOGGER_DEFAULT
if (getuid() == AID_ROOT) {
#ifndef NO_PSTORE
bool pmsgActiveAfter__android_log_btwrite = isPmsgActive();
@@ -210,7 +185,6 @@
logdwActiveAfter__android_log_btwrite = isLogdwActive();
EXPECT_TRUE(logdwActiveAfter__android_log_btwrite);
}
-#endif
usleep(1000000);
int count = 0;
@@ -244,8 +218,8 @@
}
}
- EXPECT_EQ(SUPPORTS_END_TO_END, count);
- EXPECT_EQ(SUPPORTS_END_TO_END, second_count);
+ EXPECT_EQ(1, count);
+ EXPECT_EQ(1, second_count);
android_logger_list_close(logger_list);
#else
@@ -253,144 +227,8 @@
#endif
}
-#ifdef __ANDROID__
-static void print_transport(const char* prefix, int logger) {
- static const char orstr[] = " | ";
-
- if (!prefix) {
- prefix = "";
- }
- if (logger < 0) {
- fprintf(stderr, "%s%s\n", prefix, strerror(-logger));
- return;
- }
-
- if (logger == LOGGER_DEFAULT) {
- fprintf(stderr, "%sLOGGER_DEFAULT", prefix);
- prefix = orstr;
- }
- if (logger & LOGGER_LOGD) {
- fprintf(stderr, "%sLOGGER_LOGD", prefix);
- prefix = orstr;
- }
- if (logger & LOGGER_KERNEL) {
- fprintf(stderr, "%sLOGGER_KERNEL", prefix);
- prefix = orstr;
- }
- if (logger & LOGGER_NULL) {
- fprintf(stderr, "%sLOGGER_NULL", prefix);
- prefix = orstr;
- }
- if (logger & LOGGER_STDERR) {
- fprintf(stderr, "%sLOGGER_STDERR", prefix);
- prefix = orstr;
- }
- logger &= ~(LOGGER_LOGD | LOGGER_KERNEL | LOGGER_NULL | LOGGER_STDERR);
- if (logger) {
- fprintf(stderr, "%s0x%x", prefix, logger);
- prefix = orstr;
- }
- if (prefix == orstr) {
- fprintf(stderr, "\n");
- }
-}
-#endif
-
-// This test makes little sense standalone, and requires the tests ahead
-// and behind us, to make us whole. We could incorporate a prefix and
-// suffix test to make this standalone, but opted to not complicate this.
-TEST(liblog, android_set_log_transport) {
-#ifdef __ANDROID__
-#ifdef TEST_PREFIX
- TEST_PREFIX
-#endif
-
- int logger = android_get_log_transport();
- print_transport("android_get_log_transport = ", logger);
- EXPECT_NE(LOGGER_NULL, logger);
-
- int ret;
- EXPECT_EQ(LOGGER_NULL, ret = android_set_log_transport(LOGGER_NULL));
- print_transport("android_set_log_transport = ", ret);
- EXPECT_EQ(LOGGER_NULL, ret = android_get_log_transport());
- print_transport("android_get_log_transport = ", ret);
-
- pid_t pid = getpid();
-
- struct logger_list* logger_list;
- ASSERT_TRUE(NULL !=
- (logger_list = android_logger_list_open(
- LOG_ID_EVENTS, ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK,
- 1000, pid)));
-
- log_time ts(CLOCK_MONOTONIC);
- EXPECT_LT(0, __android_log_btwrite(0, EVENT_TYPE_LONG, &ts, sizeof(ts)));
-
- usleep(1000000);
-
- int count = 0;
-
- for (;;) {
- log_msg log_msg;
- if (android_logger_list_read(logger_list, &log_msg) <= 0) {
- break;
- }
-
- EXPECT_EQ(log_msg.entry.pid, pid);
-
- if ((log_msg.entry.len != sizeof(android_log_event_long_t)) ||
- (log_msg.id() != LOG_ID_EVENTS)) {
- continue;
- }
-
- android_log_event_long_t* eventData;
- eventData = reinterpret_cast<android_log_event_long_t*>(log_msg.msg());
-
- if (!eventData || (eventData->payload.type != EVENT_TYPE_LONG)) {
- continue;
- }
-
- log_time tx(reinterpret_cast<char*>(&eventData->payload.data));
- if (ts == tx) {
- ++count;
- }
- }
-
- android_logger_list_close(logger_list);
-
- EXPECT_EQ(logger, ret = android_set_log_transport(logger));
- print_transport("android_set_log_transport = ", ret);
- EXPECT_EQ(logger, ret = android_get_log_transport());
- print_transport("android_get_log_transport = ", ret);
-
- // False negative if liblog.__android_log_btwrite__android_logger_list_read
- // fails above, so we will likely succeed. But we will have so many
- // failures elsewhere that it is probably not worthwhile for us to
- // highlight yet another disappointment.
- //
- // We also expect failures in the following tests if the set does not
- // react in an appropriate manner internally, yet passes, so we depend
- // on this test being in the middle of a series of tests performed in
- // the same process.
- EXPECT_EQ(0, count);
-#else
- GTEST_LOG_(INFO) << "This test does nothing.\n";
-#endif
-}
-
-#ifdef TEST_PREFIX
-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) {
-#ifdef TEST_PREFIX
- TEST_PREFIX
+#ifdef __ANDROID__
struct logger_list* logger_list;
pid_t pid = getpid();
@@ -400,11 +238,7 @@
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
EXPECT_LT(0, __android_log_bswrite(0, message));
size_t num_lines = 1, size = 0, length = 0, total = 0;
@@ -455,7 +289,7 @@
continue;
}
- size_t len = get4LE(reinterpret_cast<char*>(&eventData->length));
+ size_t len = eventData->length;
if (len == total) {
++count;
@@ -486,7 +320,7 @@
}
}
- EXPECT_EQ(SUPPORTS_END_TO_END, count);
+ EXPECT_EQ(1, count);
android_logger_list_close(logger_list);
#else
@@ -516,8 +350,7 @@
}
static void buf_write_test(const char* message) {
-#ifdef TEST_PREFIX
- TEST_PREFIX
+#ifdef __ANDROID__
struct logger_list* logger_list;
pid_t pid = getpid();
@@ -528,11 +361,7 @@
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));
@@ -590,7 +419,7 @@
android_log_format_free(logformat);
}
- EXPECT_EQ(SUPPORTS_END_TO_END, count);
+ EXPECT_EQ(1, count);
android_logger_list_close(logger_list);
#else
@@ -611,8 +440,7 @@
buf_write_test("\n Hello World \n");
}
-#ifdef USING_LOGGER_DEFAULT // requires blocking reader functionality
-#ifdef TEST_PREFIX
+#ifdef __ANDROID__
static unsigned signaled;
static log_time signal_time;
@@ -673,8 +501,7 @@
#endif
TEST(liblog, android_logger_list_read__cpu_signal) {
-#ifdef TEST_PREFIX
- TEST_PREFIX
+#ifdef __ANDROID__
struct logger_list* logger_list;
unsigned long long v = 0xDEADBEEFA55A0000ULL;
@@ -766,7 +593,7 @@
#endif
}
-#ifdef TEST_PREFIX
+#ifdef __ANDROID__
/*
* Strictly, we are not allowed to log messages in a signal context, the
* correct way to handle this is to ensure the messages are constructed in
@@ -830,8 +657,7 @@
#endif
TEST(liblog, android_logger_list_read__cpu_thread) {
-#ifdef TEST_PREFIX
- TEST_PREFIX
+#ifdef __ANDROID__
struct logger_list* logger_list;
unsigned long long v = 0xDEADBEAFA55A0000ULL;
@@ -923,9 +749,8 @@
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif
}
-#endif // USING_LOGGER_DEFAULT
-#ifdef TEST_PREFIX
+#ifdef __ANDROID__
static const char max_payload_tag[] = "TEST_max_payload_and_longish_tag_XXXX";
#define SIZEOF_MAX_PAYLOAD_BUF \
(LOGGER_ENTRY_MAX_PAYLOAD - sizeof(max_payload_tag) - 1)
@@ -1062,10 +887,8 @@
when you depart from me, sorrow abides and happiness\n\
takes his leave.";
-#ifdef USING_LOGGER_DEFAULT
TEST(liblog, max_payload) {
-#ifdef TEST_PREFIX
- TEST_PREFIX
+#ifdef __ANDROID__
pid_t pid = getpid();
char tag[sizeof(max_payload_tag)];
memcpy(tag, max_payload_tag, sizeof(tag));
@@ -1120,22 +943,16 @@
android_logger_list_close(logger_list);
-#if SUPPORTS_END_TO_END
EXPECT_EQ(true, matches);
EXPECT_LE(SIZEOF_MAX_PAYLOAD_BUF, static_cast<size_t>(max_len));
#else
- EXPECT_EQ(false, matches);
-#endif
-#else
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif
}
-#endif
TEST(liblog, __android_log_buf_print__maxtag) {
-#ifdef TEST_PREFIX
- TEST_PREFIX
+#ifdef __ANDROID__
struct logger_list* logger_list;
pid_t pid = getpid();
@@ -1145,11 +962,7 @@
(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));
@@ -1192,7 +1005,7 @@
android_log_format_free(logformat);
}
- EXPECT_EQ(SUPPORTS_END_TO_END, count);
+ EXPECT_EQ(1, count);
android_logger_list_close(logger_list);
#else
@@ -1201,8 +1014,7 @@
}
TEST(liblog, too_big_payload) {
-#ifdef TEST_PREFIX
- TEST_PREFIX
+#ifdef __ANDROID__
pid_t pid = getpid();
static const char big_payload_tag[] = "TEST_big_payload_XXXX";
char tag[sizeof(big_payload_tag)];
@@ -1254,10 +1066,6 @@
android_logger_list_close(logger_list);
-#if !SUPPORTS_END_TO_END
- max_len =
- max_len ? max_len : LOGGER_ENTRY_MAX_PAYLOAD - sizeof(big_payload_tag);
-#endif
EXPECT_LE(LOGGER_ENTRY_MAX_PAYLOAD - sizeof(big_payload_tag),
static_cast<size_t>(max_len));
@@ -1273,10 +1081,8 @@
#endif
}
-#ifdef USING_LOGGER_DEFAULT
TEST(liblog, dual_reader) {
-#ifdef TEST_PREFIX
- TEST_PREFIX
+#ifdef __ANDROID__
static const int num = 25;
@@ -1331,15 +1137,13 @@
android_logger_list_close(logger_list1);
android_logger_list_close(logger_list2);
- EXPECT_EQ(num * SUPPORTS_END_TO_END, count1);
- EXPECT_EQ((num - 10) * SUPPORTS_END_TO_END, count2);
+ EXPECT_EQ(num, count1);
+ EXPECT_EQ(num - 10, count2);
#else
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif
}
-#endif
-#ifdef USING_LOGGER_DEFAULT // Do not retest logprint
static bool checkPriForTag(AndroidLogFormat* p_format, const char* tag,
android_LogPriority pri) {
return android_log_shouldPrintLine(p_format, tag, pri) &&
@@ -1415,9 +1219,7 @@
android_log_format_free(p_format);
}
-#endif // USING_LOGGER_DEFAULT
-#ifdef USING_LOGGER_DEFAULT // Do not retest property handling
TEST(liblog, is_loggable) {
#ifdef __ANDROID__
static const char tag[] = "is_loggable";
@@ -1705,14 +1507,11 @@
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif
}
-#endif // USING_LOGGER_DEFAULT
// 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.
-#ifdef USING_LOGGER_DEFAULT
#ifdef __ANDROID__
-#ifdef TEST_PREFIX
// helper to liblog.enoent to count end-to-end matching logging messages.
static int count_matching_ts(log_time ts) {
usleep(1000000);
@@ -1747,19 +1546,17 @@
return count;
}
-#endif // TEST_PREFIX
TEST(liblog, enoent) {
-#ifdef TEST_PREFIX
+#ifdef __ANDROID__
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));
+ EXPECT_EQ(1, count_matching_ts(ts));
// This call will fail unless we are root, beware of any
// test prior to this one playing with setuid and causing interference.
@@ -1800,19 +1597,17 @@
ts = log_time(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));
+ EXPECT_EQ(1, count_matching_ts(ts));
#else
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif
}
#endif // __ANDROID__
-#endif // USING_LOGGER_DEFAULT
// Below this point we run risks of setuid(AID_SYSTEM) which may affect others.
// Do not retest properties, and cannot log into LOG_ID_SECURITY
-#ifdef USING_LOGGER_DEFAULT
TEST(liblog, __security) {
#ifdef __ANDROID__
static const char persist_key[] = "persist.logd.security";
@@ -2069,13 +1864,11 @@
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif
}
-#endif // USING_LOGGER_DEFAULT
-#ifdef TEST_PREFIX
+#ifdef __ANDROID__
static void android_errorWriteWithInfoLog_helper(int TAG, const char* SUBTAG,
int UID, const char* payload,
int DATA_LEN, int& count) {
- TEST_PREFIX
struct logger_list* logger_list;
pid_t pid = getpid();
@@ -2111,7 +1904,7 @@
char* original = eventData;
// Tag
- int tag = get4LE(eventData);
+ int tag = *reinterpret_cast<int32_t*>(eventData);
eventData += 4;
if (tag != TAG) {
@@ -2138,7 +1931,7 @@
unsigned subtag_len = strlen(SUBTAG);
if (subtag_len > 32) subtag_len = 32;
- ASSERT_EQ(subtag_len, get4LE(eventData));
+ ASSERT_EQ(subtag_len, *reinterpret_cast<uint32_t*>(eventData));
eventData += 4;
if (memcmp(SUBTAG, eventData, subtag_len)) {
@@ -2150,14 +1943,14 @@
ASSERT_EQ(EVENT_TYPE_INT, eventData[0]);
eventData++;
- ASSERT_EQ(UID, (int)get4LE(eventData));
+ ASSERT_EQ(UID, *reinterpret_cast<int32_t*>(eventData));
eventData += 4;
// Element #3: string type for data
ASSERT_EQ(EVENT_TYPE_STRING, eventData[0]);
eventData++;
- size_t dataLen = get4LE(eventData);
+ size_t dataLen = *reinterpret_cast<int32_t*>(eventData);
eventData += 4;
if (DATA_LEN < 512) ASSERT_EQ(DATA_LEN, (int)dataLen);
@@ -2189,11 +1982,11 @@
#endif
TEST(liblog, android_errorWriteWithInfoLog__android_logger_list_read__typical) {
-#ifdef TEST_PREFIX
+#ifdef __ANDROID__
int count;
android_errorWriteWithInfoLog_helper(UNIQUE_TAG(1), "test-subtag", -1,
max_payload_buf, 200, count);
- EXPECT_EQ(SUPPORTS_END_TO_END, count);
+ EXPECT_EQ(1, count);
#else
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif
@@ -2201,12 +1994,12 @@
TEST(liblog,
android_errorWriteWithInfoLog__android_logger_list_read__data_too_large) {
-#ifdef TEST_PREFIX
+#ifdef __ANDROID__
int count;
android_errorWriteWithInfoLog_helper(UNIQUE_TAG(2), "test-subtag", -1,
max_payload_buf, sizeof(max_payload_buf),
count);
- EXPECT_EQ(SUPPORTS_END_TO_END, count);
+ EXPECT_EQ(1, count);
#else
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif
@@ -2214,7 +2007,7 @@
TEST(liblog,
android_errorWriteWithInfoLog__android_logger_list_read__null_data) {
-#ifdef TEST_PREFIX
+#ifdef __ANDROID__
int count;
android_errorWriteWithInfoLog_helper(UNIQUE_TAG(3), "test-subtag", -1, NULL,
200, count);
@@ -2226,12 +2019,12 @@
TEST(liblog,
android_errorWriteWithInfoLog__android_logger_list_read__subtag_too_long) {
-#ifdef TEST_PREFIX
+#ifdef __ANDROID__
int count;
android_errorWriteWithInfoLog_helper(
UNIQUE_TAG(4), "abcdefghijklmnopqrstuvwxyz now i know my abc", -1,
max_payload_buf, 200, count);
- EXPECT_EQ(SUPPORTS_END_TO_END, count);
+ EXPECT_EQ(1, count);
#else
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif
@@ -2245,10 +2038,9 @@
buf_write_test(max_payload_buf);
}
-#ifdef TEST_PREFIX
+#ifdef __ANDROID__
static void android_errorWriteLog_helper(int TAG, const char* SUBTAG,
int& count) {
- TEST_PREFIX
struct logger_list* logger_list;
pid_t pid = getpid();
@@ -2270,7 +2062,7 @@
if (!eventData) continue;
// Tag
- int tag = get4LE(eventData);
+ int tag = *reinterpret_cast<int32_t*>(eventData);
eventData += 4;
if (tag != TAG) continue;
@@ -2323,7 +2115,7 @@
}
// Tag
- int tag = get4LE(eventData);
+ int tag = *reinterpret_cast<int32_t*>(eventData);
eventData += 4;
if (tag != TAG) {
@@ -2348,7 +2140,7 @@
ASSERT_EQ(EVENT_TYPE_STRING, eventData[0]);
eventData++;
- ASSERT_EQ(strlen(SUBTAG), get4LE(eventData));
+ ASSERT_EQ(strlen(SUBTAG), *reinterpret_cast<uint32_t*>(eventData));
eventData += 4;
if (memcmp(SUBTAG, eventData, strlen(SUBTAG))) {
@@ -2362,17 +2154,17 @@
#endif
TEST(liblog, android_errorWriteLog__android_logger_list_read__success) {
-#ifdef TEST_PREFIX
+#ifdef __ANDROID__
int count;
android_errorWriteLog_helper(UNIQUE_TAG(5), "test-subtag", count);
- EXPECT_EQ(SUPPORTS_END_TO_END, count);
+ EXPECT_EQ(1, count);
#else
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif
}
TEST(liblog, android_errorWriteLog__android_logger_list_read__null_subtag) {
-#ifdef TEST_PREFIX
+#ifdef __ANDROID__
int count;
android_errorWriteLog_helper(UNIQUE_TAG(6), NULL, count);
EXPECT_EQ(0, count);
@@ -2382,7 +2174,7 @@
}
// Do not retest logger list handling
-#ifdef TEST_PREFIX
+#ifdef __ANDROID__
static int is_real_element(int type) {
return ((type == EVENT_TYPE_INT) || (type == EVENT_TYPE_LONG) ||
(type == EVENT_TYPE_STRING) || (type == EVENT_TYPE_FLOAT));
@@ -2537,9 +2329,9 @@
return 0;
}
-#endif // TEST_PREFIX
+#endif // __ANDROID__
-#ifdef TEST_PREFIX
+#ifdef __ANDROID__
static const char* event_test_int32(uint32_t tag, size_t& expected_len) {
android_log_context ctx;
@@ -2793,7 +2585,6 @@
static void create_android_logger(const char* (*fn)(uint32_t tag,
size_t& expected_len)) {
- TEST_PREFIX
struct logger_list* logger_list;
pid_t pid = getpid();
@@ -2862,7 +2653,7 @@
// test buffer reading API
int buffer_to_string = -1;
if (eventData) {
- snprintf(msgBuf, sizeof(msgBuf), "I/[%" PRIu32 "]", get4LE(eventData));
+ snprintf(msgBuf, sizeof(msgBuf), "I/[%" PRIu32 "]", *reinterpret_cast<uint32_t*>(eventData));
print_barrier();
fprintf(stderr, "%-10s(%5u): ", msgBuf, pid);
memset(msgBuf, 0, sizeof(msgBuf));
@@ -2877,14 +2668,14 @@
EXPECT_EQ(0, strcmp(expected_string, msgBuf));
}
- EXPECT_EQ(SUPPORTS_END_TO_END, count);
+ EXPECT_EQ(1, count);
android_logger_list_close(logger_list);
}
#endif
TEST(liblog, create_android_logger_int32) {
-#ifdef TEST_PREFIX
+#ifdef __ANDROID__
create_android_logger(event_test_int32);
#else
GTEST_LOG_(INFO) << "This test does nothing.\n";
@@ -2892,7 +2683,7 @@
}
TEST(liblog, create_android_logger_int64) {
-#ifdef TEST_PREFIX
+#ifdef __ANDROID__
create_android_logger(event_test_int64);
#else
GTEST_LOG_(INFO) << "This test does nothing.\n";
@@ -2900,7 +2691,7 @@
}
TEST(liblog, create_android_logger_list_int64) {
-#ifdef TEST_PREFIX
+#ifdef __ANDROID__
create_android_logger(event_test_list_int64);
#else
GTEST_LOG_(INFO) << "This test does nothing.\n";
@@ -2908,7 +2699,7 @@
}
TEST(liblog, create_android_logger_simple_automagic_list) {
-#ifdef TEST_PREFIX
+#ifdef __ANDROID__
create_android_logger(event_test_simple_automagic_list);
#else
GTEST_LOG_(INFO) << "This test does nothing.\n";
@@ -2916,7 +2707,7 @@
}
TEST(liblog, create_android_logger_list_empty) {
-#ifdef TEST_PREFIX
+#ifdef __ANDROID__
create_android_logger(event_test_list_empty);
#else
GTEST_LOG_(INFO) << "This test does nothing.\n";
@@ -2924,7 +2715,7 @@
}
TEST(liblog, create_android_logger_complex_nested_list) {
-#ifdef TEST_PREFIX
+#ifdef __ANDROID__
create_android_logger(event_test_complex_nested_list);
#else
GTEST_LOG_(INFO) << "This test does nothing.\n";
@@ -2932,7 +2723,7 @@
}
TEST(liblog, create_android_logger_7_level_prefix) {
-#ifdef TEST_PREFIX
+#ifdef __ANDROID__
create_android_logger(event_test_7_level_prefix);
#else
GTEST_LOG_(INFO) << "This test does nothing.\n";
@@ -2940,7 +2731,7 @@
}
TEST(liblog, create_android_logger_7_level_suffix) {
-#ifdef TEST_PREFIX
+#ifdef __ANDROID__
create_android_logger(event_test_7_level_suffix);
#else
GTEST_LOG_(INFO) << "This test does nothing.\n";
@@ -2948,7 +2739,7 @@
}
TEST(liblog, create_android_logger_android_log_error_write) {
-#ifdef TEST_PREFIX
+#ifdef __ANDROID__
create_android_logger(event_test_android_log_error_write);
#else
GTEST_LOG_(INFO) << "This test does nothing.\n";
@@ -2956,14 +2747,13 @@
}
TEST(liblog, create_android_logger_android_log_error_write_null) {
-#ifdef TEST_PREFIX
+#ifdef __ANDROID__
create_android_logger(event_test_android_log_error_write_null);
#else
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif
}
-#ifdef USING_LOGGER_DEFAULT // Do not retest logger list handling
TEST(liblog, create_android_logger_overflow) {
android_log_context ctx;
@@ -2990,9 +2780,7 @@
EXPECT_LE(0, android_log_destroy(&ctx));
ASSERT_TRUE(NULL == ctx);
}
-#endif // USING_LOGGER_DEFAULT
-#ifdef USING_LOGGER_DEFAULT // Do not retest pmsg functionality
#ifdef __ANDROID__
#ifndef NO_PSTORE
static const char __pmsg_file[] =
@@ -3129,9 +2917,7 @@
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif
}
-#endif // USING_LOGGER_DEFAULT
-#ifdef USING_LOGGER_DEFAULT // Do not retest event mapping functionality
TEST(liblog, android_lookupEventTagNum) {
#ifdef __ANDROID__
EventTagMap* map = android_openEventTagMap(NULL);
@@ -3148,4 +2934,3 @@
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif
}
-#endif // USING_LOGGER_DEFAULT
diff --git a/liblog/tests/liblog_test_default.cpp b/liblog/tests/liblog_test_default.cpp
deleted file mode 100644
index 2edea27..0000000
--- a/liblog/tests/liblog_test_default.cpp
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifdef __ANDROID__
-#include <log/log_transport.h>
-#define TEST_LOGGER LOGGER_DEFAULT
-#endif
-#define USING_LOGGER_DEFAULT
-#include "liblog_test.cpp"
diff --git a/liblog/tests/liblog_test_stderr.cpp b/liblog/tests/liblog_test_stderr.cpp
deleted file mode 100644
index abc1b9c..0000000
--- a/liblog/tests/liblog_test_stderr.cpp
+++ /dev/null
@@ -1,5 +0,0 @@
-#include <log/log_transport.h>
-#define liblog liblog_stderr
-#define TEST_LOGGER LOGGER_STDERR
-#define USING_LOGGER_STDERR
-#include "liblog_test.cpp"