diff options
author | mikehoran <mikehoran@google.com> | 2017-09-01 02:37:38 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-09-01 02:37:38 +0000 |
commit | 2b1f1c5391dec3c2a5a394e87522db3c1e9a94b7 (patch) | |
tree | 8532926943e5632230b183e3e738e25189a73b16 | |
parent | ad39b14bcbcd30de5a61b8c7dc4808069f95dada (diff) | |
parent | 49d8c0f10360df28819a02c328210dfab9d9b473 (diff) | |
download | tradefederation-2b1f1c5391dec3c2a5a394e87522db3c1e9a94b7.tar.gz |
Merge "Add support for android host test cases." into oc-dev am: 9a9c8f69bf
am: 49d8c0f103
Change-Id: I20c2b097e6126ef264ec6f55d0554db7396e6e30
-rw-r--r-- | src/com/android/tradefed/config/ConfigurationFactory.java | 5 | ||||
-rw-r--r-- | src/com/android/tradefed/util/SystemUtil.java | 14 | ||||
-rw-r--r-- | tests/src/com/android/tradefed/util/SystemUtilTest.java | 21 |
3 files changed, 22 insertions, 18 deletions
diff --git a/src/com/android/tradefed/config/ConfigurationFactory.java b/src/com/android/tradefed/config/ConfigurationFactory.java index 92f8a6d4b..d200b1f6c 100644 --- a/src/com/android/tradefed/config/ConfigurationFactory.java +++ b/src/com/android/tradefed/config/ConfigurationFactory.java @@ -220,6 +220,7 @@ public class ConfigurationFactory implements IConfigurationFactory { for (String configFileName : possibleConfigFileNames) { File config = FileUtil.findFile(testCasesDir, configFileName); if (config != null) { + CLog.d("Using config: %s/%s", testCasesDir.getAbsoluteFile(), configFileName); return config; } } @@ -272,9 +273,7 @@ public class ConfigurationFactory implements IConfigurationFactory { } else { if (templateMap != null) { // Clearing the map before returning the cached config to - // avoid seeing them as - // unused. - CLog.d("Using cached configuration, ensuring map is clean."); + // avoid seeing them as unused. templateMap.clear(); } } diff --git a/src/com/android/tradefed/util/SystemUtil.java b/src/com/android/tradefed/util/SystemUtil.java index b1e9284ef..727ad9108 100644 --- a/src/com/android/tradefed/util/SystemUtil.java +++ b/src/com/android/tradefed/util/SystemUtil.java @@ -25,9 +25,8 @@ import com.google.common.annotations.VisibleForTesting; import java.io.File; import java.util.ArrayList; import java.util.Arrays; -import java.util.HashSet; import java.util.List; -import java.util.Set; + /** Utility class for making system calls. */ public class SystemUtil { @@ -63,14 +62,17 @@ public class SystemUtil { /** Get a list of {@link File} pointing to tests directories external to Tradefed. */ public static List<File> getExternalTestCasesDirs() { List<File> testCasesDirs = new ArrayList<File>(); - // TODO(b/36782030): Add ENV_ANDROID_HOST_OUT_TESTCASES back to the list. - Set<String> testCasesDirNames = - new HashSet<String>( - Arrays.asList(singleton.getEnv(ENV_ANDROID_TARGET_OUT_TESTCASES))); + // TODO(b/36782030): Support running both HOST and TARGET tests. + List<String> testCasesDirNames = + // List order matters. ConfigurationFactory caller uses first dir with test config. + Arrays.asList( + singleton.getEnv(ENV_ANDROID_TARGET_OUT_TESTCASES), + singleton.getEnv(ENV_ANDROID_HOST_OUT_TESTCASES)); for (String testCasesDirName : testCasesDirNames) { if (testCasesDirName != null) { File dir = new File(testCasesDirName); if (dir.exists() && dir.isDirectory()) { + CLog.d("Found test case dir: %s", testCasesDirName); testCasesDirs.add(dir); } else { CLog.w( diff --git a/tests/src/com/android/tradefed/util/SystemUtilTest.java b/tests/src/com/android/tradefed/util/SystemUtilTest.java index 5b670af17..f003ccaf6 100644 --- a/tests/src/com/android/tradefed/util/SystemUtilTest.java +++ b/tests/src/com/android/tradefed/util/SystemUtilTest.java @@ -14,7 +14,6 @@ * limitations under the License. */ package com.android.tradefed.util; - import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -24,8 +23,8 @@ import org.mockito.Mockito; import java.io.File; import java.io.IOException; -import java.util.HashSet; -import java.util.Set; +import java.util.ArrayList; +import java.util.List; import org.junit.Test; @@ -38,7 +37,7 @@ public class SystemUtilTest { * environment variables. */ @Test - public void testGetTestCasesDirs() throws IOException { + public void testGetExternalTestCasesDirs() throws IOException { File targetOutDir = null; File hostOutDir = null; try { @@ -48,10 +47,12 @@ public class SystemUtilTest { SystemUtil.singleton = Mockito.mock(SystemUtil.class); Mockito.when(SystemUtil.singleton.getEnv(SystemUtil.ENV_ANDROID_TARGET_OUT_TESTCASES)) .thenReturn(targetOutDir.getAbsolutePath()); + Mockito.when(SystemUtil.singleton.getEnv(SystemUtil.ENV_ANDROID_HOST_OUT_TESTCASES)) + .thenReturn(hostOutDir.getAbsolutePath()); - Set<File> testCasesDirs = new HashSet<File>(SystemUtil.getTestCasesDirs(null)); - assertTrue(testCasesDirs.contains(targetOutDir)); - assertTrue(!testCasesDirs.contains(hostOutDir)); + List<File> testCasesDirs = new ArrayList<File>(SystemUtil.getExternalTestCasesDirs()); + assertTrue(testCasesDirs.get(0).equals(targetOutDir)); + assertTrue(testCasesDirs.get(1).equals(hostOutDir)); } finally { FileUtil.recursiveDelete(targetOutDir); FileUtil.recursiveDelete(hostOutDir); @@ -63,14 +64,16 @@ public class SystemUtilTest { * environment variable is set or the directory does not exist. */ @Test - public void testGetTestCasesDirsNoDir() { + public void testGetExternalTestCasesDirsNoDir() { File targetOutDir = new File("/path/not/exist_1"); SystemUtil.singleton = Mockito.mock(SystemUtil.class); Mockito.when(SystemUtil.singleton.getEnv(SystemUtil.ENV_ANDROID_TARGET_OUT_TESTCASES)) .thenReturn(targetOutDir.getAbsolutePath()); + Mockito.when(SystemUtil.singleton.getEnv(SystemUtil.ENV_ANDROID_HOST_OUT_TESTCASES)) + .thenReturn(null); - Set<File> testCasesDirs = new HashSet<File>(SystemUtil.getTestCasesDirs(null)); + List<File> testCasesDirs = new ArrayList<File>(SystemUtil.getExternalTestCasesDirs()); assertEquals(testCasesDirs.size(), 0); } } |