aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2018-08-06 23:29:34 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2018-08-06 23:29:34 +0000
commitf1798eca82c359471d5c234b04ac619cd7dd8e37 (patch)
treebcfaa340410c4391381474af37734bd438babbdf
parentb02687060629d1fe7c567b641a3903594f361670 (diff)
parent2d8e69a4ca9c407a7be5a3668286d06fd2625906 (diff)
downloadtradefederation-temp_p_merge.tar.gz
Merge "Include test class and method in atest runner instruction" into stage-aosp-mastertemp_p_merge
-rw-r--r--src/com/android/tradefed/util/LocalRunInstructionBuilder.java39
-rw-r--r--tests/src/com/android/tradefed/util/LocalRunInstructionBuilderTest.java55
2 files changed, 86 insertions, 8 deletions
diff --git a/src/com/android/tradefed/util/LocalRunInstructionBuilder.java b/src/com/android/tradefed/util/LocalRunInstructionBuilder.java
index ddef61922..1da94ffc9 100644
--- a/src/com/android/tradefed/util/LocalRunInstructionBuilder.java
+++ b/src/com/android/tradefed/util/LocalRunInstructionBuilder.java
@@ -19,10 +19,14 @@ package com.android.tradefed.util;
import com.android.tradefed.config.ConfigurationDef.OptionDef;
import com.android.tradefed.config.ConfigurationDescriptor;
import com.android.tradefed.config.ConfigurationDescriptor.LocalTestRunner;
+import com.android.tradefed.log.LogUtil.CLog;
+import com.android.tradefed.result.TestDescription;
/** Utility to compile the instruction to run test locally. */
public class LocalRunInstructionBuilder {
+ // TODO(dshi): The method is added for backwards compatibility. Remove this method after lab is
+ // updated.
/**
* Compile the instruction to run test locally.
*
@@ -32,13 +36,30 @@ public class LocalRunInstructionBuilder {
*/
public static String getInstruction(
ConfigurationDescriptor configDescriptor, LocalTestRunner runner) {
+ return getInstruction(configDescriptor, runner, null);
+ }
+
+ /**
+ * Compile the instruction to run test locally.
+ *
+ * @param configDescriptor {@link ConfigurationDescriptor} to create instruction for.
+ * @param runner {@link LocalTestRunner} to be used to build instruction.
+ * @param testId {@link TestDescription} of the test to run. It can be null when building local
+ * run instruction for the whole module.
+ * @return {@link String} of the instruction.
+ */
+ public static String getInstruction(
+ ConfigurationDescriptor configDescriptor,
+ LocalTestRunner runner,
+ TestDescription testId) {
if (runner == null) {
return null;
}
switch (runner) {
case ATEST:
- return getAtestInstruction(configDescriptor);
+ return getAtestInstruction(configDescriptor, testId);
default:
+ CLog.v("Runner %s is not supported yet, no instruction will be built.", runner);
return null;
}
}
@@ -47,12 +68,24 @@ public class LocalRunInstructionBuilder {
* Compile the instruction to run test locally using atest.
*
* @param configDescriptor {@link ConfigurationDescriptor} to create instruction for.
+ * @param testId {@link TestDescription} of the test to run.
* @return {@link String} of the instruction.
*/
- private static String getAtestInstruction(ConfigurationDescriptor configDescriptor) {
+ private static String getAtestInstruction(
+ ConfigurationDescriptor configDescriptor, TestDescription testId) {
StringBuilder instruction = new StringBuilder();
instruction.append("Run following command to try the test in a local setup:\n");
- instruction.append(String.format("atest %s --", configDescriptor.getModuleName()));
+ StringBuilder testName = new StringBuilder(configDescriptor.getModuleName());
+ if (testId != null) {
+ testName.append(String.format(":%s", testId.getClassName()));
+ // Atest doesn't support test parameter, so ignore the method filter if parameter is
+ // set.
+ if (testId.getTestName().equals(testId.getTestNameWithoutParams())) {
+ testName.append(String.format("#%s", testId.getTestName()));
+ }
+ }
+
+ instruction.append(String.format("atest %s --", testName));
if (configDescriptor.getAbi() != null) {
instruction.append(String.format(" --abi %s", configDescriptor.getAbi().getName()));
}
diff --git a/tests/src/com/android/tradefed/util/LocalRunInstructionBuilderTest.java b/tests/src/com/android/tradefed/util/LocalRunInstructionBuilderTest.java
index d40ad6c6b..01662a1b4 100644
--- a/tests/src/com/android/tradefed/util/LocalRunInstructionBuilderTest.java
+++ b/tests/src/com/android/tradefed/util/LocalRunInstructionBuilderTest.java
@@ -20,6 +20,7 @@ import static org.junit.Assert.assertEquals;
import com.android.tradefed.config.ConfigurationDef.OptionDef;
import com.android.tradefed.config.ConfigurationDescriptor;
import com.android.tradefed.config.ConfigurationDescriptor.LocalTestRunner;
+import com.android.tradefed.result.TestDescription;
import com.android.tradefed.testtype.Abi;
import org.junit.Test;
@@ -34,12 +35,15 @@ public class LocalRunInstructionBuilderTest {
private static final String OPTION_VALUE = "value";
private static final String OPTION_NAME_ONLY = "option_only";
private static final String OPTION_VALUE_ONLY = "value_only";
- private static final String OPTION_SOURCE = "test_name";
+ private static final String OPTION_SOURCE = "module_name";
+ private static final String CLASS_NAME = "class_name";
+ private static final String METHOD_NAME = "method_name";
+ private static final String METHOD_NAME_WITH_PARAMETER = "method_name[parameter_value]";
private static final String ABI_NAME = "arm";
/**
* test {@link LocalRunInstructionBuilder#getInstruction(ConfigurationDescriptor,
- * LocalTestRunner)}
+ * LocalTestRunner, TestDescription)}
*/
@Test
public void testGetInstruction() {
@@ -51,11 +55,52 @@ public class LocalRunInstructionBuilderTest {
configDescriptor.setAbi(new Abi(ABI_NAME, "32"));
configDescriptor.setModuleName(OPTION_SOURCE);
String instruction =
- LocalRunInstructionBuilder.getInstruction(configDescriptor, LocalTestRunner.ATEST);
+ LocalRunInstructionBuilder.getInstruction(
+ configDescriptor, LocalTestRunner.ATEST, null);
assertEquals(
"Run following command to try the test in a local setup:\n"
- + "atest test_name -- --abi arm --module-arg test_name:option:key:=value "
- + "--module-arg test_name:option_only:value_only",
+ + "atest module_name -- --abi arm "
+ + "--module-arg module_name:option:key:=value "
+ + "--module-arg module_name:option_only:value_only",
+ instruction);
+ }
+
+ /**
+ * test {@link LocalRunInstructionBuilder#getInstruction(ConfigurationDescriptor,
+ * LocalTestRunner, TestDescription)} with TestId specified.
+ */
+ @Test
+ public void testGetInstruction_withTestId() {
+ ConfigurationDescriptor configDescriptor = new ConfigurationDescriptor();
+ configDescriptor.setAbi(new Abi(ABI_NAME, "32"));
+ configDescriptor.setModuleName(OPTION_SOURCE);
+ TestDescription testId = new TestDescription(CLASS_NAME, METHOD_NAME);
+ String instruction =
+ LocalRunInstructionBuilder.getInstruction(
+ configDescriptor, LocalTestRunner.ATEST, testId);
+ assertEquals(
+ "Run following command to try the test in a local setup:\n"
+ + "atest module_name:class_name#method_name -- --abi arm",
+ instruction);
+ }
+
+ /**
+ * test {@link LocalRunInstructionBuilder#getInstruction(ConfigurationDescriptor,
+ * LocalTestRunner, TestDescription)} with TestId specified which contains parameter for test
+ * method.
+ */
+ @Test
+ public void testGetInstruction_withTestIdAndParameter() {
+ ConfigurationDescriptor configDescriptor = new ConfigurationDescriptor();
+ configDescriptor.setAbi(new Abi(ABI_NAME, "32"));
+ configDescriptor.setModuleName(OPTION_SOURCE);
+ TestDescription testId = new TestDescription(CLASS_NAME, METHOD_NAME_WITH_PARAMETER);
+ String instruction =
+ LocalRunInstructionBuilder.getInstruction(
+ configDescriptor, LocalTestRunner.ATEST, testId);
+ assertEquals(
+ "Run following command to try the test in a local setup:\n"
+ + "atest module_name:class_name -- --abi arm",
instruction);
}
}