diff options
author | Parth Sane <parthsane@google.com> | 2024-03-06 12:51:53 +0000 |
---|---|---|
committer | Parth Sane <parthsane@google.com> | 2024-03-08 10:27:47 +0000 |
commit | 93155f0f8f2ac4ca1b42858b9b8474bea10d5ce2 (patch) | |
tree | a13840d82d8a48e194d9ebd666bce87b488f4801 | |
parent | 11d57c200a2b8f9089f1cda4075b76b1349c74ac (diff) | |
download | platform_testing-93155f0f8f2ac4ca1b42858b9b8474bea10d5ce2.tar.gz |
Add a crystalball test rule for dittobench
Test: N/A
Bug: 326389812
Change-Id: I333a9f5db25123dd44289c9c0cd6256f1984786e
-rw-r--r-- | libraries/health/rules/src/android/platform/test/rule/DittoBenchRule.java | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/libraries/health/rules/src/android/platform/test/rule/DittoBenchRule.java b/libraries/health/rules/src/android/platform/test/rule/DittoBenchRule.java new file mode 100644 index 000000000..94f4c5008 --- /dev/null +++ b/libraries/health/rules/src/android/platform/test/rule/DittoBenchRule.java @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.platform.test.rule; + +import androidx.annotation.VisibleForTesting; + +import org.junit.runner.Description; + +/** This rule will start dittobench using the provided config. */ +public class DittoBenchRule extends TestWatcher { + @VisibleForTesting static final String DITTOBENCH_PATH = "dittobench-path"; + @VisibleForTesting static final String DITTO_CONFIG_PATH = "ditto-config-path"; + String mDittoBenchPath = "/data/local/tmp/dittobench"; + String mDittoConfigPath = "/data/local/tmp/config.ditto"; + + @Override + protected void starting(Description description) { + mDittoBenchPath = getArguments().getString(DITTOBENCH_PATH, "/data/local/tmp/dittobench"); + mDittoConfigPath = + getArguments().getString(DITTO_CONFIG_PATH, "/data/local/tmp/config.ditto"); + executeShellCommand(mDittoBenchPath + " " + mDittoConfigPath); + } + + @Override + protected void finished(Description description) { + super.finished(description); + String[] splitPath = mDittoBenchPath.split("/"); + if (splitPath != null && splitPath.length != 0) { + String dittoBinaryName = splitPath[splitPath.length - 1]; + executeShellCommand("pkill " + dittoBinaryName); + } + } +} |