diff options
author | Yabin Cui <yabinc@google.com> | 2020-02-19 01:45:13 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2020-02-19 01:45:13 +0000 |
commit | da95b3f323f1ba535be8d583b366f1cfdba8e1c8 (patch) | |
tree | 4644f852e3307931c7a07da920ba095bfa74088b | |
parent | e35ebc47e067322e85958169e82cffdf65a6b715 (diff) | |
parent | 94c148de3309a5510dc3d2cf820d2cb51eb07357 (diff) | |
download | extras-da95b3f323f1ba535be8d583b366f1cfdba8e1c8.tar.gz |
Merge "simpleperf: force testing run-as and app_runner separately."
-rw-r--r-- | simpleperf/cmd_api_test.cpp | 1 | ||||
-rw-r--r-- | simpleperf/cmd_record_test.cpp | 6 | ||||
-rw-r--r-- | simpleperf/cmd_stat_test.cpp | 4 | ||||
-rw-r--r-- | simpleperf/environment.cpp | 27 | ||||
-rw-r--r-- | simpleperf/environment.h | 1 |
5 files changed, 34 insertions, 5 deletions
diff --git a/simpleperf/cmd_api_test.cpp b/simpleperf/cmd_api_test.cpp index 6b618e0f..4157bdef 100644 --- a/simpleperf/cmd_api_test.cpp +++ b/simpleperf/cmd_api_test.cpp @@ -71,6 +71,7 @@ static void RecordApp(const std::string& package_name, const std::string& apk_pa ASSERT_TRUE(WaitUntilAppExit(package_name)); // 4. Collect perf.data. + SetRunInAppToolForTesting(true, true); TemporaryFile tmpfile; ASSERT_TRUE( CreateCommandInstance("api-collect")->Run({"--app", package_name, "-o", tmpfile.path})); diff --git a/simpleperf/cmd_record_test.cpp b/simpleperf/cmd_record_test.cpp index 82f48ed0..ec8c44c9 100644 --- a/simpleperf/cmd_record_test.cpp +++ b/simpleperf/cmd_record_test.cpp @@ -820,11 +820,15 @@ static void TestRecordingApps(const std::string& app_name) { TEST(record_cmd, app_option_for_debuggable_app) { TEST_REQUIRE_APPS(); + SetRunInAppToolForTesting(true, false); + TestRecordingApps("com.android.simpleperf.debuggable"); + SetRunInAppToolForTesting(false, true); TestRecordingApps("com.android.simpleperf.debuggable"); } TEST(record_cmd, app_option_for_profileable_app) { TEST_REQUIRE_APPS(); + SetRunInAppToolForTesting(false, true); TestRecordingApps("com.android.simpleperf.profileable"); } @@ -845,6 +849,7 @@ TEST(record_cmd, record_java_app) { "androidx.test.runner.AndroidJUnitRunner")); // 3. Record perf.data. + SetRunInAppToolForTesting(true, true); ASSERT_TRUE(helper.RecordData( "-e cpu-clock --app com.example.android.displayingbitmaps -g --duration 10")); @@ -877,6 +882,7 @@ TEST(record_cmd, record_native_app) { "android.intent.action.MAIN -c android.intent.category.LAUNCHER")); // 3. Record perf.data. + SetRunInAppToolForTesting(true, true); ASSERT_TRUE(helper.RecordData("-e cpu-clock --app com.google.sample.tunnel -g --duration 10")); // 4. Check perf.data. diff --git a/simpleperf/cmd_stat_test.cpp b/simpleperf/cmd_stat_test.cpp index cc82317d..bbeb4b66 100644 --- a/simpleperf/cmd_stat_test.cpp +++ b/simpleperf/cmd_stat_test.cpp @@ -312,11 +312,15 @@ static void TestStatingApps(const std::string& app_name) { TEST(stat_cmd, app_option_for_debuggable_app) { TEST_REQUIRE_APPS(); + SetRunInAppToolForTesting(true, false); + TestStatingApps("com.android.simpleperf.debuggable"); + SetRunInAppToolForTesting(false, true); TestStatingApps("com.android.simpleperf.debuggable"); } TEST(stat_cmd, app_option_for_profileable_app) { TEST_REQUIRE_APPS(); + SetRunInAppToolForTesting(false, true); TestStatingApps("com.android.simpleperf.profileable"); } diff --git a/simpleperf/environment.cpp b/simpleperf/environment.cpp index 29e43ac2..af14fa3f 100644 --- a/simpleperf/environment.cpp +++ b/simpleperf/environment.cpp @@ -786,18 +786,35 @@ class SimpleperfAppRunner : public InAppRunner { } // namespace +static bool allow_run_as = true; +static bool allow_simpleperf_app_runner = true; + +void SetRunInAppToolForTesting(bool run_as, bool simpleperf_app_runner) { + allow_run_as = run_as; + allow_simpleperf_app_runner = simpleperf_app_runner; +} + bool RunInAppContext(const std::string& app_package_name, const std::string& cmd, const std::vector<std::string>& args, size_t workload_args_size, const std::string& output_filepath, bool need_tracepoint_events) { - std::unique_ptr<InAppRunner> in_app_runner(new RunAs(app_package_name)); - if (!in_app_runner->Prepare()) { + std::unique_ptr<InAppRunner> in_app_runner; + if (allow_run_as) { + in_app_runner.reset(new RunAs(app_package_name)); + if (!in_app_runner->Prepare()) { + in_app_runner = nullptr; + } + } + if (!in_app_runner && allow_simpleperf_app_runner) { in_app_runner.reset(new SimpleperfAppRunner(app_package_name)); if (!in_app_runner->Prepare()) { - LOG(ERROR) << "Package " << app_package_name - << " doesn't exist or isn't debuggable/profileable."; - return false; + in_app_runner = nullptr; } } + if (!in_app_runner) { + LOG(ERROR) << "Package " << app_package_name + << " doesn't exist or isn't debuggable/profileable."; + return false; + } return in_app_runner->RunCmdInApp(cmd, args, workload_args_size, output_filepath, need_tracepoint_events); } diff --git a/simpleperf/environment.h b/simpleperf/environment.h index ab93364f..533d2987 100644 --- a/simpleperf/environment.h +++ b/simpleperf/environment.h @@ -104,6 +104,7 @@ void PrepareVdsoFile(); std::set<pid_t> WaitForAppProcesses(const std::string& package_name); bool IsAppDebuggable(const std::string& package_name); +void SetRunInAppToolForTesting(bool run_as, bool simpleperf_app_runner); // for testing only bool RunInAppContext(const std::string& app_package_name, const std::string& cmd, const std::vector<std::string>& args, size_t workload_args_size, const std::string& output_filepath, bool need_tracepoint_events); |