summaryrefslogtreecommitdiffstats
path: root/logcat
diff options
context:
space:
mode:
authorMark Salyzyn <salyzyn@google.com>2017-04-03 09:30:20 -0700
committerMark Salyzyn <salyzyn@google.com>2017-04-04 08:01:11 -0700
commite74e51ded7bd1bcb2420015715aa2439799d2d8b (patch)
tree8bb22243e990a64c54fa4e04bddb2b8d5fad9e23 /logcat
parent815578cef2ef0d6084cfc5f648a264f353836ffa (diff)
downloadcore-e74e51ded7bd1bcb2420015715aa2439799d2d8b.tar.gz
core-e74e51ded7bd1bcb2420015715aa2439799d2d8b.tar.bz2
core-e74e51ded7bd1bcb2420015715aa2439799d2d8b.zip
logcat: Add -h and --help flags
If -h or --help argument was supplied, logcat would report the help message but also return an error. Officially add -h and --help as recognized flags, report all help with a (zero) success error code. Adding this, and the associated test, was split off as a stepping stone to resolving an issue with logcat -L or --last flag operations. Test: gTest logcat-unit-tests --gtest_filter=*.help Bug: 28788401 Bug: 30041146 Bug: 30612424 Bug: 35326290 Change-Id: I948e7fa4e92bd23f52717758ffd96bbd068c53d4
Diffstat (limited to 'logcat')
-rw-r--r--logcat/logcat.cpp11
-rw-r--r--logcat/tests/logcat_test.cpp19
2 files changed, 27 insertions, 3 deletions
diff --git a/logcat/logcat.cpp b/logcat/logcat.cpp
index 813493699..64d1d2f41 100644
--- a/logcat/logcat.cpp
+++ b/logcat/logcat.cpp
@@ -882,6 +882,7 @@ static int __logcat(android_logcat_context_internal* context) {
{ "grep", required_argument, nullptr, 'e' },
// hidden and undocumented reserved alias for --max-count
{ "head", required_argument, nullptr, 'm' },
+ { "help", no_argument, nullptr, 'h' },
{ id_str, required_argument, nullptr, 0 },
{ "last", no_argument, nullptr, 'L' },
{ "max-count", required_argument, nullptr, 'm' },
@@ -900,9 +901,8 @@ static int __logcat(android_logcat_context_internal* context) {
};
// clang-format on
- ret = getopt_long_r(argc, argv,
- ":cdDLt:T:gG:sQf:r:n:v:b:BSpP:m:e:", long_options,
- &option_index, &optctx);
+ ret = getopt_long_r(argc, argv, ":cdDhLt:T:gG:sQf:r:n:v:b:BSpP:m:e:",
+ long_options, &option_index, &optctx);
if (ret < 0) break;
switch (ret) {
@@ -1304,6 +1304,11 @@ static int __logcat(android_logcat_context_internal* context) {
"Option -%c needs an argument\n", optctx.optopt);
goto exit;
+ case 'h':
+ show_help(context);
+ show_format_help(context);
+ goto exit;
+
default:
logcat_panic(context, HELP_TRUE, "Unrecognized Option %c\n",
optctx.optopt);
diff --git a/logcat/tests/logcat_test.cpp b/logcat/tests/logcat_test.cpp
index a3a017609..d802b2663 100644
--- a/logcat/tests/logcat_test.cpp
+++ b/logcat/tests/logcat_test.cpp
@@ -1668,3 +1668,22 @@ TEST(logcat, security) {
EXPECT_TRUE(reportedSecurity("logcat -b security -c 2>&1"));
EXPECT_TRUE(reportedSecurity("logcat -b security -G 256K 2>&1"));
}
+
+static size_t commandOutputSize(const char* command) {
+ logcat_define(ctx);
+ FILE* fp = logcat_popen(ctx, command);
+ if (!fp) return 0;
+
+ std::string ret;
+ if (!android::base::ReadFdToString(fileno(fp), &ret)) return 0;
+ if (logcat_pclose(ctx, fp) != 0) return 0;
+
+ return ret.size();
+}
+
+TEST(logcat, help) {
+ size_t logcatHelpTextSize = commandOutputSize("logcat -h 2>&1");
+ EXPECT_LT(4096UL, logcatHelpTextSize);
+ size_t logcatLastHelpTextSize = commandOutputSize("logcat -L -h 2>&1");
+ EXPECT_EQ(logcatHelpTextSize, logcatLastHelpTextSize);
+}