diff options
author | android-build-prod (mdb) <android-build-team-robot@google.com> | 2020-07-17 20:06:55 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2020-07-17 20:06:55 +0000 |
commit | c8c9d1eec9ca51c84bf9d95582ba57e62752e7a6 (patch) | |
tree | c8882dcd57cb30a3bb4a65b8363f2a7969c647e7 | |
parent | fce526b8d996e39f1bc37cdfb48367ebda583ae9 (diff) | |
parent | 66bc4d15d2d9d1319d9aee7accd1b0ff256a67f8 (diff) | |
download | extras-c8c9d1eec9ca51c84bf9d95582ba57e62752e7a6.tar.gz |
Merge "Snap for 6689265 from 1b0881c929f311b92e0ffd9295a9087ec55734c1 to android10-tests-release" into android10-tests-releaseandroid-vts-10.0_r8android-vts-10.0_r7android-vts-10.0_r6android-vts-10.0_r5android-cts-10.0_r8android-cts-10.0_r7android-cts-10.0_r6
-rw-r--r-- | simpleperf/cmd_record_test.cpp | 8 | ||||
-rw-r--r-- | simpleperf/cmd_stat_test.cpp | 4 | ||||
-rw-r--r-- | simpleperf/environment.cpp | 27 | ||||
-rw-r--r-- | simpleperf/environment.h | 1 |
4 files changed, 32 insertions, 8 deletions
diff --git a/simpleperf/cmd_record_test.cpp b/simpleperf/cmd_record_test.cpp index b0c74674..7ae589d7 100644 --- a/simpleperf/cmd_record_test.cpp +++ b/simpleperf/cmd_record_test.cpp @@ -792,13 +792,15 @@ static void TestRecordingApps(const std::string& app_name) { } TEST(record_cmd, app_option_for_debuggable_app) { - TEST_REQUIRE_HW_COUNTER(); 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_HW_COUNTER(); TEST_REQUIRE_APPS(); + SetRunInAppToolForTesting(false, true); TestRecordingApps("com.android.simpleperf.profileable"); -} +}
\ No newline at end of file diff --git a/simpleperf/cmd_stat_test.cpp b/simpleperf/cmd_stat_test.cpp index ecc7404e..eb0fa2f7 100644 --- a/simpleperf/cmd_stat_test.cpp +++ b/simpleperf/cmd_stat_test.cpp @@ -296,10 +296,14 @@ 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 3591626e..ab537dcc 100644 --- a/simpleperf/environment.cpp +++ b/simpleperf/environment.cpp @@ -808,18 +808,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 173cdcc6..074c2320 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); |