Added initial tests for dumpstate.
BUG: 31807540
Test: mmm -j32 frameworks/native/cmds/dumpstate/ && adb push ${ANDROID_PRODUCT_OUT}/data/nativetest/dumpstate_test* /data/nativetest && adb shell /data/nativetest/dumpstate_test/dumpstate_test
Change-Id: If5497784052b8d13d7c856f9400dbcd8c2015d05
diff --git a/cmds/dumpstate/utils.cpp b/cmds/dumpstate/utils.cpp
index e29d90d..55316c5 100644
--- a/cmds/dumpstate/utils.cpp
+++ b/cmds/dumpstate/utils.cpp
@@ -60,6 +60,9 @@
const CommandOptions& options = CommandOptions::DEFAULT) {
return ds.RunCommand(title, fullCommand, options);
}
+static bool IsDryRun() {
+ return Dumpstate::GetInstance().IsDryRun();
+}
/* list of native processes to include in the native dumps */
// This matches the /proc/pid/exe link instead of /proc/pid/cmdline.
@@ -154,11 +157,11 @@
return CommandOptions::CommandOptionsBuilder(timeout);
}
-Dumpstate::Dumpstate() {
+Dumpstate::Dumpstate(bool dryRun) : dryRun_(dryRun) {
}
Dumpstate& Dumpstate::GetInstance() {
- static Dumpstate sSingleton;
+ static Dumpstate sSingleton(android::base::GetBoolProperty("dumpstate.dry_run", false));
return sSingleton;
}
@@ -190,13 +193,16 @@
return (uint64_t) ts.tv_sec * NANOS_PER_SEC + ts.tv_nsec;
}
-// TODO: temporary function used during the C++ refactoring
-static bool is_dry_run() {
- return Dumpstate::GetInstance().IsDryRun();
+bool Dumpstate::IsDryRun() {
+ return dryRun_;
+}
+
+bool Dumpstate::IsUserBuild() {
+ return "user" == buildType_;
}
void for_each_userid(void (*func)(int), const char *header) {
- if (is_dry_run()) return;
+ if (IsDryRun()) return;
DIR *d;
struct dirent *de;
@@ -279,7 +285,7 @@
}
void for_each_pid(for_each_pid_func func, const char *header) {
- if (is_dry_run()) return;
+ if (IsDryRun()) return;
__for_each_pid(for_each_pid_helper, header, (void *) func);
}
@@ -333,13 +339,13 @@
}
void for_each_tid(for_each_tid_func func, const char *header) {
- if (is_dry_run()) return;
+ if (IsDryRun()) return;
__for_each_pid(for_each_tid_helper, header, (void *) func);
}
void show_wchan(int pid, int tid, const char *name) {
- if (is_dry_run()) return;
+ if (IsDryRun()) return;
char path[255];
char buffer[255];
@@ -406,7 +412,7 @@
}
void show_showtime(int pid, const char *name) {
- if (is_dry_run()) return;
+ if (IsDryRun()) return;
char path[255];
char buffer[1023];
@@ -474,7 +480,7 @@
DurationReporter duration_reporter(title);
printf("------ %s ------\n", title);
- if (is_dry_run()) return;
+ if (IsDryRun()) return;
/* Get size of kernel buffer */
int size = klogctl(KLOG_SIZE_BUFFER, NULL, 0);
@@ -526,7 +532,7 @@
}
printf(") ------\n");
}
- if (is_dry_run()) {
+ if (IsDryRun()) {
update_progress(WEIGHT_FILE);
close(fd);
return 0;
@@ -627,7 +633,7 @@
if (!title.empty()) {
printf("------ %s (%s) ------\n", title.c_str(), dir);
}
- if (is_dry_run()) return 0;
+ if (IsDryRun()) return 0;
if (dir[strlen(dir) - 1] == '/') {
++slash;
@@ -684,7 +690,7 @@
* stuck.
*/
int dump_file_from_fd(const char *title, const char *path, int fd) {
- if (is_dry_run()) return 0;
+ if (IsDryRun()) return 0;
int flags = fcntl(fd, F_GETFL);
if (flags == -1) {
@@ -796,7 +802,10 @@
MYLOGI(loggingMessage.c_str(), commandString.c_str());
}
- if (is_dry_run() && !options.Always()) {
+ if (IsDryRun() && !options.Always()) {
+ if (!title.empty()) {
+ printf("\t(skipped on dry run)\n");
+ }
update_progress(options.Timeout());
return 0;
}
@@ -988,7 +997,7 @@
const char* title = "SYSTEM PROPERTIES";
DurationReporter duration_reporter(title);
printf("------ %s ------\n", title);
- if (is_dry_run()) return;
+ if (IsDryRun()) return;
size_t i;
num_props = 0;
property_list(print_prop, NULL);
@@ -1094,7 +1103,7 @@
/* dump Dalvik and native stack traces, return the trace file location (NULL if none) */
const char *dump_traces() {
DurationReporter duration_reporter("DUMP TRACES", nullptr);
- if (is_dry_run()) return nullptr;
+ if (IsDryRun()) return nullptr;
const char* result = nullptr;
@@ -1246,7 +1255,7 @@
void dump_route_tables() {
DurationReporter duration_reporter("DUMP ROUTE TABLES");
- if (is_dry_run()) return;
+ if (IsDryRun()) return;
const char* const RT_TABLES_PATH = "/data/misc/net/rt_tables";
ds.DumpFile("RT_TABLES", RT_TABLES_PATH);
FILE* fp = fopen(RT_TABLES_PATH, "re");