diff options
author | Jean-Marie Henaff <jmhenaff@google.com> | 2015-01-15 16:37:55 +0100 |
---|---|---|
committer | Jean-Marie Henaff <jmhenaff@google.com> | 2015-01-22 16:22:08 +0100 |
commit | 7a2eeb82356f80d7c34c32b92e367a9338c694ee (patch) | |
tree | 0c287d6fc7c1c94491c9cfe65e6d002cc566c5ab /jack/tests | |
parent | 94966cfd72001f277bda90ef03062739ed0e2083 (diff) | |
download | toolchain_jack-7a2eeb82356f80d7c34c32b92e367a9338c694ee.tar.gz toolchain_jack-7a2eeb82356f80d7c34c32b92e367a9338c694ee.tar.bz2 toolchain_jack-7a2eeb82356f80d7c34c32b92e367a9338c694ee.zip |
Move test location lookup to jack project
- Introduce undocumented test property "android.home"
for tests that really require an Android source tree
Otherwise use the mandatory jack.home property
- Get rid of ANDROID_BUILD_TOP
Change-Id: Ifabc83fcb8a872eafe35e9e79c28ab9ee3348c6b
Diffstat (limited to 'jack/tests')
-rw-r--r-- | jack/tests/com/android/jack/TestTools.java | 48 | ||||
-rw-r--r-- | jack/tests/com/android/jack/test/TestConfigurationException.java | 43 | ||||
-rw-r--r-- | jack/tests/com/android/jack/test/TestsProperties.java | 98 |
3 files changed, 162 insertions, 27 deletions
diff --git a/jack/tests/com/android/jack/TestTools.java b/jack/tests/com/android/jack/TestTools.java index b851bb83..8925dec6 100644 --- a/jack/tests/com/android/jack/TestTools.java +++ b/jack/tests/com/android/jack/TestTools.java @@ -31,6 +31,7 @@ import com.android.jack.shrob.ListingComparator; import com.android.jack.shrob.proguard.GrammarActions; import com.android.jack.shrob.shrink.ShrinkStructurePrinter; import com.android.jack.shrob.spec.Flags; +import com.android.jack.test.TestsProperties; import com.android.jack.util.ExecuteFile; import com.android.jack.util.TextUtils; import com.android.jack.util.filter.SignatureMethodFilter; @@ -69,10 +70,10 @@ import javax.annotation.Nonnull; public class TestTools { @Nonnull - private static final String JACK_UNIT_TESTS_PATH = "toolchain/jack/jack/tests/"; + private static final String JACK_UNIT_TESTS_PATH = "jack/tests/"; @Nonnull - private static final String JACK_TESTS_PATH = "toolchain/jack/jack-tests/tests/"; + private static final String JACK_TESTS_PATH = "jack-tests/tests/"; @Nonnull private static final String JACK_PACKAGE = "com/android/jack/"; @@ -110,32 +111,36 @@ public class TestTools { @Nonnull public static File getJackTestsWithJackFolder(@Nonnull String testName) { - return getFromAndroidTree(JACK_TESTS_PATH + JACK_PACKAGE + testName + "/jack"); + return new File(getJackTestFolder(testName), "jack"); } @Nonnull public static File getJackTestFolder(@Nonnull String testName) { - return getFromAndroidTree(JACK_TESTS_PATH + JACK_PACKAGE + testName); + return new File(TestsProperties.getJackRootDir(), + JACK_TESTS_PATH + JACK_PACKAGE + testName); } @Nonnull public static File getJackTestFromBinaryName(@Nonnull String signature) { - return getFromAndroidTree(JACK_TESTS_PATH + signature + ".java"); + return new File(TestsProperties.getJackRootDir(), JACK_TESTS_PATH + + signature + ".java"); } @Nonnull public static File getJackTestLibFolder(@Nonnull String testName) { - return getFromAndroidTree(JACK_TESTS_PATH + JACK_PACKAGE + testName + "/lib"); + return new File(getJackTestFolder(testName), "lib"); } @Nonnull public static File getJackUnitTestSrc(@Nonnull String path) { - return getFromAndroidTree(JACK_UNIT_TESTS_PATH + path); + return new File(TestsProperties.getJackRootDir(), + JACK_UNIT_TESTS_PATH + path); } @Nonnull public static File getJackUnitTestFromBinaryName(@Nonnull String signature) { - return getFromAndroidTree(JACK_UNIT_TESTS_PATH + signature + ".java"); + return new File(TestsProperties.getJackRootDir(), + JACK_UNIT_TESTS_PATH + signature + ".java"); } @Nonnull @@ -150,7 +155,7 @@ public class TestTools { @Nonnull public static Sourcelist getSourcelistWithAbsPath(@Nonnull String fileName) { - File sourcelist = new File(getAndroidTop(), fileName); + File sourcelist = new File(TestsProperties.getAndroidRootDir(), fileName); if (!sourcelist.exists()) { throw new AssertionError("Failed to locate sourcelist for \"" + fileName + "\"."); @@ -164,7 +169,8 @@ public class TestTools { String line; while ((line = inBr.readLine()) != null) { - outBr.write(getAndroidTop() + File.separator + line + TextUtils.LINE_SEPARATOR); + outBr.write(TestsProperties.getAndroidRootDir().getPath() + File.separator + line + + TextUtils.LINE_SEPARATOR); } outBr.close(); @@ -196,7 +202,7 @@ public class TestTools { @Nonnull public static File getFromAndroidTree(@Nonnull String filePath) { - File sourceFile = new File(getAndroidTop(), filePath); + File sourceFile = new File(TestsProperties.getAndroidRootDir(), filePath); if (!sourceFile.exists()) { throw new AssertionError("Failed to locate file \"" + filePath + "\"."); } @@ -259,19 +265,16 @@ public class TestTools { "out/host/common/obj/JAVA_LIBRARIES/core-hostdex_intermediates/classes.dex"); } - - @Nonnull public static File[] getDefaultClasspath() { - return new File[] {getFromAndroidTree( - "toolchain/jack/jack/prebuilts/core-stubs-mini.jack")}; + return new File[] { + new File(TestsProperties.getJackRootDir(), "jack-tests/prebuilts/core-stubs-mini.jack")}; } @Nonnull public static String getDefaultClasspathString() { - return getFromAndroidTree( - "toolchain/jack/jack/prebuilts/core-stubs-mini.jack") - .getAbsolutePath(); + return new File(TestsProperties.getJackRootDir(), + "jack-tests/prebuilts/core-stubs-mini.jack").getAbsolutePath(); } @CheckForNull @@ -496,15 +499,6 @@ public class TestTools { } @Nonnull - public static String getAndroidTop() { - String androidTop = System.getenv("ANDROID_BUILD_TOP"); - if (androidTop == null) { - throw new AssertionError("Failed to locate environment variable ANDROID_BUILD_TOP."); - } - return androidTop; - } - - @Nonnull public static JMethod getJMethodWithRejectAllFilter(@Nonnull File fileName, @Nonnull String className, @Nonnull String methodSignature) throws Exception { Options commandLineArgs = TestTools.buildCommandLineArgs(fileName); diff --git a/jack/tests/com/android/jack/test/TestConfigurationException.java b/jack/tests/com/android/jack/test/TestConfigurationException.java new file mode 100644 index 00000000..7f91586d --- /dev/null +++ b/jack/tests/com/android/jack/test/TestConfigurationException.java @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.test; + +import javax.annotation.Nonnull; + +/** + * This {@code Exception} is thrown when something is wrong with the configuration + * of the test framework (unset variables, ...) + */ +public class TestConfigurationException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + public TestConfigurationException() { + } + + public TestConfigurationException(@Nonnull String message) { + super(message); + } + + public TestConfigurationException(@Nonnull Throwable cause) { + super(cause); + } + + public TestConfigurationException(@Nonnull String message, @Nonnull Throwable cause) { + super(message, cause); + } +} diff --git a/jack/tests/com/android/jack/test/TestsProperties.java b/jack/tests/com/android/jack/test/TestsProperties.java new file mode 100644 index 00000000..a11c3e02 --- /dev/null +++ b/jack/tests/com/android/jack/test/TestsProperties.java @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.test; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.Properties; + +import javax.annotation.Nonnull; + +public class TestsProperties { + + @Nonnull + private static final File JACK_ROOT_DIR; + + @Nonnull + private static final String JACK_TESTS_FOLDER = "jack-tests"; + + @Nonnull + private static final Properties testsProperties; + + static { + testsProperties = new Properties(); + String filePath = System.getProperty("tests.config"); + + if (filePath == null) { + throw new TestConfigurationException( + "Configuration file not specified. It must be passed with -Dtests.config on command" + + "line."); + } + File propertyFile; + propertyFile = new File(filePath); + if (!propertyFile.isAbsolute()) { + propertyFile = + new File(System.getenv("user.dir") , filePath); + } + + if (!propertyFile.exists()) { + throw new TestConfigurationException("Configuration file not found: '" + filePath + "'"); + } + try { + testsProperties.load(new FileInputStream(propertyFile)); + } catch (FileNotFoundException e) { + throw new TestConfigurationException(e); + } catch (IOException e) { + throw new TestConfigurationException(e); + } + + String jackHome = testsProperties.getProperty("jack.home"); + + if (jackHome == null) { + throw new TestConfigurationException("'jack.home' property is not set"); + } + JACK_ROOT_DIR = new File(jackHome); + } + + @Nonnull + public static final File getJackRootDir() { + return JACK_ROOT_DIR; + } + + @Nonnull + public static final File getAndroidRootDir() { + return new File(getProperty("android.home")); + } + + @Nonnull + public static String getProperty(@Nonnull String key) { + String value = testsProperties.getProperty(key); + if (value == null) { + throw new TestConfigurationException("Undefined property : '" + key + "'"); + } + return value; + } + + @Nonnull + public static Properties getGlobalProperties() { + return testsProperties; + } + + +} |