Use new file names of ART run-test expected-output files in `ArtRunTest`.
Expected output files now have a unique name, in order to support
TradeFed test suites. (Previously these files were all named
`expected.txt` and would telescope each other when added to the set
of "flattened" tests artifacts of a test suite package.)
This partially reverts commit 9f052906640b4b1b4a05484896adeb09c230e4e4.
Test: m tradefed tradefed-tests
Test: tools/tradefederation/core/tests/run_tradefed_tests.sh \
--class com.android.tradefed.testtype.ArtRunTestTest
Test: atest art-run-test-001-HelloWorld
Bug: 147812905
Change-Id: Ie90eed7fe66cd5e207180f39dd3b4f1e8a9956a4
diff --git a/test_framework/com/android/tradefed/testtype/ArtRunTest.java b/test_framework/com/android/tradefed/testtype/ArtRunTest.java
index a982104..f442e1d 100644
--- a/test_framework/com/android/tradefed/testtype/ArtRunTest.java
+++ b/test_framework/com/android/tradefed/testtype/ArtRunTest.java
@@ -22,7 +22,6 @@
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;
@@ -32,7 +31,6 @@
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;
@@ -143,7 +141,9 @@
// Check the output producted by the test.
if (output != null) {
try {
- File expectedFile = getDependencyFileFromRunTestDir(testInfo, "expected.txt");
+ String expectedFileName = String.format("%s-expected.txt", mRunTestName);
+ File expectedFile =
+ testInfo.getDependencyFile(expectedFileName, /* targetFirst */ true);
CLog.i("Found expected output for run-test %s: %s", mRunTestName, expectedFile);
String expected = FileUtil.readStringFromFile(expectedFile);
if (!output.equals(expected)) {
@@ -176,24 +176,4 @@
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 23d8b75..81c8242 100644
--- a/tests/src/com/android/tradefed/testtype/ArtRunTestTest.java
+++ b/tests/src/com/android/tradefed/testtype/ArtRunTestTest.java
@@ -25,7 +25,6 @@
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;
@@ -49,9 +48,6 @@
@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;
@@ -60,9 +56,9 @@
private ArtRunTest mArtRunTest;
private OptionSetter mSetter;
private TestInformation mTestInfo;
- // Target tests directory.
- private File mTmpTargetTestsDir;
- // Expected output file (under the target tests directory).
+ // Test dependencies directory on host.
+ private File mTmpDepsDir;
+ // Expected output file (within the dependencies directory).
private File mTmpExpectedFile;
@Before
@@ -82,23 +78,22 @@
mArtRunTest.setDevice(mMockITestDevice);
mSetter = new OptionSetter(mArtRunTest);
- // 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();
-
- // Set the target tests directory in test information object.
- mTestInfo = TestInformation.newBuilder().build();
- mTestInfo.executionFiles().put(FilesKey.TARGET_TESTS_DIRECTORY, mTmpTargetTestsDir);
+ // Temporary test directory (e.g. for the expected-output file).
+ mTmpDepsDir = FileUtil.createTempDir("art-run-test-deps");
+ mTestInfo = TestInformation.newBuilder().setDependenciesFolder(mTmpDepsDir).build();
}
@After
public void tearDown() {
- FileUtil.recursiveDelete(mTmpTargetTestsDir);
+ FileUtil.recursiveDelete(mTmpDepsDir);
+ }
+
+ /** Helper creating an expected-output file within the (temporary) test directory. */
+ private void createExpectedOutputFile(String runTestName) throws IOException {
+ mTmpExpectedFile = new File(mTmpDepsDir, runTestName + "-expected.txt");
+ FileWriter fw = new FileWriter(mTmpExpectedFile);
+ fw.write("output\n");
+ fw.close();
}
/** Helper mocking writing the output of a test command. */
@@ -151,7 +146,9 @@
@Test
public void testRunSingleTest_unsetClasspathOption()
throws ConfigurationException, DeviceNotAvailableException, IOException {
- mSetter.setOptionValue("run-test-name", RUN_TEST_NAME);
+ final String runTestName = "test";
+ mSetter.setOptionValue("run-test-name", runTestName);
+ createExpectedOutputFile(runTestName);
replayMocks();
try {
@@ -167,7 +164,9 @@
@Test
public void testRunSingleTest()
throws ConfigurationException, DeviceNotAvailableException, IOException {
- mSetter.setOptionValue("run-test-name", RUN_TEST_NAME);
+ final String runTestName = "test";
+ mSetter.setOptionValue("run-test-name", runTestName);
+ createExpectedOutputFile(runTestName);
final String classpath = "/data/local/tmp/test/test.jar";
mSetter.setOptionValue("classpath", classpath);
@@ -177,7 +176,7 @@
String runName = "ArtRunTest_abi";
// Beginning of test.
mMockInvocationListener.testRunStarted(runName, 1);
- TestDescription testId = new TestDescription(runName, RUN_TEST_NAME);
+ TestDescription testId = new TestDescription(runName, runTestName);
mMockInvocationListener.testStarted(testId);
String cmd = String.format("dalvikvm64 -classpath %s Main", classpath);
// Test execution.
@@ -205,7 +204,9 @@
@Test
public void testRunSingleTest_unexpectedOutput()
throws ConfigurationException, DeviceNotAvailableException, IOException {
- mSetter.setOptionValue("run-test-name", RUN_TEST_NAME);
+ final String runTestName = "test";
+ mSetter.setOptionValue("run-test-name", runTestName);
+ createExpectedOutputFile(runTestName);
final String classpath = "/data/local/tmp/test/test.jar";
mSetter.setOptionValue("classpath", classpath);
@@ -215,7 +216,7 @@
String runName = "ArtRunTest_abi";
// Beginning of test.
mMockInvocationListener.testRunStarted(runName, 1);
- TestDescription testId = new TestDescription(runName, RUN_TEST_NAME);
+ TestDescription testId = new TestDescription(runName, runTestName);
mMockInvocationListener.testStarted(testId);
String cmd = String.format("dalvikvm64 -classpath %s Main", classpath);
// Test execution.