diff options
| author | Treehugger Robot <treehugger-gerrit@google.com> | 2020-09-03 01:10:07 +0000 |
|---|---|---|
| committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-09-03 01:10:07 +0000 |
| commit | 24796df151c890714d204abbbdcb1ff66fdded74 (patch) | |
| tree | 01e9f827ec531c3bd8b2bfbd584725035fff2bde | |
| parent | a9cd5d14ef0655878ffd0c9d33013bc9ea64f4a1 (diff) | |
| parent | d561db73611fe8146b82a1ff34cf9f3525b8cf3a (diff) | |
| download | platform_test_suite_harness-24796df151c890714d204abbbdcb1ff66fdded74.tar.gz platform_test_suite_harness-24796df151c890714d204abbbdcb1ff66fdded74.tar.bz2 platform_test_suite_harness-24796df151c890714d204abbbdcb1ff66fdded74.zip | |
Merge "Convert test name with brackets to regex to get subtest name." am: d561db7361
Original change: https://android-review.googlesource.com/c/platform/test/suite_harness/+/1413448
Change-Id: I63562b0f4c5a25a63234338d616adeb8c669e1e6
| -rw-r--r-- | common/util/src/com/android/compatibility/common/util/TestResultHistory.java | 16 | ||||
| -rw-r--r-- | common/util/tests/src/com/android/compatibility/common/util/ResultHandlerTest.java | 72 |
2 files changed, 82 insertions, 6 deletions
diff --git a/common/util/src/com/android/compatibility/common/util/TestResultHistory.java b/common/util/src/com/android/compatibility/common/util/TestResultHistory.java index 15a93194..73096cb0 100644 --- a/common/util/src/com/android/compatibility/common/util/TestResultHistory.java +++ b/common/util/src/com/android/compatibility/common/util/TestResultHistory.java @@ -104,7 +104,7 @@ public class TestResultHistory implements Serializable { serializer.startTag(null, RUN_HISTORY_TAG); // Only show sub-test names in test attribute in run history node. - String name = resultHistory.getTestName().replaceFirst(testName + ":", ""); + String name = getSubTestName(testName, resultHistory.getTestName()); if (!name.isEmpty() && !name.equalsIgnoreCase(testName)) { serializer.attribute(null, SUB_TEST_ATTR, name); } @@ -120,6 +120,20 @@ public class TestResultHistory implements Serializable { serializer.endTag(null, RUN_HISTORY_TAG); } + /** + * Get subtest name by replacing top-level test name. + * + * @param testName top-level test name. + * @param fullTestName test name with the combination of top-level and subtest name. + * @return subtest name without top-level test name + */ + protected static String getSubTestName(String testName, String fullTestName) { + // Handle test name with brackets, like [folded] as the suffix for foldable test plan. + testName = testName.replace("[", "\\[").replace("]", "\\]"); + String subTestName = fullTestName.replaceFirst(testName + ":", ""); + return subTestName; + } + /** Execution Record about start time, end time and isAutomated */ public static class ExecutionRecord implements Serializable { diff --git a/common/util/tests/src/com/android/compatibility/common/util/ResultHandlerTest.java b/common/util/tests/src/com/android/compatibility/common/util/ResultHandlerTest.java index 9155b93c..581e2018 100644 --- a/common/util/tests/src/com/android/compatibility/common/util/ResultHandlerTest.java +++ b/common/util/tests/src/com/android/compatibility/common/util/ResultHandlerTest.java @@ -92,6 +92,9 @@ public class ResultHandlerTest extends TestCase { private static final String METHOD_3 = "testBlah3"; private static final String METHOD_4 = "testBlah4"; private static final String METHOD_5 = "testBlah5"; + private static final String METHOD_6_BRACKETS = "testBlah6[suffix]"; + private static final String SUB_METHOD_3 = "subTestBlah3"; + private static final String SUB_METHOD_6_BRACKETS = "subTestBlah6[suffix]"; private static final String SUMMARY_SOURCE = String.format("%s#%s:20", CLASS_B, METHOD_4); private static final String SUMMARY_MESSAGE = "Headline"; private static final double SUMMARY_VALUE = 9001; @@ -316,7 +319,8 @@ public class ResultHandlerTest extends TestCase { moduleBTest3.setLog(LOGCAT); moduleBTest3.setScreenshot(SCREENSHOT); List<TestResultHistory> resultHistories = new ArrayList<TestResultHistory>(); - TestResultHistory resultHistory = new TestResultHistory(METHOD_3, executionRecords); + TestResultHistory resultHistory = + new TestResultHistory(METHOD_3 + ":" + SUB_METHOD_3, executionRecords); resultHistories.add(resultHistory); moduleBTest3.setTestResultHistories(resultHistories); ITestResult moduleBTest4 = moduleBCase.getOrCreateResult(METHOD_4); @@ -333,6 +337,15 @@ public class ResultHandlerTest extends TestCase { moduleBTest4.setReportLog(report); ITestResult moduleBTest5 = moduleBCase.getOrCreateResult(METHOD_5); moduleBTest5.skipped(); + // For test name with bracket as suffix in CTS Verifier. + ITestResult moduleBTest6 = moduleBCase.getOrCreateResult(METHOD_6_BRACKETS); + moduleBTest6.setResultStatus(TestStatus.FAIL); + List<TestResultHistory> resultHistories2 = new ArrayList<TestResultHistory>(); + TestResultHistory resultHistory2 = + new TestResultHistory( + METHOD_6_BRACKETS + ":" + SUB_METHOD_6_BRACKETS, executionRecords); + resultHistories2.add(resultHistory2); + moduleBTest6.setTestResultHistories(resultHistories2); // Serialize to file File res = @@ -514,7 +527,13 @@ public class ResultHandlerTest extends TestCase { IInvocationResult result, String expectedBuildFingerprint, boolean newTestFormat, boolean checkResultHistories) throws Exception { assertEquals("Expected 3 passes", 3, result.countResults(TestStatus.PASS)); - assertEquals("Expected 1 failure", 1, result.countResults(TestStatus.FAIL)); + if (checkResultHistories) { + assertEquals("Expected 1 failure", 1, result.countResults(TestStatus.FAIL)); + } else { + // CTS Verifier needs to check the condition of the test name with bracket, + // so adds one more test with failure result. + assertEquals("Expected 2 failure", 2, result.countResults(TestStatus.FAIL)); + } Map<String, String> buildInfo = result.getInvocationInfo(); assertEquals("Incorrect Build Fingerprint", expectedBuildFingerprint, result.getBuildFingerprint()); @@ -558,7 +577,13 @@ public class ResultHandlerTest extends TestCase { IModuleResult moduleB = modules.get(1); assertEquals("Expected 2 passes", 2, moduleB.countResults(TestStatus.PASS)); - assertEquals("Expected 1 failure", 1, moduleB.countResults(TestStatus.FAIL)); + if (checkResultHistories) { + assertEquals("Expected 1 failure", 1, moduleB.countResults(TestStatus.FAIL)); + } else { + // CTS Verifier needs to check the condition of the test name with bracket, + // so adds one more test with failure result. + assertEquals("Expected 2 failure", 2, moduleB.countResults(TestStatus.FAIL)); + } assertEquals("Incorrect ABI", ABI, moduleB.getAbi()); assertEquals("Incorrect name", NAME_B, moduleB.getName()); assertEquals("Incorrect ID", ID_B, moduleB.getId()); @@ -568,7 +593,13 @@ public class ResultHandlerTest extends TestCase { ICaseResult moduleBCase = moduleBCases.get(0); assertEquals("Incorrect name", CLASS_B, moduleBCase.getName()); List<ITestResult> moduleBResults = moduleBCase.getResults(); - assertEquals("Expected 3 results", 3, moduleBResults.size()); + if (checkResultHistories) { + assertEquals("Expected 3 results", 3, moduleBResults.size()); + } else { + // CTS Verifier needs to check the condition of the test name with bracket, + // so adds one more test with failure result. + assertEquals("Expected 4 results", 4, moduleBResults.size()); + } ITestResult moduleBTest3 = moduleBResults.get(0); assertEquals("Incorrect name", METHOD_3, moduleBTest3.getName()); assertEquals("Incorrect result", TestStatus.FAIL, moduleBTest3.getResultStatus()); @@ -589,7 +620,10 @@ public class ResultHandlerTest extends TestCase { assertEquals("Expected 1 test result history", 1, resultHistories.size()); for (TestResultHistory resultHistory : resultHistories) { assertNotNull("Expected test result history", resultHistory); - assertEquals("Incorrect test name", METHOD_3, resultHistory.getTestName()); + assertEquals( + "Incorrect test name", + SUB_METHOD_3, + resultHistory.getSubTestName(METHOD_3, resultHistory.getTestName())); for (TestResultHistory.ExecutionRecord execRecord : resultHistory.getExecutionRecords()) { assertEquals( @@ -633,6 +667,34 @@ public class ResultHandlerTest extends TestCase { assertNull("Unexpected message", moduleBTest5.getMessage()); assertNull("Unexpected stack trace", moduleBTest5.getStackTrace()); assertNull("Unexpected report", moduleBTest5.getReportLog()); + if (!checkResultHistories) { + // CTS Verifier needs to check the condition of the test name with bracket, + // so adds one more test with failure result. + ITestResult moduleBTest6 = moduleBResults.get(3); + assertEquals("Incorrect name", METHOD_6_BRACKETS, moduleBTest6.getName()); + assertEquals("Incorrect result", TestStatus.FAIL, moduleBTest6.getResultStatus()); + List<TestResultHistory> resultHistories2 = moduleBTest6.getTestResultHistories(); + assertNotNull("Expected test result history list", resultHistories2); + assertEquals("Expected 1 test result history", 1, resultHistories2.size()); + for (TestResultHistory resultHistory : resultHistories2) { + assertNotNull("Expected test result history", resultHistory); + assertEquals( + "Incorrect test name", + SUB_METHOD_6_BRACKETS, + resultHistory.getSubTestName( + METHOD_6_BRACKETS, resultHistory.getTestName())); + for (TestResultHistory.ExecutionRecord execRecord : + resultHistory.getExecutionRecords()) { + assertEquals( + "Incorrect test start time", TEST_START_MS, execRecord.getStartTime()); + assertEquals("Incorrect test end time", TEST_END_MS, execRecord.getEndTime()); + assertEquals( + "Incorrect test is automated", + TEST_IS_AUTOMATED, + execRecord.getIsAutomated()); + } + } + } } /** Return all XML nodes that match the given xPathExpression. */ |
