diff options
author | Roland Levillain <rpl@google.com> | 2020-07-08 17:00:30 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-07-08 17:00:30 +0000 |
commit | 03ae35f78b2ccaec6cb2a1785e4e33d80e02ba40 (patch) | |
tree | c8bffe03809fede84079b6b2b8e211e46fa03ab2 | |
parent | 5a6b0f4b053256476d7b1d698b0641b6511c0fda (diff) | |
parent | ed7e6422f695f4253e192d657a40bbc55abc982e (diff) | |
download | tradefederation-03ae35f78b2ccaec6cb2a1785e4e33d80e02ba40.tar.gz |
Merge "Fix the logic to fetch the expected output file in `ArtRunTest`." am: 6f78ac5bc9 am: c1109eebe2 am: 6980442920 am: a17ca56964 am: ed7e6422f6
Original change: https://android-review.googlesource.com/c/platform/tools/tradefederation/+/1352359
Change-Id: I93101cbbf6ba75d95b962f5357966cca7b9e17aa
-rw-r--r-- | test_framework/com/android/tradefed/testtype/ArtRunTest.java | 26 | ||||
-rw-r--r-- | tests/src/com/android/tradefed/testtype/ArtRunTestTest.java | 37 |
2 files changed, 45 insertions, 18 deletions
diff --git a/test_framework/com/android/tradefed/testtype/ArtRunTest.java b/test_framework/com/android/tradefed/testtype/ArtRunTest.java index 1b1631693..a98210452 100644 --- a/test_framework/com/android/tradefed/testtype/ArtRunTest.java +++ b/test_framework/com/android/tradefed/testtype/ArtRunTest.java @@ -22,6 +22,7 @@ import com.android.tradefed.config.Option; import com.android.tradefed.device.DeviceNotAvailableException; import com.android.tradefed.device.ITestDevice; import com.android.tradefed.invoker.TestInformation; +import com.android.tradefed.invoker.ExecutionFiles.FilesKey; import com.android.tradefed.log.LogUtil.CLog; import com.android.tradefed.metrics.proto.MetricMeasurement.Metric; import com.android.tradefed.result.ITestInvocationListener; @@ -31,6 +32,7 @@ import com.android.tradefed.util.ArrayUtil; import com.android.tradefed.util.FileUtil; import java.io.File; +import java.io.FileNotFoundException; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; @@ -141,8 +143,8 @@ public class ArtRunTest implements IDeviceTest, IRemoteTest, IAbiReceiver { // Check the output producted by the test. if (output != null) { try { - File expectedFile = - testInfo.getDependencyFile("expected.txt", /* targetFirst */ false); + File expectedFile = getDependencyFileFromRunTestDir(testInfo, "expected.txt"); + CLog.i("Found expected output for run-test %s: %s", mRunTestName, expectedFile); String expected = FileUtil.readStringFromFile(expectedFile); if (!output.equals(expected)) { String error = String.format("'%s' instead of '%s'", output, expected); @@ -174,4 +176,24 @@ public class ArtRunTest implements IDeviceTest, IRemoteTest, IAbiReceiver { protected CollectingOutputReceiver createTestOutputReceiver() { return new CollectingOutputReceiver(); } + + /** Search for a dependency/artifact file in the run-test's directory. */ + protected File getDependencyFileFromRunTestDir(TestInformation testInfo, String fileName) + throws FileNotFoundException { + File testsDir = testInfo.executionFiles().get(FilesKey.TARGET_TESTS_DIRECTORY); + if (testsDir == null || !testsDir.exists()) { + throw new FileNotFoundException( + String.format( + "Could not find target tests directory for test %s.", mRunTestName)); + } + File runTestDir = new File(testsDir, mRunTestName); + File file = FileUtil.findFile(runTestDir, fileName); + if (file == null) { + throw new FileNotFoundException( + String.format( + "Could not find an artifact file associated with %s in directory %s.", + fileName, runTestDir)); + } + return file; + } } diff --git a/tests/src/com/android/tradefed/testtype/ArtRunTestTest.java b/tests/src/com/android/tradefed/testtype/ArtRunTestTest.java index 0e5b50295..23d8b7590 100644 --- a/tests/src/com/android/tradefed/testtype/ArtRunTestTest.java +++ b/tests/src/com/android/tradefed/testtype/ArtRunTestTest.java @@ -25,6 +25,7 @@ import com.android.tradefed.config.OptionSetter; import com.android.tradefed.device.DeviceNotAvailableException; import com.android.tradefed.device.ITestDevice; import com.android.tradefed.invoker.TestInformation; +import com.android.tradefed.invoker.ExecutionFiles.FilesKey; import com.android.tradefed.metrics.proto.MetricMeasurement.Metric; import com.android.tradefed.result.ITestInvocationListener; import com.android.tradefed.result.TestDescription; @@ -48,6 +49,9 @@ import org.junit.runners.JUnit4; @RunWith(JUnit4.class) public class ArtRunTestTest { + // Default run-test name. + private static final String RUN_TEST_NAME = "run-test"; + private ITestInvocationListener mMockInvocationListener; private IAbi mMockAbi; private ITestDevice mMockITestDevice; @@ -56,9 +60,9 @@ public class ArtRunTestTest { private ArtRunTest mArtRunTest; private OptionSetter mSetter; private TestInformation mTestInfo; - // Test dependencies directory on host. - private File mTmpDepsDir; - // Expected output file (within the dependencies directory). + // Target tests directory. + private File mTmpTargetTestsDir; + // Expected output file (under the target tests directory). private File mTmpExpectedFile; @Before @@ -78,19 +82,23 @@ public class ArtRunTestTest { mArtRunTest.setDevice(mMockITestDevice); mSetter = new OptionSetter(mArtRunTest); - // Expected output file. - mTmpDepsDir = FileUtil.createTempDir("art-run-test-deps"); - mTmpExpectedFile = new File(mTmpDepsDir, "expected.txt"); + // Set up target tests directory and expected output file. + mTmpTargetTestsDir = FileUtil.createTempDir("target_testcases"); + File runTestDir = new File(mTmpTargetTestsDir, RUN_TEST_NAME); + runTestDir.mkdir(); + mTmpExpectedFile = new File(runTestDir, "expected.txt"); FileWriter fw = new FileWriter(mTmpExpectedFile); fw.write("output\n"); fw.close(); - mTestInfo = TestInformation.newBuilder().setDependenciesFolder(mTmpDepsDir).build(); + // Set the target tests directory in test information object. + mTestInfo = TestInformation.newBuilder().build(); + mTestInfo.executionFiles().put(FilesKey.TARGET_TESTS_DIRECTORY, mTmpTargetTestsDir); } @After public void tearDown() { - FileUtil.recursiveDelete(mTmpDepsDir); + FileUtil.recursiveDelete(mTmpTargetTestsDir); } /** Helper mocking writing the output of a test command. */ @@ -143,8 +151,7 @@ public class ArtRunTestTest { @Test public void testRunSingleTest_unsetClasspathOption() throws ConfigurationException, DeviceNotAvailableException, IOException { - final String runTestName = "test"; - mSetter.setOptionValue("run-test-name", runTestName); + mSetter.setOptionValue("run-test-name", RUN_TEST_NAME); replayMocks(); try { @@ -160,8 +167,7 @@ public class ArtRunTestTest { @Test public void testRunSingleTest() throws ConfigurationException, DeviceNotAvailableException, IOException { - final String runTestName = "test"; - mSetter.setOptionValue("run-test-name", runTestName); + mSetter.setOptionValue("run-test-name", RUN_TEST_NAME); final String classpath = "/data/local/tmp/test/test.jar"; mSetter.setOptionValue("classpath", classpath); @@ -171,7 +177,7 @@ public class ArtRunTestTest { String runName = "ArtRunTest_abi"; // Beginning of test. mMockInvocationListener.testRunStarted(runName, 1); - TestDescription testId = new TestDescription(runName, runTestName); + TestDescription testId = new TestDescription(runName, RUN_TEST_NAME); mMockInvocationListener.testStarted(testId); String cmd = String.format("dalvikvm64 -classpath %s Main", classpath); // Test execution. @@ -199,8 +205,7 @@ public class ArtRunTestTest { @Test public void testRunSingleTest_unexpectedOutput() throws ConfigurationException, DeviceNotAvailableException, IOException { - final String runTestName = "test"; - mSetter.setOptionValue("run-test-name", runTestName); + mSetter.setOptionValue("run-test-name", RUN_TEST_NAME); final String classpath = "/data/local/tmp/test/test.jar"; mSetter.setOptionValue("classpath", classpath); @@ -210,7 +215,7 @@ public class ArtRunTestTest { String runName = "ArtRunTest_abi"; // Beginning of test. mMockInvocationListener.testRunStarted(runName, 1); - TestDescription testId = new TestDescription(runName, runTestName); + TestDescription testId = new TestDescription(runName, RUN_TEST_NAME); mMockInvocationListener.testStarted(testId); String cmd = String.format("dalvikvm64 -classpath %s Main", classpath); // Test execution. |