logcat: expand -n, -r and -b
- Add property expansion to the -n/--rotate-count,
-r/--rotate-kbytes and -b/--buffer parameters.
e.g. -r '${logcat.rotate-count:-6}' will expand the property
logcat.rotate-count, and if not present will default to 6
- Add gtest to confirm mid-stream expansion
- No longer support ",:;<whitespace>" for buffer tokenization,
settling on only supporting ",".
Bug: 28120456
Change-Id: I7ebb6146f72047631536c457952fa50d0abb98ab
diff --git a/logcat/tests/Android.mk b/logcat/tests/Android.mk
index a28664e..3bf8a0b 100644
--- a/logcat/tests/Android.mk
+++ b/logcat/tests/Android.mk
@@ -56,6 +56,6 @@
LOCAL_MODULE := $(test_module_prefix)unit-tests
LOCAL_MODULE_TAGS := $(test_tags)
LOCAL_CFLAGS += $(test_c_flags)
-LOCAL_SHARED_LIBRARIES := liblog
+LOCAL_SHARED_LIBRARIES := liblog libcutils
LOCAL_SRC_FILES := $(test_src_files)
include $(BUILD_NATIVE_TEST)
diff --git a/logcat/tests/logcat_test.cpp b/logcat/tests/logcat_test.cpp
index 2c3579d..997e682 100644
--- a/logcat/tests/logcat_test.cpp
+++ b/logcat/tests/logcat_test.cpp
@@ -25,6 +25,7 @@
#include <memory>
+#include <cutils/properties.h>
#include <gtest/gtest.h>
#include <log/log.h>
#include <log/logger.h>
@@ -425,6 +426,14 @@
"logcat -v brief -b radio,events,system,main -g 2>/dev/null"));
}
+// duplicate test for get_size, but use test.logcat.buffer property
+TEST(logcat, property_expand) {
+ property_set("test.logcat.buffer", "radio,events");
+ EXPECT_EQ(4, get_groups(
+ "logcat -v brief -b 'system,${test.logcat.buffer:-bogo},main' -g 2>/dev/null"));
+ property_set("test.logcat.buffer", "");
+}
+
TEST(logcat, bad_buffer) {
ASSERT_EQ(0, get_groups(
"logcat -v brief -b radio,events,bogo,system,main -g 2>/dev/null"));