summaryrefslogtreecommitdiff
path: root/simpleperf/environment.cpp
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2020-02-18 14:32:33 -0800
committerYabin Cui <yabinc@google.com>2020-02-18 14:37:20 -0800
commit94c148de3309a5510dc3d2cf820d2cb51eb07357 (patch)
treec4fb0dceb50515dfd445529176bc337d3eab3cc6 /simpleperf/environment.cpp
parent83ba19ecb19c6e0d642dcc9e47776f181bdb6c17 (diff)
downloadextras-94c148de3309a5510dc3d2cf820d2cb51eb07357.tar.gz
simpleperf: force testing run-as and app_runner separately.
In CtsSimpleperfTestCases, two methods are used to record an app: through run-as and through simpleperf_app_runner. Tests don't fail unless both methods fail. This can't detect the situation when only one method fails. So change to test run-as and simpleperf_app_runner separately. Bug: none Test: run simpleperf_unit_test. Change-Id: I023aa7793f748e695f809c153ed23f006e13ea12
Diffstat (limited to 'simpleperf/environment.cpp')
-rw-r--r--simpleperf/environment.cpp27
1 files changed, 22 insertions, 5 deletions
diff --git a/simpleperf/environment.cpp b/simpleperf/environment.cpp
index e5be3026..4a1ea47f 100644
--- a/simpleperf/environment.cpp
+++ b/simpleperf/environment.cpp
@@ -780,18 +780,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);
}