diff options
| author | Jean-Marie Henaff <jmhenaff@google.com> | 2014-10-15 12:07:58 +0200 |
|---|---|---|
| committer | Jean-Marie Henaff <jmhenaff@google.com> | 2014-12-02 16:54:47 +0100 |
| commit | 8a2287c6a462fbd338086d0f3f819c4bd2469bd9 (patch) | |
| tree | 0bb7547db282ab3413000bbbdc6c448085ba5cdc | |
| parent | 4a95fec33c3822eb6a7b8c6bb8144608ae161f41 (diff) | |
| download | toolchain_jack-8a2287c6a462fbd338086d0f3f819c4bd2469bd9.tar.gz toolchain_jack-8a2287c6a462fbd338086d0f3f819c4bd2469bd9.tar.bz2 toolchain_jack-8a2287c6a462fbd338086d0f3f819c4bd2469bd9.zip | |
Use new JUnit based test framework
Bug: 18547020
Change-Id: I5d02ebdecbf79bea035ae8a042d50a06aa7c2a62
232 files changed, 9995 insertions, 8002 deletions
@@ -237,7 +237,7 @@ </filelist> <filelist id="jackunittests.static.libs.fileset" dir="/"> <file name="${jack.dist.dir}/${jack.libname}" /> - <file name="${junit4.dist.dir}/${junit4.libname}" /> + <file name="${junit4.dist.dir}/${junit4.execname}" /> <file name="${dexlib.dist.dir}/${dexlib.libname}" /> <file name="${dx-ref.dist.dir}/${dx-ref.libname}" /> <file name="${dexcomparator.dist.dir}/${dexcomparator.libname}" /> @@ -285,10 +285,11 @@ <!-- jack-tests --> <!-- ******************* --> <property name="jack-tests.libs.dir" value="${jack-tests.dir}/libs" /> - <property name="jack-tests.build.dir" value="${jack-tests.dir}/build" /> + <property name="jack-tests.build.dir" value="${jack-tests.dir}/intermediates" /> <property name="jack-tests.build.outdir" value="${jack-tests.build.dir}/classes" /> <property name="jack-tests.dist.dir" value="${jack-tests.dir}/dist" /> <property name="jack-tests.libname" value="jack-tests-lib.jar" /> + <property name="jack-tests.execname" value="jack-tests.jar" /> <target name="jack-tests-clean"> <delete dir="${jack-tests.libs.dir}" /> @@ -314,7 +315,7 @@ </copy> </target> - <target name="jack-tests" depends="jack-tests-copy-libs, jack-lib, jackunittests-lib"> + <target name="jack-tests" depends="jack-tests-copy-libs, jack-lib, jackunittests"> <!-- project layout --> <mkdir dir="${jack-tests.build.outdir}"/> <mkdir dir="${jack-tests.dist.dir}"/> @@ -346,9 +347,19 @@ </classpath> </javac> <!-- package --> - <jar destfile="${jack-tests.dist.dir}/${jack-tests.libname}" + <jar destfile="${jack-tests.build.dir}/${jack-tests.libname}" basedir="${jack-tests.build.outdir}" includes="**"/> + <!-- add sched support --> + <pathconvert property="jackunittests.static.libs.list" pathsep=" " refid="jackunittests.static.libs.fileset" /> + <pathconvert property="jack.static.libs.list" pathsep=" " refid="jack.static.libs.fileset" /> + <java jar="${jackunittests.tools.dir}/${sched-build.execname}" fork="true" failonerror="true"> + <arg value="${jack-tests.build.dir}/${jack-tests.libname}" /> + <arg value="${jackunittests.dist.dir}/${jackunittests.libname}" /> + <arg line="${jackunittests.static.libs.list}" /> + <arg line="${jack.static.libs.list}" /> + <arg value="${jack-tests.dist.dir}/${jack-tests.execname}" /> + </java> </target> @@ -1021,7 +1032,7 @@ manifest="${dexcomparator.dir}/etc/manifest.txt" basedir="${dexcomparator.build.outdir}" includes="**"> <zipgroupfileset dir="${dexcomparator.dir}/libs" includes="**/*.jar" /> - </jar> + </jar> </target> <!-- ******************* --> @@ -1082,8 +1093,8 @@ <!-- ******************* --> <property name="core-stubs-mini.dist.dir" value="${core-stubs-mini.dir}/dist"/> <property name="core-stubs-mini.build.dir" value="${core-stubs-mini.dir}/build"/> - <property name="core-stubs-mini.build.outdir" value="${core-stubs-mini.build.dir}/classes"/> - <property name="core-stubs-mini.libname" value="core-stubs-mini.jar"/> + <property name="core-stubs-mini.build.outdir" value="${core-stubs-mini.build.dir}/classes"/> + <property name="core-stubs-mini.libname" value="core-stubs-mini.jar"/> <target name="core-stubs-mini-clean"> <delete dir="${core-stubs-mini.build.dir}" /> @@ -1115,6 +1126,30 @@ </filelist> </copy> </target> + + <property name="tests.config" value="no-file"/> + <property name="test-jack.script" location="${jack-tests.dir}/run-jack-tests" /> + <target name="test-jack" > + <exec executable="${test-jack.script}" failonerror="true"> + <arg value="${tests.config}" /> + <arg value="com.android.jack.PreSubmitTests" /> + </exec> + </target> + + <target name="test-jack-long" > + <exec executable="${test-jack.script}" failonerror="true"> + <arg value="${tests.config}" /> + <arg value="com.android.jack.LongLastingTests" /> + </exec> + </target> + + <target name="test-jack-all" > + <exec executable="${test-jack.script}" failonerror="true"> + <arg value="${tests.config}" /> + <arg value="com.android.jack.AllTests" /> + </exec> + </target> + </project> diff --git a/jack-tests/.classpath b/jack-tests/.classpath index 6e2cd3f0..3cc771dd 100644 --- a/jack-tests/.classpath +++ b/jack-tests/.classpath @@ -2,7 +2,7 @@ <classpath> <classpathentry kind="src" path="src"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> - <classpathentry excluding="com/android/jack/classpath/test002/lib1override/|com/android/jack/compiletime/|com/android/jack/enums/test003/link/Other.java|com/android/jack/enums/test003/link/Values.java|com/android/jack/error/test001/jack/A.java|com/android/jack/error/test002/jack/A.java|com/android/jack/java7/boxing/|com/android/jack/java7/exceptions/|com/android/jack/java7/parser/|com/android/jack/java7/switches/|com/android/jack/java7/trywithresources/|com/android/jack/nopackage/jack/|com/android/jack/lookup/test001/liboverride/|com/android/jack/jarjar/test003/dontcompile/" kind="src" path="tests"/> + <classpathentry excluding="com/android/jack/classpath/test002/lib1override/|com/android/jack/compiletime/test*/**|com/android/jack/enums/test003/link/Other.java|com/android/jack/enums/test003/link/Values.java|com/android/jack/error/test001/jack/A.java|com/android/jack/error/test002/jack/A.java|com/android/jack/jarjar/test003/dontcompile/|com/android/jack/java7/boxing/|com/android/jack/java7/exceptions/|com/android/jack/java7/parser/|com/android/jack/java7/switches/|com/android/jack/java7/trywithresources/|com/android/jack/lookup/test001/liboverride/|com/android/jack/nopackage/test*/**" kind="src" path="tests"/> <classpathentry kind="lib" path="libs/junit4.jar"/> <classpathentry kind="lib" path="libs/antlr-runtime-lib.jar"/> <classpathentry kind="lib" path="libs/dx-ref.jar"/> diff --git a/jack-tests/.settings/org.eclipse.jdt.core.prefs b/jack-tests/.settings/org.eclipse.jdt.core.prefs index 10d8c88d..992473c0 100644 --- a/jack-tests/.settings/org.eclipse.jdt.core.prefs +++ b/jack-tests/.settings/org.eclipse.jdt.core.prefs @@ -6,6 +6,7 @@ org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annota org.eclipse.jdt.core.compiler.annotation.nullable=javax.annotation.CheckForNull org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve org.eclipse.jdt.core.compiler.compliance=1.6 diff --git a/jack-tests/Android.mk b/jack-tests/Android.mk index b0b2e6c7..aec6857e 100644 --- a/jack-tests/Android.mk +++ b/jack-tests/Android.mk @@ -93,7 +93,7 @@ $(call declare-test-with-name,assertion/test002) $(call declare-test-with-name,assertion/test003) # Assign -$(call declare-test-with-name,assign) +$(call declare-test-with-name,assign/test001) # Box $(call declare-test-with-name,box/test001) @@ -173,7 +173,7 @@ $(call declare-test-with-name,tryfinally/finally003) $(call declare-test-with-name,tryfinally/finally004) # Fibonacci -$(call declare-test-with-name,fibonacci) +$(call declare-test-with-name,fibonacci/test001) # Flow $(call declare-test-with-name,flow/loop) @@ -242,7 +242,7 @@ $(call declare-test-with-name,optimizations/exprsimplifier/test001) $(call declare-test,$(JACK_PATH)/tests/com/android/jack/opcodes/test-opcodes.mk) # Order -$(call declare-test-with-name,order) +$(call declare-test-with-name,order/test001) # Return $(call declare-test-with-name,returnstatement/returnvoid) @@ -275,7 +275,7 @@ $(call declare-test-with-name,switchstatement/test010) $(call declare-test-with-name,synchronize/test001) # Three Address -$(call declare-test-with-name,threeaddress) +$(call declare-test-with-name,threeaddress/test001) # Throws $(call declare-test-with-name,throwstatement/test001) diff --git a/jack-tests/README b/jack-tests/README new file mode 100644 index 00000000..3e4f7e65 --- /dev/null +++ b/jack-tests/README @@ -0,0 +1,38 @@ +# 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. + +To run the tests a configuration file must be provided. + +Make a copy of the template so that your settings are not committed. + +It can be passed by setting the property tests.config (with -D) with the path to the file. + +To be able to use jack-tests to run the tests, the configuration file +must define following properties: + * jack.home: it must point to the parent dir of Jack git project + * runtime.location.<runtime environment name>: location of host android runtime environments + +The follwing values are supported: + * runtime.location.dalvik-fast-host + * runtime.location.dalvik-jit + * runtime.location.art-host + +Indicate the location of the legacy java compiler with: + * toolchain.prebuilt.legacy-java-compiler + +In Eclipse: define a run configuration with -Dtests.config as a VM argument. +On the command line: + * use run-jack-tests script with the config file path as first parameter, and the test suite to +run as the second parameter + * use Ant tasks (e.g. jack-test) to run common sets of tests. diff --git a/jack-tests/prebuilts/dexdump b/jack-tests/prebuilts/dexdump Binary files differnew file mode 100755 index 00000000..d10116ef --- /dev/null +++ b/jack-tests/prebuilts/dexdump diff --git a/jack-tests/prebuilts/junit4-targetdex-jack.zip b/jack-tests/prebuilts/junit4-targetdex-jack.zip Binary files differnew file mode 100644 index 00000000..acf39fed --- /dev/null +++ b/jack-tests/prebuilts/junit4-targetdex-jack.zip diff --git a/jack-tests/run-jack-tests b/jack-tests/run-jack-tests new file mode 100755 index 00000000..31d8593d --- /dev/null +++ b/jack-tests/run-jack-tests @@ -0,0 +1,25 @@ +# Copyright (C) 2012 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. + +#!/bin/bash + +if [ $# -lt 2 ] +then + echo "Usage: $(basename $0) <tests config file path> <test suite>+" + exit 1 +fi +set -x +CURRENT_DIR=$(dirname $0) +java -Dtests.config=$1 -cp $CURRENT_DIR/dist/jack-tests.jar:$CURRENT_DIR/../jack/dist/jackunittests-lib.jar org.junit.runner.JUnitCore $2 + diff --git a/jack-tests/src/com/android/jack/test/category/ExtraTests.java b/jack-tests/src/com/android/jack/test/category/ExtraTests.java new file mode 100644 index 00000000..c1e5c951 --- /dev/null +++ b/jack-tests/src/com/android/jack/test/category/ExtraTests.java @@ -0,0 +1,24 @@ +/* + * 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.category; + +/** + * Tests that are not critical, so that we do not want to run them each time we submit a CL. + */ +public interface ExtraTests extends NonPreSubmitTests { + +} diff --git a/jack-tests/src/com/android/jack/test/category/KnownBugs.java b/jack-tests/src/com/android/jack/test/category/KnownBugs.java new file mode 100644 index 00000000..86c6910e --- /dev/null +++ b/jack-tests/src/com/android/jack/test/category/KnownBugs.java @@ -0,0 +1,24 @@ +/* + * 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.category; + +/** + * Tests that show a known Jack bug. + */ +public interface KnownBugs extends NonPreSubmitTests { + +} diff --git a/jack-tests/src/com/android/jack/test/category/NonPreSubmitTests.java b/jack-tests/src/com/android/jack/test/category/NonPreSubmitTests.java new file mode 100644 index 00000000..70cf3cb4 --- /dev/null +++ b/jack-tests/src/com/android/jack/test/category/NonPreSubmitTests.java @@ -0,0 +1,24 @@ +/* + * 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.category; + +/** + * Tests that we do not need to run before submitting a CL. + */ +public interface NonPreSubmitTests { + +} diff --git a/jack-tests/src/com/android/jack/test/category/RedundantTests.java b/jack-tests/src/com/android/jack/test/category/RedundantTests.java new file mode 100644 index 00000000..42fac240 --- /dev/null +++ b/jack-tests/src/com/android/jack/test/category/RedundantTests.java @@ -0,0 +1,25 @@ +/* + * 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.category; + +/** + * Tests that are already covered by another test. They may be interesting on their own, but do not + * need to be included in a pre-submit test suite. + */ +public interface RedundantTests extends NonPreSubmitTests { + +} diff --git a/jack-tests/src/com/android/jack/test/category/SlowTests.java b/jack-tests/src/com/android/jack/test/category/SlowTests.java new file mode 100644 index 00000000..0a7fdbd3 --- /dev/null +++ b/jack-tests/src/com/android/jack/test/category/SlowTests.java @@ -0,0 +1,24 @@ +/* + * 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.category; + +/** + * Tests that are time-consuming, so that we do not want to run them each time we submit a CL. + */ +public interface SlowTests extends NonPreSubmitTests { + +} diff --git a/jack-tests/tests/com/android/jack/enums/EnumTests.java b/jack-tests/src/com/android/jack/test/comparator/ComparatorSeeds.java index 361e6a65..47dbe9d3 100644 --- a/jack-tests/tests/com/android/jack/enums/EnumTests.java +++ b/jack-tests/src/com/android/jack/test/comparator/ComparatorSeeds.java @@ -14,30 +14,30 @@ * limitations under the License. */ -package com.android.jack.enums; +package com.android.jack.test.comparator; -import com.android.jack.test.helper.RuntimeTestHelper; -import com.android.jack.test.runtime.RuntimeTestInfo; -import com.android.jack.test.toolchain.AbstractTestTools; - -import org.junit.Before; -import org.junit.Test; +import com.android.jack.DifferenceFoundException; +import com.android.jack.shrob.SeedsComparator; import java.io.File; +import java.io.IOException; -public class EnumTests { - - private File baseDir; +/** + * This {@link Comparator} is used to compare shrob seeds. + */ +public class ComparatorSeeds extends ComparatorFile { - @Before - public void setUp() { - baseDir = AbstractTestTools.getTestRootDir("com.android.jack.enums.test003"); + public ComparatorSeeds(File candidate, File reference) { + super(candidate, reference); } - @Test - public void compileAndRunTest() throws Exception { - new RuntimeTestHelper(new RuntimeTestInfo(baseDir, "com.android.jack.enums.test003.dx.Tests")) - .compileAndRunTest(); + @Override + public void compare() throws DifferenceFoundException, ComparatorException { + try { + SeedsComparator.compare(reference, candidate); + } catch (IOException e) { + throw new ComparatorException(e); + } } } diff --git a/jack-tests/src/com/android/jack/test/helper/CheckDexStructureTestHelper.java b/jack-tests/src/com/android/jack/test/helper/CheckDexStructureTestHelper.java index f3858bf2..d00d3673 100644 --- a/jack-tests/src/com/android/jack/test/helper/CheckDexStructureTestHelper.java +++ b/jack-tests/src/com/android/jack/test/helper/CheckDexStructureTestHelper.java @@ -17,6 +17,8 @@ package com.android.jack.test.helper; +import com.android.jack.test.toolchain.AndroidToolchain; + import java.io.File; import javax.annotation.Nonnull; @@ -26,8 +28,74 @@ import javax.annotation.Nonnull; */ public class CheckDexStructureTestHelper extends SourceToDexComparisonTestHelper { - public CheckDexStructureTestHelper(@Nonnull File fileOrSourceList) throws Exception { - super(fileOrSourceList); + public CheckDexStructureTestHelper(@Nonnull File... filesOrSourceList) throws Exception { + super(filesOrSourceList); + } + + @Override + @Nonnull + public CheckDexStructureTestHelper setCandidateTestTools( + @Nonnull AndroidToolchain candidateTestTools) { + return (CheckDexStructureTestHelper) super.setCandidateTestTools(candidateTestTools); + } + + @Override + @Nonnull + public CheckDexStructureTestHelper setReferenceTestTools( + @Nonnull AndroidToolchain referenceTestTools) { + return (CheckDexStructureTestHelper) super.setReferenceTestTools(referenceTestTools); + } + + @Override + @Nonnull + public CheckDexStructureTestHelper setCandidateClasspath(@Nonnull File[] classpath) { + return (CheckDexStructureTestHelper) super.setCandidateClasspath(classpath); + } + + @Override + @Nonnull + public CheckDexStructureTestHelper setReferenceClasspath(@Nonnull File[] classpath) { + return (CheckDexStructureTestHelper) super.setReferenceClasspath(classpath); + } + + @Override + @Nonnull + public CheckDexStructureTestHelper setWithDebugInfo(boolean withDebugInfo) { + return (CheckDexStructureTestHelper) super.setWithDebugInfo(withDebugInfo); + } + + @Override + @Nonnull + public CheckDexStructureTestHelper setJarjarRulesFile(@Nonnull File jarjarRulesFile) { + return (CheckDexStructureTestHelper) super.setJarjarRulesFile(jarjarRulesFile); + } + + @Override + @Nonnull + public CheckDexStructureTestHelper setProguardFlags(@Nonnull File... proguardFlags) { + return (CheckDexStructureTestHelper) super.setProguardFlags(proguardFlags); + } + + @Override + @Nonnull + protected void executeCandidateToolchain() throws Exception { + if (withDebugInfos) { + getCandidateToolchain().disableDxOptimizations(); + } else { + getCandidateToolchain().enableDxOptimizations(); + } + super.executeCandidateToolchain(); + } + + @Override + @Nonnull + protected void executeReferenceToolchain() throws Exception { + if (withDebugInfos) { + getReferenceToolchain().disableDxOptimizations(); + } else { + getReferenceToolchain().enableDxOptimizations(); + } + super.executeReferenceToolchain(); } public void compare() throws Exception { diff --git a/jack-tests/src/com/android/jack/test/helper/FileChecker.java b/jack-tests/src/com/android/jack/test/helper/FileChecker.java new file mode 100644 index 00000000..89494c4e --- /dev/null +++ b/jack-tests/src/com/android/jack/test/helper/FileChecker.java @@ -0,0 +1,31 @@ +/* + * 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.helper; + +import java.io.File; + +import javax.annotation.Nonnull; + +/** + * This interface declares a callback method for the caller of a helper to + * add specific checks on a file. + */ +public interface FileChecker { + + void check(@Nonnull File file) throws Exception; + +} diff --git a/jack-tests/src/com/android/jack/test/helper/IncrementalTestHelper.java b/jack-tests/src/com/android/jack/test/helper/IncrementalTestHelper.java index 4f5e1724..39a2740e 100644 --- a/jack-tests/src/com/android/jack/test/helper/IncrementalTestHelper.java +++ b/jack-tests/src/com/android/jack/test/helper/IncrementalTestHelper.java @@ -17,10 +17,12 @@ package com.android.jack.test.helper; import com.android.jack.backend.jayce.JayceFileImporter; +import com.android.jack.library.FileType; import com.android.jack.test.runner.DalvikRunnerHost; import com.android.jack.test.runner.RuntimeRunnerFactory; import com.android.jack.test.toolchain.AbstractTestTools; -import com.android.jack.test.toolchain.JackBasedToolchain; +import com.android.jack.test.toolchain.IToolchain; +import com.android.jack.test.toolchain.JackApiToolchain; import com.android.jack.test.toolchain.JillBasedToolchain; import junit.framework.Assert; @@ -28,13 +30,16 @@ import junit.framework.Assert; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; +import java.io.OutputStream; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import javax.annotation.CheckForNull; import javax.annotation.Nonnull; /** @@ -58,6 +63,10 @@ public class IncrementalTestHelper { private final Set<File> javaFiles = new HashSet<File>(); @Nonnull private final Map<String, Long> fileModificationDate = new HashMap<String, Long>(); + @Nonnull + private OutputStream out = System.out; + @Nonnull + private OutputStream err = System.err; public IncrementalTestHelper(@Nonnull File testingFolder) throws IOException { this.testingFolder = testingFolder; @@ -77,10 +86,18 @@ public class IncrementalTestHelper { jackFolder = new File(compilerStateFolder, "jackFiles"); } + public void setOut(OutputStream out) { + this.out = out; + } + + public void setErr(OutputStream err) { + this.err = err; + } + @Nonnull public File addJavaFile(@Nonnull String packageName, @Nonnull String fileName, @Nonnull String fileContent) throws IOException { - File file = AbstractTestTools.createJavaFile(sourceFolder, packageName, fileName, fileContent); + File file = AbstractTestTools.createFile(sourceFolder, packageName, fileName, fileContent); javaFiles.add(file); return file; } @@ -130,8 +147,9 @@ public class IncrementalTestHelper { Long previousDate = fileModificationDate.get(jackFile.getAbsolutePath()); if (previousDate == null || jackFile.lastModified() > previousDate.longValue()) { String jackFileName = jackFile.getAbsolutePath(); - String binaryTypeName = jackFileName.substring(0, jackFileName.indexOf(".jack")); - binaryTypeName = binaryTypeName.substring(jackFolder.getAbsolutePath().length() + 1); + String binaryTypeName = jackFileName.substring(0, jackFileName.indexOf(".jayce")); + binaryTypeName = binaryTypeName.substring((jackFolder.getAbsolutePath() + File.separatorChar + + FileType.JAYCE.getPrefix()).length() + 1); fqnOfRebuiltTypes.add(binaryTypeName.replace(File.separatorChar, '.')); } } @@ -140,13 +158,32 @@ public class IncrementalTestHelper { } public void incrementalBuildFromFolder() throws Exception { - JackBasedToolchain jackToolchain = - AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class, JillBasedToolchain.class); + incrementalBuildFromFolder(null, Collections.<File>emptyList()); + } + + public void incrementalBuildFromFolder(@Nonnull File[] classpath) throws Exception { + incrementalBuildFromFolder(classpath, Collections.<File>emptyList()); + } + + public void incrementalBuildFromFolder(@CheckForNull File[] classpath, + @Nonnull List<File> imports) throws Exception { + + List<Class<? extends IToolchain>> excludeList = new ArrayList<Class<? extends IToolchain>>(1); + excludeList.add(JillBasedToolchain.class); + + JackApiToolchain jackToolchain = + AbstractTestTools.getCandidateToolchain(JackApiToolchain.class, excludeList); jackToolchain.setIncrementalFolder(getCompilerStateFolder()); + jackToolchain.addStaticLibs(imports.toArray(new File[imports.size()])); + + jackToolchain.setOutputStream(out); + jackToolchain.setErrorStream(err); - jackToolchain.srcToExe( - AbstractTestTools.getClasspathAsString(jackToolchain.getDefaultBootClasspath()), dexOutDir, - sourceFolder); + File[] bootclasspath = jackToolchain.getDefaultBootClasspath(); + + jackToolchain.srcToExe(classpath == null ? AbstractTestTools.getClasspathAsString(bootclasspath) + : AbstractTestTools.getClasspathsAsString(bootclasspath, classpath), dexOutDir, + /* zipFile = */ false, sourceFolder); Thread.sleep(1000); } @@ -162,8 +199,18 @@ public class IncrementalTestHelper { } @Nonnull + public File getDexFile() { + return dexFile; + } + + @Nonnull + public File getJackFolder() { + return jackFolder; + } + + @Nonnull public List<File> getJackFiles() { - return AbstractTestTools.getFiles(jackFolder, ".jack"); + return AbstractTestTools.getFiles(jackFolder, ".jayce"); } } diff --git a/jack-tests/src/com/android/jack/test/helper/RuntimeTestHelper.java b/jack-tests/src/com/android/jack/test/helper/RuntimeTestHelper.java index 29236999..2d1a8738 100644 --- a/jack-tests/src/com/android/jack/test/helper/RuntimeTestHelper.java +++ b/jack-tests/src/com/android/jack/test/helper/RuntimeTestHelper.java @@ -18,6 +18,7 @@ package com.android.jack.test.helper; import com.google.common.base.CharMatcher; import com.google.common.base.Splitter; +import com.google.common.io.Files; import com.android.jack.test.runner.RuntimeRunner; import com.android.jack.test.runtime.RuntimeTestInfo; @@ -45,14 +46,11 @@ import javax.annotation.Nonnull; public class RuntimeTestHelper { @Nonnull - private AndroidToolchain candidateTestTools; - @Nonnull - private AndroidToolchain referenceTestTools; - - @Nonnull private List<File> baseDirs = new ArrayList<File>(1); @Nonnull private List<String> jUnitClasses = new ArrayList<String>(1); + @Nonnull + private List<File> referenceExtraSources = new ArrayList<File>(0); @Nonnull private String srcDirName = "jack"; @@ -65,6 +63,11 @@ public class RuntimeTestHelper { private boolean withDebugInfos = false; + private SourceLevel level = SourceLevel.JAVA_6; + + @Nonnull + private List<FileChecker> testExeCheckers = new ArrayList<FileChecker>(0); + @CheckForNull private String jarjarRulesFileName; @CheckForNull @@ -73,11 +76,6 @@ public class RuntimeTestHelper { @Nonnull private String propertyFileName = "test.properties"; - { - candidateTestTools = AbstractTestTools.getCandidateToolchain(AndroidToolchain.class); - referenceTestTools = AbstractTestTools.getReferenceToolchain(AndroidToolchain.class); - } - public RuntimeTestHelper(@Nonnull RuntimeTestInfo... rtTestInfos) { for (RuntimeTestInfo info : rtTestInfos) { baseDirs.add(info.directory); @@ -117,8 +115,7 @@ public class RuntimeTestHelper { @Nonnull public RuntimeTestHelper setSourceLevel(@Nonnull SourceLevel level) { - candidateTestTools.setSourceLevel(level); - referenceTestTools.setSourceLevel(level); + this.level = level; return this; } @@ -140,7 +137,25 @@ public class RuntimeTestHelper { return this; } + @Nonnull + public RuntimeTestHelper addTestExeFileChecker(@Nonnull FileChecker checker) { + this.testExeCheckers.add(checker); + return this; + } + + @Nonnull + public RuntimeTestHelper addReferenceExtraSources (@Nonnull File... extraSrc) { + for (File file : extraSrc) { + referenceExtraSources.add(file); + } + return this; + } + public void compileAndRunTest() throws Exception { + compileAndRunTest(/* checkStructure = */ false); + } + + public void compileAndRunTest(boolean checkStructure) throws Exception { Properties testProperties = new Properties(); try { loadTestProperties(testProperties); @@ -148,8 +163,19 @@ public class RuntimeTestHelper { // No file, no pb } - candidateTestTools.setWithDebugInfos(withDebugInfos); - referenceTestTools.setWithDebugInfos(withDebugInfos); +// AndroidToolchain candidateTestTools = +// AbstractTestTools.getCandidateToolchain(AndroidToolchain.class); +// AndroidToolchain referenceTestTools = +// AbstractTestTools.getReferenceToolchain(AndroidToolchain.class); +// +// candidateTestTools.setSourceLevel(level); +// referenceTestTools.setSourceLevel(level); +// +// candidateTestTools.setWithDebugInfos(withDebugInfos); +// referenceTestTools.setWithDebugInfos(withDebugInfos); + + AndroidToolchain candidateTestTools = createCandidateToolchain(); + AndroidToolchain referenceTestTools = createReferenceToolchain(); File[] candidateBootClasspath = candidateTestTools.getDefaultBootClasspath(); File[] referenceBootClasspath = referenceTestTools.getDefaultBootClasspath(); @@ -165,27 +191,30 @@ public class RuntimeTestHelper { File libLibCandidate = null; if (getLibSrc().length != 0) { libLibRef = - AbstractTestTools.createTempFile("-lib-ref", referenceTestTools.getLibraryExtension()); + AbstractTestTools.createTempFile("lib-ref", referenceTestTools.getLibraryExtension()); File libBinaryRefDir = AbstractTestTools.createTempDir(); libBinaryRef = new File(libBinaryRefDir, referenceTestTools.getBinaryFileName()); - referenceTestTools.srcToLib(referenceBootClasspathAsString, libLibRef, /* zipFiles = */true, + referenceTestTools.srcToLib(referenceBootClasspathAsString, libLibRef, /* zipFiles = */ true, getLibSrc()); - referenceTestTools.libToDex(libLibRef, libBinaryRefDir); + referenceTestTools.libToExe(libLibRef, libBinaryRefDir, /* zipFile */ false); - libLibCandidate = AbstractTestTools.createTempFile("-lib-candidate", + libLibCandidate = AbstractTestTools.createTempFile("lib-candidate", candidateTestTools.getLibraryExtension()); candidateTestTools.srcToLib(candidateBootClasspathAsString, libLibCandidate, - /* zipFiles = */true, getLibSrc()); + /* zipFiles = */ true, getLibSrc()); } // Compile test src + candidateTestTools = createCandidateToolchain(); + String candidateClasspathAsString; String referenceClasspathAsString; + File[] candidateClassPath = candidateBootClasspath; if (getLibSrc().length != 0) { - File[] candidateClassPath = new File[candidateBootClasspath.length + 1]; + candidateClassPath = new File[candidateBootClasspath.length + 1]; System.arraycopy(candidateBootClasspath, 0, candidateClassPath, 0, candidateBootClasspath.length); - candidateClassPath[candidateClassPath.length - 1] = libLibRef; + candidateClassPath[candidateClassPath.length - 1] = libLibCandidate; candidateClasspathAsString = AbstractTestTools.getClasspathAsString(candidateClassPath); File[] referenceClasspath = new File[referenceBootClasspath.length + 1]; System.arraycopy(referenceBootClasspath, 0, referenceClasspath, 0, @@ -202,28 +231,53 @@ public class RuntimeTestHelper { File testBinaryDir = AbstractTestTools.createTempDir(); File testBinary = new File(testBinaryDir, candidateTestTools.getBinaryFileName()); - if (jarjarRules != null) { - candidateTestTools.setJarjarRules(jarjarRules); + + if (checkStructure) { + CheckDexStructureTestHelper helper = new CheckDexStructureTestHelper(getSrcDir()); + helper.setCandidateClasspath(candidateClassPath); + helper.setCandidateTestTools(candidateTestTools); + if (jarjarRules != null) { + helper.setJarjarRulesFile(jarjarRules); + } + helper.setProguardFlags(proguargFlags.toArray(new File[proguargFlags.size()])); + helper.compare(); + Files.copy(helper.getCandidateDex(), + new File(testBinaryDir, helper.getCandidateDex().getName())); + } else { + if (jarjarRules != null) { + candidateTestTools.setJarjarRules(jarjarRules); + } + candidateTestTools.addProguardFlags(proguargFlags.toArray(new File [proguargFlags.size()])); + candidateTestTools.srcToExe(candidateClasspathAsString, testBinaryDir, /* zipFile = */ false, + getSrcDir()); + } + + for (FileChecker checker : testExeCheckers) { + checker.check(testBinary); } - candidateTestTools.addProguardFlags(proguargFlags.toArray(new File [proguargFlags.size()])); - candidateTestTools.srcToExe(candidateClasspathAsString, testBinaryDir, getSrcDir()); + referenceTestTools = createReferenceToolchain(); File testLib = AbstractTestTools.createTempFile("testRef", referenceTestTools.getLibraryExtension()); - referenceTestTools.srcToLib(referenceClasspathAsString, testLib, /* zipFiles = */true, + referenceTestTools.srcToLib(referenceClasspathAsString, testLib, /* zipFiles = */ true, getSrcDir()); // Compile link src + candidateTestTools = createCandidateToolchain(); + File linkBinary = null; if (getLinkSrc().length != 0) { File linkBinaryDir = AbstractTestTools.createTempDir(); linkBinary = new File(linkBinaryDir, candidateTestTools.getBinaryFileName()); candidateTestTools.setJarjarRules(jarjarRules); candidateTestTools.addProguardFlags(proguargFlags.toArray(new File [proguargFlags.size()])); - candidateTestTools.srcToExe(candidateBootClasspathAsString, linkBinaryDir, getLinkSrc()); + candidateTestTools.srcToExe(candidateBootClasspathAsString, linkBinaryDir, + /* zipFile = */ false, getLinkSrc()); } // Compile ref part src + referenceTestTools = createReferenceToolchain(); + List<File> referenceClasspath = new ArrayList<File>(); for (File f : referenceBootClasspath) { referenceClasspath.add(f); @@ -234,12 +288,29 @@ public class RuntimeTestHelper { if (testLib != null) { referenceClasspath.add(testLib); } + referenceClasspathAsString = AbstractTestTools.getClasspathAsString( referenceClasspath.toArray(new File[referenceClasspath.size()])); + + File [] refSources = getRefSrcDir(); +// File [] sources = new File [referenceExtraSources.size() + refSources.length]; + List<File> sources = new ArrayList<File>(referenceExtraSources.size() + refSources.length); + sources = Lists.addAll(sources, refSources); + sources = Lists.addAll(sources, referenceExtraSources); + File refPartBinaryDir = AbstractTestTools.createTempDir(); +// File [] sources = new File [referenceExtraSources.size() + 1]; +// sources[0] = getRefSrcDir()[0]; +// for (int i = 1; i < sources.length; i++) { +// sources[i] = referenceExtraSources.get(i - 1); +// } File refPartBinary = new File(refPartBinaryDir, referenceTestTools.getBinaryFileName()); - referenceTestTools.srcToExe(referenceClasspathAsString, refPartBinaryDir, getRefSrcDir()); + referenceTestTools.srcToExe( + referenceClasspathAsString, + refPartBinaryDir, + /* zipFile = */ false, + sources.toArray(new File[sources.size()])); List<File> rtClasspath = new ArrayList<File>(); rtClasspath.add(new File(AbstractTestTools.getJackRootDir(), @@ -264,13 +335,32 @@ public class RuntimeTestHelper { rtClasspath.toArray(new File[rtClasspath.size()])); } + @Nonnull + private AndroidToolchain createCandidateToolchain() { + AndroidToolchain candidateTestTools = + AbstractTestTools.getCandidateToolchain(AndroidToolchain.class); + candidateTestTools.setSourceLevel(level); + candidateTestTools.setWithDebugInfos(withDebugInfos); + return candidateTestTools; + } + + @Nonnull + private AndroidToolchain createReferenceToolchain() { + AndroidToolchain referenceTestTools = + AbstractTestTools.getReferenceToolchain(AndroidToolchain.class); + referenceTestTools.setSourceLevel(level); + referenceTestTools.setWithDebugInfos(withDebugInfos); + return referenceTestTools; + } + private static void runOnRuntimeEnvironments(@Nonnull List<String> jUnitClasses, @Nonnull Properties testProperties, @Nonnull File... classpathFiles) throws Exception { List<RuntimeRunner> runnerList = AbstractTestTools.listRuntimeTestRunners(testProperties); + String[] names = Lists.add(jUnitClasses, 0, AbstractTestTools.JUNIT_RUNNER_NAME).toArray( + new String[jUnitClasses.size()]); for (RuntimeRunner runner : runnerList) { Assert.assertEquals(0, runner.run( - getRuntimeArgs(runner.getClass().getSimpleName(), testProperties), Lists.add(jUnitClasses, - 0, AbstractTestTools.JUNIT_RUNNER_NAME).toArray(new String[jUnitClasses.size() + 1]), + getRuntimeArgs(runner.getClass().getSimpleName(), testProperties), names, classpathFiles)); } } diff --git a/jack-tests/src/com/android/jack/test/helper/SourceToDexComparisonTestHelper.java b/jack-tests/src/com/android/jack/test/helper/SourceToDexComparisonTestHelper.java index 72d9108a..87db1bea 100644 --- a/jack-tests/src/com/android/jack/test/helper/SourceToDexComparisonTestHelper.java +++ b/jack-tests/src/com/android/jack/test/helper/SourceToDexComparisonTestHelper.java @@ -47,7 +47,7 @@ public class SourceToDexComparisonTestHelper extends GenericComparisonTestHelper private File[] referenceClasspath; @Nonnull - private File fileOrSourceList; + private File[] filesOrSourceList; @CheckForNull private File jarjarRulesFile = null; @@ -61,9 +61,9 @@ public class SourceToDexComparisonTestHelper extends GenericComparisonTestHelper protected boolean withDebugInfos = false; - public SourceToDexComparisonTestHelper(@Nonnull File fileOrSourceList) throws Exception { + public SourceToDexComparisonTestHelper(@Nonnull File... filesOrSourceList) throws Exception { - this.fileOrSourceList = fileOrSourceList; + this.filesOrSourceList = filesOrSourceList; candidateTestTools = getCandidateToolchain(); referenceTestTools = getReferenceToolchain(); @@ -120,6 +120,22 @@ public class SourceToDexComparisonTestHelper extends GenericComparisonTestHelper return this; } + public File getCandidateDex() { + return candidateDex; + } + + public File getCandidateDexDir() { + return candidateDexDir; + } + + public File getReferenceDex() { + return refDex; + } + + public File getReferenceDexDir() { + return refDexDir; + } + @Nonnull public Comparator createDexFileComparator() { ComparatorDex comparator = new ComparatorDex(candidateDex, refDex); @@ -138,7 +154,7 @@ public class SourceToDexComparisonTestHelper extends GenericComparisonTestHelper } @Nonnull - public SourceToDexComparisonTestHelper setProguardFlags(@Nonnull File[] proguardFlags) { + public SourceToDexComparisonTestHelper setProguardFlags(@Nonnull File... proguardFlags) { this.proguardFlagFiles = proguardFlags; return this; } @@ -149,9 +165,10 @@ public class SourceToDexComparisonTestHelper extends GenericComparisonTestHelper if (jarjarRulesFile != null) { candidateTestTools.setJarjarRules(jarjarRulesFile); } + candidateTestTools.setWithDebugInfos(withDebugInfos); candidateTestTools.addProguardFlags(proguardFlagFiles).srcToExe( AbstractTestTools.getClasspathAsString(candidateClasspath), candidateDexDir, - fileOrSourceList); + /* zipFile = */ false, filesOrSourceList); } @Override @@ -160,7 +177,9 @@ public class SourceToDexComparisonTestHelper extends GenericComparisonTestHelper if (jarjarRulesFile != null) { referenceTestTools.setJarjarRules(jarjarRulesFile); } + referenceTestTools.setWithDebugInfos(withDebugInfos); referenceTestTools.addProguardFlags(proguardFlagFiles).srcToExe( - AbstractTestTools.getClasspathAsString(referenceClasspath), refDexDir, fileOrSourceList); + AbstractTestTools.getClasspathAsString(referenceClasspath), refDexDir, + /* zipFile = */ false, filesOrSourceList); } } diff --git a/jack-tests/src/com/android/jack/test/runtime/RuntimeTest.java b/jack-tests/src/com/android/jack/test/runtime/RuntimeTest.java index 3fdb14ae..d1d20768 100644 --- a/jack-tests/src/com/android/jack/test/runtime/RuntimeTest.java +++ b/jack-tests/src/com/android/jack/test/runtime/RuntimeTest.java @@ -19,6 +19,7 @@ package com.android.jack.test.runtime; import java.util.ArrayList; import java.util.List; +import javax.annotation.CheckForNull; import javax.annotation.Nonnull; /** @@ -27,15 +28,15 @@ import javax.annotation.Nonnull; */ public abstract class RuntimeTest { - @Nonnull - protected List<RuntimeTestInfo> rtTestInfos = new ArrayList<RuntimeTestInfo>(); - - protected RuntimeTest() { - fillRtTestInfos(); - } + @CheckForNull + protected List<RuntimeTestInfo> rtTestInfos = null; @Nonnull public final List<RuntimeTestInfo> getRuntimeTestInfos() { + if (rtTestInfos == null) { + rtTestInfos = new ArrayList<RuntimeTestInfo>(); + fillRtTestInfos(); + } return rtTestInfos; } diff --git a/jack-tests/src/com/android/jack/test/toolchain/AbstractTestTools.java b/jack-tests/src/com/android/jack/test/toolchain/AbstractTestTools.java index ed0f6b07..448927a5 100644 --- a/jack-tests/src/com/android/jack/test/toolchain/AbstractTestTools.java +++ b/jack-tests/src/com/android/jack/test/toolchain/AbstractTestTools.java @@ -50,13 +50,14 @@ public abstract class AbstractTestTools { @Nonnull public static final String JUNIT_RUNNER_NAME = "org.junit.runner.JUnitCore"; - @Nonnull - public static final String TESTS_CONFIGURATION_FILE_VARIABLE = "TESTS_CONFIGURATION_FILE"; @Nonnull private static HashMap<String, ToolchainBuilder> toolchainBuilders; @Nonnull + private static final File JACK_ROOT_DIR; + + @Nonnull private static final String JACK_TESTS_FOLDER = "toolchain" + File.separator + "jack" + File.separator + "jack-tests"; @@ -85,6 +86,57 @@ public abstract class AbstractTestTools { private static final Map<String, File> runtimeEnvironmentLocations = new HashMap<String, File>(); + static { + + toolchainBuilders = new HashMap<String, ToolchainBuilder>(); + toolchainBuilders.put("jack-cli" , new JackCliToolchainBuilder()); + toolchainBuilders.put("jack-api" , new JackApiToolchainBuilder()); + toolchainBuilders.put("legacy" , new LegacyToolchainBuilder()); + toolchainBuilders.put("jill-legacy", new LegacyJillToolchainBuilder()); + + 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)); + runtimes.addAll(parseRuntimeList(testsProperties.getProperty(RUNTIME_LIST_KEY))); + } catch (FileNotFoundException e) { + throw new TestConfigurationException(e); + } catch (IOException e) { + throw new TestConfigurationException(e); + } catch (SecurityException e) { + throw new TestConfigurationException(e); + } catch (IllegalArgumentException e) { + throw new TestConfigurationException(e); + } catch (RuntimeRunnerException 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); + } + private interface ToolchainBuilder { IToolchain build(); } @@ -126,12 +178,15 @@ public abstract class AbstractTestTools { } } - private static File getPrebuilt(@Nonnull String prebuiltName) { - String prebuiltPath = getProperty(TOOLCHAIN_PREBUILT_PREFIX + prebuiltName); + public static File getPrebuilt(@Nonnull String prebuiltName) { + String prebuiltVarName = TOOLCHAIN_PREBUILT_PREFIX + prebuiltName; + String prebuiltPath; - if (prebuiltPath == null) { + try { + prebuiltPath = getProperty(prebuiltVarName); + } catch (TestConfigurationException e) { throw new TestConfigurationException( - "Cannot find path for prebuilt 'prebuiltName' in test.properties"); + "Cannot find path for prebuilt '" + prebuiltName + "'", e); } File result = new File(prebuiltPath); @@ -146,56 +201,10 @@ public abstract class AbstractTestTools { return result; } - static { - toolchainBuilders = new HashMap<String, ToolchainBuilder>(); - toolchainBuilders.put("jack-cli" , new JackCliToolchainBuilder()); - toolchainBuilders.put("jack-api" , new JackApiToolchainBuilder()); - toolchainBuilders.put("legacy" , new LegacyToolchainBuilder()); - toolchainBuilders.put("jill-legacy", new LegacyJillToolchainBuilder()); - - testsProperties = new Properties(); - String filePath = System.getenv(TESTS_CONFIGURATION_FILE_VARIABLE); - File propertyFile; - if (filePath != null) { - propertyFile = new File(filePath); - if (!propertyFile.isAbsolute()) { - propertyFile = new File(System.getProperty("user.dir"), filePath); - } - } else { - filePath = JACK_TESTS_FOLDER + File.separatorChar + "tests.properties"; - propertyFile = - new File(getJackRootDir(), filePath); - } - - if (!propertyFile.exists()) { - throw new TestConfigurationException("Configuration file not found: '" + filePath + "'"); - } - - try { - testsProperties.load(new FileInputStream(propertyFile)); - runtimes.addAll(parseRuntimeList(testsProperties.getProperty(RUNTIME_LIST_KEY))); - } catch (FileNotFoundException e) { - throw new TestConfigurationException(e); - } catch (IOException e) { - throw new TestConfigurationException(e); - } catch (SecurityException e) { - throw new TestConfigurationException(e); - } catch (IllegalArgumentException e) { - throw new TestConfigurationException(e); - } catch (RuntimeRunnerException e) { - throw new TestConfigurationException(e); - } - } @Nonnull public static final File getJackRootDir() { - String pwdPath = System.getProperty("user.dir"); - String[] splitPath = pwdPath.split(JACK_TESTS_FOLDER); - if (splitPath[0].equals(pwdPath)) { - assert splitPath.length == 1; - throw new AssertionError("Unable to compute tests root directory"); - } - return new File(splitPath[0]); + return JACK_ROOT_DIR; } @Nonnull @@ -208,42 +217,59 @@ public abstract class AbstractTestTools { return new File(getTestsRootDir(), packageName.replace(".", File.separator)); } - /** - * Return the {@link IToolchain} specified in the tests configuration file if it matches the - * requirements expressed in paramters. Otherwise, test is ignored. - * - * @param classes Optional list of types. The first one is used to check that the candidate type - * is of this type. Otherwise JUnit test will be ignored. If more types are provided, they - * serve to narrow the expected type set, and are used for exclusion, i.e. if returned - * type is of one of these types, test is ignored. - * @return The candidate toolchain that fulfills the requirements. - */ @SuppressWarnings("unchecked") @Nonnull - public static final <T extends IToolchain> T getCandidateToolchain( - @Nonnull Class<? extends IToolchain>... classes) { + public static final <T extends IToolchain> T getCandidateToolchain() { IToolchain result = createToolchain("candidate.toolchain"); - if (classes.length > 0) { - Assume.assumeTrue(classes[0].isAssignableFrom(result.getClass())); - for (int i = 1; i < classes.length; i++) { - Assume.assumeTrue(!classes[i].isAssignableFrom(result.getClass())); - } - } return (T) result; } @Nonnull - public static final IToolchain getReferenceToolchain() { - return createToolchain("reference.toolchain"); + public static final <T extends IToolchain> T getCandidateToolchain( + @Nonnull Class<? extends IToolchain> clazz) { + T result = getCandidateToolchain(); + Assume.assumeTrue(clazz.isAssignableFrom(result.getClass())); + return result; + } + + @Nonnull + public static final <T extends IToolchain> T getCandidateToolchain( + @Nonnull Class<? extends IToolchain> clazz, + @Nonnull List<Class<? extends IToolchain>> excludeClazz) { + T result = getCandidateToolchain(clazz); + + for (Class<? extends IToolchain> c : excludeClazz) { + Assume.assumeTrue(!c.isAssignableFrom(result.getClass())); + } + + return result; } @SuppressWarnings("unchecked") @Nonnull + public static final <T extends IToolchain> T getReferenceToolchain() { + return (T) createToolchain("reference.toolchain"); + } + + @Nonnull public static final <T extends IToolchain> T getReferenceToolchain( - @Nonnull Class<?> expectedClass) { - IToolchain result = getReferenceToolchain(); - Assume.assumeTrue(expectedClass.isAssignableFrom(result.getClass())); - return (T) result; + @Nonnull Class<? extends IToolchain> clazz) { + T result = getReferenceToolchain(); + Assume.assumeTrue(clazz.isAssignableFrom(result.getClass())); + return result; + } + + @Nonnull + public static final <T extends IToolchain> T getReferenceToolchain( + @Nonnull Class<? extends IToolchain> clazz, + @Nonnull List<Class<? extends IToolchain>> excludeClazz) { + T result = getReferenceToolchain(clazz); + + for (Class<? extends IToolchain> c : excludeClazz) { + Assume.assumeTrue(!c.isAssignableFrom(result.getClass())); + } + + return result; } @Nonnull @@ -374,7 +400,7 @@ public abstract class AbstractTestTools { } @Nonnull - public static File createJavaFile(@Nonnull File folder, @Nonnull String packageName, + public static File createFile(@Nonnull File folder, @Nonnull String packageName, @Nonnull String fileName, @Nonnull String fileContent) throws IOException { File packageFolder = new File(folder, packageName.replace('.', File.separatorChar)); if (!packageFolder.exists() && !packageFolder.mkdirs()) { @@ -549,7 +575,8 @@ public abstract class AbstractTestTools { if (rtLocationPath == null) { throw new TestConfigurationException( - "Location for runtime '" + rtName + "' is not specified"); + "Location for runtime '" + rtName + "' is not specified. Set property '" + + RUNTIME_LOCATION_PREFIX + rtName + "'"); } File rtLocation = new File(rtLocationPath); if (!rtLocation.exists()) { diff --git a/jack-tests/src/com/android/jack/test/toolchain/DummyToolchain.java b/jack-tests/src/com/android/jack/test/toolchain/DummyToolchain.java index 9e130688..f66578fe 100644 --- a/jack-tests/src/com/android/jack/test/toolchain/DummyToolchain.java +++ b/jack-tests/src/com/android/jack/test/toolchain/DummyToolchain.java @@ -18,6 +18,7 @@ package com.android.jack.test.toolchain; import java.io.File; +import javax.annotation.CheckForNull; import javax.annotation.Nonnull; /** @@ -34,24 +35,24 @@ public class DummyToolchain extends AndroidToolchain { @Override @Nonnull - public void srcToExe(@Nonnull String classpath, @Nonnull File out, - @Nonnull File... sources) throws Exception { + public void srcToExe(@CheckForNull String classpath, @Nonnull File out, + boolean zipFile, @Nonnull File... sources) throws Exception { } @Override @Nonnull - public void srcToLib(@Nonnull String classpath, @Nonnull File out, + public void srcToLib(@CheckForNull String classpath, @Nonnull File out, boolean zipFiles, @Nonnull File... sources) throws Exception { } @Override @Nonnull - public void libToDex(@Nonnull File in, @Nonnull File out) throws Exception { + public void libToExe(@Nonnull File in, @Nonnull File out, boolean zipFile) throws Exception { } @Override @Nonnull - public void libToLib(@Nonnull File in, @Nonnull File out) throws Exception { + public void libToLib(@Nonnull File[] in, @Nonnull File out, boolean zipFiles) throws Exception { } @Override @@ -73,4 +74,5 @@ public class DummyToolchain extends AndroidToolchain { // Do nothing return this; } + } diff --git a/jack-tests/src/com/android/jack/test/toolchain/IToolchain.java b/jack-tests/src/com/android/jack/test/toolchain/IToolchain.java index 8c35d1dc..184682b6 100644 --- a/jack-tests/src/com/android/jack/test/toolchain/IToolchain.java +++ b/jack-tests/src/com/android/jack/test/toolchain/IToolchain.java @@ -20,7 +20,9 @@ import com.android.jack.test.toolchain.Toolchain.SourceLevel; import java.io.File; import java.io.OutputStream; +import java.util.List; +import javax.annotation.CheckForNull; import javax.annotation.Nonnull; import javax.annotation.processing.Processor; @@ -31,18 +33,24 @@ import javax.annotation.processing.Processor; public interface IToolchain { @Nonnull - void srcToExe(@Nonnull String classpath, @Nonnull File out, @Nonnull File... sources) - throws Exception; + void srcToExe(@CheckForNull String classpath, @Nonnull File out, boolean zipFile, + @Nonnull File... sources) throws Exception; @Nonnull - void srcToLib(@Nonnull String classpath, @Nonnull File out, boolean zipFiles, + void srcToLib(@CheckForNull String classpath, @Nonnull File out, boolean zipFiles, @Nonnull File... sources) throws Exception; @Nonnull - void libToDex(@Nonnull File in, @Nonnull File out) throws Exception; + void libToExe(@Nonnull File in, @Nonnull File out, boolean zipFile) throws Exception; + + @Nonnull + void libToLib(@Nonnull File in, @Nonnull File out, boolean zipFiles) throws Exception; + + @Nonnull + void libToLib(@Nonnull File[] in, @Nonnull File out, boolean zipFiles) throws Exception; @Nonnull - void libToLib(@Nonnull File in, @Nonnull File out) throws Exception; + void libToLib(@Nonnull List<File> in, @Nonnull File out, boolean zipFiles) throws Exception; @Nonnull IToolchain addStaticLibs(@Nonnull File... staticLibs); diff --git a/jack-tests/src/com/android/jack/test/toolchain/JackApiToolchain.java b/jack-tests/src/com/android/jack/test/toolchain/JackApiToolchain.java index 7466b937..4e3b167d 100644 --- a/jack-tests/src/com/android/jack/test/toolchain/JackApiToolchain.java +++ b/jack-tests/src/com/android/jack/test/toolchain/JackApiToolchain.java @@ -18,15 +18,16 @@ package com.android.jack.test.toolchain; import com.android.jack.Jack; import com.android.jack.Options; +import com.android.jack.backend.dex.rop.CodeItemBuilder; import com.android.jack.experimental.incremental.JackIncremental; import com.android.jack.shrob.spec.Flags; import java.io.File; import java.util.ArrayList; -import java.util.List; import java.util.Map; import java.util.Map.Entry; +import javax.annotation.CheckForNull; import javax.annotation.Nonnull; /** @@ -39,36 +40,26 @@ public class JackApiToolchain extends JackBasedToolchain { JackApiToolchain() {} - @Override @Nonnull - public JackApiToolchain disableDxOptimizations() { - jackOptions.disableDxOptimizations(); + public JackApiToolchain setVerbosityLevel(@Nonnull Options.VerbosityLevel level) { + jackOptions.setVerbosityLevel(level); return this; } @Override @Nonnull - public JackApiToolchain enableDxOptimizations() { - jackOptions.enableDxOptimizations(); - return this; - } - - @Override - @Nonnull - public void srcToExe(@Nonnull String classpath, @Nonnull File out, @Nonnull File... sources) - throws Exception { + public void srcToExe(@CheckForNull String classpath, @Nonnull File out, boolean zipFile, + @Nonnull File... sources) throws Exception { try { - System.setOut(outRedirectStream); - System.setErr(errRedirectStream); - addProperties(properties, jackOptions); if (jackOptions.getFlags() != null) { jackOptions.applyShrobFlags(); } - jackOptions.setEcjArguments(AbstractTestTools.buildEcjArgs()); + // jackOptions.setEcjArguments(AbstractTestTools.buildEcjArgs()); + jackOptions.setEcjArguments(new ArrayList<String>()); if (annotationProcessorClass != null) { jackOptions.getEcjArguments().add("-processor"); @@ -88,25 +79,26 @@ public class JackApiToolchain extends JackBasedToolchain { /* mustExist = */false, sources); jackOptions.setClasspath(classpath); - // !zip - jackOptions.setOutputDir(out); + if (zipFile) { + jackOptions.setOutputZip(out); + } else { + jackOptions.setOutputDir(out); + } jackOptions.setJayceImports(staticLibs); jackOptions.setJarjarRulesFile(jarjarRules); - List<File> proguardFlagsFiles = new ArrayList<File>(); - - for (File flagFile : proguardFlagsFiles) { - proguardFlagsFiles.add(flagFile); - } - if (proguardFlagsFiles.size() > 0) { - jackOptions.setProguardFlagsFile(proguardFlagsFiles); + if (proguardFlags.size() > 0) { + jackOptions.setProguardFlagsFile(proguardFlags); } jackOptions.addProperty(Options.EMIT_LOCAL_DEBUG_INFO.getName(), Boolean.toString(withDebugInfos)); + System.setOut(outRedirectStream); + System.setErr(errRedirectStream); + if (jackOptions.getIncrementalFolder() != null) { JackIncremental.run(jackOptions); } else { @@ -121,51 +113,63 @@ public class JackApiToolchain extends JackBasedToolchain { @Override @Nonnull - public void srcToLib(@Nonnull String classpath, @Nonnull File out, boolean zipFiles, + public void srcToLib(@CheckForNull String classpath, @Nonnull File out, boolean zipFiles, @Nonnull File... sources) throws Exception { try { - Options options = jackOptions; + addProperties(properties, jackOptions); - addProperties(properties, options); + if (jackOptions.getFlags() != null) { + jackOptions.applyShrobFlags(); + } - options.setClasspath(classpath); + jackOptions.setClasspath(classpath); if (zipFiles) { - options.setJayceOutputZip(out); + jackOptions.setJayceOutputZip(out); } else { - options.setJayceOutputDir(out); + jackOptions.setJayceOutputDir(out); } - options.setEcjArguments(AbstractTestTools.buildEcjArgs()); + jackOptions.setEcjArguments(new ArrayList<String>()); if (annotationProcessorClass != null) { - options.getEcjArguments().add("-processor"); - options.getEcjArguments().add(annotationProcessorClass.getName()); + jackOptions.getEcjArguments().add("-processor"); + jackOptions.getEcjArguments().add(annotationProcessorClass.getName()); } if (annotationProcessorOutDir != null) { - options.getEcjArguments().add("-d"); - options.getEcjArguments().add(annotationProcessorOutDir.getAbsolutePath()); + jackOptions.getEcjArguments().add("-d"); + jackOptions.getEcjArguments().add(annotationProcessorOutDir.getAbsolutePath()); } for (String ecjArg : extraEcjArgs) { - options.getEcjArguments().add(ecjArg); + jackOptions.getEcjArguments().add(ecjArg); } - AbstractTestTools.addFile(options.getEcjArguments(), + AbstractTestTools.addFile(jackOptions.getEcjArguments(), /* mustExist = */false, sources); - options.addProperty(Options.EMIT_LOCAL_DEBUG_INFO.getName(), + + jackOptions.setJarjarRulesFile(jarjarRules); + + if (proguardFlags.size() > 0) { + jackOptions.setProguardFlagsFile(proguardFlags); + } + + jackOptions.addProperty(Options.EMIT_LOCAL_DEBUG_INFO.getName(), Boolean.toString(withDebugInfos)); + jackOptions.addProperty(CodeItemBuilder.DEX_OPTIMIZE.getName(), + Boolean.toString(!withDebugInfos)); + System.setOut(outRedirectStream); System.setErr(errRedirectStream); - if (options.getIncrementalFolder() != null) { - JackIncremental.run(options); + if (jackOptions.getIncrementalFolder() != null) { + JackIncremental.run(jackOptions); } else { - Jack.run(options); + Jack.run(jackOptions); } } finally { @@ -176,24 +180,36 @@ public class JackApiToolchain extends JackBasedToolchain { @Override @Nonnull - public void libToDex(@Nonnull File in, @Nonnull File out) throws Exception { + public void libToExe(@Nonnull File in, @Nonnull File out, boolean zipFile) throws Exception { System.setOut(outRedirectStream); System.setErr(errRedirectStream); try { - Options options = jackOptions; - addProperties(properties, options); + addProperties(properties, jackOptions); + + if (jackOptions.getFlags() != null) { + jackOptions.applyShrobFlags(); + } + + jackOptions.setJarjarRulesFile(jarjarRules); - options.getJayceImport().add(in); - options.getJayceImport().addAll(staticLibs); + if (proguardFlags.size() > 0) { + jackOptions.setProguardFlagsFile(proguardFlags); + } + + jackOptions.getJayceImport().add(in); + jackOptions.getJayceImport().addAll(staticLibs); - // !zip - options.setOutputDir(out); + if (zipFile) { + jackOptions.setOutputZip(out); + } else { + jackOptions.setOutputDir(out); + } - if (options.getIncrementalFolder() != null) { - JackIncremental.run(options); + if (jackOptions.getIncrementalFolder() != null) { + JackIncremental.run(jackOptions); } else { - Jack.run(options); + Jack.run(jackOptions); } } finally { @@ -204,8 +220,38 @@ public class JackApiToolchain extends JackBasedToolchain { @Override @Nonnull - public void libToLib(@Nonnull File in, @Nonnull File out) throws Exception { - throw new AssertionError("Not Yet Implemented"); + public void libToLib(@Nonnull File[] in, @Nonnull File out, boolean zipFiles) throws Exception { + addProperties(properties, jackOptions); + + jackOptions.setJarjarRulesFile(jarjarRules); + + if (jackOptions.getFlags() != null) { + jackOptions.applyShrobFlags(); + } + + if (proguardFlags.size() > 0) { + jackOptions.setProguardFlagsFile(proguardFlags); + } + + for (File staticLib : in) { + jackOptions.getJayceImport().add(staticLib); + } + + for (File staticLib : staticLibs) { + jackOptions.getJayceImport().add(staticLib); + } + + if (zipFiles) { + jackOptions.setJayceOutputZip(out); + } else { + jackOptions.setJayceOutputDir(out); + } + + if (jackOptions.getIncrementalFolder() != null) { + JackIncremental.run(jackOptions); + } else { + Jack.run(jackOptions); + } } @Nonnull diff --git a/jack-tests/src/com/android/jack/test/toolchain/JackBasedToolchain.java b/jack-tests/src/com/android/jack/test/toolchain/JackBasedToolchain.java index 729eb89c..3e13d9e7 100644 --- a/jack-tests/src/com/android/jack/test/toolchain/JackBasedToolchain.java +++ b/jack-tests/src/com/android/jack/test/toolchain/JackBasedToolchain.java @@ -16,6 +16,10 @@ package com.android.jack.test.toolchain; +import com.android.jack.backend.dex.DexFileWriter; +import com.android.jack.backend.dex.MultiDexLegacy; +import com.android.jack.backend.dex.rop.CodeItemBuilder; + import java.io.File; import java.util.ArrayList; import java.util.HashMap; @@ -30,6 +34,15 @@ import javax.annotation.Nonnull; */ public abstract class JackBasedToolchain extends AndroidToolchain { + /** + * Available mode for the multidex feature + */ + public enum MultiDexKind { + NONE, + NATIVE, + LEGACY + } + @Nonnull protected final Map<String, String> properties = new HashMap<String, String>(); @CheckForNull @@ -44,6 +57,23 @@ public abstract class JackBasedToolchain extends AndroidToolchain { return this; } + public final JackBasedToolchain setMultiDexKind(@Nonnull MultiDexKind kind) { + switch (kind) { + case NATIVE: + addProperty(DexFileWriter.DEX_WRITING_POLICY.getName(), "multidex"); + break; + case LEGACY: + addProperty(DexFileWriter.DEX_WRITING_POLICY.getName(), "multidex"); + addProperty(MultiDexLegacy.MULTIDEX_LEGACY.getName(), "true"); + break; + case NONE: + break; + default: + throw new AssertionError("Unsupported multi dex kind: '" + kind.name() + "'"); + } + return this; + } + @Nonnull public final JackBasedToolchain addEcjArgs(@Nonnull String arg) { extraEcjArgs.add(arg); @@ -79,10 +109,24 @@ public abstract class JackBasedToolchain extends AndroidToolchain { @Override @Nonnull + public JackBasedToolchain disableDxOptimizations() { + addProperty(CodeItemBuilder.DEX_OPTIMIZE.getName(), "false"); + return this; + } + + @Override + @Nonnull + public JackBasedToolchain enableDxOptimizations() { + addProperty(CodeItemBuilder.DEX_OPTIMIZE.getName(), "true"); + return this; + } + + @Override + @Nonnull public File[] getDefaultBootClasspath() { return new File[] {new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/libs/core-stubs-mini.jar"), new File( AbstractTestTools.getJackRootDir(), - "toolchain/jack/jack-tests/prebuilts/junit4-hostdex.jar")}; + "toolchain/jack/jack-tests/prebuilts/junit4-targetdex-jack.zip")}; } } diff --git a/jack-tests/src/com/android/jack/test/toolchain/JackCliToolchain.java b/jack-tests/src/com/android/jack/test/toolchain/JackCliToolchain.java index 17f11dd7..34d974f9 100644 --- a/jack-tests/src/com/android/jack/test/toolchain/JackCliToolchain.java +++ b/jack-tests/src/com/android/jack/test/toolchain/JackCliToolchain.java @@ -16,7 +16,6 @@ package com.android.jack.test.toolchain; -import com.android.jack.backend.dex.rop.CodeItemBuilder; import com.android.jack.util.ExecuteFile; import java.io.File; @@ -47,8 +46,8 @@ public class JackCliToolchain extends JackBasedToolchain { @Override @Nonnull - public void srcToExe(@Nonnull String classpath, @Nonnull File out, - @Nonnull File... sources) throws Exception { + public void srcToExe(@CheckForNull String classpath, @Nonnull File out, + boolean zipFile, @Nonnull File... sources) throws Exception { List<String> args = new ArrayList<String>(); args.add("java"); @@ -63,41 +62,37 @@ public class JackCliToolchain extends JackBasedToolchain { args.add(com.android.jack.Main.class.getName()); } - if (withDebugInfos) { - args.add("-D"); - args.add("jack.dex.optimize=false"); - } else { - args.add("-D"); - args.add("jack.dex.optimize=true"); - } - addProperties(properties, args); - args.add("--classpath"); - args.add(classpath); + if (classpath != null) { + args.add("--classpath"); + args.add(classpath); + } - args.add("-o"); + if (zipFile) { + args.add("--output-dex-zip"); + } else { + args.add("--output-dex"); + } args.add(out.getAbsolutePath()); if (jarjarRules != null) { - args.add("--jarjar-rules"); + args.add("--config-jarjar"); args.add(jarjarRules.getAbsolutePath()); } for (File flags : proguardFlags) { - args.add("--proguard-flags"); + args.add("--config-proguard"); args.add(flags.getAbsolutePath()); } for (File staticLib : staticLibs) { - args.add("--import-jack"); + args.add("--import"); args.add(staticLib.getAbsolutePath()); } args.addAll(extraJackArgs); - args.add("--ecj"); - if (withDebugInfos) { args.add("-g"); } @@ -129,7 +124,7 @@ public class JackCliToolchain extends JackBasedToolchain { @Override @Nonnull - public void srcToLib(@Nonnull String classpath, @Nonnull File out, + public void srcToLib(@CheckForNull String classpath, @Nonnull File out, boolean zipFiles, @Nonnull File... sources) throws Exception { List<String> args = new ArrayList<String>(); @@ -147,19 +142,29 @@ public class JackCliToolchain extends JackBasedToolchain { addProperties(properties, args); - args.add("--classpath"); - args.add(classpath); + if (classpath != null) { + args.add("--classpath"); + args.add(classpath); + } if (zipFiles) { - args.add("--jack-output-zip"); + args.add("--output-jack"); } else { - args.add("--jack-output"); + args.add("--output-jack-dir"); } args.add(out.getAbsolutePath()); args.addAll(extraJackArgs); - args.add("--ecj"); + if (jarjarRules != null) { + args.add("--config-jarjar"); + args.add(jarjarRules.getAbsolutePath()); + } + + for (File flags : proguardFlags) { + args.add("--config-proguard"); + args.add(flags.getAbsolutePath()); + } if (withDebugInfos) { args.add("-g"); @@ -192,7 +197,7 @@ public class JackCliToolchain extends JackBasedToolchain { @Override @Nonnull - public void libToDex(@Nonnull File in, @Nonnull File out) throws Exception { + public void libToExe(@Nonnull File in, @Nonnull File out, boolean zipFile) throws Exception { List<String> args = new ArrayList<String>(); args.add("java"); @@ -217,15 +222,20 @@ public class JackCliToolchain extends JackBasedToolchain { addProperties(properties, args); - args.add("--import-jack"); + args.add("--import"); args.add(in.getAbsolutePath()); for (File staticLib : staticLibs) { - args.add("--import-jack"); + args.add("--import"); args.add(staticLib.getAbsolutePath()); } - args.add("-o"); + if (zipFile) { + args.add("--output-dex-zip"); + } else { + args.add("--output-dex"); + } + args.add(out.getAbsolutePath()); ExecuteFile exec = new ExecuteFile(args.toArray(new String[args.size()])); @@ -240,22 +250,58 @@ public class JackCliToolchain extends JackBasedToolchain { @Override @Nonnull - public void libToLib(@Nonnull File in, @Nonnull File out) throws Exception { - throw new AssertionError("Not Yet Implemented"); - } + public void libToLib(@Nonnull File[] in, @Nonnull File out, boolean zipFiles) throws Exception { + List<String> args = new ArrayList<String>(); + args.add("java"); + args.add("-cp"); + args.add(jackPrebuilt.getAbsolutePath()); - @Override - @Nonnull - public JackCliToolchain disableDxOptimizations() { - addProperty(CodeItemBuilder.DEX_OPTIMIZE.getName(), "false"); - return this; - } + if (incrementalFolder != null) { + args.add(com.android.jack.experimental.incremental.Main.class.getName()); + args.add("--incremental-folder"); + args.add(incrementalFolder.getAbsolutePath()); + } else { + args.add(com.android.jack.Main.class.getName()); + } + + addProperties(properties, args); + + if (jarjarRules != null) { + args.add("--config-jarjar"); + args.add(jarjarRules.getAbsolutePath()); + } + + for (File flags : proguardFlags) { + args.add("--config-proguard"); + args.add(flags.getAbsolutePath()); + } + + for (File staticlib : in) { + args.add("--import"); + args.add(staticlib.getAbsolutePath()); + } + + for (File staticLib : staticLibs) { + args.add("--import"); + args.add(staticLib.getAbsolutePath()); + } + + if (zipFiles) { + args.add("--output-jack"); + } else { + args.add("--output-jack-dir"); + } + args.add(out.getAbsolutePath()); + + ExecuteFile exec = new ExecuteFile(args.toArray(new String[args.size()])); + exec.setErr(outRedirectStream); + exec.setOut(errRedirectStream); + exec.setVerbose(true); + + if (!exec.run()) { + throw new RuntimeException("Jack compiler exited with an error"); + } - @Override - @Nonnull - public JackCliToolchain enableDxOptimizations() { - addProperty(CodeItemBuilder.DEX_OPTIMIZE.getName(), "true"); - return this; } @Nonnull @@ -278,4 +324,5 @@ public class JackCliToolchain extends JackBasedToolchain { args.add(entry.getKey() + "=" + entry.getValue()); } } + } diff --git a/jack-tests/src/com/android/jack/test/toolchain/LegacyJillToolchain.java b/jack-tests/src/com/android/jack/test/toolchain/LegacyJillToolchain.java index 5ebf6e4f..ebf83f8f 100644 --- a/jack-tests/src/com/android/jack/test/toolchain/LegacyJillToolchain.java +++ b/jack-tests/src/com/android/jack/test/toolchain/LegacyJillToolchain.java @@ -45,8 +45,8 @@ public class LegacyJillToolchain extends JillBasedToolchain { @Override @Nonnull - public void srcToExe(@Nonnull String classpath, @Nonnull File out, @Nonnull File... sources) - throws Exception { + public void srcToExe(@Nonnull String classpath, @Nonnull File out, boolean zipFile, + @Nonnull File... sources) throws Exception { try { File jarFile = AbstractTestTools.createTempFile("legacyLib", ".jar"); @@ -71,7 +71,7 @@ public class LegacyJillToolchain extends JillBasedToolchain { File jillLib = AbstractTestTools.createTempFile("jillLib", ".jar"); executeJill(jarFileProguard, jillLib, true); - libToDex(jillLib, out); + libToExe(jillLib, out, zipFile); } catch (IOException e) { throw new RuntimeException("Legacy toolchain exited with an error", e); @@ -112,7 +112,7 @@ public class LegacyJillToolchain extends JillBasedToolchain { @Override @Nonnull - public void libToLib(@Nonnull File in, @Nonnull File out) throws Exception { + public void libToLib(@Nonnull File[] in, @Nonnull File out, boolean zipFiles) throws Exception { throw new AssertionError("Not Yet Implemented"); } diff --git a/jack-tests/src/com/android/jack/test/toolchain/LegacyToolchain.java b/jack-tests/src/com/android/jack/test/toolchain/LegacyToolchain.java index 3a5a231d..19fcf927 100644 --- a/jack-tests/src/com/android/jack/test/toolchain/LegacyToolchain.java +++ b/jack-tests/src/com/android/jack/test/toolchain/LegacyToolchain.java @@ -25,6 +25,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import javax.annotation.CheckForNull; import javax.annotation.Nonnull; /** @@ -50,8 +51,8 @@ public class LegacyToolchain extends AndroidToolchain { @Override @Nonnull - public void srcToExe(@Nonnull String classpath, @Nonnull File out, - @Nonnull File... sources) throws Exception { + public void srcToExe(@CheckForNull String classpath, @Nonnull File out, + boolean zipFile, @Nonnull File... sources) throws Exception { try { @@ -74,7 +75,7 @@ public class LegacyToolchain extends AndroidToolchain { jarFileProguard = jarFileJarjar; } - libToDex(jarFileProguard, out); + libToExe(jarFileProguard, out, zipFile); } catch (IOException e) { throw new RuntimeException("Legacy toolchain exited with an error", e); @@ -83,7 +84,7 @@ public class LegacyToolchain extends AndroidToolchain { @Override @Nonnull - public void srcToLib(@Nonnull String classpath, @Nonnull File out, + public void srcToLib(@CheckForNull String classpath, @Nonnull File out, boolean zipFiles, @Nonnull File... sources) throws Exception { try { @@ -113,10 +114,10 @@ public class LegacyToolchain extends AndroidToolchain { @Override @Nonnull - public void libToDex(@Nonnull File in, @Nonnull File out) throws Exception { + public void libToExe(@Nonnull File in, @Nonnull File out, boolean zipFile) throws Exception { try { - compileWithDx(in, out); + compileWithDx(in, out, zipFile); } catch (IOException e) { throw new RuntimeException("Legacy toolchain exited with an error", e); } @@ -124,7 +125,7 @@ public class LegacyToolchain extends AndroidToolchain { @Override @Nonnull - public void libToLib(@Nonnull File in, @Nonnull File out) throws Exception { + public void libToLib(@Nonnull File[] in, @Nonnull File out, boolean zipFiles) throws Exception { throw new AssertionError("Not Yet Implemented"); } @@ -170,8 +171,10 @@ public class LegacyToolchain extends AndroidToolchain { args.add(inJar.getAbsolutePath()); args.add("-outjars"); args.add(outJar.getAbsolutePath()); - args.add("-libraryjars"); - args.add(bootclasspathStr); + if (bootclasspathStr != null) { + args.add("-libraryjars"); + args.add(bootclasspathStr); + } args.add("-verbose"); args.add("-forceprocessing"); args.add("-dontoptimize"); @@ -194,10 +197,22 @@ public class LegacyToolchain extends AndroidToolchain { } } - private void compileWithEcj(@Nonnull File[] sources, @Nonnull String classpath, + private void compileWithEcj(@Nonnull File[] sources, @CheckForNull String classpath, @Nonnull File out) { - - throw new AssertionError("Not yet implemented"); + List<String> args = new ArrayList<String>(4 + sources.length); + if (classpath != null) { + args.add("-classpath"); + args.add(classpath); + } + addSourceLevel(sourceLevel, args); + args.add("-noExit"); + args.add("-preserveAllLocals"); + args.add("-d"); + args.add(out.getAbsolutePath()); + for (File sourceFile : sources) { + args.add(sourceFile.getAbsolutePath()); + } + org.eclipse.jdt.internal.compiler.batch.Main.main(args.toArray(new String[args.size()])); } @Override @@ -229,7 +244,7 @@ public class LegacyToolchain extends AndroidToolchain { } private void compileWithExternalRefCompiler(@Nonnull File[] sources, - @Nonnull String classpath, @Nonnull File out) { + @CheckForNull String classpath, @Nonnull File out) { List<String> arguments = new ArrayList<String>(); @@ -265,7 +280,7 @@ public class LegacyToolchain extends AndroidToolchain { } } - private void compileWithDx(File in, File out) + private void compileWithDx(@Nonnull File in, @Nonnull File out, boolean zipFile) throws IOException { try { @@ -274,7 +289,7 @@ public class LegacyToolchain extends AndroidToolchain { Arguments arguments = new Arguments(); - arguments.jarOutput = false; + arguments.jarOutput = zipFile; arguments.outName = new File(out, getBinaryFileName()).getAbsolutePath(); arguments.optimize = !withDebugInfos && useDxOptimization; // this only means we deactivate the check that no core classes are included diff --git a/jack-tests/src/com/android/jack/test/toolchain/Toolchain.java b/jack-tests/src/com/android/jack/test/toolchain/Toolchain.java index d35d814b..6954f276 100644 --- a/jack-tests/src/com/android/jack/test/toolchain/Toolchain.java +++ b/jack-tests/src/com/android/jack/test/toolchain/Toolchain.java @@ -67,21 +67,32 @@ public abstract class Toolchain implements IToolchain { @Override @Nonnull - public abstract void srcToExe(@Nonnull String classpath, @Nonnull File out, - @Nonnull File... sources) throws Exception; + public abstract void srcToExe(@CheckForNull String classpath, @Nonnull File out, + boolean zipFile, @Nonnull File... sources) throws Exception; @Override @Nonnull - public abstract void srcToLib(@Nonnull String classpath, @Nonnull File out, + public abstract void srcToLib(@CheckForNull String classpath, @Nonnull File out, boolean zipFiles, @Nonnull File... sources) throws Exception; @Override @Nonnull - public abstract void libToDex(@Nonnull File in, @Nonnull File out) throws Exception; + public abstract void libToExe(@Nonnull File in, @Nonnull File out, boolean zipFile) + throws Exception; @Override @Nonnull - public abstract void libToLib(@Nonnull File in, @Nonnull File out) throws Exception; + public final void libToLib(@Nonnull File in, @Nonnull File out, boolean zipFiles) + throws Exception { + libToLib(new File[] {in}, out, zipFiles); + } + + @Override + @Nonnull + public final void libToLib(@Nonnull List<File> in, @Nonnull File out, boolean zipFiles) + throws Exception { + libToLib(in.toArray(new File[in.size()]), out, zipFiles); + } @Override @Nonnull @@ -135,9 +146,6 @@ public abstract class Toolchain implements IToolchain { @Override @Nonnull public final Toolchain setOutputStream(@Nonnull OutputStream outputStream) { - if (outRedirectStream != null) { - outRedirectStream.close(); - } outRedirectStream = new PrintStream(outputStream); return this; } @@ -145,9 +153,6 @@ public abstract class Toolchain implements IToolchain { @Override @Nonnull public final Toolchain setErrorStream(@Nonnull OutputStream errorStream) { - if (errRedirectStream != null) { - errRedirectStream.close(); - } errRedirectStream = new PrintStream(errorStream); return this; } diff --git a/jack-tests/tests.properties b/jack-tests/tests.properties deleted file mode 100644 index 34ce165f..00000000 --- a/jack-tests/tests.properties +++ /dev/null @@ -1,12 +0,0 @@ -reference.toolchain=legacy -candidate.toolchain=jack-api -#candidate.toolchain=jill-legacy -toolchain.prebuilt.jack=toolchain/jack/jack/dist/jack.jar -toolchain.prebuilt.jill=toolchain/jill/jill/dist/jill.jar -toolchain.prebuilt.jarjar=toolchain/jack/jack-tests/prebuilts/jarjar.jar -toolchain.prebuilt.proguard=toolchain/jack/jack-tests/prebuilts/proguard.jar -toolchain.prebuilt.legacy-java-compiler=/usr/lib/jvm/java-6-sun/bin/javac -runtime.list=dalvik-fast-host,art-host,dalvik-fast-device -runtime.location.dalvik-fast-host=/disk2/tmp/dalvik-host.rt -runtime.location.dalvik-jit-host=/disk2/tmp/dalvik-host.rt -runtime.location.art-host=/disk2/tmp/art-host.rt diff --git a/jack-tests/tests.properties.template b/jack-tests/tests.properties.template new file mode 100644 index 00000000..995cec5c --- /dev/null +++ b/jack-tests/tests.properties.template @@ -0,0 +1,20 @@ +jack.home= + +# Toolchain names among legacy, jill-legacy, jack-api, jack-cli +reference.toolchain= +candidate.toolchain= + +toolchain.prebuilt.jack=toolchain/jack/jack/dist/jack.jar +toolchain.prebuilt.jill=toolchain/jill/jill/dist/jill.jar +toolchain.prebuilt.jarjar=toolchain/jack/jack-tests/prebuilts/jarjar.jar +toolchain.prebuilt.proguard=toolchain/jack/jack-tests/prebuilts/proguard.jar +toolchain.prebuilt.dexdump=toolchain/jack/jack-tests/prebuilts/dexdump + +# dalvik-fast-host, dalvik-jit-host, art-host, +runtime.list= +runtime.location.dalvik-fast-host= +runtime.location.dalvik-jit-host= +runtime.location.art-host= + +toolchain.prebuilt.legacy-java-compiler= + diff --git a/jack-tests/tests/com/android/jack/AllTests.java b/jack-tests/tests/com/android/jack/AllTests.java index 091867be..e8579dc7 100644 --- a/jack-tests/tests/com/android/jack/AllTests.java +++ b/jack-tests/tests/com/android/jack/AllTests.java @@ -1,54 +1,133 @@ -/* - * 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; +import com.android.jack.analysis.dfa.reachingdefs.ReachingDefsTests; import com.android.jack.annotation.AnnotationTests; import com.android.jack.arithmetic.ArithmeticTests; -import com.android.jack.classpath.ClasspathTest; -import com.android.jack.enums.EnumTests; -import com.android.jack.error.AnnotationProcessorErrorTest; -import com.android.jack.error.CommandLineErrorTest; -import com.android.jack.error.FileAccessErrorTest; -import com.android.jack.experimenal.incremental.DependenciesTests005; +import com.android.jack.array.ArrayTests; +import com.android.jack.assertion.AssertionTests; +import com.android.jack.assign.AssignTests; +import com.android.jack.box.BoxTests; +import com.android.jack.bridge.BridgeTests; +import com.android.jack.cast.CastAllTests; +import com.android.jack.classpath.ClasspathTests; +import com.android.jack.clinit.ClinitTests; +import com.android.jack.comparison.ComparisonTests; +import com.android.jack.compiletime.CompileTimeTests; +import com.android.jack.conditional.ConditionalTests; +import com.android.jack.constant.ConstantTests; +import com.android.jack.debug.DebugTests; +import com.android.jack.dx.DxTests; +import com.android.jack.enums.EnumsTests; +import com.android.jack.error.ErrorHandlingAllTests; +import com.android.jack.experimental.incremental.DependencyAllTests; +import com.android.jack.external.ExternalTests; +import com.android.jack.fibonacci.FibonacciTests; +import com.android.jack.field.FieldTests; +import com.android.jack.fileconflict.FileConflictTests; +import com.android.jack.flow.FlowTests; +import com.android.jack.frontend.MissingClassTest; +import com.android.jack.generic.basic.GenericTests; +import com.android.jack.ifstatement.IfstatementTests; +import com.android.jack.imports.ImportTests; +import com.android.jack.init.InitTests; +import com.android.jack.inner.InnerTests; +import com.android.jack.instance.InstanceTest; +import com.android.jack.invoke.InvokeTests; import com.android.jack.jarjar.JarjarTests; -import com.android.jack.shrob.ObfuscationWithoutMappingTests; +import com.android.jack.java7.Java7AllTest; +import com.android.jack.label.LabelTest; +import com.android.jack.lookup.LookupTests; +import com.android.jack.multidex.MultiDexAllTests; +import com.android.jack.newarray.NewarrayTests; +import com.android.jack.nopackage.NoPackageTests; +import com.android.jack.opcodes.OpcodesTests; +import com.android.jack.optimizations.exprsimplifier.ExprsimplifierTests; +import com.android.jack.optimizations.notsimplifier.NotsimplifierTests; +import com.android.jack.optimizations.uselesscopy.UselessVariableCopyTest; +import com.android.jack.order.OrderTests; +import com.android.jack.preprocessor.PreProcessorTests; +import com.android.jack.resource.ResourceTests; +import com.android.jack.returnstatement.ReturnstatementTests; +import com.android.jack.shrob.ShrobAllTests; +import com.android.jack.string.StringTests; +import com.android.jack.switchstatement.SwitchstatementTests; +import com.android.jack.synchronize.SynchronizeTests; +import com.android.jack.threeaddress.ThreeaddressTests; +import com.android.jack.throwstatement.ThrowstatementTests; import com.android.jack.tools.merger.MergerAllTests; +import com.android.jack.trycatch.TrycatchTests; +import com.android.jack.tryfinally.TryfinallyTests; +import com.android.jack.type.TypeTests; +import com.android.jack.unary.UnaryTests; +import com.android.jack.verify.VerifyTests; +import com.android.jack.withphantom.WithPhantomTests; import org.junit.runner.RunWith; import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; -/** - * Test suite containing all tests (except for regression tests that must be run from the command - * line). - */ @RunWith(Suite.class) @SuiteClasses(value = { AnnotationTests.class, ArithmeticTests.class, - ClasspathTest.class, - DependenciesTests005.class, - EnumTests.class, + ArrayTests.class, + AssertionTests.class, + AssignTests.class, + BoxTests.class, + BridgeTests.class, + CastAllTests.class, + ClasspathTests.class, + ClinitTests.class, + ComparisonTests.class, + CompileTimeTests.class, + ConditionalTests.class, + ConstantTests.class, + DebugTests.class, + DependencyAllTests.class, + DxTests.class, + EnumsTests.class, + ExternalTests.class, + ErrorHandlingAllTests.class, + FibonacciTests.class, + FieldTests.class, + FileConflictTests.class, + FlowTests.class, + GenericTests.class, JarjarTests.class, + IfstatementTests.class, + InitTests.class, + InnerTests.class, + InstanceTest.class, + ImportTests.class, + InvokeTests.class, + Java7AllTest.class, + LabelTest.class, + LookupTests.class, MergerAllTests.class, - ObfuscationWithoutMappingTests.class, - AnnotationProcessorErrorTest.class, - FileAccessErrorTest.class, - CommandLineErrorTest.class + MissingClassTest.class, + MultiDexAllTests.class, + NewarrayTests.class, + ExprsimplifierTests.class, + NotsimplifierTests.class, + NoPackageTests.class, + OrderTests.class, + OpcodesTests.class, + PreProcessorTests.class, + ReturnstatementTests.class, + ResourceTests.class, + ReachingDefsTests.class, + ShrobAllTests.class, + StringTests.class, + SwitchstatementTests.class, + SynchronizeTests.class, + ThreeaddressTests.class, + ThrowstatementTests.class, + TrycatchTests.class, + TryfinallyTests.class, + TypeTests.class, + UnaryTests.class, + UselessVariableCopyTest.class, + VerifyTests.class, + WithPhantomTests.class, }) -public class AllTests { -} +public class AllTests {} diff --git a/jack/tests/com/android/jack/SynchronizeTest.java b/jack-tests/tests/com/android/jack/LongLastingTests.java index 988eec2b..d0a3f406 100644 --- a/jack/tests/com/android/jack/SynchronizeTest.java +++ b/jack-tests/tests/com/android/jack/LongLastingTests.java @@ -16,28 +16,25 @@ package com.android.jack; -import org.junit.BeforeClass; -import org.junit.Test; -import java.io.File; +import com.android.jack.test.category.KnownBugs; +import com.android.jack.test.category.SlowTests; + +import org.junit.experimental.categories.Categories; +import org.junit.experimental.categories.Categories.ExcludeCategory; +import org.junit.experimental.categories.Categories.IncludeCategory; +import org.junit.runner.RunWith; +import org.junit.runners.Suite.SuiteClasses; -/** - * JUnit test for compilation of synchronize tests. - */ -public class SynchronizeTest { - private static final File FILE = - TestTools.getJackTestsWithJackFolder("synchronize/test001"); - @BeforeClass - public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); - } - /** - * Verifies that the test source can compiled from source to dex file. - */ - @Test - public void testCompile() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(FILE)); - } +/** + * Test suite containing tests that are too time-consuming and cannot be run before submitting each + * CL. + */ +@RunWith(Categories.class) +@IncludeCategory(SlowTests.class) +@ExcludeCategory(KnownBugs.class) +@SuiteClasses(value = {AllTests.class}) +public class LongLastingTests { } diff --git a/jack/tests/com/android/jack/transformations/flow/AllTests.java b/jack-tests/tests/com/android/jack/PreSubmitTests.java index 6fa06a6e..ac877716 100644 --- a/jack/tests/com/android/jack/transformations/flow/AllTests.java +++ b/jack-tests/tests/com/android/jack/PreSubmitTests.java @@ -13,13 +13,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.jack.transformations.flow; +package com.android.jack; + + +import com.android.jack.test.category.NonPreSubmitTests; + +import org.junit.experimental.categories.Categories; +import org.junit.experimental.categories.Categories.ExcludeCategory; import org.junit.runner.RunWith; -import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; -@RunWith(Suite.class) -@SuiteClasses(value = {CompileFlowTest.class}) -public class AllTests { -}
\ No newline at end of file +/** + * Test suite to run before submitting a CL (along with regression tests). + */ +@RunWith(Categories.class) +@ExcludeCategory(NonPreSubmitTests.class) +@SuiteClasses(value = {AllWithRegressionTests.class}) +public class PreSubmitTests { +} diff --git a/jack-tests/tests/com/android/jack/RegressionTests.java b/jack-tests/tests/com/android/jack/RegressionTests.java index 3a7ecc6a..5cc95a04 100644 --- a/jack-tests/tests/com/android/jack/RegressionTests.java +++ b/jack-tests/tests/com/android/jack/RegressionTests.java @@ -18,9 +18,46 @@ package com.android.jack; import com.android.jack.annotation.AnnotationTests; import com.android.jack.arithmetic.ArithmeticTests; +import com.android.jack.array.ArrayTests; +import com.android.jack.assertion.AssertionTests; +import com.android.jack.assign.AssignTests; +import com.android.jack.box.BoxTests; +import com.android.jack.bridge.BridgeTests; +import com.android.jack.cast.CastTests; +import com.android.jack.comparison.ComparisonTests; +import com.android.jack.conditional.ConditionalTests; +import com.android.jack.constant.ConstantTests; +import com.android.jack.debug.DebugTests; +import com.android.jack.dx.DxTests; +import com.android.jack.enums.EnumsTests; +import com.android.jack.external.ExternalTests; +import com.android.jack.fibonacci.FibonacciTests; +import com.android.jack.field.FieldTests; +import com.android.jack.flow.FlowTests; +import com.android.jack.ifstatement.IfstatementTests; +import com.android.jack.init.InitTests; +import com.android.jack.inner.InnerTests; +import com.android.jack.invoke.InvokeTests; +import com.android.jack.newarray.NewarrayTests; +import com.android.jack.opcodes.OpcodesTests; +import com.android.jack.optimizations.exprsimplifier.ExprsimplifierTests; +import com.android.jack.optimizations.notsimplifier.NotsimplifierTests; +import com.android.jack.order.OrderTests; +import com.android.jack.returnstatement.ReturnstatementTests; +import com.android.jack.shrob.ShrobRuntimeTests; +import com.android.jack.string.StringTests; +import com.android.jack.switchstatement.SwitchstatementTests; +import com.android.jack.synchronize.SynchronizeTests; import com.android.jack.test.helper.RuntimeTestHelper; import com.android.jack.test.runtime.RuntimeTest; import com.android.jack.test.runtime.RuntimeTestInfo; +import com.android.jack.threeaddress.ThreeaddressTests; +import com.android.jack.throwstatement.ThrowstatementTests; +import com.android.jack.trycatch.TrycatchTests; +import com.android.jack.tryfinally.TryfinallyTests; +import com.android.jack.type.TypeTests; +import com.android.jack.unary.UnaryTests; +import com.android.jack.verify.VerifyTests; import org.junit.BeforeClass; import org.junit.Test; @@ -32,7 +69,44 @@ public class RegressionTests { public RuntimeTest[] tests = { new AnnotationTests(), - new ArithmeticTests() + new ArithmeticTests(), + new ArrayTests(), + new AssertionTests(), + new AssignTests(), + new BoxTests(), + new BridgeTests(), + new CastTests(), + new ComparisonTests(), + new ConditionalTests(), + new ConstantTests(), + new DebugTests(), + new DxTests(), + new EnumsTests(), + new ExprsimplifierTests(), + new ExternalTests(), + new FibonacciTests(), + new FieldTests(), + new FlowTests(), + new IfstatementTests(), + new InitTests(), + new InnerTests(), + new InvokeTests(), + new NewarrayTests(), + new NotsimplifierTests(), +// new OpcodesTests(), + new OrderTests(), + new ReturnstatementTests(), + new ShrobRuntimeTests(), + new StringTests(), + new SwitchstatementTests(), + new SynchronizeTests(), + new ThreeaddressTests(), + new ThrowstatementTests(), + new TrycatchTests(), + new TryfinallyTests(), + new TypeTests(), + new UnaryTests(), + new VerifyTests(), }; @BeforeClass diff --git a/jack-tests/tests/com/android/jack/analysis/dfa/reachingdefs/ReachingDefsTests.java b/jack-tests/tests/com/android/jack/analysis/dfa/reachingdefs/ReachingDefsTests.java new file mode 100644 index 00000000..9053198f --- /dev/null +++ b/jack-tests/tests/com/android/jack/analysis/dfa/reachingdefs/ReachingDefsTests.java @@ -0,0 +1,46 @@ +/* + * 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.analysis.dfa.reachingdefs; + +import com.android.jack.Options; +import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.JackApiToolchain; +import com.android.jack.util.filter.SignatureMethodFilter; + +import org.junit.Test; + +import java.io.File; + +public class ReachingDefsTests { + + @Test + public void testDfa001() throws Exception { + + JackApiToolchain toolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); + + toolchain.addProperty(Options.METHOD_FILTER.getName(), "method-with-signature"); + toolchain.addProperty(SignatureMethodFilter.METHOD_SIGNATURE_FILTER.getName(), + "dfaWithSwitch(I)I"); + toolchain.addProperty(ReachingDefinitions.REACHING_DEFS_CHECKER.getName(), "test001Checker"); + + String classpath = AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()); + File dexOutDir = AbstractTestTools.createTempDir(); + File testSourceDir = AbstractTestTools.getTestRootDir("com.android.jack.analysis.dfa.reachingdefs.test001"); + + toolchain.srcToExe(classpath, dexOutDir, /* zipFile = */ false, testSourceDir); + } +} diff --git a/jack-tests/tests/com/android/jack/annotation/AnnotationTests.java b/jack-tests/tests/com/android/jack/annotation/AnnotationTests.java index e68228ef..9b1aa63b 100644 --- a/jack-tests/tests/com/android/jack/annotation/AnnotationTests.java +++ b/jack-tests/tests/com/android/jack/annotation/AnnotationTests.java @@ -1,28 +1,29 @@ /* - * 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. - */ +* 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.annotation; -import com.android.jack.Main; +import com.android.jack.test.category.KnownBugs; import com.android.jack.test.category.RuntimeRegressionTest; import com.android.jack.test.helper.CheckDexStructureTestHelper; import com.android.jack.test.helper.RuntimeTestHelper; import com.android.jack.test.runtime.RuntimeTest; import com.android.jack.test.runtime.RuntimeTestInfo; import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.IToolchain; import org.junit.BeforeClass; import org.junit.Test; @@ -32,35 +33,148 @@ import java.io.File; public class AnnotationTests extends RuntimeTest { + private RuntimeTestInfo TEST001 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.annotation.test001"), + "com.android.jack.annotation.test001.dx.Tests"); + + private RuntimeTestInfo TEST002 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.annotation.test002"), + "com.android.jack.annotation.test002.dx.Tests"); + + private RuntimeTestInfo TEST003 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.annotation.test003"), + "com.android.jack.annotation.test003.dx.Tests"); + + private RuntimeTestInfo TEST005 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.annotation.test005"), + "com.android.jack.annotation.test005.dx.Tests"); + + private RuntimeTestInfo TEST006 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.annotation.test006"), + "com.android.jack.annotation.test006.dx.Tests"); + + private RuntimeTestInfo TEST007 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.annotation.test007"), + "com.android.jack.annotation.test007.dx.Tests"); + + private RuntimeTestInfo TEST008 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.annotation.test008"), + "com.android.jack.annotation.test008.dx.Tests"); + + private RuntimeTestInfo TEST009 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.annotation.test009"), + "com.android.jack.annotation.test009.dx.Tests"); + private static final File ANNOTATION001_PATH = AbstractTestTools.getTestRootDir("com.android.jack.annotation.test001.jack"); - private RuntimeTestInfo TEST001 = new RuntimeTestInfo( - AbstractTestTools.getTestRootDir("com.android.jack.annotation.test001"), - "com.android.jack.annotation.test001.dx.Tests"); - @BeforeClass public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); + AnnotationTests.class.getClassLoader().setDefaultAssertionStatus(true); + } + @Test + @Category(RuntimeRegressionTest.class) + public void test001() throws Exception { + new RuntimeTestHelper(TEST001).compileAndRunTest(/* checkStructure = */ true); } @Test - public void checkStructure() throws Exception { - CheckDexStructureTestHelper env = - new CheckDexStructureTestHelper(new File(ANNOTATION001_PATH, "Annotation2.java")); - env.setWithDebugInfo(true); - env.compare(); + public void test001_2() throws Exception { + IToolchain toolchain = AbstractTestTools.getCandidateToolchain(); + toolchain.srcToExe( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + AbstractTestTools.createTempDir(), + /* zipFile = */ false, + new File[] { + new File(ANNOTATION001_PATH, "Annotation8.java"), + new File(ANNOTATION001_PATH, "Annotated2.java")}); } + @Test @Category(RuntimeRegressionTest.class) - public void runtimeTest001() throws Exception { - new RuntimeTestHelper(TEST001).compileAndRunTest(); + public void test002() throws Exception { + new RuntimeTestHelper(TEST002).compileAndRunTest(/* checkStructure = */ true); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test003() throws Exception { + new RuntimeTestHelper(TEST003).compileAndRunTest(/* checkStructure = */ true); + } + + @Test + public void test003_1() throws Exception { + CheckDexStructureTestHelper helper = new CheckDexStructureTestHelper( + AbstractTestTools.getTestRootDir("com.android.jack.annotation.test003.jack")); + helper.compare(); + } + + @Test + public void test004() throws Exception { + File testFolder = AbstractTestTools.getTestRootDir("com.android.jack.annotation.test004"); + IToolchain toolchain = AbstractTestTools.getCandidateToolchain(); + toolchain.srcToExe( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + AbstractTestTools.createTempDir(), + /* zipFile = */ false, + testFolder); + } + + @Test + public void test004_1() throws Exception { + CheckDexStructureTestHelper helper = new CheckDexStructureTestHelper( + AbstractTestTools.getTestRootDir("com.android.jack.annotation.test004.jack")); + helper.compare(); + } + + @Test + // Annotation on package are not supported in dex format: http://code.google.com/p/android/issues/detail?id=16149 + @Category({RuntimeRegressionTest.class, KnownBugs.class}) + public void test005() throws Exception { + new RuntimeTestHelper(TEST005).compileAndRunTest(); + } + + @Test + public void test005_1() throws Exception { + CheckDexStructureTestHelper helper = new CheckDexStructureTestHelper( + AbstractTestTools.getTestRootDir("com.android.jack.annotation.test005.jack")); + helper.compare(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test006() throws Exception { + new RuntimeTestHelper(TEST006).compileAndRunTest(/* checkStructure = */ true); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test007() throws Exception { + new RuntimeTestHelper(TEST007).compileAndRunTest(/* checkStructure = */ true); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test008() throws Exception { + new RuntimeTestHelper(TEST008).compileAndRunTest(/* checkStructure = */ true); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test009() throws Exception { + new RuntimeTestHelper(TEST009).compileAndRunTest(/* checkStructure = */ true); } @Override protected void fillRtTestInfos() { rtTestInfos.add(TEST001); + rtTestInfos.add(TEST002); + rtTestInfos.add(TEST003); +// rtTestInfos.add(TEST005); // KnownBug + rtTestInfos.add(TEST006); + rtTestInfos.add(TEST007); + rtTestInfos.add(TEST008); + rtTestInfos.add(TEST009); } - } diff --git a/jack-tests/tests/com/android/jack/arithmetic/ArithmeticTests.java b/jack-tests/tests/com/android/jack/arithmetic/ArithmeticTests.java index 1b6ee1a0..28a42725 100644 --- a/jack-tests/tests/com/android/jack/arithmetic/ArithmeticTests.java +++ b/jack-tests/tests/com/android/jack/arithmetic/ArithmeticTests.java @@ -1,18 +1,18 @@ /* - * 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. - */ +* 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.arithmetic; @@ -29,22 +29,54 @@ import org.junit.experimental.categories.Category; public class ArithmeticTests extends RuntimeTest { private RuntimeTestInfo TEST001 = new RuntimeTestInfo( - AbstractTestTools.getTestRootDir("com.android.jack.arithmetic.test001"), - "com.android.jack.arithmetic.test001.dx.Tests"); + AbstractTestTools.getTestRootDir("com.android.jack.arithmetic.test001"), + "com.android.jack.arithmetic.test001.dx.Tests"); + + private RuntimeTestInfo TEST002 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.arithmetic.test002"), + "com.android.jack.arithmetic.test002.dx.Tests"); + + private RuntimeTestInfo TEST003 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.arithmetic.test003"), + "com.android.jack.arithmetic.test003.dx.Tests"); + + private RuntimeTestInfo TEST004 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.arithmetic.test004"), + "com.android.jack.arithmetic.test004.dx.Tests"); @BeforeClass public static void setUpClass() { ArithmeticTests.class.getClassLoader().setDefaultAssertionStatus(true); } - @Test @Category(RuntimeRegressionTest.class) public void test001() throws Exception { new RuntimeTestHelper(TEST001).compileAndRunTest(); } + @Test + @Category(RuntimeRegressionTest.class) + public void test002() throws Exception { + new RuntimeTestHelper(TEST002).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test003() throws Exception { + new RuntimeTestHelper(TEST003).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test004() throws Exception { + new RuntimeTestHelper(TEST004).compileAndRunTest(); + } + @Override protected void fillRtTestInfos() { rtTestInfos.add(TEST001); + rtTestInfos.add(TEST002); + rtTestInfos.add(TEST003); + rtTestInfos.add(TEST004); } } diff --git a/jack-tests/tests/com/android/jack/array/ArrayTests.java b/jack-tests/tests/com/android/jack/array/ArrayTests.java new file mode 100644 index 00000000..db2a4e85 --- /dev/null +++ b/jack-tests/tests/com/android/jack/array/ArrayTests.java @@ -0,0 +1,49 @@ +/* +* 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.array; + +import com.android.jack.test.category.RuntimeRegressionTest; +import com.android.jack.test.helper.RuntimeTestHelper; +import com.android.jack.test.runtime.RuntimeTest; +import com.android.jack.test.runtime.RuntimeTestInfo; +import com.android.jack.test.toolchain.AbstractTestTools; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +public class ArrayTests extends RuntimeTest { + + private RuntimeTestInfo TEST001 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.array.test001"), + "com.android.jack.array.test001.dx.Tests"); + + @BeforeClass + public static void setUpClass() { + ArrayTests.class.getClassLoader().setDefaultAssertionStatus(true); + } + @Test + @Category(RuntimeRegressionTest.class) + public void test001() throws Exception { + new RuntimeTestHelper(TEST001).compileAndRunTest(); + } + + @Override + protected void fillRtTestInfos() { + rtTestInfos.add(TEST001); + } +} diff --git a/jack-tests/tests/com/android/jack/assertion/AssertionTests.java b/jack-tests/tests/com/android/jack/assertion/AssertionTests.java new file mode 100644 index 00000000..be97229c --- /dev/null +++ b/jack-tests/tests/com/android/jack/assertion/AssertionTests.java @@ -0,0 +1,73 @@ +/* +* 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.assertion; + +import com.android.jack.test.category.KnownBugs; +import com.android.jack.test.category.RuntimeRegressionTest; +import com.android.jack.test.helper.RuntimeTestHelper; +import com.android.jack.test.runtime.RuntimeTest; +import com.android.jack.test.runtime.RuntimeTestInfo; +import com.android.jack.test.toolchain.AbstractTestTools; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +public class AssertionTests extends RuntimeTest { + + private RuntimeTestInfo TEST001 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.assertion.test001"), + "com.android.jack.assertion.test001.dx.Tests"); + + private RuntimeTestInfo TEST002 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.assertion.test002"), + "com.android.jack.assertion.test002.dx.Tests"); + + private RuntimeTestInfo TEST003 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.assertion.test003"), + "com.android.jack.assertion.test003.dx.Tests"); + + @BeforeClass + public static void setUpClass() { + AssertionTests.class.getClassLoader().setDefaultAssertionStatus(true); + } + @Test + // this test must be run with assertions enabled (for now, use dalvik) + @Category({RuntimeRegressionTest.class, KnownBugs.class}) + public void test001() throws Exception { + new RuntimeTestHelper(TEST001).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test002() throws Exception { + new RuntimeTestHelper(TEST002).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test003() throws Exception { + new RuntimeTestHelper(TEST003).compileAndRunTest(); + } + + @Override + protected void fillRtTestInfos() { +// rtTestInfos.add(TEST001); + rtTestInfos.add(TEST002); + rtTestInfos.add(TEST003); + } +} diff --git a/jack-tests/tests/com/android/jack/assign/AssignTests.java b/jack-tests/tests/com/android/jack/assign/AssignTests.java new file mode 100644 index 00000000..565996a4 --- /dev/null +++ b/jack-tests/tests/com/android/jack/assign/AssignTests.java @@ -0,0 +1,49 @@ +/* +* 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.assign; + +import com.android.jack.test.category.RuntimeRegressionTest; +import com.android.jack.test.helper.RuntimeTestHelper; +import com.android.jack.test.runtime.RuntimeTest; +import com.android.jack.test.runtime.RuntimeTestInfo; +import com.android.jack.test.toolchain.AbstractTestTools; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +public class AssignTests extends RuntimeTest { + + private RuntimeTestInfo TEST001 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.assign.test001"), + "com.android.jack.assign.test001.dx.Tests"); + + @BeforeClass + public static void setUpClass() { + AssignTests.class.getClassLoader().setDefaultAssertionStatus(true); + } + @Test + @Category(RuntimeRegressionTest.class) + public void test001() throws Exception { + new RuntimeTestHelper(TEST001).compileAndRunTest(); + } + + @Override + protected void fillRtTestInfos() { + rtTestInfos.add(TEST001); + } +} diff --git a/jack-tests/tests/com/android/jack/assign/dx/Tests.java b/jack-tests/tests/com/android/jack/assign/test001/dx/Tests.java index 24e1d415..4ca76b91 100644 --- a/jack-tests/tests/com/android/jack/assign/dx/Tests.java +++ b/jack-tests/tests/com/android/jack/assign/test001/dx/Tests.java @@ -14,13 +14,13 @@ * limitations under the License. */ -package com.android.jack.assign.dx; +package com.android.jack.assign.test001.dx; + +import com.android.jack.assign.test001.jack.Assignments; import org.junit.Assert; import org.junit.Test; -import com.android.jack.assign.jack.Assignments; - /** * Tests Assignments. */ diff --git a/jack-tests/tests/com/android/jack/assign/jack/Assignments.java b/jack-tests/tests/com/android/jack/assign/test001/jack/Assignments.java index d2a03d2a..7718129e 100644 --- a/jack-tests/tests/com/android/jack/assign/jack/Assignments.java +++ b/jack-tests/tests/com/android/jack/assign/test001/jack/Assignments.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.jack.assign.jack; +package com.android.jack.assign.test001.jack; public class Assignments { public static int field = 5; diff --git a/jack-tests/tests/com/android/jack/box/BoxTests.java b/jack-tests/tests/com/android/jack/box/BoxTests.java new file mode 100644 index 00000000..9f8c94d6 --- /dev/null +++ b/jack-tests/tests/com/android/jack/box/BoxTests.java @@ -0,0 +1,49 @@ +/* +* 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.box; + +import com.android.jack.test.category.RuntimeRegressionTest; +import com.android.jack.test.helper.RuntimeTestHelper; +import com.android.jack.test.runtime.RuntimeTest; +import com.android.jack.test.runtime.RuntimeTestInfo; +import com.android.jack.test.toolchain.AbstractTestTools; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +public class BoxTests extends RuntimeTest { + + private RuntimeTestInfo TEST001 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.box.test001"), + "com.android.jack.box.test001.dx.Tests"); + + @BeforeClass + public static void setUpClass() { + BoxTests.class.getClassLoader().setDefaultAssertionStatus(true); + } + @Test + @Category(RuntimeRegressionTest.class) + public void test001() throws Exception { + new RuntimeTestHelper(TEST001).compileAndRunTest(); + } + + @Override + protected void fillRtTestInfos() { + rtTestInfos.add(TEST001); + } +} diff --git a/jack-tests/tests/com/android/jack/bridge/BridgeTests.java b/jack-tests/tests/com/android/jack/bridge/BridgeTests.java new file mode 100644 index 00000000..0b4eab9c --- /dev/null +++ b/jack-tests/tests/com/android/jack/bridge/BridgeTests.java @@ -0,0 +1,161 @@ +/* +* 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.bridge; + +import com.android.jack.test.category.RuntimeRegressionTest; +import com.android.jack.test.helper.RuntimeTestHelper; +import com.android.jack.test.runtime.RuntimeTest; +import com.android.jack.test.runtime.RuntimeTestInfo; +import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.IToolchain; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import java.io.File; + +public class BridgeTests extends RuntimeTest { + + private RuntimeTestInfo TEST001 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.bridge.test001"), + "com.android.jack.bridge.test001.dx.Tests"); + + private RuntimeTestInfo TEST002 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.bridge.test002"), + "com.android.jack.bridge.test002.dx.Tests"); + + private RuntimeTestInfo TEST003 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.bridge.test003"), + "com.android.jack.bridge.test003.dx.Tests"); + + private RuntimeTestInfo TEST004 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.bridge.test004"), + "com.android.jack.bridge.test004.dx.Tests"); + + private RuntimeTestInfo TEST005 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.bridge.test005"), + "com.android.jack.bridge.test005.dx.Tests"); + + private RuntimeTestInfo TEST006 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.bridge.test006"), + "com.android.jack.bridge.test006.dx.Tests"); + + private RuntimeTestInfo TEST007 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.bridge.test007"), + "com.android.jack.bridge.test007.dx.Tests"); + + @BeforeClass + public static void setUpClass() { + BridgeTests.class.getClassLoader().setDefaultAssertionStatus(true); + } + @Test + @Category(RuntimeRegressionTest.class) + public void test001() throws Exception { + new RuntimeTestHelper(TEST001).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test002() throws Exception { + new RuntimeTestHelper(TEST002).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test003() throws Exception { + new RuntimeTestHelper(TEST003).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test004() throws Exception { + new RuntimeTestHelper(TEST004).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test005() throws Exception { + new RuntimeTestHelper(TEST005).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test006() throws Exception { + new RuntimeTestHelper(TEST006).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + // TODO(jmhenaff): reintroduce ExtraTests category for this one? + public void test007() throws Exception { + new RuntimeTestHelper(TEST007).compileAndRunTest(); + } + + @Test + public void test008() throws Exception { + + IToolchain toolchain = AbstractTestTools.getCandidateToolchain(); + File srcFolder = AbstractTestTools.getTestRootDir("com.android.jack.bridge.test008.jack"); + File jackZipOfGenericPackageProtected = AbstractTestTools.createTempFile("tmpBridge", ".zip"); + toolchain.srcToLib( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + jackZipOfGenericPackageProtected, + /* zipFiles = */ true, + srcFolder); + + // Build jack file from PublicExtendsGeneric.java + toolchain = AbstractTestTools.getCandidateToolchain(); + File jackZipOfPublicExtendsGeneric = AbstractTestTools.createTempFile("tmpBridge", ".zip"); + toolchain.srcToLib( + AbstractTestTools.getClasspathsAsString(toolchain.getDefaultBootClasspath(), new File [] {jackZipOfGenericPackageProtected}), + jackZipOfPublicExtendsGeneric, + /* zipFiles = */ true, + new File(srcFolder, "sub/PublicExtendsGeneric.java")); + + // Build dex file representing Caller.java + toolchain = AbstractTestTools.getCandidateToolchain(); + toolchain = toolchain.addStaticLibs(jackZipOfPublicExtendsGeneric); + File outDexFolder = AbstractTestTools.createTempDir(); + toolchain.srcToExe( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + outDexFolder, + /* zipFile = */ false, + new File(srcFolder, "Caller.java")); + } + + @Test + public void test009() throws Exception { + IToolchain toolchain = AbstractTestTools.getCandidateToolchain(); + toolchain.srcToExe( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + AbstractTestTools.createTempDir(), + /* zipFile = */ false, + AbstractTestTools.getTestRootDir("com.android.jack.bridge.test009")); + } + + @Override + protected void fillRtTestInfos() { + rtTestInfos.add(TEST001); + rtTestInfos.add(TEST002); + rtTestInfos.add(TEST003); + rtTestInfos.add(TEST004); + rtTestInfos.add(TEST005); + rtTestInfos.add(TEST006); + rtTestInfos.add(TEST007); + } +} diff --git a/jack/tests/com/android/jack/tools/merger/MergerAllTests.java b/jack-tests/tests/com/android/jack/cast/CastAllTests.java index 6d222de5..803546b0 100644 --- a/jack/tests/com/android/jack/tools/merger/MergerAllTests.java +++ b/jack-tests/tests/com/android/jack/cast/CastAllTests.java @@ -13,9 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.jack.tools.merger; - -import com.android.jack.tools.merger.test011.MergerTest011; +package com.android.jack.cast; import org.junit.experimental.categories.Categories; import org.junit.runner.RunWith; @@ -23,6 +21,9 @@ import org.junit.runners.Suite.SuiteClasses; @RunWith(Categories.class) @SuiteClasses( -value = {MergerTest011.class}) -public class MergerAllTests { +value = { + CastTests.class, + UselessCastRemoverTest.class + }) +public class CastAllTests { }
\ No newline at end of file diff --git a/jack-tests/tests/com/android/jack/cast/CastTests.java b/jack-tests/tests/com/android/jack/cast/CastTests.java new file mode 100644 index 00000000..c0761f7f --- /dev/null +++ b/jack-tests/tests/com/android/jack/cast/CastTests.java @@ -0,0 +1,139 @@ +/* +* 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.cast; + +import com.android.jack.test.category.RuntimeRegressionTest; +import com.android.jack.test.helper.RuntimeTestHelper; +import com.android.jack.test.runtime.RuntimeTest; +import com.android.jack.test.runtime.RuntimeTestInfo; +import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.IToolchain; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import javax.annotation.Nonnull; + +public class CastTests extends RuntimeTest { + + private RuntimeTestInfo EXPLICIT001 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.cast.explicit001"), + "com.android.jack.cast.explicit001.dx.Tests"); + + private RuntimeTestInfo IMPLICIT001 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.cast.implicit001"), + "com.android.jack.cast.implicit001.dx.Tests"); + + private RuntimeTestInfo IMPLICIT002 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.cast.implicit002"), + "com.android.jack.cast.implicit002.dx.Tests"); + + private RuntimeTestInfo IMPLICIT003 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.cast.implicit003"), + "com.android.jack.cast.implicit003.dx.Tests"); + + private RuntimeTestInfo IMPLICIT004 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.cast.implicit004"), + "com.android.jack.cast.implicit004.dx.Tests"); + + private RuntimeTestInfo USELESS001 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.cast.useless001"), + "com.android.jack.cast.useless001.dx.Tests"); + + private RuntimeTestInfo USELESS002 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.cast.useless002"), + "com.android.jack.cast.useless002.dx.Tests"); + + @BeforeClass + public static void setUpClass() { + CastTests.class.getClassLoader().setDefaultAssertionStatus(true); + } + @Test + @Category(RuntimeRegressionTest.class) + public void explicit001() throws Exception { + new RuntimeTestHelper(EXPLICIT001).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void implicit001() throws Exception { + new RuntimeTestHelper(IMPLICIT001).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void implicit002() throws Exception { + new RuntimeTestHelper(IMPLICIT002).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void implicit003() throws Exception { + new RuntimeTestHelper(IMPLICIT003).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void implicit004() throws Exception { + new RuntimeTestHelper(IMPLICIT004).compileAndRunTest(); + } + + @Test + public void implicitCast005() throws Exception { + compileTest("implicit005"); + } + + @Test + public void implicitCast006() throws Exception { + compileTest("implicit006"); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void useless001() throws Exception { + new RuntimeTestHelper(USELESS001).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void useless002() throws Exception { + new RuntimeTestHelper(USELESS002).compileAndRunTest(); + } + + /** + * Verifies that the test source can compile from source to dex file. + */ + private void compileTest(@Nonnull String name) throws Exception { + IToolchain toolchain = AbstractTestTools.getCandidateToolchain(); + toolchain.srcToExe(AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + AbstractTestTools.createTempDir(), + /* zipFile = */false, + AbstractTestTools.getTestRootDir("com.android.jack.cast." + name + ".jack")); + } + + @Override + protected void fillRtTestInfos() { + rtTestInfos.add(EXPLICIT001); + rtTestInfos.add(IMPLICIT001); + rtTestInfos.add(IMPLICIT002); + rtTestInfos.add(IMPLICIT003); + rtTestInfos.add(IMPLICIT004); + rtTestInfos.add(USELESS001); + rtTestInfos.add(USELESS002); + } +} diff --git a/jack-tests/tests/com/android/jack/cast/UselessCastRemoverTest.java b/jack-tests/tests/com/android/jack/cast/UselessCastRemoverTest.java new file mode 100644 index 00000000..da117bde --- /dev/null +++ b/jack-tests/tests/com/android/jack/cast/UselessCastRemoverTest.java @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2012 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.cast; + + +import com.android.jack.TestTools; +import com.android.jack.backend.dex.DexFileWriter; +import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.IToolchain; + +import junit.framework.Assert; + +import org.jf.dexlib.CodeItem; +import org.jf.dexlib.DexFile; +import org.jf.dexlib.Code.Instruction; +import org.jf.dexlib.Code.Opcode; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.File; + +import javax.annotation.Nonnull; + +public class UselessCastRemoverTest { + + @Nonnull + private static final String CAST = "com/android/jack/transformations/cast/jack/Data"; + + @Nonnull + private static final String CAST_USELESS002 = "com/android/jack/cast/useless002/jack/UselessCast"; + @Nonnull + private static final String CAST_USELESS003 = "com/android/jack/cast/useless003/jack/UselessCast"; + + @BeforeClass + public static void setUp() throws Exception { + UselessCastRemoverTest.class.getClassLoader().setDefaultAssertionStatus(true); + } + + @Test + public void test001() throws Exception { + compileAndCheckUselessCast("com.android.jack.cast.test001", + "Lcom/android/jack/cast/test001/jack/Test001;", "get", + "(Lcom/android/jack/cast/test001/jack/Test001;)I"); + } + + @Test + public void test002() throws Exception { + compileAndCheckUselessCast("com.android.jack.cast.test002", + "Lcom/android/jack/cast/test002/jack/Test002;", "get", + "(Lcom/android/jack/cast/test002/jack/Test002;)I"); + } + + @Test + public void test003() throws Exception { + compileAndCheckUselessCast("com.android.jack.cast.test003", + "Lcom/android/jack/cast/test003/jack/Test003;", "get", + "(Lcom/android/jack/cast/test003/jack/A;)I"); + } + + private void compileAndCheckUselessCast(@Nonnull String testPackage, @Nonnull String typeSig, + @Nonnull String methodName, @Nonnull String methSig) throws Exception { + File testFolder = AbstractTestTools.getTestRootDir(testPackage); + File outFolder = AbstractTestTools.createTempDir(); + File out = new File(outFolder, DexFileWriter.DEX_FILENAME); + + IToolchain toolchain = AbstractTestTools.getCandidateToolchain(); + toolchain.srcToExe(AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + outFolder, + /* zipFile = */false, testFolder); + + DexFile dexFile = new DexFile(out); + CodeItem ci = TestTools.getEncodedMethod(dexFile, typeSig, methodName, methSig).codeItem; + + Assert.assertFalse(hasOpcode(ci, Opcode.CHECK_CAST)); + Assert.assertFalse(hasOpcode(ci, Opcode.CHECK_CAST_JUMBO)); + } + + private boolean hasOpcode(@Nonnull CodeItem codeItem, @Nonnull Opcode opcode) { + for (Instruction inst : codeItem.getInstructions()) { + if (inst.opcode == opcode) { + return true; + } + } + return false; + } + +}
\ No newline at end of file diff --git a/jack-tests/tests/com/android/jack/classpath/ClasspathTest.java b/jack-tests/tests/com/android/jack/classpath/ClasspathTest.java deleted file mode 100644 index 8fde0388..00000000 --- a/jack-tests/tests/com/android/jack/classpath/ClasspathTest.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) 2012 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.classpath; - -import com.android.jack.test.toolchain.AbstractTestTools; -import com.android.jack.test.toolchain.IToolchain; - -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.File; - -public class ClasspathTest { - - @BeforeClass - public static void setUpClass() { - ClasspathTest.class.getClassLoader().setDefaultAssertionStatus(true); - } - - @Test - public void test001() throws Exception { - File libOut = AbstractTestTools.createTempDir(); - - IToolchain toolchain = AbstractTestTools.getCandidateToolchain(); - toolchain.srcToLib(AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), - libOut, false, - new File(AbstractTestTools.getTestRootDir("com.android.jack.classpath.test001"), "lib")); - - File testOut = AbstractTestTools.createTempDir(); - toolchain.srcToLib(AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()) - + File.pathSeparatorChar + libOut.getAbsolutePath(), testOut, false, - new File(AbstractTestTools.getTestRootDir("com.android.jack.classpath.test001"), "jack")); - } - - @Test - public void test002() throws Exception { - IToolchain toolchain = AbstractTestTools.getCandidateToolchain(); - - File testFolder = AbstractTestTools.getTestRootDir("com.android.jack.classpath.test002"); - File outFolder = AbstractTestTools.createTempDir(); - - File lib1Out = AbstractTestTools.createDir(outFolder, "lib1"); - toolchain.srcToLib(AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), - lib1Out, - /* zipFiles = */ false, new File(testFolder, "lib1")); - - File lib1BisOut = AbstractTestTools.createDir(outFolder, "lib1override"); - toolchain.srcToLib(AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), - lib1BisOut, - /* zipFiles = */false, new File(testFolder, "lib1override")); - - File lib2Out = AbstractTestTools.createDir(outFolder, "lib2"); - toolchain.srcToLib(AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()) - + File.pathSeparatorChar + lib1Out.getAbsolutePath(), lib2Out, - /* zipFiles = */false, new File(testFolder, "lib2")); - - toolchain.addStaticLibs(lib2Out); - toolchain.srcToExe(AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()) - + File.pathSeparatorChar + lib1BisOut.getAbsolutePath(), outFolder, - new File(testFolder, "jack")); - - } -} diff --git a/jack-tests/tests/com/android/jack/classpath/ClasspathTests.java b/jack-tests/tests/com/android/jack/classpath/ClasspathTests.java new file mode 100644 index 00000000..f43e3b05 --- /dev/null +++ b/jack-tests/tests/com/android/jack/classpath/ClasspathTests.java @@ -0,0 +1,202 @@ +/* + * Copyright (C) 2012 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.classpath; + +import com.android.jack.Jack; +import com.android.jack.JackAbortException; +import com.android.jack.Options; +import com.android.jack.TestTools; +import com.android.jack.library.FileType; +import com.android.jack.library.LibraryReadingException; +import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.IToolchain; + +import junit.framework.Assert; + +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; + +public class ClasspathTests { + + @BeforeClass + public static void setUpClass() { + ClasspathTests.class.getClassLoader().setDefaultAssertionStatus(true); + } + + @Test + public void test001() throws Exception { + File libOut = AbstractTestTools.createTempDir(); + + IToolchain toolchain = AbstractTestTools.getCandidateToolchain(); + toolchain.srcToLib(AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + libOut, false, + new File(AbstractTestTools.getTestRootDir("com.android.jack.classpath.test001"), "lib")); + + File testOut = AbstractTestTools.createTempDir(); + toolchain.srcToLib(AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()) + + File.pathSeparatorChar + libOut.getAbsolutePath(), testOut, false, + new File(AbstractTestTools.getTestRootDir("com.android.jack.classpath.test001"), "jack")); + } + + @Test + public void test002() throws Exception { + IToolchain toolchain = AbstractTestTools.getCandidateToolchain(); + + String defaultBootCp = + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()); + + File testFolder = AbstractTestTools.getTestRootDir("com.android.jack.classpath.test002"); + File outFolder = AbstractTestTools.createTempDir(); + + File lib1Out = AbstractTestTools.createDir(outFolder, "lib1"); + toolchain.srcToLib(defaultBootCp, + lib1Out, + /* zipFiles = */ false, new File(testFolder, "lib1")); + + File lib1BisOut = AbstractTestTools.createDir(outFolder, "lib1override"); + toolchain = AbstractTestTools.getCandidateToolchain(); + toolchain.srcToLib(defaultBootCp, + lib1BisOut, + /* zipFiles = */ false, new File(testFolder, "lib1override")); + + File lib2Out = AbstractTestTools.createDir(outFolder, "lib2"); + toolchain = AbstractTestTools.getCandidateToolchain(); + toolchain.srcToLib(defaultBootCp + + File.pathSeparatorChar + lib1Out.getAbsolutePath(), lib2Out, + /* zipFiles = */ false, new File(testFolder, "lib2")); + + toolchain = AbstractTestTools.getCandidateToolchain(); + toolchain.addStaticLibs(lib2Out); + toolchain.srcToExe(defaultBootCp + + File.pathSeparatorChar + lib1BisOut.getAbsolutePath(), outFolder, + /* zipFile = */ false, new File(testFolder, "jack")); + + } + + @Test + public void test003() throws Exception { + File testDir = AbstractTestTools.getTestRootDir("com.android.jack.classpath.test003"); + + IToolchain toolchain = AbstractTestTools.getCandidateToolchain(); + File libOut = AbstractTestTools.createTempDir(); + File libSrc = new File(testDir, "lib"); + String defaultBootClasspath = + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()); + toolchain.srcToLib(defaultBootClasspath, libOut, /* zipFiles = */ false, libSrc); + + { + // reference compilation + toolchain = AbstractTestTools.getCandidateToolchain(); + File testOut = AbstractTestTools.createTempDir(); + File testSrc = new File(testDir, "jack"); + toolchain.srcToLib(defaultBootClasspath + File.pathSeparatorChar + libOut.getAbsolutePath(), + testOut, /* zipFiles = */ false, testSrc); + } + + { + // delete unused inner in classpath and check we can still compile with it + boolean deleted = + new File(libOut, FileType.JAYCE.getPrefix() + + "/com/android/jack/classpath/test003/lib/HasInnersClasses$InnerToDelete.jayce") + .delete(); + Assert.assertTrue(deleted); + toolchain = AbstractTestTools.getCandidateToolchain(); + File testOut = AbstractTestTools.createTempDir(); + File testSrc = new File(testDir, "jack"); + toolchain.srcToLib(defaultBootClasspath + File.pathSeparatorChar + libOut.getAbsolutePath(), + testOut, /* zipFiles = */ false, testSrc); + } + } + + @Test + public void libOfLib() throws Exception { + IToolchain toolchain = AbstractTestTools.getCandidateToolchain(); + String defaultClasspath = + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()); + File libOfLibOut = AbstractTestTools.createTempFile("libOfLibOut", ".zip"); + File sourceDir = AbstractTestTools.getTestRootDir("com.android.jack.liboflib.lib2"); + toolchain.srcToLib(defaultClasspath, libOfLibOut, /* zipFiles = */ true, sourceDir); + + toolchain = AbstractTestTools.getCandidateToolchain(); + File libOut = AbstractTestTools.createTempFile("libOut", ".zip"); + sourceDir = AbstractTestTools.getTestRootDir("com.android.jack.liboflib.lib"); + toolchain.srcToLib(defaultClasspath + File.pathSeparatorChar + libOfLibOut.getAbsolutePath(), + libOut, /* zipFiles = */ true, sourceDir); + + toolchain = AbstractTestTools.getCandidateToolchain(); + File mainOut = AbstractTestTools.createTempFile("mainOut", ".zip"); + sourceDir = AbstractTestTools.getTestRootDir("com.android.jack.liboflib.main"); + toolchain.srcToLib(defaultClasspath + File.pathSeparatorChar + libOut.getAbsolutePath(), + mainOut, /* zipFiles = */ true, sourceDir); + } + + @Test + public void testMissingClasspathEntry() throws Exception { + String defaultClasspath = TestTools.getDefaultBootclasspathString(); + File srcDir = TestTools.getJackTestsWithJackFolder("classpath/test004"); + String classpathWithMissingEntry = defaultClasspath + File.pathSeparator + + new File(srcDir, "missing.jack").getAbsolutePath(); + + File testOut = TestTools.createTempFile("ClasspathTest", "missing"); + TestTools.compileSourceToJack(new Options(), srcDir, classpathWithMissingEntry, + testOut, true); + + Options strict = new Options(); + strict.addProperty(Jack.STRICT_CLASSPATH.getName(), "true"); + try { + TestTools.compileSourceToJack(strict, srcDir, classpathWithMissingEntry, + testOut, true); + Assert.fail(); + } catch (JackAbortException e) { + Assert.assertTrue(e.getCause() instanceof LibraryReadingException); + } + } + + @Test + public void testInvalidClasspathEntry() throws Exception { + File srcDir = TestTools.getJackTestsWithJackFolder("classpath/test004"); + compileWithInvalidClasspathEntry(srcDir, new File(srcDir, "Classpath004.java")); + compileWithInvalidClasspathEntry(srcDir, new File(srcDir, "invalid.jack")); + compileWithInvalidClasspathEntry(srcDir, new File(srcDir, "notjack.zip")); + } + + private void compileWithInvalidClasspathEntry(File srcDir, File invalidJack) throws IOException, + Exception { + Assert.assertTrue(invalidJack.isFile()); + String classpathWithInvalidEntry = TestTools.getDefaultBootclasspathString() + + File.pathSeparator + invalidJack.getAbsolutePath(); + + File testOut = TestTools.createTempFile("ClasspathTest", "invalid"); + TestTools.compileSourceToJack(new Options(), srcDir, classpathWithInvalidEntry, + testOut, true); + + Options strict = new Options(); + strict.addProperty(Jack.STRICT_CLASSPATH.getName(), "true"); + try { + TestTools.compileSourceToJack(strict, srcDir, classpathWithInvalidEntry, + testOut, true); + Assert.fail(); + } catch (JackAbortException e) { + Assert.assertTrue(e.getCause() instanceof LibraryReadingException); + } + } + + +} diff --git a/jack/tests/com/android/jack/transformations/flow/CompileFlowTest.java b/jack-tests/tests/com/android/jack/clinit/ClinitTests.java index 81dc1dfa..be461e2d 100644 --- a/jack/tests/com/android/jack/transformations/flow/CompileFlowTest.java +++ b/jack-tests/tests/com/android/jack/clinit/ClinitTests.java @@ -14,31 +14,33 @@ * limitations under the License. */ -package com.android.jack.transformations.flow; +package com.android.jack.clinit; import com.android.jack.Main; -import com.android.jack.TestTools; +import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.IToolchain; -import org.junit.BeforeClass; +import org.junit.Before; import org.junit.Test; -/** - * JUnit test for compilation of arithmetic tests. - */ -public class CompileFlowTest { +public class ClinitTests { + + public static final String CLASS_WITH_VARIABLE_INIT_BINARY_NAME + = "com/android/jack/clinit/jack/ClInitWithVariableInit"; - @BeforeClass - public static void setUpClass() { + @Before + public void setUp() throws Exception { Main.class.getClassLoader().setDefaultAssertionStatus(true); } - /** - * Verifies that the test source can compiled from source to dex file. - */ @Test - public void testCompile() throws Exception { - // TODO(delphinemartin) find a way to check that the loops have been removed - // and that the generated code is correct - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getJackTestsWithJackFolder("flow/loop"))); + public void testCompileWithClinit() throws Exception { + IToolchain toolchain = AbstractTestTools.getCandidateToolchain(); + toolchain.srcToExe( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + AbstractTestTools.createTempDir(), + /* zipFile = */ false, + AbstractTestTools.getTestRootDir("com.android.jack.clinit.jack")); } + } diff --git a/jack-tests/tests/com/android/jack/comparison/ComparisonTests.java b/jack-tests/tests/com/android/jack/comparison/ComparisonTests.java new file mode 100644 index 00000000..6a85530e --- /dev/null +++ b/jack-tests/tests/com/android/jack/comparison/ComparisonTests.java @@ -0,0 +1,50 @@ +/* +* 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.comparison; + +import com.android.jack.test.category.RuntimeRegressionTest; +import com.android.jack.test.helper.RuntimeTestHelper; +import com.android.jack.test.runtime.RuntimeTest; +import com.android.jack.test.runtime.RuntimeTestInfo; +import com.android.jack.test.toolchain.AbstractTestTools; + +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +public class ComparisonTests extends RuntimeTest { + + private RuntimeTestInfo TEST001 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.comparison.test001"), + "com.android.jack.comparison.test001.dx.Tests"); + + @BeforeClass + public static void setUpClass() { + ComparisonTests.class.getClassLoader().setDefaultAssertionStatus(true); + } + @Test + @Category(RuntimeRegressionTest.class) + public void test001() throws Exception { + new RuntimeTestHelper(TEST001).compileAndRunTest(); + } + + @Override + protected void fillRtTestInfos() { + rtTestInfos.add(TEST001); + } +} diff --git a/jack-tests/tests/com/android/jack/compiletime/CompileTimeTests.java b/jack-tests/tests/com/android/jack/compiletime/CompileTimeTests.java new file mode 100644 index 00000000..878fd40d --- /dev/null +++ b/jack-tests/tests/com/android/jack/compiletime/CompileTimeTests.java @@ -0,0 +1,53 @@ +/* +* 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.compiletime; + +import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.IToolchain; + +import org.junit.BeforeClass; +import org.junit.Test; + +public class CompileTimeTests { + + + @BeforeClass + public static void setUpClass() { + CompileTimeTests.class.getClassLoader().setDefaultAssertionStatus(true); + } + + @Test + public void test001() throws Exception { + IToolchain toolchain = AbstractTestTools.getCandidateToolchain(); + toolchain.srcToExe( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + AbstractTestTools.createTempDir(), + /* zipFile = */ false, + AbstractTestTools.getTestRootDir("com.android.jack.compiletime.test001.jack")); + } + + @Test + public void test002() throws Exception { + IToolchain toolchain = AbstractTestTools.getCandidateToolchain(); + toolchain.srcToExe( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + AbstractTestTools.createTempDir(), + /* zipFile = */ false, + AbstractTestTools.getTestRootDir("com.android.jack.compiletime.test002.jack")); + } + +} diff --git a/jack-tests/tests/com/android/jack/conditional/ConditionalTests.java b/jack-tests/tests/com/android/jack/conditional/ConditionalTests.java new file mode 100644 index 00000000..c7d42543 --- /dev/null +++ b/jack-tests/tests/com/android/jack/conditional/ConditionalTests.java @@ -0,0 +1,115 @@ +/* +* 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.conditional; + +import com.android.jack.test.category.RuntimeRegressionTest; +import com.android.jack.test.helper.RuntimeTestHelper; +import com.android.jack.test.runtime.RuntimeTest; +import com.android.jack.test.runtime.RuntimeTestInfo; +import com.android.jack.test.toolchain.AbstractTestTools; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +public class ConditionalTests extends RuntimeTest { + + private RuntimeTestInfo TEST001 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.conditional.test001"), + "com.android.jack.conditional.test001.dx.Tests"); + + private RuntimeTestInfo TEST002 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.conditional.test002"), + "com.android.jack.conditional.test002.dx.Tests"); + + private RuntimeTestInfo TEST003 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.conditional.test003"), + "com.android.jack.conditional.test003.dx.Tests"); + + private RuntimeTestInfo TEST004 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.conditional.test004"), + "com.android.jack.conditional.test004.dx.Tests"); + + private RuntimeTestInfo TEST005 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.conditional.test005"), + "com.android.jack.conditional.test005.dx.Tests"); + + private RuntimeTestInfo TEST006 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.conditional.test006"), + "com.android.jack.conditional.test006.dx.Tests"); + + private RuntimeTestInfo TEST007 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.conditional.test007"), + "com.android.jack.conditional.test007.dx.Tests"); + + @BeforeClass + public static void setUpClass() { + ConditionalTests.class.getClassLoader().setDefaultAssertionStatus(true); + } + @Test + @Category(RuntimeRegressionTest.class) + public void test001() throws Exception { + new RuntimeTestHelper(TEST001).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test002() throws Exception { + new RuntimeTestHelper(TEST002).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test003() throws Exception { + new RuntimeTestHelper(TEST003).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test004() throws Exception { + new RuntimeTestHelper(TEST004).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test005() throws Exception { + new RuntimeTestHelper(TEST005).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test006() throws Exception { + new RuntimeTestHelper(TEST006).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test007() throws Exception { + new RuntimeTestHelper(TEST007).compileAndRunTest(); + } + + @Override + protected void fillRtTestInfos() { + rtTestInfos.add(TEST001); + rtTestInfos.add(TEST002); + rtTestInfos.add(TEST003); + rtTestInfos.add(TEST004); + rtTestInfos.add(TEST005); + rtTestInfos.add(TEST006); + rtTestInfos.add(TEST007); + } +} diff --git a/jack-tests/tests/com/android/jack/constant/ConstantTests.java b/jack-tests/tests/com/android/jack/constant/ConstantTests.java new file mode 100644 index 00000000..d60fb2f7 --- /dev/null +++ b/jack-tests/tests/com/android/jack/constant/ConstantTests.java @@ -0,0 +1,174 @@ +/* +* 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.constant; + +import com.android.jack.TestTools; +import com.android.jack.test.category.RuntimeRegressionTest; +import com.android.jack.test.helper.FileChecker; +import com.android.jack.test.helper.RuntimeTestHelper; +import com.android.jack.test.runtime.RuntimeTest; +import com.android.jack.test.runtime.RuntimeTestInfo; +import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.IToolchain; + +import junit.framework.Assert; + +import org.jf.dexlib.CodeItem; +import org.jf.dexlib.DexFile; +import org.jf.dexlib.Code.Instruction; +import org.jf.dexlib.Code.Opcode; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import java.io.File; + +import javax.annotation.Nonnegative; +import javax.annotation.Nonnull; + +public class ConstantTests extends RuntimeTest { + + private RuntimeTestInfo CLAZZ = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.constant.clazz"), + "com.android.jack.constant.clazz.dx.Tests"); + + private RuntimeTestInfo TEST001 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.constant.test001"), + "com.android.jack.constant.test001.dx.Tests"); + + private RuntimeTestInfo TEST002 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.constant.test002"), + "com.android.jack.constant.test002.dx.Tests"); + + private RuntimeTestInfo TEST003 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.constant.test003"), + "com.android.jack.constant.test003.dx.Tests"); + + private RuntimeTestInfo TEST004 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.constant.test004"), + "com.android.jack.constant.test004.dx.Tests"); + + private RuntimeTestInfo TEST005 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.constant.test005"), + "com.android.jack.constant.test005.dx.Tests"); + + private RuntimeTestInfo TEST006 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.constant.test006"), + "com.android.jack.constant.test006.dx.Tests"); + + private RuntimeTestInfo TEST007 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.constant.test007"), + "com.android.jack.constant.test007.dx.Tests"); + + @BeforeClass + public static void setUpClass() { + ConstantTests.class.getClassLoader().setDefaultAssertionStatus(true); + } + @Test + @Category(RuntimeRegressionTest.class) + public void clazz() throws Exception { + new RuntimeTestHelper(CLAZZ).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test001() throws Exception { + new RuntimeTestHelper(TEST001).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test002() throws Exception { + new RuntimeTestHelper(TEST002).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test003() throws Exception { + new RuntimeTestHelper(TEST003).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test004() throws Exception { + new RuntimeTestHelper(TEST004).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test005() throws Exception { + new RuntimeTestHelper(TEST005) + .addTestExeFileChecker(new FileChecker() { + + @Override + public void check(@Nonnull File file) throws Exception { + DexFile dexFile = new DexFile(file); + CodeItem ci = + TestTools.getEncodedMethod(dexFile, "Lcom/android/jack/constant/test005/jack/Constant005;", + "test", "()I").codeItem; + + Assert.assertEquals(7, countOpcode(ci, Opcode.CONST_4)); + } + }).compileAndRunTest(); + } + + @Nonnegative + private int countOpcode(@Nonnull CodeItem codeItem, @Nonnull Opcode opcode) { + int countOpcode = 0; + for (Instruction inst : codeItem.getInstructions()) { + if (inst.opcode == opcode) { + countOpcode++; + } + } + return countOpcode; + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test006() throws Exception { + new RuntimeTestHelper(TEST006).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test007() throws Exception { + new RuntimeTestHelper(TEST007).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test008() throws Exception { + IToolchain toolchain = AbstractTestTools.getCandidateToolchain(); + toolchain.srcToExe( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + AbstractTestTools.createTempDir(), + /* zipFile = */ false, + AbstractTestTools.getTestRootDir("com.android.jack.constant.test008")); + } + + @Override + protected void fillRtTestInfos() { + rtTestInfos.add(CLAZZ); + rtTestInfos.add(TEST001); + rtTestInfos.add(TEST002); + rtTestInfos.add(TEST003); + rtTestInfos.add(TEST004); + rtTestInfos.add(TEST005); + rtTestInfos.add(TEST006); + rtTestInfos.add(TEST007); + } +} diff --git a/jack-tests/tests/com/android/jack/debug/DebugTests.java b/jack-tests/tests/com/android/jack/debug/DebugTests.java new file mode 100644 index 00000000..2cfd0d2d --- /dev/null +++ b/jack-tests/tests/com/android/jack/debug/DebugTests.java @@ -0,0 +1,147 @@ +/* +* 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.debug; + +import com.android.jack.test.category.RuntimeRegressionTest; +import com.android.jack.test.helper.CheckDexStructureTestHelper; +import com.android.jack.test.helper.RuntimeTestHelper; +import com.android.jack.test.runtime.RuntimeTest; +import com.android.jack.test.runtime.RuntimeTestInfo; +import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.IToolchain; + +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import javax.annotation.Nonnull; + +public class DebugTests extends RuntimeTest { + + private RuntimeTestInfo TEST001 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.debug.test001"), + "com.android.jack.debug.test001.dx.Tests"); + + private RuntimeTestInfo TEST002 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.debug.test002"), + "com.android.jack.debug.test002.dx.Tests"); + + private RuntimeTestInfo TEST004 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.debug.test004"), + "com.android.jack.debug.test004.dx.Tests"); + + @BeforeClass + public static void setUpClass() { + DebugTests.class.getClassLoader().setDefaultAssertionStatus(true); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test001() throws Exception { + new RuntimeTestHelper(TEST001) + .setWithDebugInfos(true).compileAndRunTest(/* checkStructure = */ true); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test002() throws Exception { + new RuntimeTestHelper(TEST002) + .setWithDebugInfos(true).compileAndRunTest(/* checkStructure = */ true); + } + + @Test + public void test003() throws Exception { + checkStructure("003"); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test004() throws Exception { + new RuntimeTestHelper(TEST004) + .setWithDebugInfos(true).compileAndRunTest(/* checkStructure = */ true); + } + + @Test + public void test005() throws Exception { + checkStructure("005"); + } + + @Test + public void test006() throws Exception { + checkStructure("006"); + } + + @Test + public void test007() throws Exception { + checkStructure("007"); + } + + @Test + public void test008() throws Exception { + checkStructure("008"); + } + + @Test + public void test009() throws Exception { + checkStructure("009"); + } + + @Test + public void test010() throws Exception { + checkStructure("010"); + } + + @Test + public void test011() throws Exception { + checkStructure("011"); + } + + @Test + public void test012() throws Exception { + checkStructure("012"); + } + + @Test + public void test013() throws Exception { + checkStructure("013"); + } + + @Test + public void test014() throws Exception { + checkStructure("014"); + } + + @Test + @Ignore("Debug comparison fails because of local variable default initialization") + public void test019() throws Exception { + checkStructure("019"); + } + + private void checkStructure(@Nonnull String testNumber) throws Exception { + CheckDexStructureTestHelper helper = new CheckDexStructureTestHelper( + AbstractTestTools.getTestRootDir("com.android.jack.debug.test" + testNumber + ".jack")); + helper.setWithDebugInfo(true).compare(); + } + + @Override + protected void fillRtTestInfos() { + rtTestInfos.add(TEST001); + rtTestInfos.add(TEST002); + rtTestInfos.add(TEST004); + } +} diff --git a/jack-tests/tests/com/android/jack/dx/DxTests.java b/jack-tests/tests/com/android/jack/dx/DxTests.java new file mode 100644 index 00000000..9e5e8155 --- /dev/null +++ b/jack-tests/tests/com/android/jack/dx/DxTests.java @@ -0,0 +1,171 @@ +/* +* 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.dx; + +import com.android.jack.TestTools; +import com.android.jack.test.category.RuntimeRegressionTest; +import com.android.jack.test.helper.FileChecker; +import com.android.jack.test.helper.RuntimeTestHelper; +import com.android.jack.test.runtime.RuntimeTest; +import com.android.jack.test.runtime.RuntimeTestInfo; +import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.IToolchain; + +import junit.framework.Assert; + +import org.jf.dexlib.CodeItem; +import org.jf.dexlib.DexFile; +import org.jf.dexlib.ClassDataItem.EncodedMethod; +import org.jf.dexlib.Code.Instruction; +import org.jf.dexlib.Code.Opcode; +import org.jf.dexlib.Code.Analysis.AnalyzedInstruction; +import org.jf.dexlib.Code.Analysis.MethodAnalyzer; +import org.jf.dexlib.Code.Format.Instruction23x; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import java.io.File; + +import javax.annotation.Nonnull; + +public class DxTests extends RuntimeTest { + + private RuntimeTestInfo COMPILER = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.dx.compiler"), + "com.android.jack.dx.compiler.dx.Tests"); + + private RuntimeTestInfo OPTIMIZER = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.dx.optimizer"), + "com.android.jack.dx.optimizer.dx.Tests"); + + private RuntimeTestInfo OVERLAPPING = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.dx.overlapping"), + "com.android.jack.dx.overlapping.dx.Tests"); + + @BeforeClass + public static void setUpClass() { + DxTests.class.getClassLoader().setDefaultAssertionStatus(true); + } + @Test + @Category(RuntimeRegressionTest.class) + public void compiler() throws Exception { + new RuntimeTestHelper(COMPILER).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void optimizer() throws Exception { + new RuntimeTestHelper(OPTIMIZER).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void overlapping() throws Exception { + new RuntimeTestHelper(OVERLAPPING) + .addTestExeFileChecker(new FileChecker() { + + @Override + public void check(@Nonnull File file) throws Exception { + DexFile dexFile = new DexFile(file); + EncodedMethod em = + TestTools.getEncodedMethod(dexFile, + "Lcom/android/jack/dx/overlapping/jack/Data;", "test002", + "(IJJ)J"); + + checkThatRegistersDoesNotOverlap(em); + } + + }) + .addTestExeFileChecker(new FileChecker() { + + @Override + public void check(@Nonnull File file) throws Exception { + DexFile dexFile = new DexFile(file); + EncodedMethod em = + TestTools.getEncodedMethod(dexFile, + "Lcom/android/jack/dx/overlapping/jack/Data;", "test001", + "(IJJ)J"); + + checkThatRegistersDoesNotOverlap(em); + } + + }) + .compileAndRunTest(); + } + + @Test + @Ignore("Dx register allocator use div_int instead of div_int_2addr in some cases.") + public void testRegallocator() throws Exception { + IToolchain toolchain = AbstractTestTools.getCandidateToolchain(); + File dexOutDir = AbstractTestTools.createTempDir(); + File outFile = new File(dexOutDir, "classes.dex"); + toolchain.srcToExe( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + dexOutDir, + /* zipFile = */ false, + AbstractTestTools.getTestRootDir("com.android.jack.dx.regallocator.jack")); + + DexFile dexFile = new DexFile(outFile); + + CodeItem ci = + TestTools.getEncodedMethod(dexFile, "Lcom/android/jack/dx/regallocator/jack/Data;", + "compute1", "(I)I").codeItem; + Assert.assertTrue(hasOpcode(ci, Opcode.DIV_INT_2ADDR)); + ci = + TestTools.getEncodedMethod(dexFile, "Lcom/android/jack/dx/regallocator/jack/Data;", + "compute2", "(I)I").codeItem; + Assert.assertTrue(hasOpcode(ci, Opcode.DIV_INT_2ADDR)); + } + + private boolean hasOpcode(@Nonnull CodeItem codeItem, @Nonnull Opcode opcode) { + for (Instruction inst : codeItem.getInstructions()) { + if (inst.opcode == opcode) { + return true; + } + } + return false; + } + + private void checkThatRegistersDoesNotOverlap(@Nonnull EncodedMethod em) { + MethodAnalyzer ma = new MethodAnalyzer(em, false, null); + for (AnalyzedInstruction ai : ma.getInstructions()) { + if (ai.getInstruction() instanceof Instruction23x) { + Instruction23x inst = (Instruction23x) ai.getInstruction(); + // Register overlaps in the following cases + // v0, v1 = ..., v1, v2 + // v0, v1 = v1, v2, ... + // v1, v2 = ..., v0, v1 + // v1, v2 = v0, v1, ... + if (inst.getRegisterA() + 1 == inst.getRegisterC() + || inst.getRegisterA() + 1 == inst.getRegisterB() + || inst.getRegisterA() == inst.getRegisterC() + 1 + || inst.getRegisterA() == inst.getRegisterB() + 1) { + Assert.fail("Register overlapping"); + } + } + } + } + + @Override + protected void fillRtTestInfos() { + rtTestInfos.add(COMPILER); + rtTestInfos.add(OPTIMIZER); + rtTestInfos.add(OVERLAPPING); + } +} diff --git a/jack-tests/tests/com/android/jack/enums/EnumsTests.java b/jack-tests/tests/com/android/jack/enums/EnumsTests.java new file mode 100644 index 00000000..0b6bb7d0 --- /dev/null +++ b/jack-tests/tests/com/android/jack/enums/EnumsTests.java @@ -0,0 +1,69 @@ +/* +* 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.enums; + +import com.android.jack.test.category.RuntimeRegressionTest; +import com.android.jack.test.helper.RuntimeTestHelper; +import com.android.jack.test.runtime.RuntimeTest; +import com.android.jack.test.runtime.RuntimeTestInfo; +import com.android.jack.test.toolchain.AbstractTestTools; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +public class EnumsTests extends RuntimeTest { + + private RuntimeTestInfo TEST001 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.enums.test001"), + "com.android.jack.enums.test001.dx.Tests"); + + private RuntimeTestInfo TEST002 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.enums.test002"), + "com.android.jack.enums.test002.dx.Tests"); + + private RuntimeTestInfo TEST003 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.enums.test003"), + "com.android.jack.enums.test003.dx.Tests"); + + @BeforeClass + public static void setUpClass() { + EnumsTests.class.getClassLoader().setDefaultAssertionStatus(true); + } + @Test + @Category(RuntimeRegressionTest.class) + public void test001() throws Exception { + new RuntimeTestHelper(TEST001).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test002() throws Exception { + new RuntimeTestHelper(TEST002).compileAndRunTest(); + } + + @Test + public void test003() throws Exception { + new RuntimeTestHelper(TEST003).compileAndRunTest(); + } + + @Override + protected void fillRtTestInfos() { + rtTestInfos.add(TEST001); + rtTestInfos.add(TEST002); + } +} diff --git a/jack-tests/tests/com/android/jack/error/AnnotationProcessorErrorTest.java b/jack-tests/tests/com/android/jack/error/AnnotationProcessorErrorTest.java index fea5b186..5cbd7a01 100644 --- a/jack-tests/tests/com/android/jack/error/AnnotationProcessorErrorTest.java +++ b/jack-tests/tests/com/android/jack/error/AnnotationProcessorErrorTest.java @@ -64,7 +64,7 @@ public class AnnotationProcessorErrorTest { public void testAnnotationProcessorError001() throws Exception { ErrorTestHelper te = new ErrorTestHelper(); - AbstractTestTools.createJavaFile(te.getSourceFolder(),"jack.incremental", "A.java", + AbstractTestTools.createFile(te.getSourceFolder(),"jack.incremental", "A.java", "package jack.incremental; \n"+ "public class A {} \n"); @@ -74,7 +74,7 @@ public class AnnotationProcessorErrorTest { try { jackApiToolchain.srcToExe( AbstractTestTools.getClasspathAsString(jackApiToolchain.getDefaultBootClasspath()), - te.getOutputDexFolder(), te.getSourceFolder()); + te.getOutputDexFolder(), /* zipFile = */ false, te.getSourceFolder()); Assert.fail(); } catch (JackUserException e) { // Failure is ok since output for annotation processor is not specify. @@ -110,7 +110,7 @@ public class AnnotationProcessorErrorTest { jackApiToolchain.srcToExe( AbstractTestTools.getClasspathAsString(jackApiToolchain.getDefaultBootClasspath()) - + File.pathSeparator + te.getJackFolder(), te.getOutputDexFolder(), te.getSourceFolder()); + + File.pathSeparator + te.getJackFolder(), te.getOutputDexFolder(), /* zipFile = */ false, te.getSourceFolder()); Assert.fail(); } catch (FrontendCompilationException e) { @@ -131,7 +131,7 @@ public class AnnotationProcessorErrorTest { buildAnnotationRequiredByAnnotationProc(te, new Class<?>[] {SourceAnnotationTest.class, SourceErrorAnnotationTest.class}); - AbstractTestTools.createJavaFile(te.getSourceFolder(), "jack.incremental", "A.java", "package jack.incremental;\n" + AbstractTestTools.createFile(te.getSourceFolder(), "jack.incremental", "A.java", "package jack.incremental;\n" + "import " + SourceErrorAnnotationTest.class.getName() + ";\n" + "@" + SourceErrorAnnotationTest.class.getSimpleName() + "\n" + "public class A {}\n"); @@ -146,7 +146,7 @@ public class AnnotationProcessorErrorTest { try { jackApiToolchain.srcToExe( AbstractTestTools.getClasspathAsString(jackApiToolchain.getDefaultBootClasspath()) - + File.pathSeparator + te.getJackFolder(), te.getOutputDexFolder(), te.getSourceFolder()); + + File.pathSeparator + te.getJackFolder(), te.getOutputDexFolder(), /* zipFile = */ false, te.getSourceFolder()); Assert.fail(); } catch (FrontendCompilationException ex) { // Failure is ok since source generated by annotation processor does not compile. @@ -165,7 +165,7 @@ public class AnnotationProcessorErrorTest { buildAnnotationRequiredByAnnotationProc(te, new Class<?>[] {SourceAnnotationTest.class, SourceErrorAnnotationTest.class}); - AbstractTestTools.createJavaFile(te.getSourceFolder(), "jack.incremental", "A.java", "package jack.incremental;\n" + AbstractTestTools.createFile(te.getSourceFolder(), "jack.incremental", "A.java", "package jack.incremental;\n" + "import " + SourceAnnotationTest.class.getName() + ";\n" + "@" + SourceAnnotationTest.class.getSimpleName() + "\n" + "public class A {}\n"); @@ -177,7 +177,7 @@ public class AnnotationProcessorErrorTest { File dexOutput = te.getOutputDexFolder(); jackApiToolchain.srcToExe( AbstractTestTools.getClasspathAsString(jackApiToolchain.getDefaultBootClasspath()) - + File.pathSeparator + te.getJackFolder(), dexOutput, te.getSourceFolder()); + + File.pathSeparator + te.getJackFolder(), dexOutput, /* zipFile = */ false, te.getSourceFolder()); DexFile dexFile = new DexFile(new File(dexOutput, jackApiToolchain.getBinaryFileName())); List<String> sourceFileInDex = new ArrayList<String>(); @@ -193,7 +193,7 @@ public class AnnotationProcessorErrorTest { buildAnnotationRequiredByAnnotationProc(te, new Class<?>[] {ResourceAnnotationTest.class}); - AbstractTestTools.createJavaFile(te.getSourceFolder(), "jack.incremental", "A.java", "package jack.incremental;\n" + AbstractTestTools.createFile(te.getSourceFolder(), "jack.incremental", "A.java", "package jack.incremental;\n" + "import " + ResourceAnnotationTest.class.getName() + ";\n" + "@" + ResourceAnnotationTest.class.getSimpleName() + "\n" + "public class A {}\n"); @@ -204,7 +204,7 @@ public class AnnotationProcessorErrorTest { jackApiToolchain.srcToExe( AbstractTestTools.getClasspathAsString(jackApiToolchain.getDefaultBootClasspath()) - + File.pathSeparator + te.getJackFolder(), te.getOutputDexFolder(), te.getSourceFolder()); + + File.pathSeparator + te.getJackFolder(), te.getOutputDexFolder(), /* zipFile = */ false, te.getSourceFolder()); File discoverFile = new File(te.getTestingFolder(), ResourceAnnotationProcessor.FILENAME); Assert.assertTrue(discoverFile.exists()); diff --git a/jack-tests/tests/com/android/jack/error/CommandLineErrorTest.java b/jack-tests/tests/com/android/jack/error/CommandLineErrorTest.java index 3e72329e..d9551701 100644 --- a/jack-tests/tests/com/android/jack/error/CommandLineErrorTest.java +++ b/jack-tests/tests/com/android/jack/error/CommandLineErrorTest.java @@ -19,6 +19,8 @@ package com.android.jack.error; import com.android.jack.IllegalOptionsException; import com.android.jack.Main; import com.android.jack.NothingToDoException; +import com.android.jack.test.category.KnownBugs; +import com.android.jack.frontend.FrontendCompilationException; import com.android.jack.test.helper.ErrorTestHelper; import com.android.jack.test.toolchain.AbstractTestTools; import com.android.jack.test.toolchain.JackApiToolchain; @@ -27,6 +29,7 @@ import junit.framework.Assert; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.experimental.categories.Category; import java.io.ByteArrayOutputStream; import java.io.File; @@ -56,7 +59,7 @@ public class CommandLineErrorTest { jackApiToolchain.srcToExe( AbstractTestTools.getClasspathAsString(jackApiToolchain.getDefaultBootClasspath()) + File.pathSeparator + ite.getJackFolder(), ite.getOutputDexFolder(), - ite.getSourceFolder()); + /* zipFile = */ false, ite.getSourceFolder()); Assert.fail(); } catch (IllegalOptionsException e) { // Failure is ok since a bad options is passed to ecj. @@ -82,7 +85,7 @@ public class CommandLineErrorTest { jackApiToolchain.srcToExe( AbstractTestTools.getClasspathAsString(jackApiToolchain.getDefaultBootClasspath()) + File.pathSeparator + ite.getJackFolder(), ite.getOutputDexFolder(), - ite.getSourceFolder()); + /* zipFile = */ false, ite.getSourceFolder()); Assert.fail(); } catch (NothingToDoException e) { // Failure is ok since there is no source files. @@ -92,4 +95,33 @@ public class CommandLineErrorTest { } } + /** + * Checks that compilation fails correctly when java.lang.Object does not exist on classpath. + */ + @Test + public void testCommandLineError003() throws Exception { + ErrorTestHelper ite = new ErrorTestHelper(); + + File sourceFile = AbstractTestTools.createFile(ite.getSourceFolder(), "jack.incremental", + "A.java", "package jack.incremental; \n" + "public class A {} \n"); + + JackApiToolchain jackApiToolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); + ByteArrayOutputStream errOut = new ByteArrayOutputStream(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + jackApiToolchain.setErrorStream(errOut); + jackApiToolchain.setOutputStream(out); + + try { + jackApiToolchain.srcToExe(null, ite.getOutputDexFolder(), + /* zipFile = */ false, ite.getSourceFolder()); + Assert.fail(); + } catch (FrontendCompilationException e) { + // Failure is ok, since java.lang.Object does not exists. + } finally { + Assert.assertEquals("", out.toString()); + Assert.assertTrue(errOut.toString().contains("The type java.lang.Object cannot be found in source files, " + + "imported jack libs or the classpath")); + } + } + } diff --git a/jack/tests/com/android/jack/errorhandling/ConfigErrorTest.java b/jack-tests/tests/com/android/jack/error/ConfigErrorTest.java index 86d41d9c..3e074f59 100644 --- a/jack/tests/com/android/jack/errorhandling/ConfigErrorTest.java +++ b/jack-tests/tests/com/android/jack/error/ConfigErrorTest.java @@ -14,46 +14,44 @@ * limitations under the License. */ -package com.android.jack.errorhandling; +package com.android.jack.error; -import com.android.jack.Options; -import com.android.jack.TestTools; +import com.android.jack.test.helper.ErrorTestHelper; +import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.JackApiToolchain; import com.android.sched.util.config.UnknownPropertyNameException; import org.junit.Assert; import org.junit.Test; +import java.io.ByteArrayOutputStream; import java.io.File; -import java.util.ArrayList; -import java.util.List; public class ConfigErrorTest { @Test public void testUnknownProperty001() throws Exception { - TestingEnvironment ite = new TestingEnvironment(); + ErrorTestHelper ite = new ErrorTestHelper(); - File sourceFile = ite.addFile(ite.getSourceFolder(),"jack.config", "A.java", + JackApiToolchain jackApiToolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); + ByteArrayOutputStream errOut = new ByteArrayOutputStream(); + jackApiToolchain.setErrorStream(errOut); + + File sourceFile = AbstractTestTools.createFile(ite.getSourceFolder(), "jack.config", "A.java", "package jack.config; \n"+ "public class A {} \n"); - File outZip = TestTools.createTempFile("out", ".zip"); - Options options = new Options(); - List<String> ecjArgs = new ArrayList<String>(); - ecjArgs.add(sourceFile.getAbsolutePath()); - options.setEcjArguments(ecjArgs); - options.setOutputZip(outZip); - options.addProperty("unknown", "true"); - options.setClasspath(TestTools.getDefaultBootclasspathString()); + jackApiToolchain.addProperty("unknown", "true"); try { - ite.startErrRedirection(); - ite.compile(options); + jackApiToolchain.srcToExe( + AbstractTestTools.getClasspathAsString(jackApiToolchain.getDefaultBootClasspath()), + ite.getOutputDexFolder(), /* zipFile = */ true, ite.getSourceFolder()); Assert.fail(); } catch (UnknownPropertyNameException e) { // Expected since we use an unknown property. } finally { - Assert.assertEquals("", ite.endErrRedirection()); + Assert.assertEquals("", errOut.toString()); } } diff --git a/jack/tests/com/android/jack/errorhandling/ErrorHandlingAllTests.java b/jack-tests/tests/com/android/jack/error/ErrorHandlingAllTests.java index 7b3d9cc3..f459d7a4 100644 --- a/jack/tests/com/android/jack/errorhandling/ErrorHandlingAllTests.java +++ b/jack-tests/tests/com/android/jack/error/ErrorHandlingAllTests.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.jack.errorhandling; +package com.android.jack.error; import org.junit.experimental.categories.Categories; import org.junit.runner.RunWith; @@ -21,7 +21,14 @@ import org.junit.runners.Suite.SuiteClasses; @RunWith(Categories.class) @SuiteClasses( -value = {JackFormatErrorTest.class, FileAccessErrorTest.class, - CommandLineErrorTest.class, AnnotationProcessorErrorTest.class, SourceErrorTest.class}) +value = { + AnnotationProcessorErrorTest.class, + CommandLineErrorTest.class, + ConfigErrorTest.class, + ErrorTest.class, + FileAccessErrorTest.class, + JackFormatErrorTest.class, + SourceErrorTest.class + }) public class ErrorHandlingAllTests { }
\ No newline at end of file diff --git a/jack/tests/com/android/jack/ErrorTest.java b/jack-tests/tests/com/android/jack/error/ErrorTest.java index ad0d8790..321780cb 100644 --- a/jack/tests/com/android/jack/ErrorTest.java +++ b/jack-tests/tests/com/android/jack/error/ErrorTest.java @@ -14,9 +14,11 @@ * limitations under the License. */ -package com.android.jack; +package com.android.jack.error; import com.android.jack.frontend.FrontendCompilationException; +import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.JackApiToolchain; import junit.framework.Assert; @@ -25,7 +27,6 @@ import org.junit.Test; import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.PrintStream; import javax.annotation.Nonnull; @@ -36,44 +37,36 @@ public class ErrorTest { @BeforeClass public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); + ErrorTest.class.getClassLoader().setDefaultAssertionStatus(true); } @Test public void testError001() throws Exception { - checkInternalCompilerException("error/test001"); + checkInternalCompilerException("error.test001"); } @Test public void testError002() throws Exception { - checkInternalCompilerException("error/test002"); + checkInternalCompilerException("error.test002"); } private void checkInternalCompilerException(@Nonnull String testName) throws Exception, IOException { - ByteArrayOutputStream baos = null; - PrintStream redirectStream = null; - try { - baos = new ByteArrayOutputStream(); - redirectStream = new PrintStream(baos); - System.setErr(redirectStream); + JackApiToolchain toolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); - TestTools.runCompilation( - TestTools.buildCommandLineArgs(TestTools.getJackTestsWithJackFolder(testName))); - Assert.fail(); + ByteArrayOutputStream err = new ByteArrayOutputStream(); + toolchain.setErrorStream(err); + + try { + toolchain.srcToExe( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + AbstractTestTools.createTempDir(), + /* zipFile = */ false, + AbstractTestTools.getTestRootDir("com.android.jack." + testName + ".jack")); } catch (FrontendCompilationException e) { - if (baos != null && baos.toString().contains("InternalCompilerException")) { - Assert.fail(); - } + Assert.assertTrue(!err.toString().contains("InternalCompilerException")); } catch (RuntimeException e) { Assert.fail(); - } finally { - if (redirectStream != null) { - redirectStream.close(); - } - if (baos != null) { - baos.close(); - } } } } diff --git a/jack-tests/tests/com/android/jack/error/FileAccessErrorTest.java b/jack-tests/tests/com/android/jack/error/FileAccessErrorTest.java index f9ce418a..5d52bced 100644 --- a/jack-tests/tests/com/android/jack/error/FileAccessErrorTest.java +++ b/jack-tests/tests/com/android/jack/error/FileAccessErrorTest.java @@ -16,14 +16,19 @@ package com.android.jack.error; +import com.android.jack.JackAbortException; import com.android.jack.JackUserException; import com.android.jack.Main; +import com.android.jack.backend.jayce.JayceFileImporter; import com.android.jack.frontend.FrontendCompilationException; +import com.android.jack.library.LibraryIOException; +import com.android.jack.library.LibraryReadingException; import com.android.jack.load.JackLoadingException; import com.android.jack.test.helper.ErrorTestHelper; import com.android.jack.test.toolchain.AbstractTestTools; import com.android.jack.test.toolchain.JackApiToolchain; import com.android.sched.util.config.PropertyIdException; +import com.android.sched.util.file.WrongPermissionException; import junit.framework.Assert; @@ -50,7 +55,7 @@ public class FileAccessErrorTest { public void testFileAccessError001() throws Exception { ErrorTestHelper te = new ErrorTestHelper(); - AbstractTestTools.createJavaFile(te.getSourceFolder(), "jack.incremental", "A.java", + AbstractTestTools.createFile(te.getSourceFolder(), "jack.incremental", "A.java", "package jack.incremental; \n"+ "public class A {} \n"); @@ -63,7 +68,7 @@ public class FileAccessErrorTest { try { jackApiToolchain.srcToLib( AbstractTestTools.getClasspathAsString(jackApiToolchain.getDefaultBootClasspath()), - jackOutputFile, false, te.getSourceFolder()); + jackOutputFile, /* zipFiles = */ false, te.getSourceFolder()); Assert.fail(); } catch (PropertyIdException e) { // Failure is ok since jack output folder is not readable @@ -75,13 +80,62 @@ public class FileAccessErrorTest { } /** + * Checks that compilation fails correctly when folder containing jack files is not readable. + */ + @Test + public void testFileAccessError002() throws Exception { + ErrorTestHelper helper = new ErrorTestHelper(); + + File srcFile = AbstractTestTools.createFile(helper.getSourceFolder(), "jack.incremental", + "A.java", "package jack.incremental; \n" + "public class A {} \n"); + + JackApiToolchain jackApiToolchain = + AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); + + jackApiToolchain.srcToLib( + AbstractTestTools.getClasspathAsString(jackApiToolchain.getDefaultBootClasspath()), + helper.getJackFolder(), /* zipFiles = */ false, helper.getSourceFolder()); + + AbstractTestTools.deleteFile(srcFile); + + srcFile = AbstractTestTools.createFile(helper.getSourceFolder(), "jack.incremental", "B.java", + "package jack.incremental; \n" + "public class B extends A {} \n"); + + // Modify read permission of folder containing jack files + if (!helper.getJackFolder().setReadable(false)) { + Assert.fail("Fails to change file permissions of " + helper.getJackFolder().getAbsolutePath()); + } + + jackApiToolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); + + ByteArrayOutputStream errOut = new ByteArrayOutputStream(); + jackApiToolchain.setErrorStream(errOut); + jackApiToolchain.addStaticLibs(helper.getJackFolder()); + try { + jackApiToolchain.srcToExe( + AbstractTestTools.getClasspathAsString(jackApiToolchain.getDefaultBootClasspath()), + helper.getOutputDexFolder(), /* zipFile = */ false, helper.getSourceFolder()); + Assert.fail(); + } catch (JackAbortException e) { + // Failure is ok since Jack file could not be imported since folder is not readable + Assert.assertTrue(e.getCause() instanceof LibraryReadingException); + Assert.assertTrue(e.getCause().getCause() instanceof WrongPermissionException); + } finally { + Assert.assertTrue("", errOut.toString().contains("is not readable")); + if (!helper.getJackFolder().setReadable(true)) { + Assert.fail("Fails to change file permissions of " + helper.getJackFolder().getAbsolutePath()); + } + } + } + + /** * Checks that compilation fails correctly when source file is not readable. */ @Test public void testFileAccessError003() throws Exception { ErrorTestHelper te = new ErrorTestHelper(); - File a = AbstractTestTools.createJavaFile(te.getSourceFolder(), "jack.incremental", "A.java", + File a = AbstractTestTools.createFile(te.getSourceFolder(), "jack.incremental", "A.java", "package jack.incremental; \n"+ "public class A {} \n"); if (!a.setReadable(false)) { @@ -95,7 +149,7 @@ public class FileAccessErrorTest { try { jackApiToolchain.srcToExe( AbstractTestTools.getClasspathAsString(jackApiToolchain.getDefaultBootClasspath()), - te.getOutputDexFolder(), te.getSourceFolder()); + te.getOutputDexFolder(), /* zipFile = */ false, te.getSourceFolder()); Assert.fail(); } catch (FrontendCompilationException e) { // Failure is ok since source file is not readable @@ -114,7 +168,7 @@ public class FileAccessErrorTest { public void testFileAccessError004() throws Exception { ErrorTestHelper te = new ErrorTestHelper(); - AbstractTestTools.createJavaFile(te.getSourceFolder(), "jack.incremental", "A.java", + AbstractTestTools.createFile(te.getSourceFolder(), "jack.incremental", "A.java", "package jack.incremental; \n"+ "public class A {} \n"); @@ -126,29 +180,32 @@ public class FileAccessErrorTest { AbstractTestTools.deleteJavaFile(te.getSourceFolder(), "jack.incremental", "A.java"); - AbstractTestTools.createJavaFile(te.getSourceFolder(),"jack.incremental", "B.java", + AbstractTestTools.createFile(te.getSourceFolder(),"jack.incremental", "B.java", "package jack.incremental; \n"+ "public class B extends A {} \n"); ByteArrayOutputStream errOut = new ByteArrayOutputStream(); try { - for (File jackFile : AbstractTestTools.getFiles(te.getJackFolder(), ".jack")) { + for (File jackFile : AbstractTestTools.getFiles(te.getJackFolder(), JayceFileImporter.JAYCE_FILE_EXTENSION)) { if (!jackFile.setReadable(false)) { Assert.fail("Fails to change file permissions of " + jackFile.getAbsolutePath()); } } jackApiToolchain.setErrorStream(errOut); - jackApiToolchain.srcToLib( + jackApiToolchain.srcToExe( AbstractTestTools.getClasspathAsString(jackApiToolchain.getDefaultBootClasspath()) + File.pathSeparator + te.getJackFolder().getAbsolutePath(), AbstractTestTools.createTempDir(), false, te.getSourceFolder()); Assert.fail(); - } catch (JackLoadingException e) { - // Failure is ok since jack file is not readable + } catch (JackAbortException e) { + Assert.assertTrue(e.getCause() instanceof LibraryReadingException); + Assert.assertTrue(e.getCause().getCause() instanceof LibraryIOException); } finally { - Assert.assertEquals("", errOut.toString()); - for (File jackFile : AbstractTestTools.getFiles(te.getJackFolder(), ".jack")) { + String errOutput = errOut.toString(); + Assert.assertTrue(errOutput.contains("is an invalid library")); + Assert.assertTrue(errOutput.contains("is not readable")); + for (File jackFile : AbstractTestTools.getFiles(te.getJackFolder(), JayceFileImporter.JAYCE_FILE_EXTENSION)) { if (!jackFile.setReadable(true)) { Assert.fail("Fails to change file permissions of " + jackFile.getAbsolutePath()); } @@ -169,7 +226,7 @@ public class FileAccessErrorTest { jackApiToolchain.srcToExe( AbstractTestTools.getClasspathAsString(jackApiToolchain.getDefaultBootClasspath()), - te.getOutputDexFolder(), new File(te.getSourceFolder(), "A.java")); + te.getOutputDexFolder(), /* zipFile = */ false, new File(te.getSourceFolder(), "A.java")); Assert.fail(); } catch (JackUserException e) { diff --git a/jack-tests/tests/com/android/jack/error/JackFormatErrorTest.java b/jack-tests/tests/com/android/jack/error/JackFormatErrorTest.java new file mode 100644 index 00000000..c518e9f4 --- /dev/null +++ b/jack-tests/tests/com/android/jack/error/JackFormatErrorTest.java @@ -0,0 +1,188 @@ +/* + * 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.error; + +import com.android.jack.JackAbortException; +import com.android.jack.Main; +import com.android.jack.Options.VerbosityLevel; +import com.android.jack.jayce.JayceFormatException; +import com.android.jack.jayce.JayceProperties; +import com.android.jack.library.FileType; +import com.android.jack.library.JackLibrary; +import com.android.jack.library.JackLibraryFactory; +import com.android.jack.library.LibraryFormatException; +import com.android.jack.library.LibraryReadingException; +import com.android.jack.library.v0001.Version; +import com.android.jack.load.JackLoadingException; +import com.android.jack.test.helper.ErrorTestHelper; +import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.JackApiToolchain; + +import junit.framework.Assert; + +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.ByteArrayOutputStream; +import java.io.File; + +/** + * JUnit test checking Jack behavior on exceptions. + */ +public class JackFormatErrorTest { + + @BeforeClass + public static void setUpClass() { + Main.class.getClassLoader().setDefaultAssertionStatus(true); + } + + /** + * Checks that compilation fails correctly when jayce file is corrupted. + */ + @Test + public void testJackFormatError001() throws Exception { + ErrorTestHelper helper = new ErrorTestHelper(); + + AbstractTestTools.createFile(new File(helper.getJackFolder(), FileType.JAYCE.getPrefix()), "jack.incremental", + "A.jayce", "jayce(" + JackLibraryFactory.DEFAULT_MAJOR_VERSION + "." + Version.MINOR + + ")Corrupted"); + AbstractTestTools.createFile(helper.getJackFolder(), "", "jack.properties", + JackLibrary.KEY_LIB_EMITTER + "=unknown\n" + + JackLibrary.KEY_LIB_EMITTER_VERSION + "=0\n" + + JackLibrary.KEY_LIB_MAJOR_VERSION + "=" + Version.MAJOR + "\n" + + JackLibrary.KEY_LIB_MINOR_VERSION + "=" + Version.MINOR + "\n" + + FileType.JAYCE.buildPropertyName(null /*suffix*/) + "=true\n" + + JayceProperties.KEY_JAYCE_MAJOR_VERSION + "=2\n" + + JayceProperties.KEY_JAYCE_MINOR_VERSION + "=14\n"); + + AbstractTestTools.createFile(helper.getSourceFolder(),"jack.incremental", "B.java", + "package jack.incremental; \n"+ + "public class B extends A {} \n"); + + JackApiToolchain toolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); + + toolchain.setVerbosityLevel(VerbosityLevel.DEBUG); + + ByteArrayOutputStream errOut = new ByteArrayOutputStream(); + toolchain.setErrorStream(errOut); + + try { + toolchain.srcToExe(AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()) + + File.pathSeparatorChar + helper.getJackFolder().getAbsolutePath(), + helper.getOutputDexFolder(), /* zipFile= */ false, helper.getSourceFolder()); + Assert.fail(); + } catch (JackAbortException e) { + // Failure is ok since jack file is corrupted. + Assert.assertTrue(e.getCause() instanceof LibraryReadingException); + Assert.assertTrue(e.getCause().getCause() instanceof LibraryFormatException); + } finally { + Assert.assertTrue(errOut.toString().contains("is an invalid library")); + Assert.assertTrue(errOut.toString().contains( + "Unexpected node NForStatement, NDeclaredType was expected")); + } + } + + /** + * Checks that compilation fails correctly when jack file header is corrupted. + */ + @Test + public void testJackFormatError002() throws Exception { + ErrorTestHelper helper = new ErrorTestHelper(); + + AbstractTestTools.createFile(new File(helper.getJackFolder(), FileType.JAYCE.getPrefix()), "jack.incremental", + "A.jayce", "jayce()"); + AbstractTestTools.createFile(helper.getJackFolder(), "", "jack.properties", + JackLibrary.KEY_LIB_EMITTER + "=unknown\n" + + JackLibrary.KEY_LIB_EMITTER_VERSION + "=0\n" + + JackLibrary.KEY_LIB_MAJOR_VERSION + "=" + Version.MAJOR + "\n" + + JackLibrary.KEY_LIB_MINOR_VERSION + "=" + Version.MINOR + "\n" + + FileType.JAYCE.buildPropertyName(null /*suffix*/) + "=true\n" + + JayceProperties.KEY_JAYCE_MAJOR_VERSION + "=2\n" + + JayceProperties.KEY_JAYCE_MINOR_VERSION + "=14\n"); + + + AbstractTestTools.createFile(helper.getSourceFolder(),"jack.incremental", "B.java", + "package jack.incremental; \n"+ + "public class B extends A {} \n"); + + JackApiToolchain toolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); + + toolchain.setVerbosityLevel(VerbosityLevel.DEBUG); + + ByteArrayOutputStream errOut = new ByteArrayOutputStream(); + toolchain.setErrorStream(errOut); + + try { + toolchain.srcToExe(AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()) + + File.pathSeparatorChar + helper.getJackFolder().getAbsolutePath(), + helper.getOutputDexFolder(), /* zipFile= */ false, helper.getSourceFolder()); + Assert.fail(); + } catch (JackAbortException e) { + // Failure is ok since jack file header is corrupted. + Assert.assertTrue(e.getCause() instanceof LibraryReadingException); + Assert.assertTrue(e.getCause().getCause() instanceof LibraryFormatException); + } finally { + Assert.assertTrue(errOut.toString().contains("is an invalid library")); + Assert.assertTrue(errOut.toString().contains("Invalid Jayce header")); + } + } + + /** + * Checks that compilation fails correctly when jack file is not longer supported. + */ + @Test + public void testJackFormatError003() throws Exception { + ErrorTestHelper helper = new ErrorTestHelper(); + + AbstractTestTools.createFile(new File(helper.getJackFolder(), FileType.JAYCE.getPrefix()), + "jack.incremental", + "A.jayce", "jayce()"); + AbstractTestTools.createFile(helper.getJackFolder(), "", "jack.properties", + JackLibrary.KEY_LIB_EMITTER + "=unknown\n" + + JackLibrary.KEY_LIB_EMITTER_VERSION + "=0\n" + + JackLibrary.KEY_LIB_MAJOR_VERSION + "=" + Version.MAJOR + "\n" + + JackLibrary.KEY_LIB_MINOR_VERSION + "=" + Version.MINOR + "\n" + + FileType.JAYCE.buildPropertyName(null /*suffix*/) + "=true\n" + + JayceProperties.KEY_JAYCE_MAJOR_VERSION + "=0\n" + + JayceProperties.KEY_JAYCE_MINOR_VERSION + "=0\n"); + + AbstractTestTools.createFile(helper.getSourceFolder(),"jack.incremental", "B.java", + "package jack.incremental; \n"+ + "public class B extends A {} \n"); + + JackApiToolchain toolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); + + toolchain.setVerbosityLevel(VerbosityLevel.DEBUG); + + ByteArrayOutputStream errOut = new ByteArrayOutputStream(); + toolchain.setErrorStream(errOut); + + try { + toolchain.srcToExe(AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()) + + File.pathSeparatorChar + helper.getJackFolder().getAbsolutePath(), + helper.getOutputDexFolder(), /* zipFile= */ false, helper.getSourceFolder()); + Assert.fail(); + } catch (JackAbortException e) { + // Failure is ok since jack file header is corrupted. + Assert.assertTrue(e.getCause() instanceof LibraryReadingException); + Assert.assertTrue(e.getCause().getCause() instanceof LibraryFormatException); + } finally { + Assert.assertTrue(errOut.toString().contains("is an invalid library")); + Assert.assertTrue(errOut.toString().contains("Jayce version 0 not supported")); + } + } +} diff --git a/jack-tests/tests/com/android/jack/error/SourceErrorTest.java b/jack-tests/tests/com/android/jack/error/SourceErrorTest.java new file mode 100644 index 00000000..afee3fea --- /dev/null +++ b/jack-tests/tests/com/android/jack/error/SourceErrorTest.java @@ -0,0 +1,349 @@ +/* + * 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.error; + +import com.android.jack.frontend.FrontendCompilationException; +import com.android.jack.test.helper.ErrorTestHelper; +import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.IToolchain; +import com.android.jack.test.toolchain.JackApiToolchain; + +import org.junit.Assert; +import org.junit.Test; + +import java.io.ByteArrayOutputStream; + +import javax.annotation.Nonnull; + +/** + * JUnit test checking Jack behavior with source errors. + */ +public class SourceErrorTest { + + /** + * Checks that compilation fails because of invalid "class" keyword. + */ + @Test + public void testInvalidSource001() throws Exception { + ErrorTestHelper helper = new ErrorTestHelper(); + + AbstractTestTools.createFile(helper.getSourceFolder(), "jack.invalidsource", "A.java", "package jack.invalidsource;\n" + + "public clas A {}\n"); + + JackApiToolchain toolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); + + ByteArrayOutputStream errOut = new ByteArrayOutputStream(); + toolchain.setErrorStream(errOut); + + try { + compile(toolchain, helper); + Assert.fail(); + } catch (FrontendCompilationException ex) { + // Failure is ok since source does not compile. + } finally { + Assert.assertTrue( + errOut.toString().contains("Syntax error on token \"clas\", class expected")); + } + } + + /** + * Checks that compilation fails because of invalid "public" keyword. + */ + @Test + public void testInvalidSource002() throws Exception { + ErrorTestHelper helper = new ErrorTestHelper(); + + AbstractTestTools.createFile(helper.getSourceFolder(), "jack.invalidsource", "A.java", "package jack.invalidsource;\n" + + "publi class A {}\n"); + + JackApiToolchain toolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); + + ByteArrayOutputStream errOut = new ByteArrayOutputStream(); + toolchain.setErrorStream(errOut); + + try { + compile(toolchain, helper); + Assert.fail(); + } catch (FrontendCompilationException ex) { + // Failure is ok since source does not compile. + } finally { + Assert.assertTrue( + errOut.toString().contains("Syntax error on token \"publi\", public expected")); + } + } + + /** + * Checks that compilation fails because of a class name that does not match the file name. + */ + @Test + public void testInvalidSource003() throws Exception { + ErrorTestHelper helper = new ErrorTestHelper(); + + AbstractTestTools.createFile(helper.getSourceFolder(), "jack.invalidsource", "A.java", "package jack.invalidsource;\n" + + "public class B {}\n"); + + JackApiToolchain toolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); + + ByteArrayOutputStream errOut = new ByteArrayOutputStream(); + toolchain.setErrorStream(errOut); + + try { + compile(toolchain, helper); + Assert.fail(); + } catch (FrontendCompilationException ex) { + // Failure is ok since source does not compile. + } finally { + Assert.assertTrue( + errOut.toString().contains("The public type B must be defined in its own file")); + } + } + + /** + * Checks that compilation fails because of an import of a class that is not on classpath. + */ + @Test + public void testInvalidSource004() throws Exception { + ErrorTestHelper helper = new ErrorTestHelper(); + + AbstractTestTools.createFile(helper.getSourceFolder(), "jack.invalidsource", "A.java", "package jack.invalidsource;\n" + + "import jack.invalidsource.B;\n" + + "public class A {}\n"); + + JackApiToolchain toolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); + + ByteArrayOutputStream errOut = new ByteArrayOutputStream(); + toolchain.setErrorStream(errOut); + + try { + compile(toolchain, helper); + Assert.fail(); + } catch (FrontendCompilationException ex) { + // Failure is ok since source does not compile. + } finally { + Assert.assertTrue( + errOut.toString().contains("The import jack.invalidsource.B cannot be resolved")); + } + } + + /** + * Checks that compilation fails because there are too many methods in a single class. + */ + @Test + public void testInvalidSource005() throws Exception { + ErrorTestHelper helper = new ErrorTestHelper(); + + int methodCount = 65536; + StringBuilder content = + new StringBuilder("public class A {"); + // -1 due to implicit init method + for (int mthIdx = 0; mthIdx < methodCount - 1; mthIdx++) { + content.append("public void m" + mthIdx + "() {} \n"); + } + content.append("} \n"); + + AbstractTestTools.createFile(helper.getSourceFolder(), "jack.overflow", "A.java", + "package jack.overflow; \n" + content.toString()); + + JackApiToolchain toolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + ByteArrayOutputStream errOut = new ByteArrayOutputStream(); + toolchain.setOutputStream(out); + toolchain.setErrorStream(errOut); + + try { + compile(toolchain, helper); + Assert.fail(); + } catch (FrontendCompilationException e) { + // Failure is ok, since there are too many methods. + } finally { + Assert.assertEquals("", out.toString()); + Assert.assertTrue( + errOut.toString().contains("Too many methods for type A. Maximum is 65535")); + } + } + + /** + * Checks that compilation fails because of several source errors. + */ + @Test + public void testInvalidSource006() throws Exception { + ErrorTestHelper helper = new ErrorTestHelper(); + + AbstractTestTools.createFile(helper.getSourceFolder(), "jack.invalidsource", "A.java", "package jack.invalidsource;\n" + + "public class A { private voi m() {} } \n"); + AbstractTestTools.createFile(helper.getSourceFolder(), "jack.invalidsource", "B.java", "package jack.invalidsource;\n" + + "public class B { private void m(in a) {}; \n private void n(int a) {re}; } \n"); + + JackApiToolchain toolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + ByteArrayOutputStream errOut = new ByteArrayOutputStream(); + toolchain.setOutputStream(out); + toolchain.setErrorStream(errOut); + + try { + compile(toolchain, helper); + Assert.fail(); + } catch (FrontendCompilationException ex) { + // Failure is ok since source does not compile. + } finally { + Assert.assertEquals("", out.toString()); + String errorString = errOut.toString(); + Assert.assertTrue(errorString.contains("in cannot be resolved to a type")); + Assert.assertTrue(errorString.contains( + "Syntax error, insert \"VariableDeclarators\" to complete LocalVariableDeclaration")); + Assert.assertTrue( + errorString.contains("Syntax error, insert \";\" to complete BlockStatements")); + Assert.assertTrue(errorString.contains("voi cannot be resolved to a type")); + } + } + + /** + * Checks that compilation fails because of a source error, with also some warnings. + */ + @Test + public void testInvalidSource007() throws Exception { + ErrorTestHelper helper = new ErrorTestHelper(); + + AbstractTestTools.createFile(helper.getSourceFolder(), "jack.invalidsource", "A.java", "package jack.invalidsource;\n" + + "public class A { private void m() {} } \n"); + AbstractTestTools.createFile(helper.getSourceFolder(), "jack.invalidsource", "B.java", "package jack.invalidsource;\n" + + "public class B { private void m(in a) {}; \n private void n(int a) {}; } \n"); + + JackApiToolchain toolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + ByteArrayOutputStream errOut = new ByteArrayOutputStream(); + toolchain.setOutputStream(out); + toolchain.setErrorStream(errOut); + + try { + compile(toolchain, helper); + Assert.fail(); + } catch (FrontendCompilationException ex) { + // Failure is ok since source does not compile. + } finally { + Assert.assertEquals("", out.toString()); + Assert.assertTrue(errOut.toString().contains("in cannot be resolved to a type")); + Assert.assertTrue(errOut.toString().contains( + "The method n(int) from the type B is never used locally")); + Assert.assertTrue( + errOut.toString().contains("The method m() from the type A is never used locally")); + } + } + + /** + * Checks that compilation succeeds but prints several warnings. + */ + @Test + public void testInvalidSource008() throws Exception { + ErrorTestHelper helper = new ErrorTestHelper(); + + AbstractTestTools.createFile(helper.getSourceFolder(), "jack.invalidsource", "A.java", "package jack.invalidsource;\n" + + "public class A { private void m() {} } \n"); + AbstractTestTools.createFile(helper.getSourceFolder(), "jack.invalidsource", "B.java", "package jack.invalidsource;\n" + + "public class B { private void m(int a) {}; \n private void n(int a) {}; } \n"); + + JackApiToolchain toolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + ByteArrayOutputStream errOut = new ByteArrayOutputStream(); + toolchain.setOutputStream(out); + toolchain.setErrorStream(errOut); + + try { + compile(toolchain, helper); + } finally { + Assert.assertEquals("", out.toString()); + Assert.assertTrue(errOut.toString().contains( + "The method m(int) from the type B is never used locally")); + Assert.assertTrue(errOut.toString().contains( + "The method n(int) from the type B is never used locally")); + Assert.assertTrue( + errOut.toString().contains("The method m() from the type A is never used locally")); + } + } + + /** + * Checks that compilation fails because of an invalid type. + * undefinedTypeId = typeRelatedCategory + 2 + */ + @Test + public void testInvalidSource009() throws Exception { + ErrorTestHelper helper = new ErrorTestHelper(); + + AbstractTestTools.createFile(helper.getSourceFolder(), "jack.invalidsource", "A.java", "package jack.invalidsource;\n" + + "public class A { private void m(in a) {}; } \n"); + + JackApiToolchain toolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + ByteArrayOutputStream errOut = new ByteArrayOutputStream(); + toolchain.setOutputStream(out); + toolchain.setErrorStream(errOut); + + try { + compile(toolchain, helper); + Assert.fail(); + } catch (FrontendCompilationException ex) { + // Failure is ok since source does not compile. + } finally { + Assert.assertEquals("", out.toString()); + Assert.assertTrue(errOut.toString().contains("in cannot be resolved to a type")); + } + } + + /** + * Checks that compilation fails because of a parsing error. + * parsingErrorInsertToCompleteId = syntaxCategory + internalCategory + 240 + */ + @Test + public void testInvalidSource010() throws Exception { + ErrorTestHelper helper = new ErrorTestHelper(); + + AbstractTestTools.createFile(helper.getSourceFolder(), "jack.invalidsource", "A.java", "package jack.invalidsource;\n" + + "public class A { private void n(int a) {re;} } \n"); + + JackApiToolchain toolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + ByteArrayOutputStream errOut = new ByteArrayOutputStream(); + toolchain.setOutputStream(out); + toolchain.setErrorStream(errOut); + + try { + compile(toolchain, helper); + Assert.fail(); + } catch (FrontendCompilationException ex) { + // Failure is ok since source does not compile. + } finally { + Assert.assertEquals("", out.toString()); + Assert.assertTrue(errOut.toString().contains( + "Syntax error, insert \"VariableDeclarators\" to complete LocalVariableDeclaration")); + } + } + + private void compile(@Nonnull IToolchain toolchain, @Nonnull ErrorTestHelper helper) + throws Exception { + toolchain.srcToExe( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + helper.getOutputDexFolder(), + /* zipFile = */ false, helper.getSourceFolder()); + } + +} diff --git a/jack-tests/tests/com/android/jack/experimenal/incremental/DependenciesTests005.java b/jack-tests/tests/com/android/jack/experimenal/incremental/DependenciesTests005.java deleted file mode 100644 index 6b50799f..00000000 --- a/jack-tests/tests/com/android/jack/experimenal/incremental/DependenciesTests005.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * 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.experimenal.incremental; - -import com.android.jack.Main; -import com.android.jack.test.helper.IncrementalTestHelper; -import com.android.jack.test.toolchain.AbstractTestTools; - -import junit.framework.Assert; - -import org.junit.BeforeClass; -import org.junit.Test; - -import java.util.List; - -/** - * JUnit test checking dependencies between Java files. - */ -public class DependenciesTests005 { - - @BeforeClass - public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); - } - - /** - * Check that runtime is correct after incremental compilation due to a constant modification. - */ - @Test - public void testDependency001() throws Exception { - IncrementalTestHelper ite = - new IncrementalTestHelper(AbstractTestTools.createTempDir()); - - ite.addJavaFile("jack.incremental", "A.java", - "package jack.incremental; \n"+ - "public class A { public static void main(String[] args) {" + - "System.out.print(C.str + B.str);} " + - "} \n"); - - ite.addJavaFile("jack.incremental", "B.java", - "package jack.incremental; \n"+ - "public class B { public static final String str = \"HELLO\"; } \n"); - - ite.addJavaFile("jack.incremental", "C.java", - "package jack.incremental; \n"+ - "public class C { public static final String str = \"STRING:\"; } \n"); - - ite.incrementalBuildFromFolder(); - ite.snapshotJackFilesModificationDate(); - - ite.addJavaFile("jack.incremental", "B.java", - "package jack.incremental; \n"+ - "public class B { public static final String str = \"INCREMENTAL\"; } \n"); - - ite.incrementalBuildFromFolder(); - - List<String> fqnOfRebuiltTypes = ite.getFQNOfRebuiltTypes(); - Assert.assertEquals(2, fqnOfRebuiltTypes.size()); - Assert.assertTrue(fqnOfRebuiltTypes.contains("jack.incremental.A")); - Assert.assertTrue(fqnOfRebuiltTypes.contains("jack.incremental.B")); - - Assert.assertEquals("STRING:INCREMENTAL", ite.run("jack.incremental.A")); - } - - -} diff --git a/jack/tests/com/android/jack/experimental/incremental/DependenciesTest001.java b/jack-tests/tests/com/android/jack/experimental/incremental/DependenciesTest001.java index f93cdb57..3a0a93b9 100644 --- a/jack/tests/com/android/jack/experimental/incremental/DependenciesTest001.java +++ b/jack-tests/tests/com/android/jack/experimental/incremental/DependenciesTest001.java @@ -19,12 +19,16 @@ package com.android.jack.experimental.incremental; import com.android.jack.Main; import com.android.jack.TestTools; import com.android.jack.frontend.FrontendCompilationException; +import com.android.jack.test.helper.IncrementalTestHelper; +import com.android.jack.test.toolchain.AbstractTestTools; import junit.framework.Assert; import org.junit.BeforeClass; import org.junit.Test; +import java.io.ByteArrayOutputStream; +import java.io.File; import java.util.List; /** @@ -43,20 +47,20 @@ public class DependenciesTest001 { */ @Test public void testDependency001() throws Exception { - IncrementalTestingEnvironment ite = - new IncrementalTestingEnvironment(TestTools.createTempDir("DependenciesTest_", "_001")); + IncrementalTestHelper ite = + new IncrementalTestHelper(AbstractTestTools.createTempDir()); ite.addJavaFile("jack.incremental", "A.java", "package jack.incremental; \n"+ "public class A extends B {} \n"); - ite.addJavaFile("jack.incremental", "B.java", + File f = ite.addJavaFile("jack.incremental", "B.java", "package jack.incremental; \n"+ "public class B {} \n"); ite.incrementalBuildFromFolder(); - ite.deleteJavaFile("jack.incremental", "B.java"); + ite.deleteJavaFile(f); try { ite.incrementalBuildFromFolder(); @@ -72,20 +76,20 @@ public class DependenciesTest001 { */ @Test public void testDependency002() throws Exception { - IncrementalTestingEnvironment ite = - new IncrementalTestingEnvironment(TestTools.createTempDir("DependenciesTest_", "_002")); + IncrementalTestHelper ite = + new IncrementalTestHelper(TestTools.createTempDir("DependenciesTest_", "_002")); ite.addJavaFile("jack.incremental", "A.java", "package jack.incremental; \n"+ "public class A implements I {} \n"); - ite.addJavaFile("jack.incremental", "I.java", + File f = ite.addJavaFile("jack.incremental", "I.java", "package jack.incremental; \n"+ "public interface I {} \n"); ite.incrementalBuildFromFolder(); - ite.deleteJavaFile("jack.incremental", "I.java"); + ite.deleteJavaFile(f); try { ite.incrementalBuildFromFolder(); @@ -100,8 +104,8 @@ public class DependenciesTest001 { */ @Test public void testDependency003() throws Exception { - IncrementalTestingEnvironment ite = - new IncrementalTestingEnvironment(TestTools.createTempDir("DependenciesTest_", "_003")); + IncrementalTestHelper ite = + new IncrementalTestHelper(AbstractTestTools.createTempDir()); ite.addJavaFile("jack.incremental", "A.java", "package jack.incremental; \n"+ @@ -130,8 +134,8 @@ public class DependenciesTest001 { */ @Test public void testDependency004() throws Exception { - IncrementalTestingEnvironment ite = - new IncrementalTestingEnvironment(TestTools.createTempDir("DependenciesTest_", "_004")); + IncrementalTestHelper ite = + new IncrementalTestHelper(TestTools.createTempDir("DependenciesTest_", "_004")); ite.addJavaFile("jack.incremental", "A.java", "package jack.incremental; \n"+ @@ -156,8 +160,8 @@ public class DependenciesTest001 { */ @Test public void testDependency005() throws Exception { - IncrementalTestingEnvironment ite = - new IncrementalTestingEnvironment(TestTools.createTempDir("DependenciesTest_", "_005")); + IncrementalTestHelper ite = + new IncrementalTestHelper(TestTools.createTempDir("DependenciesTest_", "_005")); ite.addJavaFile("jack.incremental", "A.java", "package jack.incremental; \n"+ @@ -192,8 +196,8 @@ public class DependenciesTest001 { */ @Test public void testDependency006() throws Exception { - IncrementalTestingEnvironment ite = - new IncrementalTestingEnvironment(TestTools.createTempDir("DependenciesTest_", "_006")); + IncrementalTestHelper ite = + new IncrementalTestHelper(TestTools.createTempDir("DependenciesTest_", "_006")); ite.addJavaFile("jack.incremental", "A.java", "package jack.incremental; \n"+ @@ -228,8 +232,8 @@ public class DependenciesTest001 { */ @Test public void testDependency007() throws Exception { - IncrementalTestingEnvironment ite = - new IncrementalTestingEnvironment(TestTools.createTempDir("DependenciesTest_", "_007")); + IncrementalTestHelper ite = + new IncrementalTestHelper(TestTools.createTempDir("DependenciesTest_", "_007")); ite.addJavaFile("jack.incremental", "A.java", "package jack.incremental; \n"+ @@ -264,8 +268,8 @@ public class DependenciesTest001 { */ @Test public void testDependency008() throws Exception { - IncrementalTestingEnvironment ite = - new IncrementalTestingEnvironment(TestTools.createTempDir("DependenciesTest_", "_008")); + IncrementalTestHelper ite = + new IncrementalTestHelper(TestTools.createTempDir("DependenciesTest_", "_008")); ite.addJavaFile("jack.incremental", "A.java", "package jack.incremental; \n"+ @@ -295,8 +299,8 @@ public class DependenciesTest001 { */ @Test public void testDependency009() throws Exception { - IncrementalTestingEnvironment ite = - new IncrementalTestingEnvironment(TestTools.createTempDir("DependenciesTest_", "_009")); + IncrementalTestHelper ite = + new IncrementalTestHelper(TestTools.createTempDir("DependenciesTest_", "_009")); ite.addJavaFile("jack.incremental", "A.java", "package jack.incremental; \n"+ @@ -327,8 +331,8 @@ public class DependenciesTest001 { */ @Test public void testDependency010() throws Exception { - IncrementalTestingEnvironment ite = - new IncrementalTestingEnvironment(TestTools.createTempDir("DependenciesTest_", "_010")); + IncrementalTestHelper ite = + new IncrementalTestHelper(TestTools.createTempDir("DependenciesTest_", "_010")); ite.addJavaFile("jack.incremental", "A.java", "package jack.incremental; \n"+ @@ -358,21 +362,21 @@ public class DependenciesTest001 { */ @Test public void testDependency011() throws Exception { - IncrementalTestingEnvironment ite = - new IncrementalTestingEnvironment(TestTools.createTempDir("DependenciesTest_", "_011")); + IncrementalTestHelper ite = + new IncrementalTestHelper(TestTools.createTempDir("DependenciesTest_", "_011")); ite.addJavaFile("jack.incremental", "A.java", "package jack.incremental; \n"+ "public class A { public boolean callTest(Object o) { return o instanceof B;} } \n"); - ite.addJavaFile("jack.incremental", "B.java", + File f = ite.addJavaFile("jack.incremental", "B.java", "package jack.incremental; \n"+ "public class B {} \n"); ite.incrementalBuildFromFolder(); ite.snapshotJackFilesModificationDate(); - ite.deleteJavaFile("jack.incremental", "B.java"); + ite.deleteJavaFile(f); try { ite.incrementalBuildFromFolder(); @@ -388,8 +392,8 @@ public class DependenciesTest001 { */ @Test public void testDependency012() throws Exception { - IncrementalTestingEnvironment ite = - new IncrementalTestingEnvironment(TestTools.createTempDir("DependenciesTest_", "_012")); + IncrementalTestHelper ite = + new IncrementalTestHelper(TestTools.createTempDir("DependenciesTest_", "_012")); ite.addJavaFile("jack.incremental", "A.java", "package jack.incremental; \n"+ @@ -420,8 +424,8 @@ public class DependenciesTest001 { */ @Test public void testDependency013() throws Exception { - IncrementalTestingEnvironment ite = - new IncrementalTestingEnvironment(TestTools.createTempDir("DependenciesTest_", "_013")); + IncrementalTestHelper ite = + new IncrementalTestHelper(TestTools.createTempDir("DependenciesTest_", "_013")); ite.addJavaFile("jack.incremental", "A.java", "package jack.incremental; \n"+ @@ -452,8 +456,8 @@ public class DependenciesTest001 { */ @Test public void testDependency014() throws Exception { - IncrementalTestingEnvironment ite = - new IncrementalTestingEnvironment(TestTools.createTempDir("DependenciesTest_", "_014")); + IncrementalTestHelper ite = + new IncrementalTestHelper(TestTools.createTempDir("DependenciesTest_", "_014")); ite.addJavaFile("jack.incremental", "A.java", "package jack.incremental; \n"+ @@ -500,8 +504,8 @@ public class DependenciesTest001 { */ @Test public void testDependency015() throws Exception { - IncrementalTestingEnvironment ite = - new IncrementalTestingEnvironment(TestTools.createTempDir("DependenciesTest_", "_015")); + IncrementalTestHelper ite = + new IncrementalTestHelper(TestTools.createTempDir("DependenciesTest_", "_015")); ite.addJavaFile("jack.incremental", "A.java", "package jack.incremental; \n"+ @@ -522,29 +526,34 @@ public class DependenciesTest001 { "package jack.incremental; \n"+ "public interface I { public void m(int i); } \n"); + ByteArrayOutputStream err = new ByteArrayOutputStream(); + ite.setErr(err); + try { ite.incrementalBuildFromFolder(); Assert.fail(); } catch (FrontendCompilationException e) { // Error is ok - String err = ite.getStringRepresentingErr(); Assert.assertTrue( - err.contains("The type B must implement the inherited abstract method I.m(int)")); + err.toString().contains("The type B must implement the inherited abstract method I.m(int)")); Assert.assertTrue( - err.contains("The method m() of type B must override or implement a supertype method")); + err.toString().contains("The method m() of type B must override or implement a supertype method")); } ite.addJavaFile("jack.incremental", "B.java", "package jack.incremental; \n"+ "public class B implements I { @Override public void m(int i) {} } \n"); + err = new ByteArrayOutputStream(); + ite.setErr(err); + try { ite.incrementalBuildFromFolder(); Assert.fail(); } catch (FrontendCompilationException e) { // Error is ok - Assert.assertTrue(ite.getStringRepresentingErr().contains( - "The method m() of type A must override or implement a supertype method")); + Assert.assertTrue(err.toString() + .contains("The method m() of type A must override or implement a supertype method")); } ite.addJavaFile("jack.incremental", "A.java", diff --git a/jack/tests/com/android/jack/experimental/incremental/DependenciesTest002.java b/jack-tests/tests/com/android/jack/experimental/incremental/DependenciesTest002.java index 2fca23dc..fcded878 100644 --- a/jack/tests/com/android/jack/experimental/incremental/DependenciesTest002.java +++ b/jack-tests/tests/com/android/jack/experimental/incremental/DependenciesTest002.java @@ -18,6 +18,7 @@ package com.android.jack.experimental.incremental; import com.android.jack.Main; import com.android.jack.TestTools; +import com.android.jack.test.helper.IncrementalTestHelper; import junit.framework.Assert; @@ -41,8 +42,8 @@ public class DependenciesTest002 { */ @Test public void testDependency001() throws Exception { - IncrementalTestingEnvironment ite = - new IncrementalTestingEnvironment(TestTools.createTempDir("DependenciesTest_", "_001")); + IncrementalTestHelper ite = + new IncrementalTestHelper(TestTools.createTempDir("DependenciesTest_", "_001")); ite.addJavaFile("jack.incremental", "A.java", "package jack.incremental; \n"+ diff --git a/jack/tests/com/android/jack/experimental/incremental/DependenciesTest003.java b/jack-tests/tests/com/android/jack/experimental/incremental/DependenciesTest003.java index a18f83fd..457cd49f 100644 --- a/jack/tests/com/android/jack/experimental/incremental/DependenciesTest003.java +++ b/jack-tests/tests/com/android/jack/experimental/incremental/DependenciesTest003.java @@ -18,6 +18,7 @@ package com.android.jack.experimental.incremental; import com.android.jack.Main; import com.android.jack.TestTools; +import com.android.jack.test.helper.IncrementalTestHelper; import junit.framework.Assert; @@ -42,8 +43,8 @@ public class DependenciesTest003 { */ @Test public void testDependency001() throws Exception { - IncrementalTestingEnvironment ite = - new IncrementalTestingEnvironment(TestTools.createTempDir("DependenciesTest_", "_001")); + IncrementalTestHelper ite = + new IncrementalTestHelper(TestTools.createTempDir("DependenciesTest_", "_001")); ite.addJavaFile("jack.incremental", "A.java", "package jack.incremental; \n"+ diff --git a/jack/tests/com/android/jack/experimental/incremental/DependenciesTest004.java b/jack-tests/tests/com/android/jack/experimental/incremental/DependenciesTest004.java index dca5066e..2d3a962a 100644 --- a/jack/tests/com/android/jack/experimental/incremental/DependenciesTest004.java +++ b/jack-tests/tests/com/android/jack/experimental/incremental/DependenciesTest004.java @@ -18,6 +18,7 @@ package com.android.jack.experimental.incremental; import com.android.jack.Main; import com.android.jack.TestTools; +import com.android.jack.test.helper.IncrementalTestHelper; import junit.framework.Assert; @@ -41,8 +42,8 @@ public class DependenciesTest004 { */ @Test public void testDependency001() throws Exception { - IncrementalTestingEnvironment ite = - new IncrementalTestingEnvironment(TestTools.createTempDir("DependenciesTest_", "_001")); + IncrementalTestHelper ite = + new IncrementalTestHelper(TestTools.createTempDir("DependenciesTest_", "_001")); ite.addJavaFile("jack.incremental", "A.java", "package jack.incremental; \n"+ diff --git a/jack/tests/com/android/jack/experimental/incremental/DependenciesTest005.java b/jack-tests/tests/com/android/jack/experimental/incremental/DependenciesTest005.java index d9a0dbd4..fffd2da3 100644 --- a/jack/tests/com/android/jack/experimental/incremental/DependenciesTest005.java +++ b/jack-tests/tests/com/android/jack/experimental/incremental/DependenciesTest005.java @@ -18,6 +18,7 @@ package com.android.jack.experimental.incremental; import com.android.jack.Main; import com.android.jack.TestTools; +import com.android.jack.test.helper.IncrementalTestHelper; import junit.framework.Assert; @@ -43,8 +44,8 @@ public class DependenciesTest005 { */ @Test public void testDependency001() throws Exception { - IncrementalTestingEnvironment ite = - new IncrementalTestingEnvironment(TestTools.createTempDir("DependenciesTest_", "_001")); + IncrementalTestHelper ite = + new IncrementalTestHelper(TestTools.createTempDir("DependenciesTest_", "_001")); ite.addJavaFile("jack.incremental", "A.java", "package jack.incremental; \n"+ @@ -83,8 +84,8 @@ public class DependenciesTest005 { */ @Test public void testDependency002() throws Exception { - IncrementalTestingEnvironment ite = - new IncrementalTestingEnvironment(TestTools.createTempDir("DependenciesTest_", "_002")); + IncrementalTestHelper ite = + new IncrementalTestHelper(TestTools.createTempDir("DependenciesTest_", "_002")); ite.addJavaFile("jack.incremental", "A.java", "package jack.incremental; \n"+ @@ -123,8 +124,8 @@ public class DependenciesTest005 { */ @Test public void testDependency003() throws Exception { - IncrementalTestingEnvironment ite = - new IncrementalTestingEnvironment(TestTools.createTempDir("DependenciesTest_", "_003")); + IncrementalTestHelper ite = + new IncrementalTestHelper(TestTools.createTempDir("DependenciesTest_", "_003")); ite.addJavaFile("jack.incremental", "A.java", "package jack.incremental; \n"+ @@ -166,8 +167,8 @@ public class DependenciesTest005 { */ @Test public void testDependency004() throws Exception { - IncrementalTestingEnvironment ite = - new IncrementalTestingEnvironment(TestTools.createTempDir("DependenciesTest_", "_004")); + IncrementalTestHelper ite = + new IncrementalTestHelper(TestTools.createTempDir("DependenciesTest_", "_004")); ite.addJavaFile("jack.incremental", "A.java", "package jack.incremental; \n"+ diff --git a/jack/tests/com/android/jack/experimental/incremental/DependenciesTest006.java b/jack-tests/tests/com/android/jack/experimental/incremental/DependenciesTest006.java index 789966c1..a27b2394 100644 --- a/jack/tests/com/android/jack/experimental/incremental/DependenciesTest006.java +++ b/jack-tests/tests/com/android/jack/experimental/incremental/DependenciesTest006.java @@ -19,6 +19,7 @@ package com.android.jack.experimental.incremental; import com.android.jack.Main; import com.android.jack.TestTools; import com.android.jack.frontend.FrontendCompilationException; +import com.android.jack.test.helper.IncrementalTestHelper; import junit.framework.Assert; @@ -26,6 +27,7 @@ import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; +import java.io.File; import java.util.List; /** @@ -44,8 +46,8 @@ public class DependenciesTest006 { */ @Test public void testDependency001() throws Exception { - IncrementalTestingEnvironment ite = - new IncrementalTestingEnvironment(TestTools.createTempDir("DependenciesTest_", "_001")); + IncrementalTestHelper ite = + new IncrementalTestHelper(TestTools.createTempDir("DependenciesTest_", "_001")); ite.addJavaFile("jack.incremental", "A.java", "package jack.incremental; \n"+ @@ -53,7 +55,7 @@ public class DependenciesTest006 { "System.out.print(new B().getString());} " + "} \n"); - ite.addJavaFile("jack.incremental", "B.java", + File f = ite.addJavaFile("jack.incremental", "B.java", "package jack.incremental; \n"+ "public class B { public String getString() { return (\"B\"); } } \n"); @@ -64,7 +66,7 @@ public class DependenciesTest006 { ite.incrementalBuildFromFolder(); ite.snapshotJackFilesModificationDate(); - ite.deleteJavaFile("jack.incremental", "B.java"); + ite.deleteJavaFile(f); ite.addJavaFile("jack.incremental", "_B.java", "package jack.incremental; \n"+ "public class _B { public String getString() { return (\"_B\"); } } \n"); diff --git a/jack/tests/com/android/jack/experimental/incremental/DependenciesTest007.java b/jack-tests/tests/com/android/jack/experimental/incremental/DependenciesTest007.java index e0c6688d..329a3e3f 100644 --- a/jack/tests/com/android/jack/experimental/incremental/DependenciesTest007.java +++ b/jack-tests/tests/com/android/jack/experimental/incremental/DependenciesTest007.java @@ -18,6 +18,7 @@ package com.android.jack.experimental.incremental; import com.android.jack.Main; import com.android.jack.TestTools; +import com.android.jack.test.helper.IncrementalTestHelper; import junit.framework.Assert; @@ -43,8 +44,8 @@ public class DependenciesTest007 { */ @Test public void testDependency001() throws Exception { - IncrementalTestingEnvironment ite = - new IncrementalTestingEnvironment(TestTools.createTempDir("DependenciesTest_", "_001")); + IncrementalTestHelper ite = + new IncrementalTestHelper(TestTools.createTempDir("DependenciesTest_", "_001")); ite.addJavaFile("jack.incremental", "A.java", "package jack.incremental; \n"+ diff --git a/jack/tests/com/android/jack/experimental/incremental/DependenciesTest008.java b/jack-tests/tests/com/android/jack/experimental/incremental/DependenciesTest008.java index 578ce5c8..2ad9b836 100644 --- a/jack/tests/com/android/jack/experimental/incremental/DependenciesTest008.java +++ b/jack-tests/tests/com/android/jack/experimental/incremental/DependenciesTest008.java @@ -19,6 +19,7 @@ package com.android.jack.experimental.incremental; import com.android.jack.Main; import com.android.jack.TestTools; import com.android.jack.frontend.FrontendCompilationException; +import com.android.jack.test.helper.IncrementalTestHelper; import junit.framework.Assert; @@ -40,8 +41,8 @@ public class DependenciesTest008 { */ @Test public void testDependency001() throws Exception { - IncrementalTestingEnvironment ite = - new IncrementalTestingEnvironment(TestTools.createTempDir("DependenciesTest_", "_001")); + IncrementalTestHelper ite = + new IncrementalTestHelper(TestTools.createTempDir("DependenciesTest_", "_001")); ite.addJavaFile("jack.incremental", "A.java", "package jack.incremental; \n" + @@ -71,8 +72,8 @@ public class DependenciesTest008 { */ @Test public void testDependency002() throws Exception { - IncrementalTestingEnvironment ite = - new IncrementalTestingEnvironment(TestTools.createTempDir("DependenciesTest_", "_002")); + IncrementalTestHelper ite = + new IncrementalTestHelper(TestTools.createTempDir("DependenciesTest_", "_002")); ite.addJavaFile("jack.incremental", "A.java", "package jack.incremental; \n" + @@ -95,8 +96,8 @@ public class DependenciesTest008 { */ @Test public void testDependency003() throws Exception { - IncrementalTestingEnvironment ite = - new IncrementalTestingEnvironment(TestTools.createTempDir("DependenciesTest_", "_003")); + IncrementalTestHelper ite = + new IncrementalTestHelper(TestTools.createTempDir("DependenciesTest_", "_003")); ite.addJavaFile("jack.incremental", "A.java", "package jack.incremental; \n" + diff --git a/jack/tests/com/android/jack/experimental/incremental/DependenciesTest009.java b/jack-tests/tests/com/android/jack/experimental/incremental/DependenciesTest009.java index a736e419..a09a1c09 100644 --- a/jack/tests/com/android/jack/experimental/incremental/DependenciesTest009.java +++ b/jack-tests/tests/com/android/jack/experimental/incremental/DependenciesTest009.java @@ -18,6 +18,8 @@ package com.android.jack.experimental.incremental; import com.android.jack.Main; import com.android.jack.TestTools; +import com.android.jack.experimental.incremental.CompilerState; +import com.android.jack.test.helper.IncrementalTestHelper; import junit.framework.Assert; @@ -43,8 +45,8 @@ public class DependenciesTest009 { */ @Test public void testDependency001() throws Exception { - IncrementalTestingEnvironment ite = - new IncrementalTestingEnvironment(TestTools.createTempDir("DependenciesTest_", "_001")); + IncrementalTestHelper ite = + new IncrementalTestHelper(TestTools.createTempDir("DependenciesTest_", "_001")); ite.addJavaFile("jack.incremental", "A.java", "package jack.incremental; \n" + "public class A extends B { }"); diff --git a/jack/tests/com/android/jack/experimental/incremental/DependenciesTest010.java b/jack-tests/tests/com/android/jack/experimental/incremental/DependenciesTest010.java index 204d336e..d5051bfb 100644 --- a/jack/tests/com/android/jack/experimental/incremental/DependenciesTest010.java +++ b/jack-tests/tests/com/android/jack/experimental/incremental/DependenciesTest010.java @@ -18,6 +18,7 @@ package com.android.jack.experimental.incremental; import com.android.jack.Main; import com.android.jack.TestTools; +import com.android.jack.test.helper.IncrementalTestHelper; import junit.framework.Assert; @@ -43,8 +44,8 @@ public class DependenciesTest010 { */ @Test public void testDependency001() throws Exception { - IncrementalTestingEnvironment ite = - new IncrementalTestingEnvironment(TestTools.createTempDir("DependenciesTest_", "_001")); + IncrementalTestHelper ite = + new IncrementalTestHelper(TestTools.createTempDir("DependenciesTest_", "_001")); ite.addJavaFile("jack.incremental", "A.java", "package jack.incremental; \n" + "public class A { " @@ -130,8 +131,8 @@ public class DependenciesTest010 { */ @Test public void testDependency002() throws Exception { - IncrementalTestingEnvironment ite = - new IncrementalTestingEnvironment(TestTools.createTempDir("DependenciesTest_", "_002")); + IncrementalTestHelper ite = + new IncrementalTestHelper(TestTools.createTempDir("DependenciesTest_", "_002")); ite.addJavaFile("jack.incremental", "A.java", "package jack.incremental; \n" + "import jack.incremental.B;" diff --git a/jack/tests/com/android/jack/experimental/incremental/DependenciesTest011.java b/jack-tests/tests/com/android/jack/experimental/incremental/DependenciesTest011.java index b00d4b86..fb05a072 100644 --- a/jack/tests/com/android/jack/experimental/incremental/DependenciesTest011.java +++ b/jack-tests/tests/com/android/jack/experimental/incremental/DependenciesTest011.java @@ -19,12 +19,14 @@ package com.android.jack.experimental.incremental; import com.android.jack.Main; import com.android.jack.TestTools; import com.android.jack.frontend.FrontendCompilationException; +import com.android.jack.test.helper.IncrementalTestHelper; import junit.framework.Assert; import org.junit.BeforeClass; import org.junit.Test; +import java.io.File; import java.util.List; /** @@ -42,10 +44,10 @@ public class DependenciesTest011 { */ @Test public void testDependency001() throws Exception { - IncrementalTestingEnvironment ite = - new IncrementalTestingEnvironment(TestTools.createTempDir("DependenciesTest_", "_001")); + IncrementalTestHelper ite = + new IncrementalTestHelper(TestTools.createTempDir("DependenciesTest_", "_001")); - ite.addJavaFile("jack.incremental", "A.java", "package jack.incremental; \n" + File f = ite.addJavaFile("jack.incremental", "A.java", "package jack.incremental; \n" + "public class A extends Exception { " + "}"); @@ -58,7 +60,7 @@ public class DependenciesTest011 { ite.snapshotJackFilesModificationDate(); Assert.assertEquals(2, ite.getJackFiles().size()); - ite.deleteJavaFile("jack.incremental", "A.java"); + ite.deleteJavaFile(f); try { ite.incrementalBuildFromFolder(); diff --git a/jack/tests/com/android/jack/experimental/incremental/DependenciesTest012.java b/jack-tests/tests/com/android/jack/experimental/incremental/DependenciesTest012.java index 02d7e010..db6d6a3b 100644 --- a/jack/tests/com/android/jack/experimental/incremental/DependenciesTest012.java +++ b/jack-tests/tests/com/android/jack/experimental/incremental/DependenciesTest012.java @@ -19,12 +19,15 @@ package com.android.jack.experimental.incremental; import com.android.jack.Main; import com.android.jack.TestTools; import com.android.jack.frontend.FrontendCompilationException; +import com.android.jack.test.helper.IncrementalTestHelper; import junit.framework.Assert; import org.junit.BeforeClass; import org.junit.Test; +import java.io.File; + /** * JUnit test checking dependencies between Java files. */ @@ -40,8 +43,8 @@ public class DependenciesTest012 { */ @Test public void testDependency001() throws Exception { - IncrementalTestingEnvironment ite = - new IncrementalTestingEnvironment(TestTools.createTempDir("DependenciesTest_", "_001")); + IncrementalTestHelper ite = + new IncrementalTestHelper(TestTools.createTempDir("DependenciesTest_", "_001")); ite.addJavaFile("jack.incremental", "A.java", "package jack.incremental; \n" + "public class A { \n" @@ -50,7 +53,7 @@ public class DependenciesTest012 { + "} " + "}"); - ite.addJavaFile("jack.incremental", "B.java", "package jack.incremental; \n" + File f = ite.addJavaFile("jack.incremental", "B.java", "package jack.incremental; \n" + "public class B { \n" + "}"); @@ -58,7 +61,7 @@ public class DependenciesTest012 { ite.snapshotJackFilesModificationDate(); Assert.assertEquals(2, ite.getJackFiles().size()); - ite.deleteJavaFile("jack.incremental", "B.java"); + ite.deleteJavaFile(f); try { ite.incrementalBuildFromFolder(); diff --git a/jack/tests/com/android/jack/experimental/incremental/DependenciesTest013.java b/jack-tests/tests/com/android/jack/experimental/incremental/DependenciesTest013.java index d69f18fa..de6116e9 100644 --- a/jack/tests/com/android/jack/experimental/incremental/DependenciesTest013.java +++ b/jack-tests/tests/com/android/jack/experimental/incremental/DependenciesTest013.java @@ -19,12 +19,16 @@ package com.android.jack.experimental.incremental; import com.android.jack.Main; import com.android.jack.TestTools; import com.android.jack.frontend.FrontendCompilationException; +import com.android.jack.test.helper.IncrementalTestHelper; import junit.framework.Assert; import org.junit.BeforeClass; import org.junit.Test; +import java.io.ByteArrayOutputStream; +import java.io.File; + /** * JUnit test checking dependencies between Java files. */ @@ -40,8 +44,8 @@ public class DependenciesTest013 { */ @Test public void testDependency001() throws Exception { - IncrementalTestingEnvironment ite = - new IncrementalTestingEnvironment(TestTools.createTempDir("DependenciesTest_", "_001")); + IncrementalTestHelper ite = + new IncrementalTestHelper(TestTools.createTempDir("DependenciesTest_", "_001")); ite.addJavaFile("jack.incremental", "A.java", "package jack.incremental; \n" + "public class A { \n" @@ -50,7 +54,7 @@ public class DependenciesTest013 { + "} " + "}"); - ite.addJavaFile("jack.incremental", "B.java", "package jack.incremental; \n" + File f = ite.addJavaFile("jack.incremental", "B.java", "package jack.incremental; \n" + "public class B { \n" + "}"); @@ -58,7 +62,10 @@ public class DependenciesTest013 { ite.snapshotJackFilesModificationDate(); Assert.assertEquals(2, ite.getJackFiles().size()); - ite.deleteJavaFile("jack.incremental", "B.java"); + ite.deleteJavaFile(f); + + ByteArrayOutputStream err = new ByteArrayOutputStream(); + ite.setErr(err); try { ite.incrementalBuildFromFolder(); @@ -66,7 +73,7 @@ public class DependenciesTest013 { } catch (FrontendCompilationException e) { // Ok } finally { - Assert.assertTrue(ite.getStringRepresentingErr().contains("B cannot be resolved to a type")); + Assert.assertTrue(err.toString().contains("B cannot be resolved to a type")); } } @@ -75,8 +82,8 @@ public class DependenciesTest013 { */ @Test public void testDependency002() throws Exception { - IncrementalTestingEnvironment ite = - new IncrementalTestingEnvironment(TestTools.createTempDir("DependenciesTest_", "_001")); + IncrementalTestHelper ite = + new IncrementalTestHelper(TestTools.createTempDir("DependenciesTest_", "_001")); ite.addJavaFile("jack.incremental", "A.java", "package jack.incremental; \n" + "public class A { \n" @@ -90,7 +97,7 @@ public class DependenciesTest013 { + "public static C []array; \n" + "}"); - ite.addJavaFile("jack.incremental", "C.java", "package jack.incremental; \n" + File f = ite.addJavaFile("jack.incremental", "C.java", "package jack.incremental; \n" + "public class C { \n" + "}"); @@ -98,7 +105,10 @@ public class DependenciesTest013 { ite.snapshotJackFilesModificationDate(); Assert.assertEquals(3, ite.getJackFiles().size()); - ite.deleteJavaFile("jack.incremental", "C.java"); + ite.deleteJavaFile(f); + + ByteArrayOutputStream err = new ByteArrayOutputStream(); + ite.setErr(err); try { ite.incrementalBuildFromFolder(); @@ -106,7 +116,7 @@ public class DependenciesTest013 { } catch (FrontendCompilationException e) { // Ok } finally { - Assert.assertTrue(ite.getStringRepresentingErr().contains("C cannot be resolved to a type")); + Assert.assertTrue(err.toString().contains("C cannot be resolved to a type")); } } @@ -115,8 +125,8 @@ public class DependenciesTest013 { */ @Test public void testDependency003() throws Exception { - IncrementalTestingEnvironment ite = - new IncrementalTestingEnvironment(TestTools.createTempDir("DependenciesTest_", "_001")); + IncrementalTestHelper ite = + new IncrementalTestHelper(TestTools.createTempDir("DependenciesTest_", "_001")); ite.addJavaFile("jack.incremental", "A.java", "package jack.incremental; \n" + "public class A { \n" @@ -130,7 +140,7 @@ public class DependenciesTest013 { + "public static C [][]array; \n" + "}"); - ite.addJavaFile("jack.incremental", "C.java", "package jack.incremental; \n" + File f = ite.addJavaFile("jack.incremental", "C.java", "package jack.incremental; \n" + "public class C { \n" + "}"); @@ -138,7 +148,10 @@ public class DependenciesTest013 { ite.snapshotJackFilesModificationDate(); Assert.assertEquals(3, ite.getJackFiles().size()); - ite.deleteJavaFile("jack.incremental", "C.java"); + ite.deleteJavaFile(f); + + ByteArrayOutputStream err = new ByteArrayOutputStream(); + ite.setErr(err); try { ite.incrementalBuildFromFolder(); @@ -146,7 +159,7 @@ public class DependenciesTest013 { } catch (FrontendCompilationException e) { // Ok } finally { - Assert.assertTrue(ite.getStringRepresentingErr().contains("C cannot be resolved to a type")); + Assert.assertTrue(err.toString().contains("C cannot be resolved to a type")); } } } diff --git a/jack/tests/com/android/jack/experimental/incremental/DependenciesTest014.java b/jack-tests/tests/com/android/jack/experimental/incremental/DependenciesTest014.java index c73e9ab6..8f768f08 100644 --- a/jack/tests/com/android/jack/experimental/incremental/DependenciesTest014.java +++ b/jack-tests/tests/com/android/jack/experimental/incremental/DependenciesTest014.java @@ -19,12 +19,14 @@ package com.android.jack.experimental.incremental; import com.android.jack.Main; import com.android.jack.TestTools; import com.android.jack.dx.io.DexBuffer; +import com.android.jack.test.helper.IncrementalTestHelper; import junit.framework.Assert; import org.junit.BeforeClass; import org.junit.Test; +import java.io.File; import java.io.FileInputStream; /** @@ -42,20 +44,20 @@ public class DependenciesTest014 { */ @Test public void testDependency001() throws Exception { - IncrementalTestingEnvironment ite = - new IncrementalTestingEnvironment(TestTools.createTempDir("DependenciesTest_", "_001")); + IncrementalTestHelper ite = + new IncrementalTestHelper(TestTools.createTempDir("DependenciesTest_", "_001")); ite.addJavaFile("jack.incremental", "A.java", "package jack.incremental; \n" + "public class A { \n" + "}"); - ite.addJavaFile("jack.incremental", "B.java", "package jack.incremental; \n" + File f = ite.addJavaFile("jack.incremental", "B.java", "package jack.incremental; \n" + "public class B { \n" + "}"); ite.incrementalBuildFromFolder(); ite.snapshotJackFilesModificationDate(); Assert.assertEquals(2, ite.getJackFiles().size()); - ite.deleteJavaFile("jack.incremental", "B.java"); + ite.deleteJavaFile(f); ite.incrementalBuildFromFolder(); DexBuffer db = new DexBuffer(new FileInputStream(ite.getDexFile())); for (String typeName : db.typeNames()) { @@ -70,24 +72,24 @@ public class DependenciesTest014 { */ @Test public void testDependency002() throws Exception { - IncrementalTestingEnvironment ite = - new IncrementalTestingEnvironment(TestTools.createTempDir("DependenciesTest_", "_001")); + IncrementalTestHelper ite = + new IncrementalTestHelper(TestTools.createTempDir("DependenciesTest_", "_001")); ite.addJavaFile("jack.incremental", "A.java", "package jack.incremental; \n" + "public class A { \n" + "}"); - ite.addJavaFile("jack.incremental", "B.java", "package jack.incremental; \n" + File fB = ite.addJavaFile("jack.incremental", "B.java", "package jack.incremental; \n" + "public class B extends C { \n" + "}"); - ite.addJavaFile("jack.incremental", "C.java", "package jack.incremental; \n" + File fC = ite.addJavaFile("jack.incremental", "C.java", "package jack.incremental; \n" + "public class C { \n" + "}"); ite.incrementalBuildFromFolder(); ite.snapshotJackFilesModificationDate(); Assert.assertEquals(3, ite.getJackFiles().size()); - ite.deleteJavaFile("jack.incremental", "B.java"); - ite.deleteJavaFile("jack.incremental", "C.java"); + ite.deleteJavaFile(fB); + ite.deleteJavaFile(fC); ite.incrementalBuildFromFolder(); DexBuffer db = new DexBuffer(new FileInputStream(ite.getDexFile())); for (String typeName : db.typeNames()) { diff --git a/jack/tests/com/android/jack/experimental/incremental/DependenciesTest015.java b/jack-tests/tests/com/android/jack/experimental/incremental/DependenciesTest015.java index acd3cb3d..d6f0ae20 100644 --- a/jack/tests/com/android/jack/experimental/incremental/DependenciesTest015.java +++ b/jack-tests/tests/com/android/jack/experimental/incremental/DependenciesTest015.java @@ -20,12 +20,14 @@ import com.android.jack.Main; import com.android.jack.TestTools; import com.android.jack.dx.io.DexBuffer; import com.android.jack.frontend.FrontendCompilationException; +import com.android.jack.test.helper.IncrementalTestHelper; import junit.framework.Assert; import org.junit.BeforeClass; import org.junit.Test; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.util.Arrays; @@ -46,10 +48,10 @@ public class DependenciesTest015 { */ @Test public void testDependency001() throws Exception { - IncrementalTestingEnvironment iteLib = - new IncrementalTestingEnvironment(TestTools.createTempDir("DependenciesTest_", "_001_lib")); + IncrementalTestHelper iteLib = + new IncrementalTestHelper(TestTools.createTempDir("DependenciesTest_", "_001_lib")); - iteLib.addJavaFile("jack.incremental", "A.java", "package jack.incremental; \n" + File f = iteLib.addJavaFile("jack.incremental", "A.java", "package jack.incremental; \n" + "public abstract class A { \n" + "public abstract void m(); }"); iteLib.incrementalBuildFromFolder(); @@ -58,8 +60,8 @@ public class DependenciesTest015 { Assert.assertEquals(1, jackFilesLib.size()); - IncrementalTestingEnvironment iteProg = - new IncrementalTestingEnvironment(TestTools.createTempDir("DependenciesTest_", "_001_prog")); + IncrementalTestHelper iteProg = + new IncrementalTestHelper(TestTools.createTempDir("DependenciesTest_", "_001_prog")); iteProg.addJavaFile("jack.incremental", "B.java", "package jack.incremental; \n" + "public class B extends A { \n" + " @Override public void m(){} }"); @@ -68,7 +70,7 @@ public class DependenciesTest015 { iteProg.snapshotJackFilesModificationDate(); Assert.assertEquals(1, iteProg.getJackFiles().size()); - iteLib.deleteJavaFile("jack.incremental", "A.java"); + iteLib.deleteJavaFile(f); iteLib.addJavaFile("jack.incremental", "A.java", "package jack.incremental; \n" + "public abstract class A { \n" + "public abstract int m(); }"); iteLib.incrementalBuildFromFolder(); @@ -76,11 +78,13 @@ public class DependenciesTest015 { jackFilesLib = iteLib.getJackFiles(); Assert.assertEquals(1, jackFilesLib.size()); + ByteArrayOutputStream err = new ByteArrayOutputStream(); + iteProg.setErr(err); try { iteProg.incrementalBuildFromFolder(new File[] {iteLib.getJackFolder()}); Assert.fail(); } catch (FrontendCompilationException e) { - Assert.assertTrue(iteProg.getStringRepresentingErr().contains( + Assert.assertTrue(err.toString().contains( "The return type is incompatible with A.m()")); } } @@ -90,8 +94,8 @@ public class DependenciesTest015 { */ @Test public void testDependency002() throws Exception { - IncrementalTestingEnvironment iteLib = - new IncrementalTestingEnvironment(TestTools.createTempDir("DependenciesTest_", "_001_lib")); + IncrementalTestHelper iteLib = + new IncrementalTestHelper(TestTools.createTempDir("DependenciesTest_", "_001_lib")); iteLib.addJavaFile("jack.incremental", "A.java", "package jack.incremental; \n" + "public class A { \n" + "public void m() {} }"); @@ -102,8 +106,8 @@ public class DependenciesTest015 { Assert.assertEquals(1, jackFilesLib.size()); - IncrementalTestingEnvironment iteProg = - new IncrementalTestingEnvironment(TestTools.createTempDir("DependenciesTest_", "_001_prog")); + IncrementalTestHelper iteProg = + new IncrementalTestHelper(TestTools.createTempDir("DependenciesTest_", "_001_prog")); iteProg.addJavaFile("jack.incremental", "B.java", "package jack.incremental; \n" + "public class B { \n" + " public void m(){} }"); diff --git a/jack/tests/com/android/jack/experimental/incremental/DependencyAllTests.java b/jack-tests/tests/com/android/jack/experimental/incremental/DependencyAllTests.java index e8b42a86..e8b42a86 100644 --- a/jack/tests/com/android/jack/experimental/incremental/DependencyAllTests.java +++ b/jack-tests/tests/com/android/jack/experimental/incremental/DependencyAllTests.java diff --git a/jack-tests/tests/com/android/jack/external/ExternalTests.java b/jack-tests/tests/com/android/jack/external/ExternalTests.java new file mode 100644 index 00000000..99838282 --- /dev/null +++ b/jack-tests/tests/com/android/jack/external/ExternalTests.java @@ -0,0 +1,49 @@ +/* +* 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.external; + +import com.android.jack.test.category.RuntimeRegressionTest; +import com.android.jack.test.helper.RuntimeTestHelper; +import com.android.jack.test.runtime.RuntimeTest; +import com.android.jack.test.runtime.RuntimeTestInfo; +import com.android.jack.test.toolchain.AbstractTestTools; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +public class ExternalTests extends RuntimeTest { + + private RuntimeTestInfo TEST001 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.external.test001"), + "com.android.jack.external.test001.dx.Tests"); + + @BeforeClass + public static void setUpClass() { + ExternalTests.class.getClassLoader().setDefaultAssertionStatus(true); + } + @Test + @Category(RuntimeRegressionTest.class) + public void test001() throws Exception { + new RuntimeTestHelper(TEST001).compileAndRunTest(); + } + + @Override + protected void fillRtTestInfos() { + rtTestInfos.add(TEST001); + } +} diff --git a/jack-tests/tests/com/android/jack/fibonacci/FibonacciTests.java b/jack-tests/tests/com/android/jack/fibonacci/FibonacciTests.java new file mode 100644 index 00000000..cfbe2f96 --- /dev/null +++ b/jack-tests/tests/com/android/jack/fibonacci/FibonacciTests.java @@ -0,0 +1,68 @@ +/* +* 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.fibonacci; + +import com.android.jack.TestTools; +import com.android.jack.test.category.RuntimeRegressionTest; +import com.android.jack.test.comparator.ComparatorDex; +import com.android.jack.test.helper.CheckDexStructureTestHelper; +import com.android.jack.test.helper.RuntimeTestHelper; +import com.android.jack.test.helper.SourceToDexComparisonTestHelper; +import com.android.jack.test.runtime.RuntimeTest; +import com.android.jack.test.runtime.RuntimeTestInfo; +import com.android.jack.test.toolchain.AbstractTestTools; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import java.io.File; + +public class FibonacciTests extends RuntimeTest { + + private RuntimeTestInfo TEST001 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.fibonacci.test001"), + "com.android.jack.fibonacci.test001.dx.Tests"); + + @BeforeClass + public static void setUpClass() { + FibonacciTests.class.getClassLoader().setDefaultAssertionStatus(true); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test001() throws Exception { + new RuntimeTestHelper(TEST001).compileAndRunTest(); + } + + /** + * Compiles FibonacciThreeAddress into a {@code DexFile} and compares it to a dex file created + * using a reference compiler and {@code dx}. + * @throws Exception + */ + @Test + public void testCompareFiboDexFile() throws Exception { + SourceToDexComparisonTestHelper helper = + new CheckDexStructureTestHelper(new File(TEST001.directory, "jack")); + helper.runTest(new ComparatorDex(helper.getCandidateDex(), helper.getReferenceDex())); + } + + @Override + protected void fillRtTestInfos() { + rtTestInfos.add(TEST001); + } +} diff --git a/jack-tests/tests/com/android/jack/fibonacci/dx/Tests.java b/jack-tests/tests/com/android/jack/fibonacci/test001/dx/Tests.java index 4bdf6f7b..a88c9cee 100644 --- a/jack-tests/tests/com/android/jack/fibonacci/dx/Tests.java +++ b/jack-tests/tests/com/android/jack/fibonacci/test001/dx/Tests.java @@ -14,9 +14,9 @@ * limitations under the License. */ -package com.android.jack.fibonacci.dx; +package com.android.jack.fibonacci.test001.dx; -import com.android.jack.fibonacci.jack.FibonacciThreeAddress; +import com.android.jack.fibonacci.test001.jack.FibonacciThreeAddress; import junit.framework.Assert; diff --git a/jack-tests/tests/com/android/jack/fibonacci/jack/Fibo.java b/jack-tests/tests/com/android/jack/fibonacci/test001/jack/Fibo.java index fdaf4be3..cb99b627 100644 --- a/jack-tests/tests/com/android/jack/fibonacci/jack/Fibo.java +++ b/jack-tests/tests/com/android/jack/fibonacci/test001/jack/Fibo.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.jack.fibonacci.jack; +package com.android.jack.fibonacci.test001.jack; /** * Fibonacci test. diff --git a/jack-tests/tests/com/android/jack/fibonacci/jack/FibonacciThreeAddress.java b/jack-tests/tests/com/android/jack/fibonacci/test001/jack/FibonacciThreeAddress.java index 099cbf12..9cf4927b 100644 --- a/jack-tests/tests/com/android/jack/fibonacci/jack/FibonacciThreeAddress.java +++ b/jack-tests/tests/com/android/jack/fibonacci/test001/jack/FibonacciThreeAddress.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.jack.fibonacci.jack; +package com.android.jack.fibonacci.test001.jack; /** * Fibonacci test in three-address style. diff --git a/jack-tests/tests/com/android/jack/field/FieldTests.java b/jack-tests/tests/com/android/jack/field/FieldTests.java new file mode 100644 index 00000000..87f20450 --- /dev/null +++ b/jack-tests/tests/com/android/jack/field/FieldTests.java @@ -0,0 +1,176 @@ +/* +* 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.field; + +import com.android.jack.TestTools; +import com.android.jack.test.category.RuntimeRegressionTest; +import com.android.jack.test.comparator.ComparatorDex; +import com.android.jack.test.helper.CheckDexStructureTestHelper; +import com.android.jack.test.helper.RuntimeTestHelper; +import com.android.jack.test.helper.SourceToDexComparisonTestHelper; +import com.android.jack.test.runtime.RuntimeTest; +import com.android.jack.test.runtime.RuntimeTestInfo; +import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.IToolchain; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import javax.annotation.Nonnull; + +public class FieldTests extends RuntimeTest { + + private RuntimeTestInfo INSTANCE001 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.field.instance001"), + "com.android.jack.field.instance001.dx.Tests"); + + private RuntimeTestInfo INSTANCE002 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.field.instance002"), + "com.android.jack.field.instance002.dx.Tests"); + + private RuntimeTestInfo INSTANCE003 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.field.instance003"), + "com.android.jack.field.instance003.dx.Tests"); + + private RuntimeTestInfo INSTANCE004 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.field.instance004"), + "com.android.jack.field.instance004.dx.Tests"); + + private RuntimeTestInfo STATIC001 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.field.static001"), + "com.android.jack.field.static001.dx.Tests"); + + private RuntimeTestInfo STATIC002 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.field.static002"), + "com.android.jack.field.static002.dx.Tests"); + + private RuntimeTestInfo STATIC004 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.field.static004"), + "com.android.jack.field.static004.dx.Tests"); + + private RuntimeTestInfo STATIC005 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.field.static005"), + "com.android.jack.field.static005.dx.Tests"); + + @BeforeClass + public static void setUpClass() { + FieldTests.class.getClassLoader().setDefaultAssertionStatus(true); + } + @Test + @Category(RuntimeRegressionTest.class) + public void instance001() throws Exception { + new RuntimeTestHelper(INSTANCE001).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void instance002() throws Exception { + new RuntimeTestHelper(INSTANCE002).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void instance003() throws Exception { + new RuntimeTestHelper(INSTANCE003).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void instance004() throws Exception { + new RuntimeTestHelper(INSTANCE004).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void static001() throws Exception { + new RuntimeTestHelper(STATIC001).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void static002() throws Exception { + new RuntimeTestHelper(STATIC002).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void static004() throws Exception { + new RuntimeTestHelper(STATIC004).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void static005() throws Exception { + new RuntimeTestHelper(STATIC005).compileAndRunTest(); + } + + @Test + public void testCompileInstance6() throws Exception { + compileTest("instance005"); + } + + @Test + public void testCompileStatic() throws Exception { + compileTest("static003"); + } + + /** + * Compiles StaticField.java into a {@code DexFile} and compares it to a dex file created + * using a reference compiler and {@code dx}. + */ + @Test + public void testStatic() throws Exception { + checkStructure("static003"); + } + + /** + * Compiles InstanceField.java into a {@code DexFile} and compares it to a dex file created + * using a reference compiler and {@code dx}. + */ + @Test + public void testInstance() throws Exception { + checkStructure("instance005"); + } + + private void compileTest(@Nonnull String test) throws Exception { + IToolchain toolchain = AbstractTestTools.getCandidateToolchain(); + toolchain.srcToExe( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + AbstractTestTools.createTempDir(), + /* zipFile = */ false, + AbstractTestTools.getTestRootDir("com.android.jack.field." + test + ".jack")); + } + + private void checkStructure(@Nonnull String test) throws Exception { + SourceToDexComparisonTestHelper helper = new CheckDexStructureTestHelper( + AbstractTestTools.getTestRootDir("com.android.jack.field." + test + ".jack")); + helper.runTest(new ComparatorDex(helper.getCandidateDex(), helper.getReferenceDex())); + } + + @Override + protected void fillRtTestInfos() { + rtTestInfos.add(INSTANCE001); + rtTestInfos.add(INSTANCE002); + rtTestInfos.add(INSTANCE003); + rtTestInfos.add(INSTANCE004); + rtTestInfos.add(STATIC001); + rtTestInfos.add(STATIC002); + rtTestInfos.add(STATIC004); + rtTestInfos.add(STATIC005); + } +} diff --git a/jack/tests/com/android/jack/FileConflictTest.java b/jack-tests/tests/com/android/jack/fileconflict/FileConflictTests.java index 91f99fa9..ccce9392 100644 --- a/jack/tests/com/android/jack/FileConflictTest.java +++ b/jack-tests/tests/com/android/jack/fileconflict/FileConflictTests.java @@ -14,14 +14,23 @@ * limitations under the License. */ -package com.android.jack; +package com.android.jack.fileconflict; +import com.android.jack.Jack; +import com.android.jack.Options; +import com.android.jack.ProguardFlags; +import com.android.jack.TestTools; import com.android.jack.backend.jayce.ImportConflictException; import com.android.jack.backend.jayce.JayceFileImporter; import com.android.jack.backend.jayce.ResourceImportConflictException; -import com.android.jack.category.KnownBugs; +import com.android.jack.test.category.KnownBugs; import com.android.jack.library.FileType; import com.android.jack.library.JackLibrary; +import com.android.jack.shrob.obfuscation.NameProviderFactory; +import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.IToolchain; +import com.android.jack.test.toolchain.JackApiToolchain; +import com.android.jack.test.toolchain.JackBasedToolchain; import com.android.sched.util.stream.ByteStreamSucker; import junit.framework.Assert; @@ -50,7 +59,7 @@ import javax.annotation.Nonnull; /** * JUnit tests for resource support. */ -public class FileConflictTest { +public class FileConflictTests { @Nonnull private static final String COMMON_PATH_001 = "com/android/jack/fileconflict/test001/jack/"; @@ -98,15 +107,15 @@ public class FileConflictTest { @Nonnull private static final File TEST001_DIR = - TestTools.getJackTestsWithJackFolder("fileconflict/test001"); + AbstractTestTools.getTestRootDir("com.android.jack.fileconflict.test001.jack"); @Nonnull private static final File TEST002_DIR = - TestTools.getJackTestsWithJackFolder("fileconflict/test002"); + AbstractTestTools.getTestRootDir("com.android.jack.fileconflict.test002.jack"); @BeforeClass public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); + FileConflictTests.class.getClassLoader().setDefaultAssertionStatus(true); } /** @@ -116,7 +125,7 @@ public class FileConflictTest { */ @Test public void test001a() throws Exception { - File jackOutput = TestTools.createTempDir("jackoutput", "dir"); + File jackOutput = AbstractTestTools.createTempDir(); try { runTest001(jackOutput, null); Assert.fail(); @@ -131,7 +140,7 @@ public class FileConflictTest { */ @Test public void test001b() throws Exception { - File jackOutput = TestTools.createTempDir("jackoutput", "dir"); + File jackOutput = AbstractTestTools.createTempDir(); try { runTest001(jackOutput, "fail"); Assert.fail(); @@ -146,7 +155,7 @@ public class FileConflictTest { */ @Test public void test001c() throws Exception { - File jackOutput = TestTools.createTempDir("jackoutput", "dir"); + File jackOutput = AbstractTestTools.createTempDir(); runTest001(jackOutput, "keep-first"); File myClass1 = new File(jackOutput, JACK_FILE_PATH_1); File myClass2 = new File(jackOutput, JACK_FILE_PATH_2); @@ -163,7 +172,7 @@ public class FileConflictTest { */ @Test public void test002a() throws Exception { - File jackOutput = TestTools.createTempDir("jackoutput", "dir"); + File jackOutput = AbstractTestTools.createTempDir(); try { runTest002(jackOutput, false /* non-zipped */, null); Assert.fail(); @@ -178,7 +187,7 @@ public class FileConflictTest { */ @Test public void test002b() throws Exception { - File jackOutput = TestTools.createTempDir("jackoutput", "dir"); + File jackOutput = AbstractTestTools.createTempDir(); try { runTest002(jackOutput, false /* non-zipped */, "fail"); Assert.fail(); @@ -193,7 +202,7 @@ public class FileConflictTest { */ @Test public void test002c() throws Exception { - File jackOutput = TestTools.createTempDir("jackoutput", "dir"); + File jackOutput = AbstractTestTools.createTempDir(); runTest002(jackOutput, false /* non-zipped */, "keep-first"); checkResourceContent(jackOutput, RESOURCE1_LONGPATH, "Res1"); checkResourceContent(jackOutput, RESOURCE2_LONGPATH, "Res2"); @@ -207,7 +216,7 @@ public class FileConflictTest { */ @Test public void test002d() throws Exception { - File jackOutput = TestTools.createTempFile("jackoutput", ".zip"); + File jackOutput = AbstractTestTools.createTempFile("jackoutput", ".zip"); try { runTest002(jackOutput, true /* zipped */, null); Assert.fail(); @@ -222,7 +231,7 @@ public class FileConflictTest { */ @Test public void test002e() throws Exception { - File jackOutput = TestTools.createTempFile("jackoutput", ".zip"); + File jackOutput = AbstractTestTools.createTempFile("jackoutput", ".zip"); try { runTest002(jackOutput, true /* zipped */, "fail"); Assert.fail(); @@ -237,7 +246,7 @@ public class FileConflictTest { */ @Test public void test002f() throws Exception { - File jackOutput = TestTools.createTempFile("jackoutput", ".zip"); + File jackOutput = AbstractTestTools.createTempFile("jackoutput", ".zip"); runTest002(jackOutput, true /* zipped */, "keep-first"); ZipFile zipFile = new ZipFile(jackOutput); checkResourceContent(zipFile, RESOURCE1_LONGPATH, "Res1"); @@ -252,13 +261,17 @@ public class FileConflictTest { */ @Test public void test003a() throws Exception { - File jackOutput = TestTools.createTempDir("jackoutput", "dir"); - // compile source files to a Jack dir - File testSrcDir = TestTools.getJackTestsWithJackFolder("fileconflict/test003"); - File tempJackFolder = TestTools.createTempDir("jack", "dir"); - TestTools.compileSourceToJack(new Options(), testSrcDir, - TestTools.getDefaultBootclasspathString(), tempJackFolder, false /* non-zipped */); + File jackOutput = AbstractTestTools.createTempDir(); + File testSrcDir = AbstractTestTools.getTestRootDir("com.android.jack.fileconflict.test003"); + File tempJackFolder = AbstractTestTools.createTempDir(); + + IToolchain toolchain = AbstractTestTools.getCandidateToolchain(); + toolchain.srcToLib( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + tempJackFolder, + /* zipFiles = */ false, + testSrcDir); // get paths for Jack files String jackFilePath = @@ -274,7 +287,7 @@ public class FileConflictTest { File libProperties = new File(tempJackFolder, libPropName); // create Jack dirs to import - File jackImport1 = TestTools.createTempDir("jackimport1", "dir"); + File jackImport1 = AbstractTestTools.createTempDir(); copyFileToDir(libProperties, libPropName, jackImport1); copyFileToDir(myClass1, jackFilePath, jackImport1); copyFileToDir(myClass1Dex, dexFilePath, jackImport1); @@ -283,14 +296,9 @@ public class FileConflictTest { copyFileToDir(myClass1, jackFilePath, jackOutput); copyFileToDir(myClass1Dex, dexFilePath, jackOutput); - // run Jack on Jack dir - ProguardFlags flags = new ProguardFlags(new File(testSrcDir, "proguard.flags")); - TestTools.shrobJackToJack(new Options(), - jackImport1, - null, - jackOutput, - Collections.singletonList(flags), - false /* non-zipped */); + toolchain = AbstractTestTools.getCandidateToolchain(); + toolchain.addProguardFlags(new File(testSrcDir, "proguard.flags")); + toolchain.libToLib(jackImport1, jackOutput, false); } /** @@ -301,13 +309,17 @@ public class FileConflictTest { @Test @Ignore("Now jack generate library, a previous file can not exists") public void test003b() throws Exception { - File jackOutput = TestTools.createTempDir("jackoutput", "dir"); + File jackOutput = AbstractTestTools.createTempDir(); // compile source files to a Jack dir - File testSrcDir = TestTools.getJackTestsWithJackFolder("fileconflict/test003"); - File tempJackFolder = TestTools.createTempDir("jack", "dir"); - TestTools.compileSourceToJack(new Options(), testSrcDir, - TestTools.getDefaultBootclasspathString(), tempJackFolder, false /* non-zipped */); + File testSrcDir = AbstractTestTools.getTestRootDir("com.android.jack.fileconflict.test003.jack"); + File tempJackFolder = AbstractTestTools.createTempDir(); + IToolchain toolchain = AbstractTestTools.getCandidateToolchain(); + toolchain.srcToLib( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + tempJackFolder, + /* zipFiles = */ false, + testSrcDir); // get paths for Jack files String jackFilePath = @@ -318,7 +330,7 @@ public class FileConflictTest { File libProperties = new File(tempJackFolder, libPropName); // create Jack dirs to import - File jackImport1 = TestTools.createTempDir("jackimport1", "dir"); + File jackImport1 = AbstractTestTools.createTempDir(); String resourcePath = "com/android/jack/fileconflict/test003/jack/Resource"; File resource = new File(testSrcDir, "Resource"); copyFileToDir(libProperties, libPropName, jackImport1); @@ -330,15 +342,11 @@ public class FileConflictTest { copyFileToDir(resource2, resourcePath, jackOutput); // run Jack on Jack dir - ProguardFlags flags = new ProguardFlags(new File(testSrcDir, "proguard.flags")); - TestTools.shrobJackToJack(new Options(), - jackImport1, - null, - jackOutput, - Collections.singletonList(flags), - false /* non-zipped */); + toolchain = AbstractTestTools.getCandidateToolchain(); + toolchain.libToLib(jackImport1, jackOutput, /* zipFiles = */ false); checkResourceContent(jackOutput, resourcePath, "Res1"); + } /** @@ -349,13 +357,18 @@ public class FileConflictTest { @Test @Category(KnownBugs.class) public void test004() throws Exception { - File jackOutput = TestTools.createTempDir("jackoutput", "dir"); + File jackOutput = AbstractTestTools.createTempDir(); // compile source files to a Jack dir - File testSrcDir = TestTools.getJackTestsWithJackFolder("fileconflict/test004"); - File tempJackFolder = TestTools.createTempDir("jack", "dir"); - TestTools.compileSourceToJack(new Options(), testSrcDir, - TestTools.getDefaultBootclasspathString(), tempJackFolder, false /* non-zipped */); + File testSrcDir = AbstractTestTools.getTestRootDir("com.android.jack.fileconflict.test004.jack"); + File tempJackFolder = AbstractTestTools.createTempDir(); + + JackApiToolchain toolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); + toolchain.srcToLib( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + tempJackFolder, + /* zipFiles = */ false, + testSrcDir); // get paths for Jack files String jackFilePath = @@ -366,7 +379,7 @@ public class FileConflictTest { File libProperties = new File(tempJackFolder, libPropName); // create Jack dirs to import - File jackImport1 = TestTools.createTempDir("jackimport1", "dir"); + File jackImport1 = AbstractTestTools.createTempDir(); File resource = new File(testSrcDir, "MyClass.txt"); copyFileToDir(libProperties, libPropName, jackImport1); copyFileToDir(myClass1, jackFilePath, jackImport1); @@ -376,18 +389,13 @@ public class FileConflictTest { // copy a different resource to output dir with the same name File resource2 = new File(testSrcDir, "a.txt"); copyFileToDir(resource2, "pcz/nbqfcvq/wnpx/svyrpcbsyvph/hrgh004/wnpx/ZmPyngg.txt", jackOutput); - System.out.println(jackOutput.getAbsolutePath()); - Options options = new Options(); - options.setNameProvider("rot13"); // run Jack on Jack dir - ProguardFlags flags = new ProguardFlags(new File(testSrcDir, "proguard.flags")); - TestTools.shrobJackToJack(options, - jackImport1, - TestTools.getDefaultBootclasspathString(), - jackOutput, - Collections.singletonList(flags), - false /* non-zipped */); + toolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); + toolchain.addProguardFlags(new File(testSrcDir, "proguard.flags")); + toolchain.addProperty(NameProviderFactory.NAMEPROVIDER.getName(), "rot13"); + toolchain.libToLib(jackImport1, jackOutput, /* zipFiles = */ false); + checkResourceContent(jackOutput, "pcz/nbqfcvq/wnpx/svyrpcbsyvph/hrgh004/wnpx/ZmPyngg.txt", "MyClass"); } @@ -395,9 +403,14 @@ public class FileConflictTest { private void runTest001(@Nonnull File jackOutput, @CheckForNull String collisionPolicy) throws Exception { // compile source files to a Jack dir - File tempJackFolder = TestTools.createTempDir("jack", "dir"); - TestTools.compileSourceToJack(new Options(), TEST001_DIR, - TestTools.getDefaultBootclasspathString(), tempJackFolder, false /* non-zipped */); + File tempJackFolder = AbstractTestTools.createTempDir(); + JackApiToolchain toolchain = + AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); + toolchain.srcToLib( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + tempJackFolder, + /* zipFile = */ false, + TEST001_DIR); // get paths for Jack files File myClass1 = new File(tempJackFolder, JACK_FILE_PATH_1); @@ -413,8 +426,8 @@ public class FileConflictTest { File libProperties = new File(tempJackFolder, libPropName); // create Jack dirs to import - File jackImport1 = TestTools.createTempDir("jackimport1", "dir"); - File jackImport2 = TestTools.createTempDir("jackimport2", "dir"); + File jackImport1 = AbstractTestTools.createTempDir(); + File jackImport2 = AbstractTestTools.createTempDir(); copyFileToDir(libProperties, libPropName, jackImport1); copyFileToDir(myClass1, JACK_FILE_PATH_1, jackImport1); copyFileToDir(myClass1Dex, DEX_FILE_PATH_1, jackImport1); @@ -427,18 +440,13 @@ public class FileConflictTest { copyFileToDir(myClass3Dex, DEX_FILE_PATH_3, jackImport2); // run Jack on Jack dirs - ProguardFlags flags = new ProguardFlags(new File(TEST001_DIR, "proguard.flags")); - Options options = new Options(); - List<File> jayceImports = new ArrayList<File>(2); - jayceImports.add(jackImport1); - jayceImports.add(jackImport2); - options.setJayceImports(jayceImports); - options.setProguardFlagsFile(Collections.<File>singletonList(flags)); - options.setJayceOutputDir(jackOutput); + toolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); + toolchain.addProguardFlags(new File(TEST001_DIR, "proguard.flags")); + toolchain.addStaticLibs(jackImport1, jackImport2); if (collisionPolicy != null) { - options.addProperty(JayceFileImporter.COLLISION_POLICY.getName(), collisionPolicy); + toolchain.addProperty(JayceFileImporter.COLLISION_POLICY.getName(), collisionPolicy); } - Jack.run(options); + toolchain.libToLib(new File [] {jackImport1, jackImport2}, jackOutput, /* zipFiles = */ false); } private void runTest002(@Nonnull File jackOutput, boolean zip, @@ -477,6 +485,61 @@ public class FileConflictTest { Jack.run(options); } +// private void runTest002(@Nonnull File jackOutput, boolean zip, +// @CheckForNull String collisionPolicy) throws Exception { +// // compile source files to a Jack dir +// // TODO(jmhenaff): adapt this when resources are added to toolchain APIs +// File jackImport1 = TestTools.createTempDir("jack", "dir"); +// Options options = new Options(); +// File lib1 = new File(TEST002_DIR, "lib1"); +// options.addResource(new File(lib1, "rsc")); +// TestTools.compileSourceToJack(options, lib1, TestTools.getDefaultBootclasspathString(), +// jackImport1, false /* non-zipped */); +// +// File jackImport2 = TestTools.createTempDir("jack", "dir"); +// options = new Options(); +// File lib2 = new File(TEST002_DIR, "lib2"); +// options.addResource(new File(lib2, "rsc")); +// TestTools.compileSourceToJack(options, lib2, TestTools.getDefaultBootclasspathString(), +// jackImport2, false /* non-zipped */); +//// File tempJackFolder = AbstractTestTools.createTempDir(); +//// JackApiToolchain toolchain = +//// AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); +//// toolchain.srcToLib( +//// AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), +//// tempJackFolder, +//// /* zipFile = */ false, +//// TEST002_DIR); +//// +//// // get paths for Jack files +//// File myClass1 = new File(tempJackFolder, JACK_FILE_PATH_002_1); +//// File myClass2 = new File(tempJackFolder, JACK_FILE_PATH_002_2); +//// +//// // get paths for resources +//// File resource1 = new File(TEST002_DIR, RESOURCE1_SHORTPATH); +//// File resource2 = new File(TEST002_DIR, RESOURCE2_SHORTPATH); +//// File resource3 = new File(TEST002_DIR, RESOURCE3_SHORTPATH); +//// +//// // create Jack dirs to import +//// File jackImport1 = AbstractTestTools.createTempDir(); +//// File jackImport2 = AbstractTestTools.createTempDir(); +//// copyFileToDir(myClass1, JACK_FILE_PATH_002_1, jackImport1); +//// copyFileToDir(resource1, RESOURCE1_LONGPATH, jackImport1); +//// copyFileToDir(resource2, RESOURCE2_LONGPATH, jackImport1); +//// copyFileToDir(myClass2, JACK_FILE_PATH_002_2, jackImport2); +//// copyFileToDir(resource2, RESOURCE1_LONGPATH, jackImport2); +//// copyFileToDir(resource3, RESOURCE3_LONGPATH, jackImport2); +// +// // run Jack on Jack dirs +// toolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); +// toolchain.addProguardFlags(new File(TEST002_DIR, "proguard.flags")); +// if (collisionPolicy != null) { +// toolchain.addProperty(JayceFileImporter.RESOURCE_COLLISION_POLICY.getName(), collisionPolicy); +// } +// toolchain.libToLib(new File [] {jackImport1, jackImport2}, jackOutput, zip); +// +// } + private void copyFileToDir(@Nonnull File fileToCopy, @Nonnull String relativePath, @Nonnull File dir) throws IOException { FileOutputStream fos = null; diff --git a/jack-tests/tests/com/android/jack/flow/FlowTests.java b/jack-tests/tests/com/android/jack/flow/FlowTests.java new file mode 100644 index 00000000..527b3cb7 --- /dev/null +++ b/jack-tests/tests/com/android/jack/flow/FlowTests.java @@ -0,0 +1,60 @@ +/* +* 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.flow; + +import com.android.jack.test.category.RuntimeRegressionTest; +import com.android.jack.test.helper.RuntimeTestHelper; +import com.android.jack.test.runtime.RuntimeTest; +import com.android.jack.test.runtime.RuntimeTestInfo; +import com.android.jack.test.toolchain.AbstractTestTools; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +public class FlowTests extends RuntimeTest { + + private RuntimeTestInfo CFG001 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.flow.cfg001"), + "com.android.jack.flow.cfg001.dx.Tests"); + + private RuntimeTestInfo LOOP = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.flow.loop"), + "com.android.jack.flow.loop.dx.Tests"); + + @BeforeClass + public static void setUpClass() { + FlowTests.class.getClassLoader().setDefaultAssertionStatus(true); + } + @Test + @Category(RuntimeRegressionTest.class) + public void cfg001() throws Exception { + new RuntimeTestHelper(CFG001).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void loop() throws Exception { + new RuntimeTestHelper(LOOP).compileAndRunTest(); + } + + @Override + protected void fillRtTestInfos() { + rtTestInfos.add(CFG001); + rtTestInfos.add(LOOP); + } +} diff --git a/jack-tests/tests/com/android/jack/frontend/MissingClassTest.java b/jack-tests/tests/com/android/jack/frontend/MissingClassTest.java new file mode 100644 index 00000000..b4c3efd1 --- /dev/null +++ b/jack-tests/tests/com/android/jack/frontend/MissingClassTest.java @@ -0,0 +1,61 @@ +/* + * 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.frontend; + +import com.android.jack.test.category.KnownBugs; +import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.IToolchain; + +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import java.io.File; + +public class MissingClassTest { + + @Test + @Category(KnownBugs.class) + public void test001() throws Exception { + File outJackTmpMissing = AbstractTestTools.createTempDir(); + File outJackTmpSuper = AbstractTestTools.createTempDir(); + File outJackTmpTest = AbstractTestTools.createTempDir(); + + IToolchain toolchain = AbstractTestTools.getCandidateToolchain(); + + toolchain.srcToLib( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + outJackTmpMissing, + /* zipFiles= */ false, + AbstractTestTools.getTestRootDir("com.android.jack.frontend.test001.jack.missing")); + + toolchain.srcToLib( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()) + + File.pathSeparatorChar + outJackTmpMissing.getPath(), + outJackTmpSuper, + /* zipFiles= */ false, + AbstractTestTools.getTestRootDir("com.android.jack.frontend.test001.jack.sub2")); + + toolchain.srcToLib( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()) + + File.pathSeparatorChar + outJackTmpSuper.getPath(), + outJackTmpTest, + /* zipFiles= */ false, + AbstractTestTools.getTestRootDir("com.android.jack.frontend.test001.jack.test")); + + } + +} diff --git a/jack/tests/com/android/jack/GenericTest.java b/jack-tests/tests/com/android/jack/generic/basic/GenericTests.java index 53922f8e..d8896917 100644 --- a/jack/tests/com/android/jack/GenericTest.java +++ b/jack-tests/tests/com/android/jack/generic/basic/GenericTests.java @@ -14,7 +14,10 @@ * limitations under the License. */ -package com.android.jack; +package com.android.jack.generic.basic; + +import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.IToolchain; import org.junit.BeforeClass; import org.junit.Test; @@ -22,11 +25,11 @@ import org.junit.Test; /** * JUnit test for compilation of generics. */ -public class GenericTest { +public class GenericTests { @BeforeClass public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); + GenericTests.class.getClassLoader().setDefaultAssertionStatus(true); } /** @@ -34,7 +37,11 @@ public class GenericTest { */ @Test public void testCompileBasic() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("generic/basic"))); + IToolchain toolchain = AbstractTestTools.getCandidateToolchain(); + toolchain.srcToExe( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + AbstractTestTools.createTempDir(), + /* zipFile = */ false, + AbstractTestTools.getTestRootDir("com.android.jack.generic.basic.jack")); } } diff --git a/jack-tests/tests/com/android/jack/ifstatement/IfstatementTests.java b/jack-tests/tests/com/android/jack/ifstatement/IfstatementTests.java new file mode 100644 index 00000000..d831f17c --- /dev/null +++ b/jack-tests/tests/com/android/jack/ifstatement/IfstatementTests.java @@ -0,0 +1,82 @@ +/* +* 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.ifstatement; + +import com.android.jack.test.category.RuntimeRegressionTest; +import com.android.jack.test.helper.RuntimeTestHelper; +import com.android.jack.test.runtime.RuntimeTest; +import com.android.jack.test.runtime.RuntimeTestInfo; +import com.android.jack.test.toolchain.AbstractTestTools; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +public class IfstatementTests extends RuntimeTest { + + private RuntimeTestInfo ADVANCEDTEST = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.ifstatement.advancedTest"), + "com.android.jack.ifstatement.advancedTest.dx.Tests"); + + private RuntimeTestInfo CFGTEST = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.ifstatement.cfgTest"), + "com.android.jack.ifstatement.cfgTest.dx.Tests"); + + private RuntimeTestInfo FASTPATH = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.ifstatement.fastpath"), + "com.android.jack.ifstatement.fastpath.dx.Tests"); + + private RuntimeTestInfo SIMPLETEST = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.ifstatement.simpleTest"), + "com.android.jack.ifstatement.simpleTest.dx.Tests"); + + @BeforeClass + public static void setUpClass() { + IfstatementTests.class.getClassLoader().setDefaultAssertionStatus(true); + } + @Test + @Category(RuntimeRegressionTest.class) + public void advancedTest() throws Exception { + new RuntimeTestHelper(ADVANCEDTEST).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void cfgTest() throws Exception { + new RuntimeTestHelper(CFGTEST).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void fastpath() throws Exception { + new RuntimeTestHelper(FASTPATH).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void simpleTest() throws Exception { + new RuntimeTestHelper(SIMPLETEST).compileAndRunTest(); + } + + @Override + protected void fillRtTestInfos() { + rtTestInfos.add(ADVANCEDTEST); + rtTestInfos.add(CFGTEST); + rtTestInfos.add(FASTPATH); + rtTestInfos.add(SIMPLETEST); + } +} diff --git a/jack-tests/tests/com/android/jack/imports/ImportTests.java b/jack-tests/tests/com/android/jack/imports/ImportTests.java new file mode 100644 index 00000000..79e9269f --- /dev/null +++ b/jack-tests/tests/com/android/jack/imports/ImportTests.java @@ -0,0 +1,172 @@ +/* + * 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.imports; + +import com.android.jack.backend.jayce.ImportConflictException; +import com.android.jack.backend.jayce.JayceFileImporter; +import com.android.jack.backend.jayce.TypeImportConflictException; +import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.IToolchain; +import com.android.jack.test.toolchain.JackApiToolchain; +import com.android.jack.test.toolchain.JackBasedToolchain; + +import junit.framework.Assert; + +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.File; + +public class ImportTests { + + @BeforeClass + public static void setUpClass() { + ImportTests.class.getClassLoader().setDefaultAssertionStatus(true); + } + + @Test + public void testCompileNonConflictingSourceAndImport() throws Exception { + File jackOut = AbstractTestTools.createTempDir(); + IToolchain toolchain = AbstractTestTools.getCandidateToolchain(); + toolchain.srcToLib( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + jackOut, + /* zipFiles = */ false, + AbstractTestTools.getTestRootDir("com.android.jack.fibonacci.test001.jack")); + + toolchain = AbstractTestTools.getCandidateToolchain(); + toolchain.addStaticLibs(jackOut); + toolchain.srcToExe( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + AbstractTestTools.createTempDir(), + /* zipFile = */ false, + AbstractTestTools.getTestRootDir("com.android.jack.threeaddress.test001.jack")); + } + + @Test + public void testCompileConflictingSourceAndImport() throws Exception { + File jackOut = AbstractTestTools.createTempDir(); + JackApiToolchain toolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); + toolchain.srcToLib( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + jackOut, + /* zipFiles = */ false, + AbstractTestTools.getTestRootDir("com.android.jack.fibonacci.test001.jack")); + + toolchain = AbstractTestTools.getCandidateToolchain(); + toolchain.addStaticLibs(jackOut); + try { + toolchain.srcToExe( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + AbstractTestTools.createTempDir(), + /* zipFile = */ false, + AbstractTestTools.getTestRootDir("com.android.jack.fibonacci.test001.jack")); + Assert.fail(); + } catch (ImportConflictException e) { + // expected + } + } + + @Test + public void testConflictingImport() throws Exception { + String testName = "com.android.jack.inner.test015"; + File lib = AbstractTestTools.createTempDir(); + JackBasedToolchain toolchain = + AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class); + toolchain.srcToLib( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + lib, + /* zipFile = */ false, + AbstractTestTools.getTestRootDir(testName + ".lib")); + + + toolchain = AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class); + toolchain.addStaticLibs(lib); + toolchain.addProperty(JayceFileImporter.COLLISION_POLICY.getName(), "keep-first"); + toolchain.srcToExe( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + AbstractTestTools.createTempFile("inner15", ".zip"), + /* zipFile = */ true, + AbstractTestTools.getTestRootDir(testName + ".jack")); + } + + @Test + public void testConflictingImportWithFailPolicy1() throws Exception { + String testName = "com.android.jack.inner.test015"; + File lib = AbstractTestTools.createTempDir(); + JackApiToolchain toolchain = + AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); + toolchain.srcToLib( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + lib, + /* zipFile = */ false, + AbstractTestTools.getTestRootDir(testName + ".lib")); + + toolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); + // import twice the same lib + toolchain.addStaticLibs(lib, lib); + toolchain.addProperty(JayceFileImporter.COLLISION_POLICY.getName(), "fail"); + try { + toolchain.srcToExe( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + AbstractTestTools.createTempFile("inner15", ".zip"), + /* zipFile = */ true, + AbstractTestTools.getTestRootDir(testName + ".jack")); + Assert.fail(); + } catch (TypeImportConflictException e) { + // Exception is ok + } + } + + @Test + public void testConflictingImportWithFailPolicy2() throws Exception { + String testName = "com.android.jack.inner.test015"; + File lib1 = AbstractTestTools.createTempDir(); + JackApiToolchain toolchain = + AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); + toolchain.srcToLib( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + lib1, + /* zipFile = */ false, + AbstractTestTools.getTestRootDir(testName + ".lib")); + + File lib2 = AbstractTestTools.createTempDir(); + toolchain = + AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); + toolchain.srcToLib( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + lib2, + /* zipFile = */ false, + AbstractTestTools.getTestRootDir(testName + ".lib")); + + toolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); + // import twice the same lib + toolchain.addStaticLibs(lib1, lib2); + toolchain.addProperty(JayceFileImporter.COLLISION_POLICY.getName(), "fail"); + + try { + toolchain.srcToExe( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + AbstractTestTools.createTempFile("inner15", ".zip"), + /* zipFile = */ true, + AbstractTestTools.getTestRootDir(testName + ".jack")); + Assert.fail(); + } catch (TypeImportConflictException e) { + // Exception is ok + } + } +} diff --git a/jack-tests/tests/com/android/jack/init/InitTests.java b/jack-tests/tests/com/android/jack/init/InitTests.java new file mode 100644 index 00000000..c6215991 --- /dev/null +++ b/jack-tests/tests/com/android/jack/init/InitTests.java @@ -0,0 +1,61 @@ +/* +* 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.init; + +import com.android.jack.test.category.RuntimeRegressionTest; +import com.android.jack.test.helper.RuntimeTestHelper; +import com.android.jack.test.runtime.RuntimeTest; +import com.android.jack.test.runtime.RuntimeTestInfo; +import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.IToolchain; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +public class InitTests extends RuntimeTest { + + private RuntimeTestInfo TEST002 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.init.test002"), + "com.android.jack.init.test002.dx.Tests"); + + @BeforeClass + public static void setUpClass() { + InitTests.class.getClassLoader().setDefaultAssertionStatus(true); + } + + @Test + public void test001() throws Exception { + IToolchain toolchain = AbstractTestTools.getCandidateToolchain(); + toolchain.srcToExe( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + AbstractTestTools.createTempDir(), + /* zipFile = */ false, + AbstractTestTools.getTestRootDir("com.android.jack.init.test001.jack")); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test002() throws Exception { + new RuntimeTestHelper(TEST002).compileAndRunTest(); + } + + @Override + protected void fillRtTestInfos() { + rtTestInfos.add(TEST002); + } +} diff --git a/jack-tests/tests/com/android/jack/inner/InnerTests.java b/jack-tests/tests/com/android/jack/inner/InnerTests.java new file mode 100644 index 00000000..26b810a8 --- /dev/null +++ b/jack-tests/tests/com/android/jack/inner/InnerTests.java @@ -0,0 +1,349 @@ +/* +* 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.inner; + +import com.android.jack.TestTools; +import com.android.jack.test.category.RedundantTests; +import com.android.jack.test.category.RuntimeRegressionTest; +import com.android.jack.test.comparator.ComparatorDex; +import com.android.jack.test.helper.CheckDexStructureTestHelper; +import com.android.jack.test.helper.RuntimeTestHelper; +import com.android.jack.test.helper.SourceToDexComparisonTestHelper; +import com.android.jack.test.runtime.RuntimeTest; +import com.android.jack.test.runtime.RuntimeTestInfo; +import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.IToolchain; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import javax.annotation.Nonnull; + +public class InnerTests extends RuntimeTest { + + private RuntimeTestInfo TEST001 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.inner.test001"), + "com.android.jack.inner.test001.dx.Tests"); + + private RuntimeTestInfo TEST002 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.inner.test002"), + "com.android.jack.inner.test002.dx.Tests"); + + private RuntimeTestInfo TEST003 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.inner.test003"), + "com.android.jack.inner.test003.dx.Tests"); + + private RuntimeTestInfo TEST004 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.inner.test004"), + "com.android.jack.inner.test004.dx.Tests"); + + private RuntimeTestInfo TEST005 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.inner.test005"), + "com.android.jack.inner.test005.dx.Tests"); + + private RuntimeTestInfo TEST006 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.inner.test006"), + "com.android.jack.inner.test006.dx.Tests"); + + private RuntimeTestInfo TEST007 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.inner.test007"), + "com.android.jack.inner.test007.dx.Tests"); + + private RuntimeTestInfo TEST008 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.inner.test008"), + "com.android.jack.inner.test008.dx.Tests"); + + private RuntimeTestInfo TEST009 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.inner.test009"), + "com.android.jack.inner.test009.dx.Tests"); + + private RuntimeTestInfo TEST010 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.inner.test010"), + "com.android.jack.inner.test010.dx.Tests"); + + private RuntimeTestInfo TEST011 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.inner.test011"), + "com.android.jack.inner.test011.dx.Tests"); + + private RuntimeTestInfo TEST012 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.inner.test012"), + "com.android.jack.inner.test012.dx.Tests"); + + private RuntimeTestInfo TEST013 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.inner.test013"), + "com.android.jack.inner.test013.dx.Tests"); + + private RuntimeTestInfo TEST014 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.inner.test014"), + "com.android.jack.inner.test014.dx.Tests"); + + private RuntimeTestInfo TEST015 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.inner.test015"), + "com.android.jack.inner.test015.dx.Tests"); + + private RuntimeTestInfo TEST016 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.inner.test016"), + "com.android.jack.inner.test016.dx.Tests"); + + private RuntimeTestInfo TEST017 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.inner.test017"), + "com.android.jack.inner.test017.dx.Tests"); + + private RuntimeTestInfo TEST018 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.inner.test018"), + "com.android.jack.inner.test018.dx.Tests"); + + private RuntimeTestInfo TEST019 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.inner.test019"), + "com.android.jack.inner.test019.dx.Tests"); + + private RuntimeTestInfo TEST020 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.inner.test020"), + "com.android.jack.inner.test020.dx.Tests"); + + private RuntimeTestInfo TEST021 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.inner.test021"), + "com.android.jack.inner.test021.dx.Tests"); + + private RuntimeTestInfo TEST022 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.inner.test022"), + "com.android.jack.inner.test022.dx.Tests"); + + private RuntimeTestInfo TEST023 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.inner.test023"), + "com.android.jack.inner.test023.dx.Tests"); + + private RuntimeTestInfo TEST024 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.inner.test024"), + "com.android.jack.inner.test024.dx.Tests"); + + private RuntimeTestInfo TEST026 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.inner.test026"), + "com.android.jack.inner.test026.dx.Tests"); + + @BeforeClass + public static void setUpClass() { + InnerTests.class.getClassLoader().setDefaultAssertionStatus(true); + } + @Test + @Category(RuntimeRegressionTest.class) + public void test001() throws Exception { + new RuntimeTestHelper(TEST001).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test002() throws Exception { + new RuntimeTestHelper(TEST002).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test003() throws Exception { + new RuntimeTestHelper(TEST003).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test004() throws Exception { + new RuntimeTestHelper(TEST004).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test005() throws Exception { + new RuntimeTestHelper(TEST005).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test006() throws Exception { + new RuntimeTestHelper(TEST006).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test007() throws Exception { + new RuntimeTestHelper(TEST007).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test008() throws Exception { + new RuntimeTestHelper(TEST008).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test009() throws Exception { + new RuntimeTestHelper(TEST009).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test010() throws Exception { + new RuntimeTestHelper(TEST010).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test011() throws Exception { + new RuntimeTestHelper(TEST011).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test012() throws Exception { + new RuntimeTestHelper(TEST012).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test013() throws Exception { + new RuntimeTestHelper(TEST013).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test014() throws Exception { + new RuntimeTestHelper(TEST014).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test015() throws Exception { + new RuntimeTestHelper(TEST015).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test016() throws Exception { + new RuntimeTestHelper(TEST016).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test017() throws Exception { + new RuntimeTestHelper(TEST017).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test018() throws Exception { + new RuntimeTestHelper(TEST018).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test019() throws Exception { + new RuntimeTestHelper(TEST019).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test020() throws Exception { + new RuntimeTestHelper(TEST020).compileAndRunTest(true); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test021() throws Exception { + new RuntimeTestHelper(TEST021).compileAndRunTest(true); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test022() throws Exception { + new RuntimeTestHelper(TEST022).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test023() throws Exception { + new RuntimeTestHelper(TEST023).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test024() throws Exception { + new RuntimeTestHelper(TEST024).compileAndRunTest(); + } + + @Test + public void test025() throws Exception { + IToolchain toolchain = AbstractTestTools.getCandidateToolchain(); + toolchain.srcToExe( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + AbstractTestTools.createTempDir(), + /* zipFile = */ false, + AbstractTestTools.getTestRootDir("com.android.jack.inner.test025.jack")); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test026() throws Exception { + new RuntimeTestHelper(TEST026).compileAndRunTest(); + } + + @Test + public void testCheckStructure20() throws Exception { + //TODO: find out why debug info check fails + checkStructure("test020"); + } + + @Test + @Category(RedundantTests.class) + public void testCompile21() throws Exception { + checkStructure("test021"); + } + + private void checkStructure(@Nonnull String test) throws Exception { + SourceToDexComparisonTestHelper helper = new CheckDexStructureTestHelper( + AbstractTestTools.getTestRootDir("com.android.jack.inner." + test + ".jack")); + helper.runTest(new ComparatorDex(helper.getCandidateDex(), helper.getReferenceDex())); + } + + @Override + protected void fillRtTestInfos() { + rtTestInfos.add(TEST001); + rtTestInfos.add(TEST002); + rtTestInfos.add(TEST003); + rtTestInfos.add(TEST004); + rtTestInfos.add(TEST005); + rtTestInfos.add(TEST006); + rtTestInfos.add(TEST007); + rtTestInfos.add(TEST008); + rtTestInfos.add(TEST009); + rtTestInfos.add(TEST010); + rtTestInfos.add(TEST011); + rtTestInfos.add(TEST012); + rtTestInfos.add(TEST013); + rtTestInfos.add(TEST014); + rtTestInfos.add(TEST015); + rtTestInfos.add(TEST016); + rtTestInfos.add(TEST017); + rtTestInfos.add(TEST018); + rtTestInfos.add(TEST019); + rtTestInfos.add(TEST020); + rtTestInfos.add(TEST021); + rtTestInfos.add(TEST022); + rtTestInfos.add(TEST023); + rtTestInfos.add(TEST024); + rtTestInfos.add(TEST026); + } +} diff --git a/jack/tests/com/android/jack/frontend/InstanceTest.java b/jack-tests/tests/com/android/jack/instance/InstanceTest.java index 8538d148..e44111cf 100644 --- a/jack/tests/com/android/jack/frontend/InstanceTest.java +++ b/jack-tests/tests/com/android/jack/instance/InstanceTest.java @@ -14,25 +14,30 @@ * limitations under the License. */ -package com.android.jack.frontend; +package com.android.jack.instance; -import com.android.jack.Options; -import com.android.jack.TestTools; +import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.IToolchain; import org.junit.Before; import org.junit.Test; +import java.io.File; + public class InstanceTest { @Before public void setUp() throws Exception { - ConstantReuseTest.class.getClassLoader().setDefaultAssertionStatus(true); + InstanceTest.class.getClassLoader().setDefaultAssertionStatus(true); } @Test public void testReturnThis() throws Exception { - Options compilerArgs = TestTools.buildCommandLineArgs( - TestTools.getJackTestFromBinaryName("com/android/jack/instance/test001/jack/Instance")); - TestTools.runCompilation(compilerArgs); + IToolchain toolchain = AbstractTestTools.getCandidateToolchain(); + toolchain.srcToExe(AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + AbstractTestTools.createTempDir(), + /* zipFile = */ false, + new File( AbstractTestTools.getTestRootDir("com.android.jack.instance.test001.jack"), + "Instance.java")); } } diff --git a/jack-tests/tests/com/android/jack/invoke/InvokeTests.java b/jack-tests/tests/com/android/jack/invoke/InvokeTests.java new file mode 100644 index 00000000..1db4e57b --- /dev/null +++ b/jack-tests/tests/com/android/jack/invoke/InvokeTests.java @@ -0,0 +1,115 @@ +/* +* 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.invoke; + +import com.android.jack.test.category.RuntimeRegressionTest; +import com.android.jack.test.helper.RuntimeTestHelper; +import com.android.jack.test.runtime.RuntimeTest; +import com.android.jack.test.runtime.RuntimeTestInfo; +import com.android.jack.test.toolchain.AbstractTestTools; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +public class InvokeTests extends RuntimeTest { + + private RuntimeTestInfo TEST001 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.invoke.test001"), + "com.android.jack.invoke.test001.dx.Tests"); + + private RuntimeTestInfo TEST002 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.invoke.test002"), + "com.android.jack.invoke.test002.dx.Tests"); + + private RuntimeTestInfo TEST003 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.invoke.test003"), + "com.android.jack.invoke.test003.dx.Tests"); + + private RuntimeTestInfo TEST004 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.invoke.test004"), + "com.android.jack.invoke.test004.dx.Tests"); + + private RuntimeTestInfo TEST005 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.invoke.test005"), + "com.android.jack.invoke.test005.dx.Tests"); + + private RuntimeTestInfo TEST006 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.invoke.test006"), + "com.android.jack.invoke.test006.dx.Tests"); + + private RuntimeTestInfo TEST007 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.invoke.test007"), + "com.android.jack.invoke.test007.dx.Tests"); + + @BeforeClass + public static void setUpClass() { + InvokeTests.class.getClassLoader().setDefaultAssertionStatus(true); + } + @Test + @Category(RuntimeRegressionTest.class) + public void test001() throws Exception { + new RuntimeTestHelper(TEST001).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test002() throws Exception { + new RuntimeTestHelper(TEST002).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test003() throws Exception { + new RuntimeTestHelper(TEST003).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test004() throws Exception { + new RuntimeTestHelper(TEST004).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test005() throws Exception { + new RuntimeTestHelper(TEST005).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test006() throws Exception { + new RuntimeTestHelper(TEST006).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test007() throws Exception { + new RuntimeTestHelper(TEST007).compileAndRunTest(); + } + + @Override + protected void fillRtTestInfos() { + rtTestInfos.add(TEST001); + rtTestInfos.add(TEST002); + rtTestInfos.add(TEST003); + rtTestInfos.add(TEST004); + rtTestInfos.add(TEST005); + rtTestInfos.add(TEST006); + rtTestInfos.add(TEST007); + } +} diff --git a/jack-tests/tests/com/android/jack/jarjar/JarjarTests.java b/jack-tests/tests/com/android/jack/jarjar/JarjarTests.java index 6bac5cc2..dbfe543a 100644 --- a/jack-tests/tests/com/android/jack/jarjar/JarjarTests.java +++ b/jack-tests/tests/com/android/jack/jarjar/JarjarTests.java @@ -19,30 +19,71 @@ package com.android.jack.jarjar; import com.android.jack.test.helper.RuntimeTestHelper; import com.android.jack.test.runtime.RuntimeTestInfo; import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.IToolchain; +import com.tonicsystems.jarjar.PackageRemapper; +import com.tonicsystems.jarjar.PatternElement; +import com.tonicsystems.jarjar.Rule; +import com.tonicsystems.jarjar.Wildcard; + +import junit.framework.Assert; import org.junit.Before; import org.junit.Test; import java.io.File; +import java.util.Collections; import javax.annotation.Nonnull; public class JarjarTests { @Nonnull - private File baseDir; + private RuntimeTestInfo JARJAR001 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.jarjar.test001"), + "com.android.jack.jarjar.test001.dx.Tests"); + + @Nonnull + private RuntimeTestInfo JARJAR003 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.jarjar.test003"), + "com.android.jack.jarjar.test003.dx.Tests"); @Before public void setUp() { - baseDir = AbstractTestTools.getTestRootDir("com.android.jack.jarjar.test001"); + JarjarTests.class.getClassLoader().setDefaultAssertionStatus(true); + } + + @Test + public void jarjar001() throws Exception { + new RuntimeTestHelper(JARJAR001) + .setJarjarRulesFileName("jarjar-rules.txt") + .compileAndRunTest(); } @Test - public void compileAndRunTest() throws Exception { - RuntimeTestHelper rtEnv = new RuntimeTestHelper( - new RuntimeTestInfo(baseDir, "com.android.jack.jarjar.test001.dx.Tests")); - rtEnv.setJarjarRulesFileName("jarjar-rules.txt"); - rtEnv.compileAndRunTest(); + public void jarjar003() throws Exception { + new RuntimeTestHelper(JARJAR003) + .setJarjarRulesFileName("jarjar-rules.txt") + .compileAndRunTest(); + } + + @Test + public void jarjar003_1() throws Exception { + IToolchain toolchain = AbstractTestTools.getCandidateToolchain(); + toolchain.setJarjarRules(new File(JARJAR003.directory, "jarjar-rules.txt")); + File lib = AbstractTestTools.createTempFile("jarjarTest003Jack", ".zip"); + toolchain.srcToLib( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + lib, + /* zipFiles = */ true, + new File(JARJAR003.directory, "jack")); + + toolchain = AbstractTestTools.getCandidateToolchain(); + toolchain.srcToLib( + AbstractTestTools.getClasspathsAsString(toolchain.getDefaultBootClasspath(), + new File [] {lib}), + AbstractTestTools.createTempFile("jarjarTest003dx", ".zip"), + /* zipFiles = */ true, + new File(JARJAR003.directory, "dontcompile/TestWithRelocatedReference.java")); } } diff --git a/jack/tests/com/android/jack/java7/BoxingTest.java b/jack-tests/tests/com/android/jack/java7/BoxingTest.java index 160a17a1..8327f68e 100644 --- a/jack/tests/com/android/jack/java7/BoxingTest.java +++ b/jack-tests/tests/com/android/jack/java7/BoxingTest.java @@ -19,12 +19,18 @@ package com.android.jack.java7; import com.android.jack.Main; import com.android.jack.Options; import com.android.jack.TestTools; -import com.android.jack.category.KnownBugs; +import com.android.jack.test.category.KnownBugs; +import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.IToolchain; +import com.android.jack.test.toolchain.JackBasedToolchain; +import com.android.jack.test.toolchain.Toolchain.SourceLevel; import org.junit.BeforeClass; import org.junit.Test; import org.junit.experimental.categories.Category; +import java.io.File; + /** * JUnit test for compilation of Java 7 features */ @@ -38,9 +44,12 @@ public class BoxingTest { @Category(KnownBugs.class) @Test public void java7Boxing001() throws Exception { - Options options = TestTools.buildCommandLineArgs(TestTools - .getJackTestsWithJackFolder("java7/boxing/test001")); - options.addProperty(Options.JAVA_SOURCE_VERSION.getName(), "1.7"); - TestTools.runCompilation(options); + IToolchain toolchain = + AbstractTestTools.getCandidateToolchain(); + toolchain.setSourceLevel(SourceLevel.JAVA_7).srcToExe( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + AbstractTestTools.createTempDir(), + /* zipFile = */ false, + AbstractTestTools.getTestRootDir("com.android.jack.java7.boxing.test001.jack")); } } diff --git a/jack-tests/tests/com/android/jack/java7/ExceptionsTest.java b/jack-tests/tests/com/android/jack/java7/ExceptionsTest.java index ecbe578d..73d4ff8e 100644 --- a/jack-tests/tests/com/android/jack/java7/ExceptionsTest.java +++ b/jack-tests/tests/com/android/jack/java7/ExceptionsTest.java @@ -68,7 +68,7 @@ public class ExceptionsTest { AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class); jackBasedToolchain.setSourceLevel(SourceLevel.JAVA_7).srcToExe( AbstractTestTools.getClasspathAsString(jackBasedToolchain.getDefaultBootClasspath()), - AbstractTestTools.createTempDir(), new File( + AbstractTestTools.createTempDir(), /* zipFile = */ false, new File( AbstractTestTools.getTestRootDir("com.android.jack.java7.exceptions." + name), "jack")); } } diff --git a/jack/tests/com/android/jack/java7/AllTest.java b/jack-tests/tests/com/android/jack/java7/Java7AllTest.java index a865c94a..fe9cdb4c 100644 --- a/jack/tests/com/android/jack/java7/AllTest.java +++ b/jack-tests/tests/com/android/jack/java7/Java7AllTest.java @@ -25,6 +25,11 @@ import org.junit.runners.Suite.SuiteClasses; * JUnit test for compilation of Java 7 features */ @RunWith(Suite.class) -@SuiteClasses(value = {SwitchesTest.class, ExceptionsTest.class, BoxingTest.class}) -public class AllTest { +@SuiteClasses(value = { + SwitchesTest.class, + ExceptionsTest.class, + BoxingTest.class, + TryWithResourcesTests.class + }) +public class Java7AllTest { } diff --git a/jack-tests/tests/com/android/jack/java7/SwitchesTest.java b/jack-tests/tests/com/android/jack/java7/SwitchesTest.java new file mode 100644 index 00000000..3fb13d3e --- /dev/null +++ b/jack-tests/tests/com/android/jack/java7/SwitchesTest.java @@ -0,0 +1,85 @@ +/* + * 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.java7; + +import com.android.jack.Main; +import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.IToolchain; +import com.android.jack.test.toolchain.Toolchain.SourceLevel; + +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.File; + +import javax.annotation.Nonnull; + +/** + * JUnit test for compilation of Java 7 features + */ +public class SwitchesTest { + + @BeforeClass + public static void setUpClass() { + Main.class.getClassLoader().setDefaultAssertionStatus(true); + } + + @Test + public void java7Switches001() throws Exception { + compileJava7Test("test001"); + } + + @Test + public void java7Switches002() throws Exception { + compileJava7Test("test002"); + } + + @Test + public void java7Switches003() throws Exception { + compileJava7Test("test003"); + } + + @Test + public void java7Switches004() throws Exception { + + File jackZipFile = AbstractTestTools.createTempFile("tmp", ".zip"); + + IToolchain toolchain = + AbstractTestTools.getCandidateToolchain(); + toolchain.setSourceLevel(SourceLevel.JAVA_7).srcToLib( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + jackZipFile, + /* zipFiles = */ true, + AbstractTestTools.getTestRootDir("com.android.jack.java7.switches.test001.jack")); + + toolchain = AbstractTestTools.getCandidateToolchain(); + toolchain.setSourceLevel(SourceLevel.JAVA_7).libToExe( + jackZipFile, + AbstractTestTools.createTempDir(), + /* zipFile = */ false); + } + + private void compileJava7Test(@Nonnull String name) throws Exception { + IToolchain toolchain = + AbstractTestTools.getCandidateToolchain(); + toolchain.setSourceLevel(SourceLevel.JAVA_7).srcToExe( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + AbstractTestTools.createTempDir(), /* zipFile = */ false, + AbstractTestTools.getTestRootDir("com.android.jack.java7.switches." + name + ".jack")); + } + +} diff --git a/jack-tests/tests/com/android/jack/java7/TryWithResourcesTests.java b/jack-tests/tests/com/android/jack/java7/TryWithResourcesTests.java new file mode 100644 index 00000000..0584b6d1 --- /dev/null +++ b/jack-tests/tests/com/android/jack/java7/TryWithResourcesTests.java @@ -0,0 +1,65 @@ +/* + * 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.java7; + +import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.IToolchain; +import com.android.jack.test.toolchain.Toolchain.SourceLevel; + +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * JUnit test for compilation of try-with-resources. + */ +public class TryWithResourcesTests { + + @BeforeClass + public static void setUpClass() { + TryWithResourcesTests.class.getClassLoader().setDefaultAssertionStatus(true); + } + + /** + * Verifies that the test source can compiled from source to dex file. + */ + @Test + public void testCompile() throws Exception { + IToolchain toolchain = + AbstractTestTools.getCandidateToolchain(); + toolchain.setSourceLevel(SourceLevel.JAVA_7) + .srcToExe( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + AbstractTestTools.createTempDir(), + /* zipFile = */ false, + AbstractTestTools.getTestRootDir("com.android.jack.java7.trywithresources.test001.jack")); + } + + /** + * Verifies that the test source can compiled from source to dex file. + */ + @Test + public void testCompile2() throws Exception { + IToolchain toolchain = + AbstractTestTools.getCandidateToolchain(); + toolchain.setSourceLevel(SourceLevel.JAVA_7) + .srcToExe( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + AbstractTestTools.createTempDir(), + /* zipFile = */ false, + AbstractTestTools.getTestRootDir("com.android.jack.java7.trywithresources.test002.jack")); + } +} diff --git a/jack/tests/com/android/jack/frontend/LabelTest.java b/jack-tests/tests/com/android/jack/label/LabelTest.java index 67b7a59f..945a215e 100644 --- a/jack/tests/com/android/jack/frontend/LabelTest.java +++ b/jack-tests/tests/com/android/jack/label/LabelTest.java @@ -14,25 +14,30 @@ * limitations under the License. */ -package com.android.jack.frontend; +package com.android.jack.label; -import com.android.jack.Options; -import com.android.jack.TestTools; +import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.IToolchain; import org.junit.Before; import org.junit.Test; +import java.io.File; + public class LabelTest { @Before public void setUp() throws Exception { - ConstantReuseTest.class.getClassLoader().setDefaultAssertionStatus(true); + LabelTest.class.getClassLoader().setDefaultAssertionStatus(true); } @Test public void labelMustNotBreakTree() throws Exception { - Options compilerArgs = TestTools.buildCommandLineArgs( - TestTools.getJackTestFromBinaryName("com/android/jack/label/test001/jack/Label")); - TestTools.runCompilation(compilerArgs); + IToolchain toolchain = AbstractTestTools.getCandidateToolchain(); + toolchain.srcToExe( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + AbstractTestTools.createTempDir(), + /* zipFile = */ false, + new File(AbstractTestTools.getTestRootDir("com.android.jack.label.test001.jack"), "Label.java")); } } diff --git a/jack-tests/tests/com/android/jack/lookup/LookupTests.java b/jack-tests/tests/com/android/jack/lookup/LookupTests.java new file mode 100644 index 00000000..a51615e9 --- /dev/null +++ b/jack-tests/tests/com/android/jack/lookup/LookupTests.java @@ -0,0 +1,62 @@ +/* + * 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.lookup; + +import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.IToolchain; + +import org.junit.Test; + +import java.io.File; + +public class LookupTests { + + @Test + public void test001() throws Exception { + IToolchain toolchain = AbstractTestTools.getCandidateToolchain(); + File lib = AbstractTestTools.createTempDir(); + toolchain.srcToLib( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + lib, + /* zipFiles = */ false, + AbstractTestTools.getTestRootDir("com.android.jack.lookup.test001.lib")); + + File libOverride = AbstractTestTools.createTempDir(); + toolchain = AbstractTestTools.getCandidateToolchain(); + toolchain.srcToLib( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + libOverride, + /* zipFiles = */ false, + AbstractTestTools.getTestRootDir("com.android.jack.lookup.test001.liboverride")); + + File jacks = AbstractTestTools.createTempDir(); + toolchain = AbstractTestTools.getCandidateToolchain(); + toolchain.srcToLib( + AbstractTestTools + .getClasspathsAsString(toolchain.getDefaultBootClasspath(), new File [] {lib}), + jacks, + /* zipFiles = */ false, + AbstractTestTools.getTestRootDir("com.android.jack.lookup.test001.jack")); + + toolchain = AbstractTestTools.getCandidateToolchain(); + toolchain.libToLib( + new File [] {jacks, libOverride}, + AbstractTestTools.createTempFile("Lookup001", ".zip"), + /* zipFiles = */ true); + } + +} diff --git a/jack-tests/tests/com/android/jack/multidex/MultiDexAllTests.java b/jack-tests/tests/com/android/jack/multidex/MultiDexAllTests.java new file mode 100644 index 00000000..957dbcf1 --- /dev/null +++ b/jack-tests/tests/com/android/jack/multidex/MultiDexAllTests.java @@ -0,0 +1,12 @@ +package com.android.jack.multidex; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + +@RunWith(Suite.class) +@SuiteClasses(value = { + MultiDexTests.class, + MultiDexOverflowTests.class}) +public class MultiDexAllTests { +} diff --git a/jack/tests/com/android/jack/multidex/MultiDexOverflowTests.java b/jack-tests/tests/com/android/jack/multidex/MultiDexOverflowTests.java index dc599f12..8152c207 100644 --- a/jack/tests/com/android/jack/multidex/MultiDexOverflowTests.java +++ b/jack-tests/tests/com/android/jack/multidex/MultiDexOverflowTests.java @@ -17,12 +17,13 @@ package com.android.jack.multidex; import com.android.jack.JackAbortException; -import com.android.jack.Options; import com.android.jack.TestTools; import com.android.jack.backend.dex.DexFileWriter; import com.android.jack.backend.dex.DexWritingException; import com.android.jack.backend.dex.MainDexOverflowException; import com.android.jack.backend.dex.MultiDexLegacy; +import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.JackApiToolchain; import com.android.jack.tools.merger.FieldIdOverflowException; import com.android.jack.tools.merger.MethodIdOverflowException; @@ -36,15 +37,14 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; -import java.io.PrintStream; import javax.annotation.Nonnegative; import javax.annotation.Nonnull; public class MultiDexOverflowTests { - @Nonnull private static File annotations; + @Nonnull private static final String EXPECTED_MESSAGE = "Error during the dex writing phase: classes.dex has too many IDs"; @@ -65,16 +65,23 @@ public class MultiDexOverflowTests { } generateJavaFileWithMethods(srcFolder, fileCount, 36); - Options options = new Options(); - options.addProperty(MultiDexLegacy.MULTIDEX_LEGACY.getName(), "true"); - options.addProperty(DexFileWriter.DEX_WRITING_POLICY.getName(), "minimal-multidex"); + JackApiToolchain toolchain = + AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); + + toolchain.addProperty(MultiDexLegacy.MULTIDEX_LEGACY.getName(), "true"); + toolchain.addProperty(DexFileWriter.DEX_WRITING_POLICY.getName(), "minimal-multidex"); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); - PrintStream redirectStream = new PrintStream(baos); - System.setErr(redirectStream); + toolchain.setErrorStream(baos); + try { - TestTools.compileSourceToDex(options, srcFolder, TestTools.getClasspathsAsString( - TestTools.getDefaultBootclasspath(), new File[] {annotations}), outFolder, false /* zip */ - ); + toolchain.srcToExe( + AbstractTestTools.getClasspathsAsString( + toolchain.getDefaultBootClasspath(), + new File[] {annotations}), + outFolder, + /* zipFile = */ false, + srcFolder); Assert.fail(); } catch (JackAbortException e) { Throwable cause = e.getCause(); @@ -82,8 +89,6 @@ public class MultiDexOverflowTests { Assert.assertTrue(cause.getCause() instanceof MainDexOverflowException); Assert.assertTrue(cause.getCause().getCause() instanceof MethodIdOverflowException); Assert.assertTrue(baos.toString().contains(EXPECTED_MESSAGE)); - } finally { - redirectStream.close(); } } @@ -98,16 +103,23 @@ public class MultiDexOverflowTests { } generateJavaFileWithFields(srcFolder, fileCount, 37); - Options options = new Options(); - options.addProperty(MultiDexLegacy.MULTIDEX_LEGACY.getName(), "true"); - options.addProperty(DexFileWriter.DEX_WRITING_POLICY.getName(), "multidex"); + JackApiToolchain toolchain = + AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); + + toolchain.addProperty(MultiDexLegacy.MULTIDEX_LEGACY.getName(), "true"); + toolchain.addProperty(DexFileWriter.DEX_WRITING_POLICY.getName(), "multidex"); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); - PrintStream redirectStream = new PrintStream(baos); - System.setErr(redirectStream); + toolchain.setErrorStream(baos); + try { - TestTools.compileSourceToDex(options, srcFolder, TestTools.getClasspathsAsString( - TestTools.getDefaultBootclasspath(), new File[] {annotations}), outFolder, false /* zip */ - ); + toolchain.srcToExe( + AbstractTestTools.getClasspathsAsString( + toolchain.getDefaultBootClasspath(), + new File[] {annotations}), + outFolder, + /* zipFile = */ false, + srcFolder); Assert.fail(); } catch (JackAbortException e) { Throwable cause = e.getCause(); @@ -115,8 +127,6 @@ public class MultiDexOverflowTests { Assert.assertTrue(cause.getCause() instanceof MainDexOverflowException); Assert.assertTrue(cause.getCause().getCause() instanceof FieldIdOverflowException); Assert.assertTrue(baos.toString().contains(EXPECTED_MESSAGE)); - } finally { - redirectStream.close(); } } diff --git a/jack/tests/com/android/jack/multidex/MultiDexTests.java b/jack-tests/tests/com/android/jack/multidex/MultiDexTests.java index 9c89ee1a..983c882c 100644 --- a/jack/tests/com/android/jack/multidex/MultiDexTests.java +++ b/jack-tests/tests/com/android/jack/multidex/MultiDexTests.java @@ -18,6 +18,7 @@ package com.android.jack.multidex; import com.google.common.io.Files; +import com.android.jack.DifferenceFoundException; import com.android.jack.Options; import com.android.jack.TestTools; import com.android.jack.backend.dex.DexFileWriter; @@ -25,6 +26,14 @@ import com.android.jack.backend.dex.MultiDexLegacy; import com.android.jack.library.FileType; import com.android.jack.preprocessor.PreProcessor; import com.android.jack.shrob.ListingComparator; +import com.android.jack.test.comparator.Comparator; +import com.android.jack.test.comparator.ComparatorException; +import com.android.jack.test.comparator.ComparatorFile; +import com.android.jack.test.helper.SourceToDexComparisonTestHelper; +import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.DummyToolchain; +import com.android.jack.test.toolchain.IToolchain; +import com.android.jack.test.toolchain.JackApiToolchain; import com.android.jack.util.ExecuteFile; import junit.framework.Assert; @@ -39,6 +48,9 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import java.util.Properties; import javax.annotation.Nonnull; @@ -49,8 +61,26 @@ public class MultiDexTests { private static File frameworks; private static File library; + private class ComparatorMultiDexListing extends ComparatorFile { + + protected ComparatorMultiDexListing(File candidate, File reference) { + super(candidate, reference); + } + + @Override + public void compare() throws DifferenceFoundException, ComparatorException { + try { + ListingComparator.compare(reference, getListingOfDex(candidate)); + } catch (IOException e) { + throw new ComparatorException(e); + } + } + } + @BeforeClass public static void init() throws IOException, Exception { + MultiDexTests.class.getClassLoader().setDefaultAssertionStatus(true); + annotations = prepareAnnotations(); frameworks = prepareFrameworks(); @@ -60,63 +90,78 @@ public class MultiDexTests { @Test public void versionedTest001a() throws Exception { + File testFolder = AbstractTestTools.getTestRootDir("com.android.jack.multidex.test001.jack"); - File testFolder = TestTools.getJackTestsWithJackFolder("multidex/test001"); - File out = TestTools.createTempDir("out", ""); - Options app1Options = createCommonOptionsForMultiDex(new File(testFolder, "config-001.jpp")); - - app1Options.addProperty(DexFileWriter.DEX_WRITING_POLICY.getName(), "multidex"); + JackApiToolchain toolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); - TestTools.compileSourceToDex(app1Options, testFolder, TestTools.getDefaultBootclasspathString() - + File.pathSeparator + annotations.getPath() + File.pathSeparator + frameworks.getPath(), - out, false); + addCommonOptionsForMultiDex(toolchain, new File(testFolder, "config-001.jpp")); + toolchain.addProperty(DexFileWriter.DEX_WRITING_POLICY.getName(), "multidex"); - File outList = getListingOfDex(new File(out, "classes.dex")); - ListingComparator.compare(new File(testFolder, "ref-list-001.txt"), outList); - Assert.assertFalse(new File(out, "classes2.dex").exists()); - return; - } + SourceToDexComparisonTestHelper env = + new SourceToDexComparisonTestHelper(testFolder); - @Test - public void versionedTest001b() throws Exception { + env.setCandidateTestTools(toolchain); - File testFolder = TestTools.getJackTestsWithJackFolder("multidex/test001"); - File out = TestTools.createTempDir("out", ""); - Options app1Options = createCommonOptionsForMultiDex(new File(testFolder, "config-001.jpp")); + List<File> cp = new ArrayList<File>(); + cp.addAll(Arrays.asList(toolchain.getDefaultBootClasspath())); + cp.add(annotations); + cp.add(frameworks); + env.setCandidateClasspath(cp.toArray(new File[cp.size()])); + env.setReferenceTestTools(new DummyToolchain()); - app1Options.addProperty(DexFileWriter.DEX_WRITING_POLICY.getName(), "minimal-multidex"); + env.runTest(new ComparatorMultiDexListing(env.getCandidateDex(), new File(testFolder, "ref-list-001.txt"))); - TestTools.compileSourceToDex(app1Options, testFolder, TestTools.getDefaultBootclasspathString() - + File.pathSeparator + annotations.getPath() + File.pathSeparator + frameworks.getPath(), - out, false); + Assert.assertFalse(new File(env.getCandidateDexDir(), "classes2.dex").exists()); + } - File outList = getListingOfDex(new File(out, "classes.dex")); - ListingComparator.compare(new File(testFolder, "ref-list-002-1.txt"), outList); - File outList2 = getListingOfDex(new File(out, "classes2.dex")); - ListingComparator.compare(new File(testFolder, "ref-list-002-2.txt"), outList2); - Assert.assertFalse(new File(out, "classes3.dex").exists()); - return; + @Test + public void versionedTest001b() throws Exception { + File testFolder = AbstractTestTools.getTestRootDir("com.android.jack.multidex.test001.jack"); + + JackApiToolchain toolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); + addCommonOptionsForMultiDex(toolchain, new File(testFolder, "config-001.jpp")); + toolchain.addProperty(DexFileWriter.DEX_WRITING_POLICY.getName(), "minimal-multidex"); + + SourceToDexComparisonTestHelper env = + new SourceToDexComparisonTestHelper(testFolder); + env.setCandidateTestTools(toolchain); + List<File> cp = new ArrayList<File>(); + cp.addAll(Arrays.asList(toolchain.getDefaultBootClasspath())); + cp.add(annotations); + cp.add(frameworks); + env.setCandidateClasspath(cp.toArray(new File[cp.size()])); + env.setReferenceTestTools(new DummyToolchain()); + + Comparator c1 = new ComparatorMultiDexListing(env.getCandidateDex(), new File(testFolder, "ref-list-002-1.txt")); + Comparator c2 = new ComparatorMultiDexListing(new File(env.getCandidateDexDir(), "classes2.dex"), new File(testFolder, "ref-list-002-2.txt")); + env.runTest(c1, c2); + + Assert.assertFalse(new File(env.getCandidateDexDir(), "classes3.dex").exists()); } @Test public void versionedTest001c() throws Exception { - - File testFolder = TestTools.getJackTestsWithJackFolder("multidex/test001"); - File out = TestTools.createTempDir("out", ""); - Options app1Options = createCommonOptionsForMultiDex(new File(testFolder, "config-003.jpp")); - - app1Options.addProperty(DexFileWriter.DEX_WRITING_POLICY.getName(), "minimal-multidex"); - - TestTools.compileSourceToDex(app1Options, testFolder, TestTools.getDefaultBootclasspathString() - + File.pathSeparator + annotations.getPath() + File.pathSeparator + frameworks.getPath(), - out, false); - - File outList = getListingOfDex(new File(out, "classes.dex")); - ListingComparator.compare(new File(testFolder, "ref-list-003-1.txt"), outList); - File outList2 = getListingOfDex(new File(out, "classes2.dex")); - ListingComparator.compare(new File(testFolder, "ref-list-003-2.txt"), outList2); - Assert.assertFalse(new File(out, "classes3.dex").exists()); - return; + File testFolder = AbstractTestTools.getTestRootDir("com.android.jack.multidex.test001.jack"); + + JackApiToolchain toolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); + addCommonOptionsForMultiDex(toolchain, new File(testFolder, "config-003.jpp")); + toolchain.addProperty(DexFileWriter.DEX_WRITING_POLICY.getName(), "minimal-multidex"); + + SourceToDexComparisonTestHelper env = + new SourceToDexComparisonTestHelper(testFolder); + env.setCandidateTestTools(toolchain); + List<File> cp = new ArrayList<File>(); + cp.addAll(Arrays.asList(toolchain.getDefaultBootClasspath())); + cp.add(annotations); + cp.add(frameworks); + env.setCandidateClasspath(cp.toArray(new File[cp.size()])); + env.setReferenceTestTools(new DummyToolchain()); + + Comparator c1 = new ComparatorMultiDexListing(env.getCandidateDex(), new File(testFolder, "ref-list-003-1.txt")); + Comparator c2 = new ComparatorMultiDexListing(new File(env.getCandidateDexDir(), "classes2.dex"), new File(testFolder, "ref-list-003-2.txt")); + env.runTest(c1, c2); + + Assert.assertFalse(new File(env.getCandidateDexDir(), "classes3.dex").exists()); } @Test @@ -124,7 +169,7 @@ public class MultiDexTests { File testFolder = TestTools.getJackTestsWithJackFolder("multidex/test001"); File out = TestTools.createTempDir("out", ""); - Options app1Options = createCommonOptionsForMultiDex(new File(testFolder, "config-001.jpp")); + Options app1Options = addCommonOptionsForMultiDex(new File(testFolder, "config-001.jpp")); app1Options.addProperty(DexFileWriter.DEX_WRITING_POLICY.getName(), "multidex"); @@ -143,7 +188,7 @@ public class MultiDexTests { File testFolder = TestTools.getJackTestsWithJackFolder("multidex/test001"); File out = TestTools.createTempDir("out", ""); - Options app1Options = createCommonOptionsForMultiDex(new File(testFolder, "config-001.jpp")); + Options app1Options = addCommonOptionsForMultiDex(new File(testFolder, "config-001.jpp")); app1Options.addProperty(DexFileWriter.DEX_WRITING_POLICY.getName(), "minimal-multidex"); @@ -164,7 +209,7 @@ public class MultiDexTests { File testFolder = TestTools.getJackTestsWithJackFolder("multidex/test001"); File out = TestTools.createTempDir("out", ""); - Options app1Options = createCommonOptionsForMultiDex(new File(testFolder, "config-003.jpp")); + Options app1Options = addCommonOptionsForMultiDex(new File(testFolder, "config-003.jpp")); app1Options.addProperty(DexFileWriter.DEX_WRITING_POLICY.getName(), "minimal-multidex"); @@ -180,7 +225,7 @@ public class MultiDexTests { return; } - private Options createCommonOptionsForMultiDex(@Nonnull File configFile) { + private Options addCommonOptionsForMultiDex(@Nonnull File configFile) { Options app1Options = new Options(); app1Options.addProperty(MultiDexLegacy.MULTIDEX_LEGACY.getName(), "true"); app1Options.addProperty(PreProcessor.ENABLE.getName(), "true"); @@ -188,11 +233,18 @@ public class MultiDexTests { return app1Options; } + private void addCommonOptionsForMultiDex(@Nonnull JackApiToolchain toolchain, + @Nonnull File configFile) { + toolchain.addProperty(MultiDexLegacy.MULTIDEX_LEGACY.getName(), "true"); + toolchain.addProperty(PreProcessor.ENABLE.getName(), "true"); + toolchain.addProperty(PreProcessor.FILE.getName(), configFile.getAbsolutePath()); + } + private File getListingOfDex(@Nonnull File dex) throws IOException, FileNotFoundException { assert dex.isFile(); ExecuteFile exec = new ExecuteFile(new String[]{ - "bash", "-c", "dexdump " + "bash", "-c", AbstractTestTools.getPrebuilt("dexdump").getAbsolutePath() + " " + dex.getAbsolutePath() + " | grep \" Class descriptor : \" | cut -d\\' -f2 | sed -e 's/$/:/'"}); @@ -207,7 +259,7 @@ public class MultiDexTests { assert dex.isFile(); ExecuteFile exec = new ExecuteFile(new String[]{ - "bash", "-c", "dexdump " + "bash", "-c", AbstractTestTools.getPrebuilt("dexdump").getAbsolutePath() + " " + dex.getAbsolutePath() + " | grep \" Class descriptor : \" | wc -l"}); @@ -226,33 +278,48 @@ public class MultiDexTests { } @Nonnull + private static File prepareLib(@Nonnull File sources, @Nonnull File... classpath) throws Exception { + File outDir = AbstractTestTools.createTempDir(); + IToolchain toolchain = AbstractTestTools.getCandidateToolchain(); + toolchain.srcToLib( + AbstractTestTools.getClasspathsAsString(toolchain.getDefaultBootClasspath(), classpath), + outDir, + /* zipFiles = */ false, + sources); + return outDir; + } + + @Nonnull private static File prepareFrameworks() throws IOException, Exception { - File frameworks = TestTools.createTempDir("frameworks", ""); - TestTools.compileSourceToJack(new Options(), - TestTools.getJackTestFolder("multidex/fakeframeworks"), - TestTools.getDefaultBootclasspathString(), frameworks, false); - return frameworks; + return prepareLib(AbstractTestTools.getTestRootDir("com.android.jack.multidex.fakeframeworks")); +// File frameworks = TestTools.createTempDir("frameworks", ""); +// TestTools.compileSourceToJack(new Options(), +// TestTools.getJackTestFolder("multidex/fakeframeworks"), +// TestTools.getDefaultBootclasspathString(), frameworks, false); +// return frameworks; } @Nonnull protected static File prepareAnnotations() throws IOException, Exception { - File annotations = TestTools.createTempDir("multidexAnnotations", ""); - TestTools.compileSourceToJack(new Options(), - TestTools.getFromAndroidTree( - "toolchain/jack/jack-tests/tests/com/android/jack/annotations/"), - TestTools.getDefaultBootclasspathString(), annotations, false); - return annotations; + return prepareLib(AbstractTestTools.getTestRootDir("com.android.jack.annotations")); +// File annotations = TestTools.createTempDir("multidexAnnotations", ""); +// TestTools.compileSourceToJack(new Options(), +// TestTools.getFromAndroidTree( +// "toolchain/jack/jack-tests/tests/com/android/jack/annotations/"), +// TestTools.getDefaultBootclasspathString(), annotations, false); +// return annotations; } @Nonnull private static File prepareLibrary(@Nonnull File frameworks) throws IOException, Exception { - File library = TestTools.createTempDir("multidexLibrary", ""); - TestTools.compileSourceToJack(new Options(), - TestTools.getJackTestFolder("multidex/fakelibrary"), - TestTools.getDefaultBootclasspathString() + File.pathSeparator + frameworks.getPath(), - library, false); - - return library; + return prepareLib(AbstractTestTools.getTestRootDir("com.android.jack.multidex.fakelibrary"), + frameworks); +// File library = TestTools.createTempDir("multidexLibrary", ""); +// TestTools.compileSourceToJack(new Options(), +// TestTools.getJackTestFolder("multidex/fakelibrary"), +// TestTools.getDefaultBootclasspathString() + File.pathSeparator + frameworks.getPath(), +// library, false); +// return library; } private static void setMetaIntoJackProperties(@Nonnull File library) throws IOException { @@ -285,16 +352,18 @@ public class MultiDexTests { @Test public void legacyAppTest002a() throws Exception { + File testFolder = AbstractTestTools.getTestRootDir("com.android.jack.multidex.test002.jack"); + File out = AbstractTestTools.createTempDir(); - File testFolder = TestTools.getJackTestsWithJackFolder("multidex/test002"); - File out = TestTools.createTempDir("out", ""); - Options app1Options = createCommonOptionsForMultiDex( - new File(testFolder,"config-001.jpp")); - app1Options.addProperty(DexFileWriter.DEX_WRITING_POLICY.getName(), "multidex"); + JackApiToolchain toolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); + addCommonOptionsForMultiDex(toolchain, new File(testFolder, "config-001.jpp")); + toolchain.addProperty(DexFileWriter.DEX_WRITING_POLICY.getName(), "multidex"); - TestTools.compileSourceToDex(app1Options, testFolder, TestTools.getDefaultBootclasspathString() - + File.pathSeparator + annotations.getPath() + File.pathSeparator + frameworks.getPath() - + File.pathSeparator + library.getPath(), out, false); + toolchain.srcToExe( + AbstractTestTools.getClasspathsAsString(toolchain.getDefaultBootClasspath(), new File [] {annotations, frameworks, library}), + out, + /* zipFile = */ false, + testFolder); File classesDex = new File(out, "classes.dex"); Assert.assertTrue(classesDex.exists()); @@ -309,17 +378,19 @@ public class MultiDexTests { @Test public void legacyAppTest002b() throws Exception { + File testFolder = AbstractTestTools.getTestRootDir("com.android.jack.multidex.test002.jack"); + File out = AbstractTestTools.createTempDir(); - File testFolder = TestTools.getJackTestsWithJackFolder("multidex/test002"); - File out = TestTools.createTempDir("out", ""); - Options app1Options = createCommonOptionsForMultiDex( - new File(testFolder,"config-001.jpp")); - app1Options.addProperty(DexFileWriter.DEX_WRITING_POLICY.getName(), "minimal-multidex"); - app1Options.addJayceImport(library); + JackApiToolchain toolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); + addCommonOptionsForMultiDex(toolchain, new File(testFolder, "config-001.jpp")); + toolchain.addProperty(DexFileWriter.DEX_WRITING_POLICY.getName(), "minimal-multidex"); + toolchain.addStaticLibs(library); - TestTools.compileSourceToDex(app1Options, testFolder, TestTools.getDefaultBootclasspathString() - + File.pathSeparator + annotations.getPath() + File.pathSeparator + frameworks.getPath(), - out, false); + toolchain.srcToExe( + AbstractTestTools.getClasspathsAsString(toolchain.getDefaultBootClasspath(), new File [] {annotations, frameworks}), + out, + /* zipFile = */ false, + testFolder); File outList = getListingOfDex(new File(out, "classes.dex")); // The old toolchain is doing a little better than us here it seems to identify when @@ -335,34 +406,33 @@ public class MultiDexTests { @Test public void legacyAppTest002b_auto() throws Exception { - - File testFolder = TestTools.getJackTestsWithJackFolder("multidex/test002"); + File testFolder = AbstractTestTools.getTestRootDir("com.android.jack.multidex.test002.jack"); File autoLibrary = prepareLibrary(frameworks); setMetaIntoJackProperties(autoLibrary); File jackInf = new File(autoLibrary, FileType.JPP.getPrefix()); Assert.assertTrue(jackInf.mkdir()); Files.copy(new File(testFolder,"config-001.jpp"), new File(jackInf, "config-001.jpp")); - File out = TestTools.createTempDir("out", ""); - Options app1Options = new Options(); - app1Options.addProperty(MultiDexLegacy.MULTIDEX_LEGACY.getName(), "true"); - app1Options.addProperty(DexFileWriter.DEX_WRITING_POLICY.getName(), "minimal-multidex"); - app1Options.addJayceImport(autoLibrary); - - TestTools.compileSourceToDex(app1Options, testFolder, TestTools.getDefaultBootclasspathString() - + File.pathSeparator + annotations.getPath() + File.pathSeparator + frameworks.getPath(), - out, false); - - File outList = getListingOfDex(new File(out, "classes.dex")); - // The old toolchain is doing a little better than us here it seems to identify when - // InterfaceWithEnum.class instance is used or not. - ListingComparator.compare( - new File(testFolder,"ref-list-002-1.txt"), outList); - File outList2 = getListingOfDex(new File(out, "classes2.dex")); - ListingComparator.compare( - new File(testFolder,"ref-list-002-2.txt"), outList2); - Assert.assertFalse(new File(out, "classes3.dex").exists()); - return; + JackApiToolchain toolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); + toolchain.addProperty(MultiDexLegacy.MULTIDEX_LEGACY.getName(), "true"); + toolchain.addProperty(DexFileWriter.DEX_WRITING_POLICY.getName(), "minimal-multidex"); + toolchain.addStaticLibs(autoLibrary); + + SourceToDexComparisonTestHelper env = + new SourceToDexComparisonTestHelper(testFolder); + env.setCandidateTestTools(toolchain); + List<File> cp = new ArrayList<File>(); + cp.addAll(Arrays.asList(toolchain.getDefaultBootClasspath())); + cp.add(annotations); + cp.add(frameworks); + env.setCandidateClasspath(cp.toArray(new File[cp.size()])); + env.setReferenceTestTools(new DummyToolchain()); + + Comparator c1 = new ComparatorMultiDexListing(env.getCandidateDex(), new File(testFolder, "ref-list-002-1.txt")); + Comparator c2 = new ComparatorMultiDexListing(new File(env.getCandidateDexDir(), "classes2.dex"), new File(testFolder, "ref-list-002-2.txt")); + env.runTest(c1, c2); + + Assert.assertFalse(new File(env.getCandidateDexDir(), "classes3.dex").exists()); } @Test @@ -370,7 +440,7 @@ public class MultiDexTests { File testFolder = TestTools.getJackTestsWithJackFolder("multidex/test002"); File out = TestTools.createTempDir("out", ""); - Options app1Options = createCommonOptionsForMultiDex( + Options app1Options = addCommonOptionsForMultiDex( new File(testFolder,"config-001.jpp")); app1Options.addProperty(DexFileWriter.DEX_WRITING_POLICY.getName(), "multidex"); @@ -394,7 +464,7 @@ public class MultiDexTests { File testFolder = TestTools.getJackTestsWithJackFolder("multidex/test002"); File out = TestTools.createTempDir("out", ""); - Options app1Options = createCommonOptionsForMultiDex( + Options app1Options = addCommonOptionsForMultiDex( new File(testFolder,"config-001.jpp")); app1Options.addProperty(DexFileWriter.DEX_WRITING_POLICY.getName(), "minimal-multidex"); app1Options.addJayceImport(library); diff --git a/jack-tests/tests/com/android/jack/newarray/NewarrayTests.java b/jack-tests/tests/com/android/jack/newarray/NewarrayTests.java new file mode 100644 index 00000000..94f84978 --- /dev/null +++ b/jack-tests/tests/com/android/jack/newarray/NewarrayTests.java @@ -0,0 +1,93 @@ +/* +* 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.newarray; + +import com.android.jack.test.category.RuntimeRegressionTest; +import com.android.jack.test.helper.RuntimeTestHelper; +import com.android.jack.test.runtime.RuntimeTest; +import com.android.jack.test.runtime.RuntimeTestInfo; +import com.android.jack.test.toolchain.AbstractTestTools; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +public class NewarrayTests extends RuntimeTest { + + private RuntimeTestInfo TEST001 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.newarray.test001"), + "com.android.jack.newarray.test001.dx.Tests"); + + private RuntimeTestInfo TEST002 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.newarray.test002"), + "com.android.jack.newarray.test002.dx.Tests"); + + private RuntimeTestInfo TEST003 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.newarray.test003"), + "com.android.jack.newarray.test003.dx.Tests"); + + private RuntimeTestInfo TEST004 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.newarray.test004"), + "com.android.jack.newarray.test004.dx.Tests"); + + private RuntimeTestInfo TEST005 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.newarray.test005"), + "com.android.jack.newarray.test005.dx.Tests"); + + @BeforeClass + public static void setUpClass() { + NewarrayTests.class.getClassLoader().setDefaultAssertionStatus(true); + } + @Test + @Category(RuntimeRegressionTest.class) + public void test001() throws Exception { + new RuntimeTestHelper(TEST001).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test002() throws Exception { + new RuntimeTestHelper(TEST002).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test003() throws Exception { + new RuntimeTestHelper(TEST003).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test004() throws Exception { + new RuntimeTestHelper(TEST004).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test005() throws Exception { + new RuntimeTestHelper(TEST005).compileAndRunTest(); + } + + @Override + protected void fillRtTestInfos() { + rtTestInfos.add(TEST001); + rtTestInfos.add(TEST002); + rtTestInfos.add(TEST003); + rtTestInfos.add(TEST004); + rtTestInfos.add(TEST005); + } +} diff --git a/jack-tests/tests/com/android/jack/nopackage/NoPackageTests.java b/jack-tests/tests/com/android/jack/nopackage/NoPackageTests.java new file mode 100644 index 00000000..54c5978b --- /dev/null +++ b/jack-tests/tests/com/android/jack/nopackage/NoPackageTests.java @@ -0,0 +1,58 @@ +/* + * 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.nopackage; + +import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.IToolchain; + +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.File; + +public class NoPackageTests { + + @BeforeClass + public static void setUpClass() { + NoPackageTests.class.getClassLoader().setDefaultAssertionStatus(true); + } + + @Test + public void test001() throws Exception { + IToolchain toolchain = AbstractTestTools.getCandidateToolchain(); + toolchain.srcToExe( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + AbstractTestTools.createTempDir(), + /* zipFile = */ false, + AbstractTestTools.getTestRootDir("com.android.jack.nopackage.test001.jack")); + } + + @Test + public void test001_throughJayce() throws Exception { + File tmpDir = AbstractTestTools.createTempDir(); + IToolchain toolchain = AbstractTestTools.getCandidateToolchain(); + toolchain.srcToLib( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + tmpDir, + /* zipFiles = */ false, + AbstractTestTools.getTestRootDir("com.android.jack.nopackage.test001.jack")); + + toolchain = AbstractTestTools.getCandidateToolchain(); + toolchain.libToExe(tmpDir, AbstractTestTools.createTempDir(), /* zipFile = */ false); + } + +} diff --git a/jack-tests/tests/com/android/jack/nopackage/jack/ClassInDefaultPackage.java b/jack-tests/tests/com/android/jack/nopackage/test001/jack/ClassInDefaultPackage.java index 91e24242..91e24242 100644 --- a/jack-tests/tests/com/android/jack/nopackage/jack/ClassInDefaultPackage.java +++ b/jack-tests/tests/com/android/jack/nopackage/test001/jack/ClassInDefaultPackage.java diff --git a/jack-tests/tests/com/android/jack/nopackage/jack/InnerInDefaultPackage.java b/jack-tests/tests/com/android/jack/nopackage/test001/jack/InnerInDefaultPackage.java index 48e7c487..48e7c487 100644 --- a/jack-tests/tests/com/android/jack/nopackage/jack/InnerInDefaultPackage.java +++ b/jack-tests/tests/com/android/jack/nopackage/test001/jack/InnerInDefaultPackage.java diff --git a/jack-tests/tests/com/android/jack/opcodes/OpcodesTests.java b/jack-tests/tests/com/android/jack/opcodes/OpcodesTests.java new file mode 100644 index 00000000..0830306b --- /dev/null +++ b/jack-tests/tests/com/android/jack/opcodes/OpcodesTests.java @@ -0,0 +1,1740 @@ +/* +* 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.opcodes; + +import com.android.jack.test.category.RuntimeRegressionTest; +import com.android.jack.test.helper.RuntimeTestHelper; +import com.android.jack.test.runtime.RuntimeTest; +import com.android.jack.test.runtime.RuntimeTestInfo; +import com.android.jack.test.toolchain.AbstractTestTools; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import java.io.File; + +import javax.annotation.Nonnull; + +public class OpcodesTests extends RuntimeTest { + + @Nonnull + private RuntimeTestInfo INVOKE_STATIC = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.invoke_static"), + "com.android.jack.opcodes.invoke_static.Test_invoke_static"); + + @Nonnull + private RuntimeTestInfo ARRAY_LENGTH = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.array_length"), + "com.android.jack.opcodes.array_length.Test_array_length"); + + @Nonnull + private RuntimeTestInfo NEG_FLOAT = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.neg_float"), + "com.android.jack.opcodes.neg_float.Test_neg_float"); + + @Nonnull + private RuntimeTestInfo SUB_DOUBLE = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.sub_double"), + "com.android.jack.opcodes.sub_double.Test_sub_double"); + + @Nonnull + private RuntimeTestInfo AGET = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.aget"), + "com.android.jack.opcodes.aget.Test_aget"); + + @Nonnull + private RuntimeTestInfo APUT_BYTE = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.aput_byte"), + "com.android.jack.opcodes.aput_byte.Test_aput_byte"); + + @Nonnull + private RuntimeTestInfo OPC_NEW = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.opc_new"), + "com.android.jack.opcodes.opc_new.Test_opc_new"); + + @Nonnull + private RuntimeTestInfo CMPL_DOUBLE = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.cmpl_double"), + "com.android.jack.opcodes.cmpl_double.Test_cmpl_double"); + + @Nonnull + private RuntimeTestInfo IF_GTZ = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.if_gtz"), + "com.android.jack.opcodes.if_gtz.Test_if_gtz"); + + @Nonnull + private RuntimeTestInfo FLOAT_TO_LONG = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.float_to_long"), + "com.android.jack.opcodes.float_to_long.Test_float_to_long"); + + @Nonnull + private RuntimeTestInfo ADD_LONG = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.add_long"), + "com.android.jack.opcodes.add_long.Test_add_long"); + + @Nonnull + private RuntimeTestInfo ADD_FLOAT = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.add_float"), + "com.android.jack.opcodes.add_float.Test_add_float"); + + @Nonnull + private RuntimeTestInfo IPUT = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.iput"), + "com.android.jack.opcodes.iput.Test_iput"); + + @Nonnull + private RuntimeTestInfo DIV_FLOAT = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.div_float"), + "com.android.jack.opcodes.div_float.Test_div_float"); + + @Nonnull + private RuntimeTestInfo USHR_LONG = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.ushr_long"), + "com.android.jack.opcodes.ushr_long.Test_ushr_long"); + + @Nonnull + private RuntimeTestInfo CONST_WIDE = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.const_wide"), + "com.android.jack.opcodes.const_wide.Test_const_wide"); + + @Nonnull + private RuntimeTestInfo XOR_INT = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.xor_int"), + "com.android.jack.opcodes.xor_int.Test_xor_int"); + + @Nonnull + private RuntimeTestInfo AGET_OBJECT = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.aget_object"), + "com.android.jack.opcodes.aget_object.Test_aget_object"); + + @Nonnull + private RuntimeTestInfo CONST4_16 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.const4_16"), + "com.android.jack.opcodes.const4_16.Test_const4_16"); + + @Nonnull + private RuntimeTestInfo REM_LONG = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.rem_long"), + "com.android.jack.opcodes.rem_long.Test_rem_long"); + + @Nonnull + private RuntimeTestInfo USHR_INT = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.ushr_int"), + "com.android.jack.opcodes.ushr_int.Test_ushr_int"); + + @Nonnull + private RuntimeTestInfo IF_GE = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.if_ge"), + "com.android.jack.opcodes.if_ge.Test_if_ge"); + + @Nonnull + private RuntimeTestInfo SUB_LONG = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.sub_long"), + "com.android.jack.opcodes.sub_long.Test_sub_long"); + + @Nonnull + private RuntimeTestInfo FLOAT_TO_INT = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.float_to_int"), + "com.android.jack.opcodes.float_to_int.Test_float_to_int"); + + @Nonnull + private RuntimeTestInfo INT_TO_LONG = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.int_to_long"), + "com.android.jack.opcodes.int_to_long.Test_int_to_long"); + + @Nonnull + private RuntimeTestInfo OR_LONG = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.or_long"), + "com.android.jack.opcodes.or_long.Test_or_long"); + + @Nonnull + private RuntimeTestInfo IF_GEZ = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.if_gez"), + "com.android.jack.opcodes.if_gez.Test_if_gez"); + + @Nonnull + private RuntimeTestInfo SHL_INT = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.shl_int"), + "com.android.jack.opcodes.shl_int.Test_shl_int"); + + @Nonnull + private RuntimeTestInfo LONG_TO_FLOAT = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.long_to_float"), + "com.android.jack.opcodes.long_to_float.Test_long_to_float"); + + @Nonnull + private RuntimeTestInfo DIV_INT = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.div_int"), + "com.android.jack.opcodes.div_int.Test_div_int"); + + @Nonnull + private RuntimeTestInfo AND_LONG = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.and_long"), + "com.android.jack.opcodes.and_long.Test_and_long"); + + @Nonnull + private RuntimeTestInfo DOUBLE_TO_LONG = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.double_to_long"), + "com.android.jack.opcodes.double_to_long.Test_double_to_long"); + + @Nonnull + private RuntimeTestInfo MUL_LONG = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.mul_long"), + "com.android.jack.opcodes.mul_long.Test_mul_long"); + + @Nonnull + private RuntimeTestInfo DOUBLE_TO_INT = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.double_to_int"), + "com.android.jack.opcodes.double_to_int.Test_double_to_int"); + + @Nonnull + private RuntimeTestInfo IF_NEZ = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.if_nez"), + "com.android.jack.opcodes.if_nez.Test_if_nez"); + + @Nonnull + private RuntimeTestInfo APUT_OBJECT = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.aput_object"), + "com.android.jack.opcodes.aput_object.Test_aput_object"); + + @Nonnull + private RuntimeTestInfo IF_LT = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.if_lt"), + "com.android.jack.opcodes.if_lt.Test_if_lt"); + + @Nonnull + private RuntimeTestInfo INT_TO_DOUBLE = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.int_to_double"), + "com.android.jack.opcodes.int_to_double.Test_int_to_double"); + + @Nonnull + private RuntimeTestInfo MUL_INT = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.mul_int"), + "com.android.jack.opcodes.mul_int.Test_mul_int"); + + @Nonnull + private RuntimeTestInfo SPUT = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.sput"), + "com.android.jack.opcodes.sput.Test_sput"); + + @Nonnull + private RuntimeTestInfo SHL_LONG = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.shl_long"), + "com.android.jack.opcodes.shl_long.Test_shl_long"); + + @Nonnull + private RuntimeTestInfo NEG_LONG = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.neg_long"), + "com.android.jack.opcodes.neg_long.Test_neg_long"); + + @Nonnull + private RuntimeTestInfo LONG_TO_INT = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.long_to_int"), + "com.android.jack.opcodes.long_to_int.Test_long_to_int"); + + @Nonnull + private RuntimeTestInfo OPC_GOTO = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.opc_goto"), + "com.android.jack.opcodes.opc_goto.Test_opc_goto"); + + @Nonnull + private RuntimeTestInfo INT_TO_FLOAT = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.int_to_float"), + "com.android.jack.opcodes.int_to_float.Test_int_to_float"); + + @Nonnull + private RuntimeTestInfo XOR_LONG = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.xor_long"), + "com.android.jack.opcodes.xor_long.Test_xor_long"); + + @Nonnull + private RuntimeTestInfo MONITOR_ENTER = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.monitor_enter"), + "com.android.jack.opcodes.monitor_enter.Test_monitor_enter"); + + @Nonnull + private RuntimeTestInfo IF_EQZ = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.if_eqz"), + "com.android.jack.opcodes.if_eqz.Test_if_eqz"); + + @Nonnull + private RuntimeTestInfo INVOKE_DIRECT = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.invoke_direct"), + "com.android.jack.opcodes.invoke_direct.Test_invoke_direct"); + + @Nonnull + private RuntimeTestInfo CMPL_FLOAT = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.cmpl_float"), + "com.android.jack.opcodes.cmpl_float.Test_cmpl_float"); + + @Nonnull + private RuntimeTestInfo CHECK_CAST = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.check_cast"), + "com.android.jack.opcodes.check_cast.Test_check_cast"); + + @Nonnull + private RuntimeTestInfo OPC_THROW = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.opc_throw"), + "com.android.jack.opcodes.opc_throw.Test_opc_throw"); + + @Nonnull + private RuntimeTestInfo INT_TO_SHORT = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.int_to_short"), + "com.android.jack.opcodes.int_to_short.Test_int_to_short"); + + @Nonnull + private RuntimeTestInfo PACKED_SWITCH = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.packed_switch"), + "com.android.jack.opcodes.packed_switch.Test_packed_switch"); + + @Nonnull + private RuntimeTestInfo AGET_CHAR = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.aget_char"), + "com.android.jack.opcodes.aget_char.Test_aget_char"); + + @Nonnull + private RuntimeTestInfo RETURN_OBJECT = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.return_object"), + "com.android.jack.opcodes.return_object.Test_return_object"); + + @Nonnull + private RuntimeTestInfo OPC_CONST = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.opc_const"), + "com.android.jack.opcodes.opc_const.Test_opc_const"); + + @Nonnull + private RuntimeTestInfo SUB_INT = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.sub_int"), + "com.android.jack.opcodes.sub_int.Test_sub_int"); + + @Nonnull + private RuntimeTestInfo APUT_CHAR = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.aput_char"), + "com.android.jack.opcodes.aput_char.Test_aput_char"); + + @Nonnull + private RuntimeTestInfo NEG_INT = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.neg_int"), + "com.android.jack.opcodes.neg_int.Test_neg_int"); + + @Nonnull + private RuntimeTestInfo MUL_DOUBLE = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.mul_double"), + "com.android.jack.opcodes.mul_double.Test_mul_double"); + + @Nonnull + private RuntimeTestInfo DOUBLE_TO_FLOAT = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.double_to_float"), + "com.android.jack.opcodes.double_to_float.Test_double_to_float"); + + @Nonnull + private RuntimeTestInfo INT_TO_BYTE = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.int_to_byte"), + "com.android.jack.opcodes.int_to_byte.Test_int_to_byte"); + + @Nonnull + private RuntimeTestInfo IF_LE = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.if_le"), + "com.android.jack.opcodes.if_le.Test_if_le"); + + @Nonnull + private RuntimeTestInfo INVOKE_VIRTUAL = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.invoke_virtual"), + "com.android.jack.opcodes.invoke_virtual.Test_invoke_virtual"); + + @Nonnull + private RuntimeTestInfo DIV_DOUBLE = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.div_double"), + "com.android.jack.opcodes.div_double.Test_div_double"); + + @Nonnull + private RuntimeTestInfo IF_GT = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.if_gt"), + "com.android.jack.opcodes.if_gt.Test_if_gt"); + + @Nonnull + private RuntimeTestInfo AGET_SHORT = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.aget_short"), + "com.android.jack.opcodes.aget_short.Test_aget_short"); + + @Nonnull + private RuntimeTestInfo CONST_STRING = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.const_string"), + "com.android.jack.opcodes.const_string.Test_const_string"); + + @Nonnull + private RuntimeTestInfo OR_INT = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.or_int"), + "com.android.jack.opcodes.or_int.Test_or_int"); + + @Nonnull + private RuntimeTestInfo REM_INT = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.rem_int"), + "com.android.jack.opcodes.rem_int.Test_rem_int"); + + @Nonnull + private RuntimeTestInfo REM_DOUBLE = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.rem_double"), + "com.android.jack.opcodes.rem_double.Test_rem_double"); + + @Nonnull + private RuntimeTestInfo LONG_TO_DOUBLE = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.long_to_double"), + "com.android.jack.opcodes.long_to_double.Test_long_to_double"); + + @Nonnull + private RuntimeTestInfo IF_NE = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.if_ne"), + "com.android.jack.opcodes.if_ne.Test_if_ne"); + + @Nonnull + private RuntimeTestInfo CMP_LONG = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.cmp_long"), + "com.android.jack.opcodes.cmp_long.Test_cmp_long"); + + @Nonnull + private RuntimeTestInfo SGET = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.sget"), + "com.android.jack.opcodes.sget.Test_sget"); + + @Nonnull + private RuntimeTestInfo AGET_WIDE = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.aget_wide"), + "com.android.jack.opcodes.aget_wide.Test_aget_wide"); + + @Nonnull + private RuntimeTestInfo IF_LTZ = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.if_ltz"), + "com.android.jack.opcodes.if_ltz.Test_if_ltz"); + + @Nonnull + private RuntimeTestInfo OPC_INSTANCEOF = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.opc_instanceof"), + "com.android.jack.opcodes.opc_instanceof.Test_opc_instanceof"); + + @Nonnull + private RuntimeTestInfo NEG_DOUBLE = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.neg_double"), + "com.android.jack.opcodes.neg_double.Test_neg_double"); + + @Nonnull + private RuntimeTestInfo RETURN_WIDE = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.return_wide"), + "com.android.jack.opcodes.return_wide.Test_return_wide"); + + @Nonnull + private RuntimeTestInfo FLOAT_TO_DOUBLE = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.float_to_double"), + "com.android.jack.opcodes.float_to_double.Test_float_to_double"); + + @Nonnull + private RuntimeTestInfo APUT_SHORT = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.aput_short"), + "com.android.jack.opcodes.aput_short.Test_aput_short"); + + @Nonnull + private RuntimeTestInfo CMPG_DOUBLE = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.cmpg_double"), + "com.android.jack.opcodes.cmpg_double.Test_cmpg_double"); + + @Nonnull + private RuntimeTestInfo IF_LEZ = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.if_lez"), + "com.android.jack.opcodes.if_lez.Test_if_lez"); + + @Nonnull + private RuntimeTestInfo IF_EQ = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.if_eq"), + "com.android.jack.opcodes.if_eq.Test_if_eq"); + + @Nonnull + private RuntimeTestInfo NEW_ARRAY = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.new_array"), + "com.android.jack.opcodes.new_array.Test_new_array"); + + @Nonnull + private RuntimeTestInfo SHR_LONG = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.shr_long"), + "com.android.jack.opcodes.shr_long.Test_shr_long"); + + @Nonnull + private RuntimeTestInfo ADD_DOUBLE = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.add_double"), + "com.android.jack.opcodes.add_double.Test_add_double"); + + @Nonnull + private RuntimeTestInfo DIV_LONG = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.div_long"), + "com.android.jack.opcodes.div_long.Test_div_long"); + + @Nonnull + private RuntimeTestInfo SPARSE_SWITCH = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.sparse_switch"), + "com.android.jack.opcodes.sparse_switch.Test_sparse_switch"); + + @Nonnull + private RuntimeTestInfo INVOKE_INTERFACE = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.invoke_interface"), + "com.android.jack.opcodes.invoke_interface.Test_invoke_interface"); + + @Nonnull + private RuntimeTestInfo APUT_WIDE = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.aput_wide"), + "com.android.jack.opcodes.aput_wide.Test_aput_wide"); + + @Nonnull + private RuntimeTestInfo AGET_BYTE = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.aget_byte"), + "com.android.jack.opcodes.aget_byte.Test_aget_byte"); + + @Nonnull + private RuntimeTestInfo APUT = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.aput"), + "com.android.jack.opcodes.aput.Test_aput"); + + @Nonnull + private RuntimeTestInfo SHR_INT = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.shr_int"), + "com.android.jack.opcodes.shr_int.Test_shr_int"); + + @Nonnull + private RuntimeTestInfo OPC_RETURN = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.opc_return"), + "com.android.jack.opcodes.opc_return.Test_opc_return"); + + @Nonnull + private RuntimeTestInfo INVOKE_SUPER = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.invoke_super"), + "com.android.jack.opcodes.invoke_super.Test_invoke_super"); + + @Nonnull + private RuntimeTestInfo MUL_FLOAT = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.mul_float"), + "com.android.jack.opcodes.mul_float.Test_mul_float"); + + @Nonnull + private RuntimeTestInfo SUB_FLOAT = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.sub_float"), + "com.android.jack.opcodes.sub_float.Test_sub_float"); + + @Nonnull + private RuntimeTestInfo ADD_INT = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.add_int"), + "com.android.jack.opcodes.add_int.Test_add_int"); + + @Nonnull + private RuntimeTestInfo INT_TO_CHAR = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.int_to_char"), + "com.android.jack.opcodes.int_to_char.Test_int_to_char"); + + @Nonnull + private RuntimeTestInfo AND_INT = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.and_int"), + "com.android.jack.opcodes.and_int.Test_and_int"); + + @Nonnull + private RuntimeTestInfo CMPG_FLOAT = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.cmpg_float"), + "com.android.jack.opcodes.cmpg_float.Test_cmpg_float"); + + @Nonnull + private RuntimeTestInfo IGET = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.iget"), + "com.android.jack.opcodes.iget.Test_iget"); + + @Nonnull + private RuntimeTestInfo REM_FLOAT = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.opcodes.rem_float"), + "com.android.jack.opcodes.rem_float.Test_rem_float"); + + + @BeforeClass + public static void setUpClass() { + OpcodesTests.class.getClassLoader().setDefaultAssertionStatus(true); + } + @Test + //@Category(RuntimeRegressionTest.class) + public void invoke_static() throws Exception { + new RuntimeTestHelper(INVOKE_STATIC) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void array_length() throws Exception { + new RuntimeTestHelper(ARRAY_LENGTH) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void neg_float() throws Exception { + new RuntimeTestHelper(NEG_FLOAT) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void sub_double() throws Exception { + new RuntimeTestHelper(SUB_DOUBLE) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void aget() throws Exception { + new RuntimeTestHelper(AGET) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void aput_byte() throws Exception { + new RuntimeTestHelper(APUT_BYTE) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void opc_new() throws Exception { + new RuntimeTestHelper(OPC_NEW) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void cmpl_double() throws Exception { + new RuntimeTestHelper(CMPL_DOUBLE) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void if_gtz() throws Exception { + new RuntimeTestHelper(IF_GTZ) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void float_to_long() throws Exception { + new RuntimeTestHelper(FLOAT_TO_LONG) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void add_long() throws Exception { + new RuntimeTestHelper(ADD_LONG) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void add_float() throws Exception { + new RuntimeTestHelper(ADD_FLOAT) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void iput() throws Exception { + new RuntimeTestHelper(IPUT) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void div_float() throws Exception { + new RuntimeTestHelper(DIV_FLOAT) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void ushr_long() throws Exception { + new RuntimeTestHelper(USHR_LONG) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void const_wide() throws Exception { + new RuntimeTestHelper(CONST_WIDE) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void xor_int() throws Exception { + new RuntimeTestHelper(XOR_INT) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void aget_object() throws Exception { + new RuntimeTestHelper(AGET_OBJECT) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void const4_16() throws Exception { + new RuntimeTestHelper(CONST4_16) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void rem_long() throws Exception { + new RuntimeTestHelper(REM_LONG) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void ushr_int() throws Exception { + new RuntimeTestHelper(USHR_INT) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void if_ge() throws Exception { + new RuntimeTestHelper(IF_GE) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void sub_long() throws Exception { + new RuntimeTestHelper(SUB_LONG) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void float_to_int() throws Exception { + new RuntimeTestHelper(FLOAT_TO_INT) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void int_to_long() throws Exception { + new RuntimeTestHelper(INT_TO_LONG) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void or_long() throws Exception { + new RuntimeTestHelper(OR_LONG) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void if_gez() throws Exception { + new RuntimeTestHelper(IF_GEZ) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void shl_int() throws Exception { + new RuntimeTestHelper(SHL_INT) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void long_to_float() throws Exception { + new RuntimeTestHelper(LONG_TO_FLOAT) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void div_int() throws Exception { + new RuntimeTestHelper(DIV_INT) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void and_long() throws Exception { + new RuntimeTestHelper(AND_LONG) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void double_to_long() throws Exception { + new RuntimeTestHelper(DOUBLE_TO_LONG) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void mul_long() throws Exception { + new RuntimeTestHelper(MUL_LONG) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void double_to_int() throws Exception { + new RuntimeTestHelper(DOUBLE_TO_INT) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void if_nez() throws Exception { + new RuntimeTestHelper(IF_NEZ) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void aput_object() throws Exception { + new RuntimeTestHelper(APUT_OBJECT) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void if_lt() throws Exception { + new RuntimeTestHelper(IF_LT) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void int_to_double() throws Exception { + new RuntimeTestHelper(INT_TO_DOUBLE) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void mul_int() throws Exception { + new RuntimeTestHelper(MUL_INT) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void sput() throws Exception { + new RuntimeTestHelper(SPUT) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void shl_long() throws Exception { + new RuntimeTestHelper(SHL_LONG) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void neg_long() throws Exception { + new RuntimeTestHelper(NEG_LONG) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void long_to_int() throws Exception { + new RuntimeTestHelper(LONG_TO_INT) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void opc_goto() throws Exception { + new RuntimeTestHelper(OPC_GOTO) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void int_to_float() throws Exception { + new RuntimeTestHelper(INT_TO_FLOAT) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void xor_long() throws Exception { + new RuntimeTestHelper(XOR_LONG) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void monitor_enter() throws Exception { + new RuntimeTestHelper(MONITOR_ENTER) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void if_eqz() throws Exception { + new RuntimeTestHelper(IF_EQZ) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void invoke_direct() throws Exception { + new RuntimeTestHelper(INVOKE_DIRECT) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void cmpl_float() throws Exception { + new RuntimeTestHelper(CMPL_FLOAT) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void check_cast() throws Exception { + new RuntimeTestHelper(CHECK_CAST) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void opc_throw() throws Exception { + new RuntimeTestHelper(OPC_THROW) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void int_to_short() throws Exception { + new RuntimeTestHelper(INT_TO_SHORT) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void packed_switch() throws Exception { + new RuntimeTestHelper(PACKED_SWITCH) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void aget_char() throws Exception { + new RuntimeTestHelper(AGET_CHAR) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void return_object() throws Exception { + new RuntimeTestHelper(RETURN_OBJECT) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void opc_const() throws Exception { + new RuntimeTestHelper(OPC_CONST) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void sub_int() throws Exception { + new RuntimeTestHelper(SUB_INT) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void aput_char() throws Exception { + new RuntimeTestHelper(APUT_CHAR) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void neg_int() throws Exception { + new RuntimeTestHelper(NEG_INT) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void mul_double() throws Exception { + new RuntimeTestHelper(MUL_DOUBLE) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void double_to_float() throws Exception { + new RuntimeTestHelper(DOUBLE_TO_FLOAT) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void int_to_byte() throws Exception { + new RuntimeTestHelper(INT_TO_BYTE) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void if_le() throws Exception { + new RuntimeTestHelper(IF_LE) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void invoke_virtual() throws Exception { + new RuntimeTestHelper(INVOKE_VIRTUAL) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void div_double() throws Exception { + new RuntimeTestHelper(DIV_DOUBLE) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void if_gt() throws Exception { + new RuntimeTestHelper(IF_GT) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void aget_short() throws Exception { + new RuntimeTestHelper(AGET_SHORT) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void const_string() throws Exception { + new RuntimeTestHelper(CONST_STRING) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void or_int() throws Exception { + new RuntimeTestHelper(OR_INT) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void rem_int() throws Exception { + new RuntimeTestHelper(REM_INT) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void rem_double() throws Exception { + new RuntimeTestHelper(REM_DOUBLE) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void long_to_double() throws Exception { + new RuntimeTestHelper(LONG_TO_DOUBLE) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void if_ne() throws Exception { + new RuntimeTestHelper(IF_NE) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void cmp_long() throws Exception { + new RuntimeTestHelper(CMP_LONG) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void sget() throws Exception { + new RuntimeTestHelper(SGET) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void aget_wide() throws Exception { + new RuntimeTestHelper(AGET_WIDE) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void if_ltz() throws Exception { + new RuntimeTestHelper(IF_LTZ) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void opc_instanceof() throws Exception { + new RuntimeTestHelper(OPC_INSTANCEOF) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void neg_double() throws Exception { + new RuntimeTestHelper(NEG_DOUBLE) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void return_wide() throws Exception { + new RuntimeTestHelper(RETURN_WIDE) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void float_to_double() throws Exception { + new RuntimeTestHelper(FLOAT_TO_DOUBLE) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void aput_short() throws Exception { + new RuntimeTestHelper(APUT_SHORT) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void cmpg_double() throws Exception { + new RuntimeTestHelper(CMPG_DOUBLE) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void if_lez() throws Exception { + new RuntimeTestHelper(IF_LEZ) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void if_eq() throws Exception { + new RuntimeTestHelper(IF_EQ) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void new_array() throws Exception { + new RuntimeTestHelper(NEW_ARRAY) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void shr_long() throws Exception { + new RuntimeTestHelper(SHR_LONG) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void add_double() throws Exception { + new RuntimeTestHelper(ADD_DOUBLE) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void div_long() throws Exception { + new RuntimeTestHelper(DIV_LONG) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void sparse_switch() throws Exception { + new RuntimeTestHelper(SPARSE_SWITCH) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void invoke_interface() throws Exception { + new RuntimeTestHelper(INVOKE_INTERFACE) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void aput_wide() throws Exception { + new RuntimeTestHelper(APUT_WIDE) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void aget_byte() throws Exception { + new RuntimeTestHelper(AGET_BYTE) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void aput() throws Exception { + new RuntimeTestHelper(APUT) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void shr_int() throws Exception { + new RuntimeTestHelper(SHR_INT) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void opc_return() throws Exception { + new RuntimeTestHelper(OPC_RETURN) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void invoke_super() throws Exception { + new RuntimeTestHelper(INVOKE_SUPER) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void mul_float() throws Exception { + new RuntimeTestHelper(MUL_FLOAT) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void sub_float() throws Exception { + new RuntimeTestHelper(SUB_FLOAT) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void add_int() throws Exception { + new RuntimeTestHelper(ADD_INT) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void int_to_char() throws Exception { + new RuntimeTestHelper(INT_TO_CHAR) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void and_int() throws Exception { + new RuntimeTestHelper(AND_INT) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void cmpg_float() throws Exception { + new RuntimeTestHelper(CMPG_FLOAT) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void iget() throws Exception { + new RuntimeTestHelper(IGET) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + @Test + //@Category(RuntimeRegressionTest.class) + public void rem_float() throws Exception { + new RuntimeTestHelper(REM_FLOAT) + .setSrcDirName("jm") + .setRefDirName( ".") + .addReferenceExtraSources(new File(AbstractTestTools.getJackRootDir(), "toolchain/jack/jack-tests/src/com/android/jack/DxTestCase.java")) + .compileAndRunTest(); + } + + + @Override + protected void fillRtTestInfos() { + rtTestInfos.add(INVOKE_STATIC); + rtTestInfos.add(ARRAY_LENGTH); + rtTestInfos.add(NEG_FLOAT); + rtTestInfos.add(SUB_DOUBLE); + rtTestInfos.add(AGET); + rtTestInfos.add(APUT_BYTE); + rtTestInfos.add(OPC_NEW); + rtTestInfos.add(CMPL_DOUBLE); + rtTestInfos.add(IF_GTZ); + rtTestInfos.add(FLOAT_TO_LONG); + rtTestInfos.add(ADD_LONG); + rtTestInfos.add(ADD_FLOAT); + rtTestInfos.add(IPUT); + rtTestInfos.add(DIV_FLOAT); + rtTestInfos.add(USHR_LONG); + rtTestInfos.add(CONST_WIDE); + rtTestInfos.add(XOR_INT); + rtTestInfos.add(AGET_OBJECT); + rtTestInfos.add(CONST4_16); + rtTestInfos.add(REM_LONG); + rtTestInfos.add(USHR_INT); + rtTestInfos.add(IF_GE); + rtTestInfos.add(SUB_LONG); + rtTestInfos.add(FLOAT_TO_INT); + rtTestInfos.add(INT_TO_LONG); + rtTestInfos.add(OR_LONG); + rtTestInfos.add(IF_GEZ); + rtTestInfos.add(SHL_INT); + rtTestInfos.add(LONG_TO_FLOAT); + rtTestInfos.add(DIV_INT); + rtTestInfos.add(AND_LONG); + rtTestInfos.add(DOUBLE_TO_LONG); + rtTestInfos.add(MUL_LONG); + rtTestInfos.add(DOUBLE_TO_INT); + rtTestInfos.add(IF_NEZ); + rtTestInfos.add(APUT_OBJECT); + rtTestInfos.add(IF_LT); + rtTestInfos.add(INT_TO_DOUBLE); + rtTestInfos.add(MUL_INT); + rtTestInfos.add(SPUT); + rtTestInfos.add(SHL_LONG); + rtTestInfos.add(NEG_LONG); + rtTestInfos.add(LONG_TO_INT); + rtTestInfos.add(OPC_GOTO); + rtTestInfos.add(INT_TO_FLOAT); + rtTestInfos.add(XOR_LONG); + rtTestInfos.add(MONITOR_ENTER); + rtTestInfos.add(IF_EQZ); + rtTestInfos.add(INVOKE_DIRECT); + rtTestInfos.add(CMPL_FLOAT); + rtTestInfos.add(CHECK_CAST); + rtTestInfos.add(OPC_THROW); + rtTestInfos.add(INT_TO_SHORT); + rtTestInfos.add(PACKED_SWITCH); + rtTestInfos.add(AGET_CHAR); + rtTestInfos.add(RETURN_OBJECT); + rtTestInfos.add(OPC_CONST); + rtTestInfos.add(SUB_INT); + rtTestInfos.add(APUT_CHAR); + rtTestInfos.add(NEG_INT); + rtTestInfos.add(MUL_DOUBLE); + rtTestInfos.add(DOUBLE_TO_FLOAT); + rtTestInfos.add(INT_TO_BYTE); + rtTestInfos.add(IF_LE); + rtTestInfos.add(INVOKE_VIRTUAL); + rtTestInfos.add(DIV_DOUBLE); + rtTestInfos.add(IF_GT); + rtTestInfos.add(AGET_SHORT); + rtTestInfos.add(CONST_STRING); + rtTestInfos.add(OR_INT); + rtTestInfos.add(REM_INT); + rtTestInfos.add(REM_DOUBLE); + rtTestInfos.add(LONG_TO_DOUBLE); + rtTestInfos.add(IF_NE); + rtTestInfos.add(CMP_LONG); + rtTestInfos.add(SGET); + rtTestInfos.add(AGET_WIDE); + rtTestInfos.add(IF_LTZ); + rtTestInfos.add(OPC_INSTANCEOF); + rtTestInfos.add(NEG_DOUBLE); + rtTestInfos.add(RETURN_WIDE); + rtTestInfos.add(FLOAT_TO_DOUBLE); + rtTestInfos.add(APUT_SHORT); + rtTestInfos.add(CMPG_DOUBLE); + rtTestInfos.add(IF_LEZ); + rtTestInfos.add(IF_EQ); + rtTestInfos.add(NEW_ARRAY); + rtTestInfos.add(SHR_LONG); + rtTestInfos.add(ADD_DOUBLE); + rtTestInfos.add(DIV_LONG); + rtTestInfos.add(SPARSE_SWITCH); + rtTestInfos.add(INVOKE_INTERFACE); + rtTestInfos.add(APUT_WIDE); + rtTestInfos.add(AGET_BYTE); + rtTestInfos.add(APUT); + rtTestInfos.add(SHR_INT); + rtTestInfos.add(OPC_RETURN); + rtTestInfos.add(INVOKE_SUPER); + rtTestInfos.add(MUL_FLOAT); + rtTestInfos.add(SUB_FLOAT); + rtTestInfos.add(ADD_INT); + rtTestInfos.add(INT_TO_CHAR); + rtTestInfos.add(AND_INT); + rtTestInfos.add(CMPG_FLOAT); + rtTestInfos.add(IGET); + rtTestInfos.add(REM_FLOAT); + } +} diff --git a/jack-tests/tests/com/android/jack/optimizations/exprsimplifier/ExprsimplifierTests.java b/jack-tests/tests/com/android/jack/optimizations/exprsimplifier/ExprsimplifierTests.java new file mode 100644 index 00000000..2534c3ca --- /dev/null +++ b/jack-tests/tests/com/android/jack/optimizations/exprsimplifier/ExprsimplifierTests.java @@ -0,0 +1,49 @@ +/* +* 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.optimizations.exprsimplifier; + +import com.android.jack.test.category.RuntimeRegressionTest; +import com.android.jack.test.helper.RuntimeTestHelper; +import com.android.jack.test.runtime.RuntimeTest; +import com.android.jack.test.runtime.RuntimeTestInfo; +import com.android.jack.test.toolchain.AbstractTestTools; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +public class ExprsimplifierTests extends RuntimeTest { + + private RuntimeTestInfo TEST001 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.optimizations.exprsimplifier.test001"), + "com.android.jack.optimizations.exprsimplifier.test001.dx.Tests"); + + @BeforeClass + public static void setUpClass() { + ExprsimplifierTests.class.getClassLoader().setDefaultAssertionStatus(true); + } + @Test + @Category(RuntimeRegressionTest.class) + public void test001() throws Exception { + new RuntimeTestHelper(TEST001).compileAndRunTest(); + } + + @Override + protected void fillRtTestInfos() { + rtTestInfos.add(TEST001); + } +} diff --git a/jack-tests/tests/com/android/jack/optimizations/notsimplifier/NotsimplifierTests.java b/jack-tests/tests/com/android/jack/optimizations/notsimplifier/NotsimplifierTests.java new file mode 100644 index 00000000..0962ae2f --- /dev/null +++ b/jack-tests/tests/com/android/jack/optimizations/notsimplifier/NotsimplifierTests.java @@ -0,0 +1,49 @@ +/* +* 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.optimizations.notsimplifier; + +import com.android.jack.test.category.RuntimeRegressionTest; +import com.android.jack.test.helper.RuntimeTestHelper; +import com.android.jack.test.runtime.RuntimeTest; +import com.android.jack.test.runtime.RuntimeTestInfo; +import com.android.jack.test.toolchain.AbstractTestTools; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +public class NotsimplifierTests extends RuntimeTest { + + private RuntimeTestInfo TEST001 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.optimizations.notsimplifier.test001"), + "com.android.jack.optimizations.notsimplifier.test001.dx.Tests"); + + @BeforeClass + public static void setUpClass() { + NotsimplifierTests.class.getClassLoader().setDefaultAssertionStatus(true); + } + @Test + @Category(RuntimeRegressionTest.class) + public void test001() throws Exception { + new RuntimeTestHelper(TEST001).compileAndRunTest(); + } + + @Override + protected void fillRtTestInfos() { + rtTestInfos.add(TEST001); + } +} diff --git a/jack/tests/com/android/jack/optimizations/UselessVariableCopyTest.java b/jack-tests/tests/com/android/jack/optimizations/uselesscopy/UselessVariableCopyTest.java index 3ba4fe0b..eaae6aee 100644 --- a/jack/tests/com/android/jack/optimizations/UselessVariableCopyTest.java +++ b/jack-tests/tests/com/android/jack/optimizations/uselesscopy/UselessVariableCopyTest.java @@ -14,11 +14,12 @@ * limitations under the License. */ -package com.android.jack.optimizations; +package com.android.jack.optimizations.uselesscopy; -import com.android.jack.Options; import com.android.jack.TestTools; -import com.android.jack.category.KnownBugs; +import com.android.jack.test.category.KnownBugs; +import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.JackBasedToolchain; import junit.framework.Assert; @@ -41,14 +42,17 @@ public class UselessVariableCopyTest { @Test @Category(KnownBugs.class) public void test001() throws Exception { - File out = TestTools.createTempFile("uselessMovInstructions", ".dex"); - Options options = new Options(); - options.disableDxOptimizations(); - TestTools.compileSourceToDex(options, - TestTools.getJackTestsWithJackFolder("optimizations/uselesscopy/test001"), - TestTools.getClasspathAsString(TestTools.getDefaultBootclasspath()), out, false); + File out = AbstractTestTools.createTempDir(); + File outDex = new File(out, "classes.dex"); + JackBasedToolchain toolchain = AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class); + toolchain.disableDxOptimizations(); + toolchain.srcToExe( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + out, + /* zipFile = */ false, + AbstractTestTools.getTestRootDir("com.android.jack.optimizations.uselesscopy.test001.jack")); - DexFile dexFile = new DexFile(out); + DexFile dexFile = new DexFile(outDex); CodeItem ci = TestTools.getEncodedMethod(dexFile, "Lcom/android/jack/optimizations/uselesscopy/test001/jack/Test001;", "test", diff --git a/jack-tests/tests/com/android/jack/order/OrderTests.java b/jack-tests/tests/com/android/jack/order/OrderTests.java new file mode 100644 index 00000000..c62c8003 --- /dev/null +++ b/jack-tests/tests/com/android/jack/order/OrderTests.java @@ -0,0 +1,49 @@ +/* +* 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.order; + +import com.android.jack.test.category.RuntimeRegressionTest; +import com.android.jack.test.helper.RuntimeTestHelper; +import com.android.jack.test.runtime.RuntimeTest; +import com.android.jack.test.runtime.RuntimeTestInfo; +import com.android.jack.test.toolchain.AbstractTestTools; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +public class OrderTests extends RuntimeTest { + + private RuntimeTestInfo TEST001 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.order.test001"), + "com.android.jack.order.test001.dx.Tests"); + + @BeforeClass + public static void setUpClass() { + OrderTests.class.getClassLoader().setDefaultAssertionStatus(true); + } + @Test + @Category(RuntimeRegressionTest.class) + public void test001() throws Exception { + new RuntimeTestHelper(TEST001).compileAndRunTest(); + } + + @Override + protected void fillRtTestInfos() { + rtTestInfos.add(TEST001); + } +} diff --git a/jack-tests/tests/com/android/jack/order/dx/Tests.java b/jack-tests/tests/com/android/jack/order/test001/dx/Tests.java index 4c2243bf..9d272672 100644 --- a/jack-tests/tests/com/android/jack/order/dx/Tests.java +++ b/jack-tests/tests/com/android/jack/order/test001/dx/Tests.java @@ -14,9 +14,9 @@ * limitations under the License. */ -package com.android.jack.order.dx; +package com.android.jack.order.test001.dx; -import com.android.jack.order.jack.Order; +import com.android.jack.order.test001.jack.Order; import org.junit.Assert; import org.junit.Test; diff --git a/jack-tests/tests/com/android/jack/order/jack/Order.java b/jack-tests/tests/com/android/jack/order/test001/jack/Order.java index 47ee620f..770f9f9b 100644 --- a/jack-tests/tests/com/android/jack/order/jack/Order.java +++ b/jack-tests/tests/com/android/jack/order/test001/jack/Order.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.jack.order.jack; +package com.android.jack.order.test001.jack; /** * Evaluation order test. diff --git a/jack-tests/tests/com/android/jack/preprocessor/PreProcessorTests.java b/jack-tests/tests/com/android/jack/preprocessor/PreProcessorTests.java new file mode 100644 index 00000000..e5627bb7 --- /dev/null +++ b/jack-tests/tests/com/android/jack/preprocessor/PreProcessorTests.java @@ -0,0 +1,109 @@ +/* + * 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.preprocessor; + +import com.android.jack.Main; +import com.android.jack.Options; +import com.android.jack.TestTools; +import com.android.jack.ir.ast.JAnnotation; +import com.android.jack.ir.ast.JDefinedClassOrInterface; +import com.android.jack.ir.ast.JMethod; +import com.android.jack.ir.ast.JSession; +import com.android.jack.lookup.JNodeLookup; +import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.JackBasedToolchain; +import com.android.sched.util.RunnableHooks; + +import junit.framework.Assert; + +import org.antlr.runtime.ANTLRFileStream; +import org.antlr.runtime.CommonTokenStream; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.File; +import java.util.Collection; + +public class PreProcessorTests { + + @BeforeClass + public static void setUpClass() throws Exception { + Main.class.getClassLoader().setDefaultAssertionStatus(true); + } + + @Test + public void test001_002() throws Exception { + File testDir = AbstractTestTools.getTestRootDir("com.android.jack.preprocessor.test001.jack"); + JackBasedToolchain toolchain = AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class); + toolchain.addProperty(PreProcessor.ENABLE.getName(), "true"); + toolchain.addProperty(PreProcessor.FILE.getName(), + new File(testDir, "config.jpp").getAbsolutePath()); + toolchain.srcToExe( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + AbstractTestTools.createTempFile("annotationAdderTest", ".out.zip"), + /* zipFile = */ true, + testDir); + } + + @Test + public void test001_001() throws Exception { + File testDir = AbstractTestTools.getTestRootDir("com.android.jack.preprocessor.test001.jack"); + File tempDir = AbstractTestTools.createTempDir(); + JackBasedToolchain toolchain = AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class); + toolchain.srcToLib( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + tempDir, + /* zipFiles = */ false, + testDir); + + Options args = TestTools.buildCommandLineArgs( + new File(testDir, "app1/ApplicationActivity1.java")); + args.setClasspath(tempDir.getPath()); + RunnableHooks hooks = new RunnableHooks(); + JSession session = TestTools.buildSession(args, hooks); + ANTLRFileStream in = new ANTLRFileStream(new File(testDir, "config.jpp").getAbsolutePath()); + PreProcessorLexer lexer = new PreProcessorLexer(in); + CommonTokenStream tokens = new CommonTokenStream(lexer); + PreProcessorParser parser = new PreProcessorParser(tokens); + Collection<Rule> rules = parser.rules(session); + Scope scope = new TypeToEmitScope(session); + for (Rule rule : rules) { + Context context = new Context(); + if (!rule.getSet().eval(scope, context).isEmpty()) { + context.getRequest(session).commit(); + } + } + + JAnnotation installerAnnotation = session.getPhantomLookup().getAnnotation( + "Lcom/android/jack/preprocessor/test001/jack/MultiDexInstaller;"); + JNodeLookup lookup = session.getLookup(); + { + JDefinedClassOrInterface coi = lookup.getClass( + "Lcom/android/jack/preprocessor/test001/jack/app1/ApplicationActivity1;"); + Assert.assertFalse(coi.getAnnotations(installerAnnotation).isEmpty()); + for (JMethod method : coi.getMethods()) { + if (method.getName().equals("noAnnotation")) { + Assert.assertTrue(method.getAnnotations(installerAnnotation).isEmpty()); + } else { + Assert.assertFalse(method.getAnnotations(installerAnnotation).isEmpty()); + } + } + } + + hooks.runHooks(); + } +} diff --git a/jack/tests/com/android/jack/ResourceTest.java b/jack-tests/tests/com/android/jack/resource/ResourceTests.java index b42ae80d..4a364b05 100644 --- a/jack/tests/com/android/jack/ResourceTest.java +++ b/jack-tests/tests/com/android/jack/resource/ResourceTests.java @@ -14,10 +14,16 @@ * limitations under the License. */ -package com.android.jack; +package com.android.jack.resource; -import com.android.jack.category.KnownBugs; +import com.android.jack.Options; +import com.android.jack.ProguardFlags; +import com.android.jack.TestTools; +import com.android.jack.test.category.KnownBugs; import com.android.jack.library.FileType; +import com.android.jack.shrob.obfuscation.NameProviderFactory; +import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.JackBasedToolchain; import com.android.sched.util.stream.ByteStreamSucker; import junit.framework.Assert; @@ -43,7 +49,7 @@ import javax.annotation.Nonnull; /** * JUnit tests for resource support. */ -public class ResourceTest { +public class ResourceTests { @Nonnull private static final String COMMON_PATH = "com/android/jack/resource/test001/jack/"; @@ -61,13 +67,14 @@ public class ResourceTest { private static final String RESOURCE3_SHORTPATH = "pack/Resource3"; @Nonnull private static final String RESOURCE4_SHORTPATH = "pack/Resource4"; + @Nonnull private static final File FILE = - TestTools.getJackTestsWithJackFolder("resource/test001"); + AbstractTestTools.getTestRootDir("com.android.jack.resource.test001.jack"); @BeforeClass public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); + ResourceTests.class.getClassLoader().setDefaultAssertionStatus(true); } @Test @@ -77,7 +84,8 @@ public class ResourceTest { // compile Jack archive to a dex dir File dexDir = TestTools.createTempDir("resourcetestdex", "dir"); - TestTools.compileJackToDex(new Options(), jackAr, dexDir, false /* zipped */); + JackBasedToolchain toolchain = AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class); + toolchain.libToExe(jackAr, dexDir, /* zipFile = */ false); // check that resources are contained in dex dir checkResourceContentFromDir(dexDir, RESOURCE1_SHORTPATH, "Res1", /*isLib*/ false); @@ -92,8 +100,9 @@ public class ResourceTest { File jackAr = createJackArchiveWithResources(); // compile Jack archive to dex archive - File dexAr = TestTools.createTempFile("resourcetestdex", ".zip"); - TestTools.compileJackToDex(new Options(), jackAr, dexAr, true /* zipped */); + File dexAr = AbstractTestTools.createTempFile("resourcetestdex", ".zip"); + JackBasedToolchain toolchain = AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class); + toolchain.libToExe(jackAr, dexAr, /* zipFile = */ true); // check that resources are contained in dex archive ZipFile zipFile = new ZipFile(dexAr); @@ -105,6 +114,9 @@ public class ResourceTest { @Test public void testJackDirToDexArchive() throws Exception { + + // TODO(jmhenaff) adapt this after rebase. Add API for resources + // compile source file to a Jack dir File jackFolder = TestTools.createTempDir("tempjack", "dir"); Options options = new Options(); @@ -122,6 +134,33 @@ public class ResourceTest { checkResourceContentFromZip(zipFile, RESOURCE2_SHORTPATH, "Res2", /*isLib*/ false); checkResourceContentFromZip(zipFile, RESOURCE3_SHORTPATH, "Res3", /*isLib*/ false); checkResourceContentFromZip(zipFile, RESOURCE4_SHORTPATH, "Res4", /*isLib*/ false); + +// // compile source file to a Jack dir +// File jackFolder = AbstractTestTools.createTempDir(); +// JackBasedToolchain toolchain = AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class); +// toolchain.srcToLib( +// AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), +// jackFolder, +// /* zipFiles = */ false, +// FILE); +// +// // add resources to Jack dir +// copyFileToDir(new File(FILE, RESOURCE1_SHORTPATH), RESOURCE1_LONGPATH, jackFolder); +// copyFileToDir(new File(FILE, RESOURCE2_SHORTPATH), RESOURCE2_LONGPATH, jackFolder); +// copyFileToDir(new File(FILE, RESOURCE3_SHORTPATH), RESOURCE3_LONGPATH, jackFolder); +// copyFileToDir(new File(FILE, RESOURCE4_SHORTPATH), RESOURCE4_LONGPATH, jackFolder); +// +// // compile Jack dir to dex archive +// File dexAr = TestTools.createTempFile("resourcetestdex", ".zip"); +// toolchain = AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class); +// toolchain.libToDex(jackFolder, dexAr, /* zipFile = */ true); +// +// // check that resources are contained in dex archive +// ZipFile zipFile = new ZipFile(dexAr); +// checkResourceContent(zipFile, RESOURCE1_LONGPATH, "Res1"); +// checkResourceContent(zipFile, RESOURCE2_LONGPATH, "Res2"); +// checkResourceContent(zipFile, RESOURCE3_LONGPATH, "Res3"); +// checkResourceContent(zipFile, RESOURCE4_LONGPATH, "Res4"); } @Test @@ -130,14 +169,10 @@ public class ResourceTest { File jackAr = createJackArchiveWithResources(); // run shrobbing from Jack archive to Jack archive - File shrobbedJackAr = TestTools.createTempFile("shrobbedJackAr", ".zip"); - ProguardFlags flags = new ProguardFlags(new File(FILE, "proguard.flags")); - TestTools.shrobJackToJack(new Options(), - jackAr, - null /* classpath */, - shrobbedJackAr, - Collections.singletonList(flags), - true /* zipped */); + File shrobbedJackAr = AbstractTestTools.createTempFile("shrobbedJackAr", ".zip"); + JackBasedToolchain toolchain = AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class); + toolchain.addProguardFlags(new File(FILE, "proguard.flags")); + toolchain.libToLib(jackAr, shrobbedJackAr, /* zipFiles = */ true); // check that resources are contained in dex archive ZipFile zipFile = new ZipFile(shrobbedJackAr); @@ -172,6 +207,35 @@ public class ResourceTest { checkResourceContentFromZip(zipFile, RESOURCE2_SHORTPATH, "Res2", /*isLib*/ true); checkResourceContentFromZip(zipFile, RESOURCE3_SHORTPATH, "Res3", /*isLib*/ true); checkResourceContentFromZip(zipFile, RESOURCE4_SHORTPATH, "Res4", /*isLib*/ true); + +// // compile source file to a Jack dir +// File jackFolder = TestTools.createTempDir("tempjack", "dir"); +// JackBasedToolchain toolchain = AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class); +// toolchain.srcToLib( +// AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), +// jackFolder, +// /* zipFiles = */ false, +// FILE); +// +// +// // add resources to Jack dir +// copyFileToDir(new File(FILE, RESOURCE1_SHORTPATH), RESOURCE1_LONGPATH, jackFolder); +// copyFileToDir(new File(FILE, RESOURCE2_SHORTPATH), RESOURCE2_LONGPATH, jackFolder); +// copyFileToDir(new File(FILE, RESOURCE3_SHORTPATH), RESOURCE3_LONGPATH, jackFolder); +// copyFileToDir(new File(FILE, RESOURCE4_SHORTPATH), RESOURCE4_LONGPATH, jackFolder); +// +// // run shrobbing from Jack dir to Jack archive +// File shrobbedJackAr = AbstractTestTools.createTempFile("shrobbedJackAr", ".zip"); +// toolchain = AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class); +// toolchain.addProguardFlags(new File(FILE, "proguard.flags")); +// toolchain.libToLib(jackFolder, shrobbedJackAr, /* zipFiles = */ true); +// +// // check that resources are contained in Jack archive +// ZipFile zipFile = new ZipFile(shrobbedJackAr); +// checkResourceContent(zipFile, RESOURCE1_LONGPATH, "Res1"); +// checkResourceContent(zipFile, RESOURCE2_LONGPATH, "Res2"); +// checkResourceContent(zipFile, RESOURCE3_LONGPATH, "Res3"); +// checkResourceContent(zipFile, RESOURCE4_LONGPATH, "Res4"); } @Test @@ -180,20 +244,17 @@ public class ResourceTest { File jackAr = createJackArchiveWithResources(); // run shrobbing from Jack archive to Jack dir - File shrobbedJackDir = TestTools.createTempDir("shrobbedJack", "dir"); - ProguardFlags flags = new ProguardFlags(new File(FILE, "proguard.flags")); - TestTools.shrobJackToJack(new Options(), - jackAr, - null /* classpath */, - shrobbedJackDir, - Collections.singletonList(flags), - false /* non-zipped */); + File shrobbedJackDir = AbstractTestTools.createTempDir(); + JackBasedToolchain toolchain = AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class); + toolchain.addProguardFlags(new File(FILE, "proguard.flags")); + toolchain.libToLib(jackAr, shrobbedJackDir, /* zipFiles = */ false); // check that resources are contained in Jack dir checkResourceContentFromDir(shrobbedJackDir, RESOURCE1_SHORTPATH, "Res1", /*isLib*/ true); checkResourceContentFromDir(shrobbedJackDir, RESOURCE2_SHORTPATH, "Res2", /*isLib*/ true); checkResourceContentFromDir(shrobbedJackDir, RESOURCE3_SHORTPATH, "Res3", /*isLib*/ true); checkResourceContentFromDir(shrobbedJackDir, RESOURCE4_SHORTPATH, "Res4", /*isLib*/ true); + } @Test @@ -220,6 +281,35 @@ public class ResourceTest { checkResourceContentFromDir(shrobbedJackDir, RESOURCE2_SHORTPATH, "Res2", /*isLib*/ true); checkResourceContentFromDir(shrobbedJackDir, RESOURCE3_SHORTPATH, "Res3", /*isLib*/ true); checkResourceContentFromDir(shrobbedJackDir, RESOURCE4_SHORTPATH, "Res4", /*isLib*/ true); + + +// // compile source file to a Jack dir +// File jackFolder = AbstractTestTools.createTempDir(); +// JackBasedToolchain toolchain = AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class); +// toolchain.srcToLib( +// AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), +// jackFolder, +// /* zipFiles = */ false, +// FILE); +// +// // add resources to Jack dir +// copyFileToDir(new File(FILE, RESOURCE1_SHORTPATH), RESOURCE1_LONGPATH, jackFolder); +// copyFileToDir(new File(FILE, RESOURCE2_SHORTPATH), RESOURCE2_LONGPATH, jackFolder); +// copyFileToDir(new File(FILE, RESOURCE3_SHORTPATH), RESOURCE3_LONGPATH, jackFolder); +// copyFileToDir(new File(FILE, RESOURCE4_SHORTPATH), RESOURCE4_LONGPATH, jackFolder); +// +// // run shrobbing from Jack dir to Jack dir +// File shrobbedJackDir = AbstractTestTools.createTempDir(); +// toolchain = AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class); +// toolchain.addProguardFlags(new File(FILE, "proguard.flags")); +// toolchain.libToLib(jackFolder, shrobbedJackDir, /* zipFiles = */ false); +// +// +// // check that resources are contained in Jack dir +// checkResourceContent(shrobbedJackDir, RESOURCE1_LONGPATH, "Res1"); +// checkResourceContent(shrobbedJackDir, RESOURCE2_LONGPATH, "Res2"); +// checkResourceContent(shrobbedJackDir, RESOURCE3_LONGPATH, "Res3"); +// checkResourceContent(shrobbedJackDir, RESOURCE4_LONGPATH, "Res4"); } @Test @@ -240,6 +330,32 @@ public class ResourceTest { checkResourceContentFromDir(dexDir, RESOURCE2_SHORTPATH, "Res2", /*isLib*/ false); checkResourceContentFromDir(dexDir, RESOURCE3_SHORTPATH, "Res3", /*isLib*/ false); checkResourceContentFromDir(dexDir, RESOURCE4_SHORTPATH, "Res4", /*isLib*/ false); + +// // compile source file to a Jack dir +// File jackFolder = AbstractTestTools.createTempDir(); +// JackBasedToolchain toolchain = AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class); +// toolchain.srcToLib( +// AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), +// jackFolder, +// /* zipFiles = */ false, +// FILE); +// +// // add resources to Jack dir +// copyFileToDir(new File(FILE, RESOURCE1_SHORTPATH), RESOURCE1_LONGPATH, jackFolder); +// copyFileToDir(new File(FILE, RESOURCE2_SHORTPATH), RESOURCE2_LONGPATH, jackFolder); +// copyFileToDir(new File(FILE, RESOURCE3_SHORTPATH), RESOURCE3_LONGPATH, jackFolder); +// copyFileToDir(new File(FILE, RESOURCE4_SHORTPATH), RESOURCE4_LONGPATH, jackFolder); +// +// // compile Jack dir to a dex dir +// File dexDir = AbstractTestTools.createTempDir(); +// AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class) +// .libToDex(jackFolder, dexDir, /* zipFile = */ false); +// +// // check that resources are contained in dex dir +// checkResourceContent(dexDir, RESOURCE1_LONGPATH, "Res1"); +// checkResourceContent(dexDir, RESOURCE2_LONGPATH, "Res2"); +// checkResourceContent(dexDir, RESOURCE3_LONGPATH, "Res3"); +// checkResourceContent(dexDir, RESOURCE4_LONGPATH, "Res4"); } @Test @@ -261,18 +377,48 @@ public class ResourceTest { checkResourceContentFromDir(dexDir, RESOURCE2_SHORTPATH, "Res2", /*isLib*/ false); checkResourceContentFromDir(dexDir, RESOURCE3_SHORTPATH, "Res3", /*isLib*/ false); checkResourceContentFromDir(dexDir, RESOURCE4_SHORTPATH, "Res4", /*isLib*/ false); + +// // compile source file to a Jack dir +// File jackFolder = AbstractTestTools.createTempDir(); +// JackBasedToolchain toolchain = AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class); +// toolchain.srcToLib( +// AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), +// jackFolder, +// /* zipFiles = */ false, +// FILE); +// +// // add resources to Jack dir +// copyFileToDir(new File(FILE, RESOURCE1_SHORTPATH), RESOURCE1_LONGPATH, jackFolder); +// copyFileToDir(new File(FILE, RESOURCE2_SHORTPATH), RESOURCE2_LONGPATH, jackFolder); +// copyFileToDir(new File(FILE, RESOURCE3_SHORTPATH), RESOURCE3_LONGPATH, jackFolder); +// copyFileToDir(new File(FILE, RESOURCE4_SHORTPATH), RESOURCE4_LONGPATH, jackFolder); +// +// // compile Jack dir to same dir +// File dexDir = jackFolder; +// AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class) +// .libToDex(jackFolder, dexDir, /* zipFile = */ false); +// +// // check that resources are contained in dex dir +// checkResourceContent(dexDir, RESOURCE1_LONGPATH, "Res1"); +// checkResourceContent(dexDir, RESOURCE2_LONGPATH, "Res2"); +// checkResourceContent(dexDir, RESOURCE3_LONGPATH, "Res3"); +// checkResourceContent(dexDir, RESOURCE4_LONGPATH, "Res4"); } @Test @Category(KnownBugs.class) public void testResourceContentAdaptation() throws Exception { - /// compile source file to a Jack dir - File jackOutputFolder = TestTools.createTempDir("tempjack", "dir"); - String testName = "resource/test003"; - File testFolder = TestTools.getJackTestFolder(testName); - File jackTestFolder = TestTools.getJackTestsWithJackFolder(testName); - TestTools.compileSourceToJack(new Options(), testFolder, TestTools.getDefaultBootclasspathString(), - jackOutputFolder, false /* non-zipped */); + // compile source file to a Jack dir + File jackOutputFolder = AbstractTestTools.createTempDir(); + //String testName = "resource/test003"; + File testFolder = AbstractTestTools.getTestRootDir("com.android.jack.resource.test003"); + File jackTestFolder = AbstractTestTools.getTestRootDir("com.android.jack.resource.test003.jack"); + JackBasedToolchain toolchain = AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class); + toolchain.srcToLib( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + jackOutputFolder, + /* zipFiles = */ false, + testFolder); String resource1LongPath = "com/android/jack/resource/test003/jack/A"; String resource2LongPath = "com/android/jack/resource/test003/jack/A.txt"; @@ -281,17 +427,11 @@ public class ResourceTest { copyFileToDir(new File(jackTestFolder, "A.txt"), resource1LongPath, jackOutputFolder); copyFileToDir(new File(jackTestFolder, "A.txt"), resource2LongPath, jackOutputFolder); - // run shrobbing from Jack dir to Jack dir - Options options = new Options(); - options.setNameProvider("rot13"); - File shrobbedJackDir = TestTools.createTempDir("shrobbedJack", "dir"); - ProguardFlags flags = new ProguardFlags(new File(testFolder, "proguard.flags001")); - TestTools.shrobJackToJack(options, - jackOutputFolder, - TestTools.getDefaultBootclasspathString(), - shrobbedJackDir, - Collections.singletonList(flags), - false /* non-zipped */); + toolchain = AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class); + toolchain.addProperty(NameProviderFactory.NAMEPROVIDER.getName(), "rot13"); + File shrobbedJackDir = AbstractTestTools.createTempDir(); + toolchain.addProguardFlags(new File(testFolder, "proguard.flags001")); + toolchain.libToLib(jackOutputFolder, shrobbedJackDir, /* zipFiles = */ false); // check that resources are contained in Jack dir and check their contents File referenceFileContent = new File(testFolder, "refs/A.txt"); @@ -312,6 +452,34 @@ public class ResourceTest { jackAr, true /* non-zipped */); return jackAr; + +// // compile source file to a Jack file +// File tempJackFolder = AbstractTestTools.createTempDir(); +// JackBasedToolchain toolchain = AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class); +// toolchain.srcToLib( +// AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), +// tempJackFolder, +// /* zipFiles = */ false, +// FILE); +// +// // create Jack archive with resources +// File singleJackFile = new File(tempJackFolder, JACK_FILE_PATH); +// File jackAr = AbstractTestTools.createTempFile("resourcetestjack", ".zip"); +// ZipOutputStream zos = null; +// try { +// zos = new ZipOutputStream(new FileOutputStream(jackAr)); +// +// copyFileToZip(singleJackFile, JACK_FILE_PATH, zos); +// copyFileToZip(new File(FILE, RESOURCE1_SHORTPATH), RESOURCE1_LONGPATH, zos); +// copyFileToZip(new File(FILE, RESOURCE2_SHORTPATH), RESOURCE2_LONGPATH, zos); +// copyFileToZip(new File(FILE, RESOURCE3_SHORTPATH), RESOURCE3_LONGPATH, zos); +// copyFileToZip(new File(FILE, RESOURCE4_SHORTPATH), RESOURCE4_LONGPATH, zos); +// } finally { +// if (zos != null) { +// zos.close(); +// } +// } +// return jackAr; } private void checkResourceContentFromZip(@Nonnull ZipFile zipFile, @Nonnull String entryName, @@ -357,6 +525,7 @@ public class ResourceTest { } } + private void checkResourceContent(@Nonnull File candidateFileContent, @Nonnull File referenceFileContent) throws IOException { Assert.assertTrue(candidateFileContent.exists()); @@ -416,4 +585,5 @@ public class ResourceTest { } } } + } diff --git a/jack-tests/tests/com/android/jack/returnstatement/ReturnstatementTests.java b/jack-tests/tests/com/android/jack/returnstatement/ReturnstatementTests.java new file mode 100644 index 00000000..1af46dc7 --- /dev/null +++ b/jack-tests/tests/com/android/jack/returnstatement/ReturnstatementTests.java @@ -0,0 +1,75 @@ +/* +* 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.returnstatement; + +import com.android.jack.test.category.RuntimeRegressionTest; +import com.android.jack.test.helper.RuntimeTestHelper; +import com.android.jack.test.runtime.RuntimeTest; +import com.android.jack.test.runtime.RuntimeTestInfo; +import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.IToolchain; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import java.io.File; + +public class ReturnstatementTests extends RuntimeTest { + + private RuntimeTestInfo RETURNS = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.returnstatement.returns"), + "com.android.jack.returnstatement.returns.dx.Tests"); + + private RuntimeTestInfo RETURNVOID = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.returnstatement.returnvoid"), + "com.android.jack.returnstatement.returnvoid.dx.Tests"); + + @BeforeClass + public static void setUpClass() { + ReturnstatementTests.class.getClassLoader().setDefaultAssertionStatus(true); + } + @Test + @Category(RuntimeRegressionTest.class) + public void returns() throws Exception { + new RuntimeTestHelper(RETURNS).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void returnvoid() throws Exception { + new RuntimeTestHelper(RETURNVOID).compileAndRunTest(); + } + + @Test + public void ropBuildMethodWithSameReturnReg() throws Exception { + IToolchain toolchain = AbstractTestTools.getCandidateToolchain(); + + String classpath = AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()); + File dexOutDir = AbstractTestTools.createTempDir(); + File testSourceDir = AbstractTestTools.getTestRootDir("com.android.jack.analysis.dfa.reachingdefs.test001"); + + toolchain.srcToExe(classpath, dexOutDir, /* zipFile = */ false, testSourceDir); + + } + + @Override + protected void fillRtTestInfos() { + rtTestInfos.add(RETURNS); + rtTestInfos.add(RETURNVOID); + } +} diff --git a/jack-tests/tests/com/android/jack/shrob/AbstractTest.java b/jack-tests/tests/com/android/jack/shrob/AbstractTest.java index 319abaff..22896b6a 100644 --- a/jack-tests/tests/com/android/jack/shrob/AbstractTest.java +++ b/jack-tests/tests/com/android/jack/shrob/AbstractTest.java @@ -19,8 +19,8 @@ package com.android.jack.shrob; import com.android.jack.Main; import com.android.jack.ProguardFlags; import com.android.jack.TestTools; -import com.android.jack.category.KnownBugs; -import com.android.jack.category.SlowTests; +import com.android.jack.test.category.KnownBugs; +import com.android.jack.test.category.SlowTests; import org.junit.BeforeClass; import org.junit.Test; diff --git a/jack/tests/com/android/jack/shrob/AnnotationsTest.java b/jack-tests/tests/com/android/jack/shrob/AnnotationsTest.java index 1d18afe5..cf819021 100644 --- a/jack/tests/com/android/jack/shrob/AnnotationsTest.java +++ b/jack-tests/tests/com/android/jack/shrob/AnnotationsTest.java @@ -16,33 +16,36 @@ package com.android.jack.shrob; -import com.android.jack.AnnotationTestTools; import com.android.jack.ProguardFlags; import com.android.jack.TestTools; +import com.android.jack.test.comparator.ComparatorDexAnnotations; +import com.android.jack.test.helper.SourceToDexComparisonTestHelper; +import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.JackBasedToolchain; import java.io.File; -import javax.annotation.CheckForNull; import javax.annotation.Nonnull; public class AnnotationsTest extends AbstractTest { @Override protected void runTest( - @CheckForNull File[] bootclasspath, - @CheckForNull File[] classpath, @Nonnull String testNumber, @Nonnull String flagNumber, @Nonnull String mappingNumber) throws Exception { - String testName = "shrob/test" + testNumber; - File testFolder = TestTools.getJackTestFolder(testName); - ProguardFlags[] proguardflagsFiles = new ProguardFlags[] { + File testFolder = AbstractTestTools.getTestRootDir("com.android.jack.shrob.test" + testNumber); + JackBasedToolchain toolchain = AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class); + + SourceToDexComparisonTestHelper env = + new SourceToDexComparisonTestHelper(new File(testFolder, "jack")); + env.setCandidateTestTools(toolchain); + env.setProguardFlags( generateApplyMapping(new File(testFolder,"proguard.flags" + flagNumber + ".mapping" + mappingNumber)), -// new ProguardFlags(TestTools.getJackTestFolder("shrob"),"keepDebugInfo.flags"), - new ProguardFlags(TestTools.getJackTestFolder("shrob"),"keepAllAttributes.flags"), - new ProguardFlags(testFolder,"proguard.flags" + flagNumber) - }; - AnnotationTestTools.checkStructure(bootclasspath, classpath, TestTools.getJackTestsWithJackFolder(testName), proguardflagsFiles); +// new ProguardFlags(TestTools.getJackTestFolder("shrob"),"keepDebugInfo.flags"), + new ProguardFlags(TestTools.getJackTestFolder("shrob"),"keepAllAttributes.flags"), + new ProguardFlags(testFolder,"proguard.flags" + flagNumber)); + env.runTest(new ComparatorDexAnnotations(env.getCandidateDex(), env.getReferenceDex())); } } diff --git a/jack/tests/com/android/jack/shrob/FlattenPackageTest.java b/jack-tests/tests/com/android/jack/shrob/FlattenPackageTests.java index 7b6f0f3e..a07b3c9f 100644 --- a/jack/tests/com/android/jack/shrob/FlattenPackageTest.java +++ b/jack-tests/tests/com/android/jack/shrob/FlattenPackageTests.java @@ -17,45 +17,57 @@ package com.android.jack.shrob; import com.android.jack.Options; -import com.android.jack.TestTools; -import com.android.jack.category.SlowTests; +import com.android.jack.test.category.SlowTests; +import com.android.jack.shrob.obfuscation.NameProviderFactory; import com.android.jack.shrob.proguard.GrammarActions; import com.android.jack.shrob.spec.Flags; +import com.android.jack.test.comparator.ComparatorMapping; +import com.android.jack.test.helper.SourceToDexComparisonTestHelper; +import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.DummyToolchain; +import com.android.jack.test.toolchain.JackApiToolchain; import org.junit.experimental.categories.Category; import java.io.File; -import javax.annotation.CheckForNull; import javax.annotation.Nonnull; @Category(SlowTests.class) -public class FlattenPackageTest extends AbstractTest { +public class FlattenPackageTests extends AbstractTest { @Override protected void runTest( - @CheckForNull File[] bootclasspath, - @CheckForNull File[] classpath, @Nonnull String testNumber, @Nonnull String flagNumber, @Nonnull String mappingNumber) throws Exception { - String testName = "shrob/test" + testNumber; - File testFolder = TestTools.getJackTestFolder(testName); + File testFolder = AbstractTestTools.getTestRootDir("com.android.jack.shrob.test" + testNumber); + JackApiToolchain toolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); Flags flags = new Flags(); + toolchain.setShrobFlags(flags); GrammarActions.parse("proguard.flags" + flagNumber, testFolder.getAbsolutePath(), flags); GrammarActions.parse("keepPackageName.flags", - TestTools.getJackTestFolder("shrob").getAbsolutePath(), flags); + AbstractTestTools.getTestRootDir("com.android.jack.shrob").getAbsolutePath(), flags); flags.setPackageForFlatHierarchy("flatpackage"); - File candidateOutputMapping = TestTools.createTempFile("mapping", ".txt"); + File candidateOutputMapping = AbstractTestTools.createTempFile("mapping", ".txt"); File refFolder = new File(testFolder, "refsFlattenPackage"); File refOutputMapping = new File(refFolder, "expected-" + flagNumber + ".txt"); flags.setOutputMapping(candidateOutputMapping); flags.setPrintMapping(true); - Options jackOptions = new Options(); - jackOptions.setNameProvider("rot13"); - TestTools.runWithFlags(jackOptions, bootclasspath, classpath, - TestTools.getJackTestsWithJackFolder(testName), flags); - ListingComparator.compare(refOutputMapping, candidateOutputMapping); + toolchain.addProperty(NameProviderFactory.NAMEPROVIDER.getName(), "rot13"); + toolchain.addProperty(Options.METHOD_FILTER.getName(), "supported-methods"); + + SourceToDexComparisonTestHelper env = + new SourceToDexComparisonTestHelper(new File(testFolder, "jack")); + + env.setCandidateTestTools(toolchain); + env.setReferenceTestTools(new DummyToolchain()); + + // TODO(jmhenaff): Find a way to avoid this line? + // This removes JUnit from default cp, otherwise this tests seems endless + env.setCandidateClasspath(new File[] {toolchain.getDefaultBootClasspath()[0]}); + + env.runTest(new ComparatorMapping(refOutputMapping, candidateOutputMapping)); } } diff --git a/jack-tests/tests/com/android/jack/shrob/ObfuscationWithAttributesTests.java b/jack-tests/tests/com/android/jack/shrob/ObfuscationWithAttributesTests.java new file mode 100644 index 00000000..5a1feaf7 --- /dev/null +++ b/jack-tests/tests/com/android/jack/shrob/ObfuscationWithAttributesTests.java @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2012 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.shrob; + +import com.android.jack.ProguardFlags; +import com.android.jack.test.comparator.ComparatorDex; +import com.android.jack.test.helper.SourceToDexComparisonTestHelper; +import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.AndroidToolchain; +import com.android.jack.test.toolchain.JackBasedToolchain; + +import org.junit.Test; + +import java.io.File; + +import javax.annotation.Nonnull; + +public class ObfuscationWithAttributesTests extends AbstractTest { + + @Override + @Test + public void test1_001() throws Exception { + super.test1_001(); + } + + @Override + protected void runTest( + @Nonnull String testNumber, + @Nonnull String flagNumber, + @Nonnull String mappingNumber) + throws Exception { + File testFolder = AbstractTestTools.getTestRootDir("com.android.jack.shrob.test" + testNumber); + JackBasedToolchain toolchain = AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class); + File [] proguardFlags = new File [] { + generateApplyMapping(new File(testFolder,"proguard.flags" + flagNumber + ".mapping" + mappingNumber)), + new ProguardFlags(AbstractTestTools.getTestRootDir("com.android.jack.shrob"),"keepAllAttributes.flags"), + new ProguardFlags(testFolder,"proguard.flags" + flagNumber) + }; + toolchain.addProguardFlags(proguardFlags); + + AndroidToolchain refToolchain = AbstractTestTools.getReferenceToolchain(AndroidToolchain.class); + refToolchain.addProguardFlags(proguardFlags); + + SourceToDexComparisonTestHelper env = + new SourceToDexComparisonTestHelper(new File(testFolder, "jack")); + env.setCandidateTestTools(toolchain); + env.setReferenceTestTools(refToolchain); + env.setWithDebugInfo(true); + env.runTest(new ComparatorDex(env.getCandidateDex(), env.getReferenceDex())); + } +} diff --git a/jack/tests/com/android/jack/shrob/ObfuscationWithAttributesTest.java b/jack-tests/tests/com/android/jack/shrob/ObfuscationWithDebugInfoTests.java index dbd494c8..80eac52d 100644 --- a/jack/tests/com/android/jack/shrob/ObfuscationWithAttributesTest.java +++ b/jack-tests/tests/com/android/jack/shrob/ObfuscationWithDebugInfoTests.java @@ -17,32 +17,34 @@ package com.android.jack.shrob; import com.android.jack.ProguardFlags; -import com.android.jack.TestTools; +import com.android.jack.test.comparator.ComparatorDex; +import com.android.jack.test.helper.SourceToDexComparisonTestHelper; +import com.android.jack.test.toolchain.AbstractTestTools; import java.io.File; -import javax.annotation.CheckForNull; import javax.annotation.Nonnull; -public class ObfuscationWithAttributesTest extends AbstractTest { +public class ObfuscationWithDebugInfoTests extends AbstractTest { @Override protected void runTest( - @CheckForNull File[] bootclasspath, - @CheckForNull File[] classpath, @Nonnull String testNumber, @Nonnull String flagNumber, @Nonnull String mappingNumber) throws Exception { - String testName = "shrob/test" + testNumber; - File testFolder = TestTools.getJackTestFolder(testName); - ProguardFlags[] proguardflagsFiles = new ProguardFlags[] { - generateApplyMapping(new File(testFolder,"proguard.flags" + flagNumber + ".mapping" + mappingNumber)), - new ProguardFlags(TestTools.getJackTestFolder("shrob"),"keepAllAttributes.flags"), - new ProguardFlags(testFolder,"proguard.flags" + flagNumber) - }; - TestTools.checkStructure( - bootclasspath, classpath, TestTools.getJackTestsWithJackFolder(testName), - true /* withDebuginfo */, proguardflagsFiles); + + File testFolder = AbstractTestTools.getTestRootDir("com.android.jack.shrob.test" + testNumber); + + SourceToDexComparisonTestHelper env = + new SourceToDexComparisonTestHelper(new File(testFolder, "jack")); + env.setWithDebugInfo(true); + env.setProguardFlags( + generateApplyMapping( + new File(testFolder, "proguard.flags" + flagNumber + ".mapping" + mappingNumber)), + new ProguardFlags(AbstractTestTools.getTestRootDir("com.android.jack.shrob"), + "keepDebugInfo.flags"), new ProguardFlags(testFolder, "proguard.flags" + flagNumber)); + + env.runTest(new ComparatorDex(env.getCandidateDex(), env.getReferenceDex())); } } diff --git a/jack/tests/com/android/jack/shrob/ObfuscationWithMappingTest.java b/jack-tests/tests/com/android/jack/shrob/ObfuscationWithMappingTests.java index 57a626ac..fb09d898 100644 --- a/jack/tests/com/android/jack/shrob/ObfuscationWithMappingTest.java +++ b/jack-tests/tests/com/android/jack/shrob/ObfuscationWithMappingTests.java @@ -16,33 +16,35 @@ package com.android.jack.shrob; -import com.android.jack.Options; -import com.android.jack.TestTools; import com.android.jack.shrob.proguard.GrammarActions; import com.android.jack.shrob.spec.Flags; +import com.android.jack.test.comparator.ComparatorMapping; +import com.android.jack.test.helper.SourceToDexComparisonTestHelper; +import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.DummyToolchain; +import com.android.jack.test.toolchain.JackApiToolchain; import org.junit.Test; import java.io.File; -import javax.annotation.CheckForNull; import javax.annotation.Nonnull; -public class ObfuscationWithMappingTest extends AbstractTest { +public class ObfuscationWithMappingTests extends AbstractTest { @Override protected void runTest( - @CheckForNull File[] bootclasspath, - @CheckForNull File[] classpath, @Nonnull String testNumber, @Nonnull String flagNumber, @Nonnull String mappingNumber) throws Exception { - String testName = "shrob/test" + testNumber; - File testFolder = TestTools.getJackTestFolder(testName); + + File testFolder = AbstractTestTools.getTestRootDir("com.android.jack.shrob.test" + testNumber); + JackApiToolchain toolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); Flags flags = new Flags(); + toolchain.setShrobFlags(flags); GrammarActions.parse("proguard.flags" + flagNumber, testFolder.getAbsolutePath(), flags); - File candidateOutputMapping = TestTools.createTempFile("mapping", ".txt"); + File candidateOutputMapping = AbstractTestTools.createTempFile("mapping", ".txt"); File refFolder = new File(testFolder, "refsObfuscationWithMapping"); File refOutputMapping = new File(refFolder, "expected-" + flagNumber + ".txt"); flags.setOutputMapping(candidateOutputMapping); @@ -52,12 +54,14 @@ public class ObfuscationWithMappingTest extends AbstractTest { if (inputMapping.exists()) { flags.setObfuscationMapping(inputMapping); } - TestTools.runWithFlags(new Options(), - bootclasspath, - classpath, - TestTools.getJackTestsWithJackFolder(testName), - flags); - ListingComparator.compare(refOutputMapping, candidateOutputMapping); + + SourceToDexComparisonTestHelper env = + new SourceToDexComparisonTestHelper(new File(testFolder, "jack")); + + env.setCandidateTestTools(toolchain); + env.setReferenceTestTools(new DummyToolchain()); + + env.runTest(new ComparatorMapping(candidateOutputMapping, refOutputMapping)); } @Override diff --git a/jack-tests/tests/com/android/jack/shrob/ObfuscationWithoutMappingTests.java b/jack-tests/tests/com/android/jack/shrob/ObfuscationWithoutMappingTests.java index 26cba495..a17b9fe0 100644 --- a/jack-tests/tests/com/android/jack/shrob/ObfuscationWithoutMappingTests.java +++ b/jack-tests/tests/com/android/jack/shrob/ObfuscationWithoutMappingTests.java @@ -17,7 +17,7 @@ package com.android.jack.shrob; import com.android.jack.Options; -import com.android.jack.category.KnownBugs; +import com.android.jack.test.category.KnownBugs; import com.android.jack.shrob.obfuscation.NameProviderFactory; import com.android.jack.shrob.proguard.GrammarActions; import com.android.jack.shrob.spec.Flags; @@ -43,8 +43,6 @@ public class ObfuscationWithoutMappingTests extends AbstractTest { @Nonnull String mappingNumber) throws Exception { - String testName = "shrob/test" + testNumber; - String testPackageName = "com.android.jack.shrob.test" + testNumber; File testFolder = AbstractTestTools.getTestRootDir(testPackageName); diff --git a/jack/tests/com/android/jack/shrob/RepackagingTest.java b/jack-tests/tests/com/android/jack/shrob/RepackagingTest.java index 22784f7c..805d2c51 100644 --- a/jack/tests/com/android/jack/shrob/RepackagingTest.java +++ b/jack-tests/tests/com/android/jack/shrob/RepackagingTest.java @@ -17,39 +17,49 @@ package com.android.jack.shrob; import com.android.jack.Options; -import com.android.jack.TestTools; +import com.android.jack.shrob.obfuscation.NameProviderFactory; import com.android.jack.shrob.proguard.GrammarActions; import com.android.jack.shrob.spec.Flags; +import com.android.jack.test.comparator.ComparatorMapping; +import com.android.jack.test.helper.SourceToDexComparisonTestHelper; +import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.DummyToolchain; +import com.android.jack.test.toolchain.JackApiToolchain; import java.io.File; -import javax.annotation.CheckForNull; import javax.annotation.Nonnull; public class RepackagingTest extends AbstractTest { @Override protected void runTest( - @CheckForNull File[] bootclasspath, - @CheckForNull File[] classpath, @Nonnull String testNumber, @Nonnull String flagNumber, @Nonnull String mappingNumber) throws Exception { - String testName = "shrob/test" + testNumber; - File testFolder = TestTools.getJackTestFolder(testName); + File testFolder = AbstractTestTools.getTestRootDir("com.android.jack.shrob.test" + testNumber); Flags flags = new Flags(); + GrammarActions.parse("proguard.flags" + flagNumber, testFolder.getAbsolutePath(), flags); flags.setPackageForRenamedClasses(""); - File candidateOutputMapping = TestTools.createTempFile("mapping", ".txt"); + File candidateOutputMapping = AbstractTestTools.createTempFile("mapping", ".txt"); File refFolder = new File(testFolder, "refsRepackageClasses"); File refOutputMapping = new File(refFolder, "expected-" + flagNumber + ".txt"); flags.setOutputMapping(candidateOutputMapping); flags.setPrintMapping(true); - Options jackOptions = new Options(); - jackOptions.setNameProvider("rot13"); - TestTools.runWithFlags(jackOptions, bootclasspath, classpath, - TestTools.getJackTestsWithJackFolder(testName), flags); - ListingComparator.compare(refOutputMapping, candidateOutputMapping); + + JackApiToolchain toolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); + toolchain.setShrobFlags(flags); + toolchain.addProperty(NameProviderFactory.NAMEPROVIDER.getName(), "rot13"); + toolchain.addProperty(Options.METHOD_FILTER.getName(), "supported-methods"); + + SourceToDexComparisonTestHelper env = + new SourceToDexComparisonTestHelper(new File(testFolder, "jack")); + + env.setCandidateTestTools(toolchain); + env.setReferenceTestTools(new DummyToolchain()); + + env.runTest(new ComparatorMapping(candidateOutputMapping, refOutputMapping)); } } diff --git a/jack/tests/com/android/jack/shrob/SeedTest.java b/jack-tests/tests/com/android/jack/shrob/SeedTests.java index b27b1499..5b966fad 100644 --- a/jack/tests/com/android/jack/shrob/SeedTest.java +++ b/jack-tests/tests/com/android/jack/shrob/SeedTests.java @@ -16,45 +16,51 @@ package com.android.jack.shrob; -import com.android.jack.Options; -import com.android.jack.TestTools; -import com.android.jack.category.SlowTests; +import com.android.jack.test.category.SlowTests; import com.android.jack.shrob.proguard.GrammarActions; import com.android.jack.shrob.spec.Flags; +import com.android.jack.test.comparator.ComparatorSeeds; +import com.android.jack.test.helper.SourceToDexComparisonTestHelper; +import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.DummyToolchain; +import com.android.jack.test.toolchain.JackApiToolchain; import org.junit.experimental.categories.Category; import java.io.File; -import javax.annotation.CheckForNull; import javax.annotation.Nonnull; @Category(SlowTests.class) -public class SeedTest extends AbstractTest { +public class SeedTests extends AbstractTest { @Override protected void runTest( - @CheckForNull File[] bootclasspath, - @CheckForNull File[] classpath, @Nonnull String testNumber, @Nonnull String flagNumber, @Nonnull String mappingNumber) throws Exception { - String testName = "shrob/test" + testNumber; - File testFolder = TestTools.getJackTestFolder(testName); + + File testFolder = AbstractTestTools.getTestRootDir("com.android.jack.shrob.test" + testNumber); Flags flags = new Flags(); flags.setShrink(false); flags.setObfuscate(false); GrammarActions.parse("proguard.flags" + flagNumber, testFolder.getAbsolutePath(), flags); File refFolder = new File(testFolder, "refsSeed"); - File candidateOutputSeeds = TestTools.createTempFile("seeds", ".txt"); + File candidateOutputSeeds = AbstractTestTools.createTempFile("seeds", ".txt"); File refOutputSeeds = new File(refFolder, "expected-" + flagNumber + ".txt"); flags.setSeedsFile(candidateOutputSeeds); flags.setPrintSeeds(true); - Options jackOptions = new Options(); - TestTools.runWithFlags(jackOptions, bootclasspath, classpath, - TestTools.getJackTestsWithJackFolder(testName), flags); - SeedsComparator.compare(refOutputSeeds, candidateOutputSeeds); + JackApiToolchain toolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); + toolchain.setShrobFlags(flags); + + SourceToDexComparisonTestHelper env = + new SourceToDexComparisonTestHelper(new File(testFolder, "jack")); + + env.setCandidateTestTools(toolchain); + env.setReferenceTestTools(new DummyToolchain()); + + env.runTest(new ComparatorSeeds(refOutputSeeds, candidateOutputSeeds)); } } diff --git a/jack-tests/tests/com/android/jack/shrob/ShrinkMultiDexTests.java b/jack-tests/tests/com/android/jack/shrob/ShrinkMultiDexTests.java new file mode 100644 index 00000000..b06855a5 --- /dev/null +++ b/jack-tests/tests/com/android/jack/shrob/ShrinkMultiDexTests.java @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2012 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.shrob; + +import com.android.jack.Main; +import com.android.jack.Options; +import com.android.jack.ProguardFlags; +import com.android.jack.backend.dex.DexFileWriter; +import com.android.jack.backend.dex.MultiDexLegacy; +import com.android.jack.preprocessor.PreProcessor; +import com.android.jack.shrob.shrink.ShrinkStructurePrinter; +import com.android.jack.test.comparator.ComparatorMapping; +import com.android.jack.test.helper.SourceToDexComparisonTestHelper; +import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.JackBasedToolchain; + +import org.junit.BeforeClass; + +import java.io.File; + +import javax.annotation.Nonnull; + +/** + * Tests for verifying that tracing for MultiDex does not disturb shrinking. + */ +public class ShrinkMultiDexTests extends AbstractTest { + + private static File shrobTestsDir = + AbstractTestTools.getTestRootDir("com.android.jack.shrob"); + + private static ProguardFlags dontObfuscateFlagFile = + new ProguardFlags(shrobTestsDir, "dontobfuscate.flags"); + + @BeforeClass + public static void setUpClass() { + Main.class.getClassLoader().setDefaultAssertionStatus(true); + } + + @Override + protected void runTest( + @Nonnull String testNumber, + @Nonnull String flagNumber, + @Nonnull String mappingNumber) + throws Exception { + File testFolder = new File(shrobTestsDir, "test" + testNumber); + JackBasedToolchain toolchain = + AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class); + + File refFolder = new File(testFolder, "refsShrinking"); + toolchain.addProperty(DexFileWriter.DEX_WRITING_POLICY.getName(), "multidex"); + toolchain.addProperty(MultiDexLegacy.MULTIDEX_LEGACY.getName(), "true"); + toolchain.addProperty(PreProcessor.ENABLE.getName(), "true"); + toolchain.addProperty(PreProcessor.FILE.getName(), + new File(shrobTestsDir, "legacyMainDexClasses.jpp").getAbsolutePath()); + + File candidateNodeListing = AbstractTestTools.createTempFile("nodeListing", ".txt"); + toolchain.addProperty(ShrinkStructurePrinter.STRUCTURE_PRINTING.getName(), "true"); + toolchain.addProperty(ShrinkStructurePrinter.STRUCTURE_PRINTING_FILE.getName(), + candidateNodeListing.getPath()); + toolchain.addProperty(Options.METHOD_FILTER.getName(), "supported-methods"); + toolchain.disableDxOptimizations(); + + File out = AbstractTestTools.createTempFile("checklisting", ".zip"); + + SourceToDexComparisonTestHelper env = + new SourceToDexComparisonTestHelper(new File(testFolder, "jack")); + env.setCandidateTestTools(toolchain); + env.setWithDebugInfo(true); + env.setProguardFlags(dontObfuscateFlagFile, + new ProguardFlags(shrobTestsDir, "keepAllAttributes.flags"), + new ProguardFlags(testFolder, "proguard.flags" + flagNumber)); + + env.runTest(new ComparatorMapping(new File(refFolder, "expected-" + flagNumber + ".txt"), + candidateNodeListing)); + } + +} diff --git a/jack-tests/tests/com/android/jack/shrob/ShrinkTests.java b/jack-tests/tests/com/android/jack/shrob/ShrinkTests.java new file mode 100644 index 00000000..175427c7 --- /dev/null +++ b/jack-tests/tests/com/android/jack/shrob/ShrinkTests.java @@ -0,0 +1,218 @@ +/* + * Copyright (C) 2012 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.shrob; + +import com.android.jack.Main; +import com.android.jack.Options; +import com.android.jack.ProguardFlags; +import com.android.jack.shrob.shrink.ShrinkStructurePrinter; +import com.android.jack.test.comparator.ComparatorMapping; +import com.android.jack.test.helper.SourceToDexComparisonTestHelper; +import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.DummyToolchain; +import com.android.jack.test.toolchain.JackApiToolchain; +import com.android.jack.test.toolchain.JackBasedToolchain; +import com.android.jack.util.TextUtils; + +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.File; + +import javax.annotation.Nonnull; + +public class ShrinkTests extends AbstractTest { + + private static File shrobTestsDir = + AbstractTestTools.getTestRootDir("com.android.jack.shrob"); + + private static ProguardFlags dontObfuscateFlagFile = + new ProguardFlags(shrobTestsDir, "dontobfuscate.flags"); + + @BeforeClass + public static void setUpClass() { + Main.class.getClassLoader().setDefaultAssertionStatus(true); + } + + @Override + protected void runTest( + @Nonnull String testNumber, + @Nonnull String flagNumber, + @Nonnull String mappingNumber) + throws Exception { + File testFolder = new File(shrobTestsDir, "test" + testNumber); + JackBasedToolchain toolchain = + AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class); + + File refFolder = new File(testFolder, "refsShrinking"); + + File candidateNodeListing = AbstractTestTools.createTempFile("nodeListing", ".txt"); + toolchain.addProperty(ShrinkStructurePrinter.STRUCTURE_PRINTING.getName(), "true"); + toolchain.addProperty(ShrinkStructurePrinter.STRUCTURE_PRINTING_FILE.getName(), + candidateNodeListing.getPath()); + toolchain.addProperty(Options.METHOD_FILTER.getName(), "supported-methods"); + toolchain.disableDxOptimizations(); + + File outFolder = AbstractTestTools.createTempDir(); + + SourceToDexComparisonTestHelper env = + new SourceToDexComparisonTestHelper(new File(testFolder, "jack")); + + env.setCandidateTestTools(toolchain); + env.setReferenceTestTools(new DummyToolchain()); + env.setProguardFlags( + dontObfuscateFlagFile, + new ProguardFlags(shrobTestsDir,"keepAllAttributes.flags"), + new ProguardFlags(testFolder, "proguard.flags" + flagNumber)); + + env.runTest(new ComparatorMapping( + new File(refFolder, "expected-" + flagNumber + ".txt"), + candidateNodeListing)); + } + + @Test + public void test020() throws Exception { + File libOut = AbstractTestTools.createTempDir(); + File testOut = null; + File shrinkOut = null; + + try { + JackApiToolchain toolchain = + AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); + toolchain.srcToLib( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + libOut, + /* zipFiles = */ false, + new File(shrobTestsDir, "test020/lib")); + + toolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); + testOut = AbstractTestTools.createTempDir(); + toolchain.srcToLib( + AbstractTestTools.getClasspathsAsString( + toolchain.getDefaultBootClasspath(), new File[] {libOut}), + testOut, + /* zipFiles = */ false, + new File(shrobTestsDir, "test020/jack")); + + shrinkOut = AbstractTestTools.createTempDir(); + toolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); + toolchain.addProguardFlags( + dontObfuscateFlagFile, + new ProguardFlags(new File(shrobTestsDir, "test020"),"proguard.flags")); + toolchain.libToLib( + testOut, + shrinkOut, + /* zipFile = */ false); + } catch (Exception e) { + String message = "Not deleting temp files of failed test ShrinkTest.test20 in:" + + TextUtils.LINE_SEPARATOR + + "- " + libOut.getAbsolutePath(); + if (testOut != null) { + message += TextUtils.LINE_SEPARATOR + "- " + testOut.getAbsolutePath(); + } + if (shrinkOut != null) { + message += TextUtils.LINE_SEPARATOR + "- " + shrinkOut.getAbsolutePath(); + } + System.err.println(); + System.err.println(message); + throw e; + } + } + + @Test + public void test021() throws Exception { + File jackOut = AbstractTestTools.createTempDir(); + File shrinkOut = null; + File dexOut = null; + + try { + JackApiToolchain toolchain = + AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); + toolchain.srcToLib( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + jackOut, + /* zipFiles = */ false, + new File(shrobTestsDir, "test021/jack")); + + toolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); + toolchain.addProguardFlags( + dontObfuscateFlagFile, + new ProguardFlags(new File( shrobTestsDir, "test021"),"proguard.flags001")); + shrinkOut = AbstractTestTools.createTempDir(); + toolchain.libToLib(jackOut, shrinkOut, /* zipFiles = */ false); + + dexOut = AbstractTestTools.createTempDir(); + toolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); + toolchain.libToExe(shrinkOut, dexOut, /* zipFile = */ false); + + } catch (Exception e) { + String message = "Not deleting temp files of failed ShrinkTest.test20 in:\n" + + "- " + jackOut.getAbsolutePath(); + if (shrinkOut != null) { + message += "\n- " + shrinkOut.getAbsolutePath(); + } + if (dexOut != null) { + message += "\n- " + dexOut.getAbsolutePath(); + } + System.err.println(); + System.err.println(message); + throw e; + } + } + + /** + * The only purpose of this test is to use jack shrink capabilities and to have no reference to + * java/lang/Class. This test will make Jack fail if java/lang/Class methods like getField and + * getMethod cannot be looked up (i.e. at the time this test is written, if the structure of + * java/lang/Class has not been preloaded). + */ + @Test + public void test028() throws Exception { + File testFolder = new File(shrobTestsDir, "test028"); + File jackar = null; + File shrinkedjackar = null; + jackar = AbstractTestTools.createTempFile("jackar", ".zip"); + shrinkedjackar = AbstractTestTools.createTempFile("shrinkedjackar", ".zip"); + ProguardFlags flags = new ProguardFlags(testFolder, "proguard.flags001"); + + JackBasedToolchain toolchain = AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class); + String classpath = AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()); + toolchain.srcToLib( + classpath, + jackar, + /* zipFiles = */ true, + testFolder); + + toolchain = AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class); + toolchain.libToLib(jackar, shrinkedjackar, /* zipFiles = */ true); + } + + @Test + public void test42_001() throws Exception { + runTest("042", "001", ""); + } + + @Test + public void test42_002() throws Exception { + runTest("042", "002", ""); + } + + @Test + public void test42_003() throws Exception { + runTest("042", "003", ""); + } +} diff --git a/jack-tests/tests/com/android/jack/shrob/ShrobAllTests.java b/jack-tests/tests/com/android/jack/shrob/ShrobAllTests.java new file mode 100644 index 00000000..fc8e0883 --- /dev/null +++ b/jack-tests/tests/com/android/jack/shrob/ShrobAllTests.java @@ -0,0 +1,22 @@ +package com.android.jack.shrob; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + +@RunWith(Suite.class) +@SuiteClasses(value = { +// AnnotationsTest.class, + FlattenPackageTests.class, +// ObfuscationWithAttributesTests.class, +// ObfuscationWithDebugInfoTests.class, + ObfuscationWithMappingTests.class, + ObfuscationWithoutMappingTests.class, + RepackagingTest.class, + SeedTests.class, + ShrinkMultiDexTests.class, + ShrinkTests.class, + ShrobRuntimeTests.class + }) +public class ShrobAllTests { +}
\ No newline at end of file diff --git a/jack-tests/tests/com/android/jack/shrob/ShrobRuntimeTests.java b/jack-tests/tests/com/android/jack/shrob/ShrobRuntimeTests.java new file mode 100644 index 00000000..e6a51804 --- /dev/null +++ b/jack-tests/tests/com/android/jack/shrob/ShrobRuntimeTests.java @@ -0,0 +1,90 @@ +/* + * 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.shrob; + +import com.android.jack.test.helper.RuntimeTestHelper; +import com.android.jack.test.runtime.RuntimeTest; +import com.android.jack.test.runtime.RuntimeTestInfo; +import com.android.jack.test.toolchain.AbstractTestTools; + +import org.junit.Test; + +import java.io.File; + +public class ShrobRuntimeTests extends RuntimeTest { + + private RuntimeTestInfo TEST011_1 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.shrob.test011"), + "com.android.jack.shrob.test011.dx.Tests"); + + private RuntimeTestInfo TEST011_2 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.shrob.test011"), + "com.android.jack.shrob.test011.dx.Tests2"); + + private RuntimeTestInfo TEST016 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.shrob.test016"), + "com.android.jack.shrob.test016.dx.Tests"); + + private RuntimeTestInfo TEST025 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.shrob.test025"), + "com.android.jack.shrob.test025.dx.Tests"); + + private RuntimeTestInfo TEST030 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.shrob.test030"), + "com.android.jack.shrob.test030.dx.Tests"); + + @Test + public void test011_1() throws Exception { + new RuntimeTestHelper(TEST011_1) + .setProguardFlagsFileNames(new String[] {"proguard.flags001", "../dontobfuscate.flags"}) + .compileAndRunTest(); + } + + @Test + public void test011_2() throws Exception { + new RuntimeTestHelper(TEST011_2) + .setProguardFlagsFileNames(new String[] {"proguard.flags002"}) + .compileAndRunTest(); + } + + @Test + public void test016() throws Exception { + new RuntimeTestHelper(TEST016) + .setProguardFlagsFileNames(new String[] {"proguard.flags001","applyMapping.flags"}) + .compileAndRunTest(); + } + + @Test + public void test025() throws Exception { + new RuntimeTestHelper(TEST025) + .setProguardFlagsFileNames(new String[] {"proguard.flags001"}) + .compileAndRunTest(); + } + + @Test + public void test030() throws Exception { + new RuntimeTestHelper(TEST030) + .setProguardFlagsFileNames(new String[] {new File(TEST030.directory, "proguard.flags001") + .getAbsolutePath()}) + .compileAndRunTest(); + } + + @Override + protected void fillRtTestInfos() { + } + +} diff --git a/jack-tests/tests/com/android/jack/string/StringTests.java b/jack-tests/tests/com/android/jack/string/StringTests.java new file mode 100644 index 00000000..92685369 --- /dev/null +++ b/jack-tests/tests/com/android/jack/string/StringTests.java @@ -0,0 +1,85 @@ +/* +* 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.string; + +import com.android.jack.test.category.RuntimeRegressionTest; +import com.android.jack.test.helper.RuntimeTestHelper; +import com.android.jack.test.runtime.RuntimeTest; +import com.android.jack.test.runtime.RuntimeTestInfo; +import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.IToolchain; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import java.io.IOException; + +public class StringTests extends RuntimeTest { + + private RuntimeTestInfo CONCAT001 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.string.concat001"), + "com.android.jack.string.concat001.dx.Tests"); + + private RuntimeTestInfo CONCAT002 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.string.concat002"), + "com.android.jack.string.concat002.dx.Tests"); + + private RuntimeTestInfo CONCAT003 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.string.concat003"), + "com.android.jack.string.concat003.dx.Tests"); + + @BeforeClass + public static void setUpClass() { + StringTests.class.getClassLoader().setDefaultAssertionStatus(true); + } + + @Test + public void testCompileNewString() throws Exception { + IToolchain toolchain = AbstractTestTools.getCandidateToolchain(); + toolchain.srcToExe( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + AbstractTestTools.createTempDir(), + /* zipFile = */ false, + AbstractTestTools.getTestRootDir("com.android.jack.string.test001.jack")); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void concat001() throws Exception { + new RuntimeTestHelper(CONCAT001).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void concat002() throws Exception { + new RuntimeTestHelper(CONCAT002).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void concat003() throws Exception { + new RuntimeTestHelper(CONCAT003).compileAndRunTest(); + } + + @Override + protected void fillRtTestInfos() { + rtTestInfos.add(CONCAT001); + rtTestInfos.add(CONCAT002); + rtTestInfos.add(CONCAT003); + } +} diff --git a/jack-tests/tests/com/android/jack/string001/jack/Strings.java b/jack-tests/tests/com/android/jack/string/test001/jack/Strings.java index 76abb8f7..a9cdcf19 100644 --- a/jack-tests/tests/com/android/jack/string001/jack/Strings.java +++ b/jack-tests/tests/com/android/jack/string/test001/jack/Strings.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.jack.string001.jack; +package com.android.jack.string.test001.jack; public class Strings { diff --git a/jack-tests/tests/com/android/jack/switchstatement/SwitchstatementTests.java b/jack-tests/tests/com/android/jack/switchstatement/SwitchstatementTests.java new file mode 100644 index 00000000..53f7e694 --- /dev/null +++ b/jack-tests/tests/com/android/jack/switchstatement/SwitchstatementTests.java @@ -0,0 +1,205 @@ +/* +* 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.switchstatement; + +import com.android.jack.TestTools; +import com.android.jack.backend.dex.DexFileWriter; +import com.android.jack.test.category.RuntimeRegressionTest; +import com.android.jack.test.helper.RuntimeTestHelper; +import com.android.jack.test.runtime.RuntimeTest; +import com.android.jack.test.runtime.RuntimeTestInfo; +import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.IToolchain; +import com.android.jack.test.toolchain.JackBasedToolchain; + +import junit.framework.Assert; + +import org.jf.dexlib.ClassDataItem.EncodedMethod; +import org.jf.dexlib.DexFile; +import org.jf.dexlib.Code.Analysis.AnalyzedInstruction; +import org.jf.dexlib.Code.Analysis.MethodAnalyzer; +import org.jf.dexlib.Code.Format.PackedSwitchDataPseudoInstruction; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import java.io.File; + +public class SwitchstatementTests extends RuntimeTest { + + private RuntimeTestInfo TEST001 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.switchstatement.test001"), + "com.android.jack.switchstatement.test001.dx.Tests"); + + private RuntimeTestInfo TEST002 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.switchstatement.test002"), + "com.android.jack.switchstatement.test002.dx.Tests"); + + private RuntimeTestInfo TEST003 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.switchstatement.test003"), + "com.android.jack.switchstatement.test003.dx.Tests"); + + private RuntimeTestInfo TEST004 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.switchstatement.test004"), + "com.android.jack.switchstatement.test004.dx.Tests"); + + private RuntimeTestInfo TEST005 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.switchstatement.test005"), + "com.android.jack.switchstatement.test005.dx.Tests"); + + private RuntimeTestInfo TEST006 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.switchstatement.test006"), + "com.android.jack.switchstatement.test006.dx.Tests"); + + private RuntimeTestInfo TEST007 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.switchstatement.test007"), + "com.android.jack.switchstatement.test007.dx.Tests"); + + private RuntimeTestInfo TEST008 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.switchstatement.test008"), + "com.android.jack.switchstatement.test008.dx.Tests"); + + private RuntimeTestInfo TEST010 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.switchstatement.test010"), + "com.android.jack.switchstatement.test010.dx.Tests"); + + @BeforeClass + public static void setUpClass() { + SwitchstatementTests.class.getClassLoader().setDefaultAssertionStatus(true); + } + @Test + @Category(RuntimeRegressionTest.class) + public void test001() throws Exception { + new RuntimeTestHelper(TEST001).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test002() throws Exception { + new RuntimeTestHelper(TEST002).compileAndRunTest(); + } + + @Test + public void testCompile002AsJackThenDex() throws Exception { + File outJackTmp = AbstractTestTools.createTempDir(); + { + // build as jack + JackBasedToolchain toolchain = + AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class); + toolchain.srcToLib( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), outJackTmp, + /* zipFiles = */false, + AbstractTestTools.getTestRootDir("com.android.jack.switchstatement.test002.jack")); + } + + { + // build dex from jack + JackBasedToolchain toolchain = + AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class); + toolchain.libToExe(outJackTmp, AbstractTestTools.createTempDir(), /* zipFile = */false); + } + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test003() throws Exception { + new RuntimeTestHelper(TEST003).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test004() throws Exception { + new RuntimeTestHelper(TEST004).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test005() throws Exception { + new RuntimeTestHelper(TEST005).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test006() throws Exception { + new RuntimeTestHelper(TEST006).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test007() throws Exception { + new RuntimeTestHelper(TEST007).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test008() throws Exception { + new RuntimeTestHelper(TEST008).compileAndRunTest(); + } + + /** + * Test allowing to check that 'packed-switch-payload' into generated dex is as small as possible. + */ + @Test + public void testCompile9() throws Exception { + File outFolder = AbstractTestTools.createTempDir(); + File out = new File(outFolder, DexFileWriter.DEX_FILENAME); + + IToolchain toolchain = AbstractTestTools.getCandidateToolchain(); + toolchain.srcToExe( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + outFolder, + /* zipFile = */ false, + AbstractTestTools.getTestRootDir("com.android.jack.switchstatement.test009.jack")); + + DexFile dexFile = new DexFile(out); + EncodedMethod em = + TestTools.getEncodedMethod(dexFile, + "Lcom/android/jack/switchstatement/test009/jack/Switch;", "switch1", + "(Lcom/android/jack/switchstatement/test009/jack/Switch$Num;)Z"); + + MethodAnalyzer ma = new MethodAnalyzer(em, false, null); + boolean packedSwitchDataPseudo = false; + for (AnalyzedInstruction ai : ma.getInstructions()) { + if (ai.getInstruction() instanceof PackedSwitchDataPseudoInstruction) { + packedSwitchDataPseudo = true; + Assert.assertEquals(5, + ((PackedSwitchDataPseudoInstruction) ai.getInstruction()).getTargetCount()); + } + } + + Assert.assertTrue(packedSwitchDataPseudo); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test010() throws Exception { + new RuntimeTestHelper(TEST010).compileAndRunTest(); + } + + @Override + protected void fillRtTestInfos() { + rtTestInfos.add(TEST001); + rtTestInfos.add(TEST002); + rtTestInfos.add(TEST003); + rtTestInfos.add(TEST004); + rtTestInfos.add(TEST005); + rtTestInfos.add(TEST006); + rtTestInfos.add(TEST007); + rtTestInfos.add(TEST008); + rtTestInfos.add(TEST010); + } +} diff --git a/jack-tests/tests/com/android/jack/synchronize/SynchronizeTests.java b/jack-tests/tests/com/android/jack/synchronize/SynchronizeTests.java new file mode 100644 index 00000000..0ee6ed88 --- /dev/null +++ b/jack-tests/tests/com/android/jack/synchronize/SynchronizeTests.java @@ -0,0 +1,49 @@ +/* +* 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.synchronize; + +import com.android.jack.test.category.RuntimeRegressionTest; +import com.android.jack.test.helper.RuntimeTestHelper; +import com.android.jack.test.runtime.RuntimeTest; +import com.android.jack.test.runtime.RuntimeTestInfo; +import com.android.jack.test.toolchain.AbstractTestTools; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +public class SynchronizeTests extends RuntimeTest { + + private RuntimeTestInfo TEST001 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.synchronize.test001"), + "com.android.jack.synchronize.test001.dx.Tests"); + + @BeforeClass + public static void setUpClass() { + SynchronizeTests.class.getClassLoader().setDefaultAssertionStatus(true); + } + @Test + @Category(RuntimeRegressionTest.class) + public void test001() throws Exception { + new RuntimeTestHelper(TEST001).compileAndRunTest(); + } + + @Override + protected void fillRtTestInfos() { + rtTestInfos.add(TEST001); + } +} diff --git a/jack-tests/tests/com/android/jack/threeaddress/ThreeaddressTests.java b/jack-tests/tests/com/android/jack/threeaddress/ThreeaddressTests.java new file mode 100644 index 00000000..6a172ebc --- /dev/null +++ b/jack-tests/tests/com/android/jack/threeaddress/ThreeaddressTests.java @@ -0,0 +1,49 @@ +/* +* 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.threeaddress; + +import com.android.jack.test.category.RuntimeRegressionTest; +import com.android.jack.test.helper.RuntimeTestHelper; +import com.android.jack.test.runtime.RuntimeTest; +import com.android.jack.test.runtime.RuntimeTestInfo; +import com.android.jack.test.toolchain.AbstractTestTools; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +public class ThreeaddressTests extends RuntimeTest { + + private RuntimeTestInfo TEST001 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.threeaddress.test001"), + "com.android.jack.threeaddress.test001.dx.Tests"); + + @BeforeClass + public static void setUpClass() { + ThreeaddressTests.class.getClassLoader().setDefaultAssertionStatus(true); + } + @Test + @Category(RuntimeRegressionTest.class) + public void test001() throws Exception { + new RuntimeTestHelper(TEST001).compileAndRunTest(); + } + + @Override + protected void fillRtTestInfos() { + rtTestInfos.add(TEST001); + } +} diff --git a/jack-tests/tests/com/android/jack/threeaddress/dx/Tests.java b/jack-tests/tests/com/android/jack/threeaddress/test001/dx/Tests.java index eca3c3b6..af80d356 100644 --- a/jack-tests/tests/com/android/jack/threeaddress/dx/Tests.java +++ b/jack-tests/tests/com/android/jack/threeaddress/test001/dx/Tests.java @@ -14,16 +14,16 @@ * limitations under the License. */ -package com.android.jack.threeaddress.dx; +package com.android.jack.threeaddress.test001.dx; + +import com.android.jack.threeaddress.test001.jack.ThreeAddressCode001; +import com.android.jack.threeaddress.test001.jack.ThreeAddressCode002; +import com.android.jack.threeaddress.test001.jack.ThreeAddressCode003; import junit.framework.Assert; import org.junit.Test; -import com.android.jack.threeaddress.jack.ThreeAddressCode001; -import com.android.jack.threeaddress.jack.ThreeAddressCode002; -import com.android.jack.threeaddress.jack.ThreeAddressCode003; - public class Tests { @Test diff --git a/jack-tests/tests/com/android/jack/threeaddress/jack/ThreeAddressCode001.java b/jack-tests/tests/com/android/jack/threeaddress/test001/jack/ThreeAddressCode001.java index a525ea0c..f5af349b 100644 --- a/jack-tests/tests/com/android/jack/threeaddress/jack/ThreeAddressCode001.java +++ b/jack-tests/tests/com/android/jack/threeaddress/test001/jack/ThreeAddressCode001.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.jack.threeaddress.jack; +package com.android.jack.threeaddress.test001.jack; public class ThreeAddressCode001 { diff --git a/jack-tests/tests/com/android/jack/threeaddress/jack/ThreeAddressCode002.java b/jack-tests/tests/com/android/jack/threeaddress/test001/jack/ThreeAddressCode002.java index ff201b69..1234ebfc 100644 --- a/jack-tests/tests/com/android/jack/threeaddress/jack/ThreeAddressCode002.java +++ b/jack-tests/tests/com/android/jack/threeaddress/test001/jack/ThreeAddressCode002.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.jack.threeaddress.jack; +package com.android.jack.threeaddress.test001.jack; public class ThreeAddressCode002 { diff --git a/jack-tests/tests/com/android/jack/threeaddress/jack/ThreeAddressCode003.java b/jack-tests/tests/com/android/jack/threeaddress/test001/jack/ThreeAddressCode003.java index bd9753d0..5b1b8d97 100644 --- a/jack-tests/tests/com/android/jack/threeaddress/jack/ThreeAddressCode003.java +++ b/jack-tests/tests/com/android/jack/threeaddress/test001/jack/ThreeAddressCode003.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.jack.threeaddress.jack; +package com.android.jack.threeaddress.test001.jack; public class ThreeAddressCode003 { diff --git a/jack-tests/tests/com/android/jack/threeaddress/jack/ThreeAddressCodeUtil001.java b/jack-tests/tests/com/android/jack/threeaddress/test001/jack/ThreeAddressCodeUtil001.java index e84e841e..0d2c4933 100644 --- a/jack-tests/tests/com/android/jack/threeaddress/jack/ThreeAddressCodeUtil001.java +++ b/jack-tests/tests/com/android/jack/threeaddress/test001/jack/ThreeAddressCodeUtil001.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.jack.threeaddress.jack; +package com.android.jack.threeaddress.test001.jack; public abstract class ThreeAddressCodeUtil001 { public abstract int f(int a, int b); diff --git a/jack-tests/tests/com/android/jack/throwstatement/ThrowstatementTests.java b/jack-tests/tests/com/android/jack/throwstatement/ThrowstatementTests.java new file mode 100644 index 00000000..e1e0b870 --- /dev/null +++ b/jack-tests/tests/com/android/jack/throwstatement/ThrowstatementTests.java @@ -0,0 +1,49 @@ +/* +* 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.throwstatement; + +import com.android.jack.test.category.RuntimeRegressionTest; +import com.android.jack.test.helper.RuntimeTestHelper; +import com.android.jack.test.runtime.RuntimeTest; +import com.android.jack.test.runtime.RuntimeTestInfo; +import com.android.jack.test.toolchain.AbstractTestTools; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +public class ThrowstatementTests extends RuntimeTest { + + private RuntimeTestInfo TEST001 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.throwstatement.test001"), + "com.android.jack.throwstatement.test001.dx.Tests"); + + @BeforeClass + public static void setUpClass() { + ThrowstatementTests.class.getClassLoader().setDefaultAssertionStatus(true); + } + @Test + @Category(RuntimeRegressionTest.class) + public void test001() throws Exception { + new RuntimeTestHelper(TEST001).compileAndRunTest(); + } + + @Override + protected void fillRtTestInfos() { + rtTestInfos.add(TEST001); + } +} diff --git a/jack-tests/tests/com/android/jack/tools/merger/MergerTestTools.java b/jack-tests/tests/com/android/jack/tools/merger/MergerTestTools.java index b163f5b0..b7f50871 100644 --- a/jack-tests/tests/com/android/jack/tools/merger/MergerTestTools.java +++ b/jack-tests/tests/com/android/jack/tools/merger/MergerTestTools.java @@ -20,11 +20,13 @@ import com.android.jack.Options; import com.android.jack.TestTools; import com.android.jack.backend.dex.DexFileWriter; import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.JackApiToolchain; import com.android.jack.test.toolchain.JackBasedToolchain; import com.android.sched.scheduler.ScheduleInstance; import java.io.File; import java.io.IOException; +import java.io.OutputStream; import javax.annotation.CheckForNull; import javax.annotation.Nonnull; @@ -33,9 +35,9 @@ public class MergerTestTools { @Nonnull protected File buildOneDexPerType(@CheckForNull String classpath, @Nonnull File sourceFolder, - boolean withDebug) throws Exception { - JackBasedToolchain toolchain = - AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class); + boolean withDebug, @CheckForNull OutputStream out, @CheckForNull OutputStream err) throws Exception { + JackApiToolchain toolchain = + AbstractTestTools.getCandidateToolchain(JackApiToolchain.class); try { File multiDexFolder = TestTools.createTempDir("multi", "dex"); File multiDex = new File(multiDexFolder, DexFileWriter.DEX_FILENAME); @@ -47,7 +49,14 @@ public class MergerTestTools { toolchain.addProperty(Options.INTERMEDIATE_DEX_DIR.getName(), multiDexOnTypePerTypeFolder.getAbsolutePath()); - toolchain.srcToExe(classpath, multiDexFolder, sourceFolder); + if (out != null) { + toolchain.setOutputStream(out); + } + if (err != null) { + toolchain.setErrorStream(err); + } + + toolchain.srcToExe(classpath, multiDexFolder, /* zipFile = */ false, sourceFolder); return multiDex; diff --git a/jack-tests/tests/com/android/jack/tools/merger/test011/MergerTest011.java b/jack-tests/tests/com/android/jack/tools/merger/test011/MergerTest011.java index f00da22b..fc593c5c 100644 --- a/jack-tests/tests/com/android/jack/tools/merger/test011/MergerTest011.java +++ b/jack-tests/tests/com/android/jack/tools/merger/test011/MergerTest011.java @@ -16,10 +16,13 @@ package com.android.jack.tools.merger.test011; +import com.android.jack.JackAbortException; import com.android.jack.JackUserException; import com.android.jack.Main; import com.android.jack.TestTools; -import com.android.jack.category.SlowTests; +import com.android.jack.backend.dex.DexWritingException; +import com.android.jack.backend.dex.SingleDexOverflowException; +import com.android.jack.test.category.SlowTests; import com.android.jack.tools.merger.FieldIdOverflowException; import com.android.jack.tools.merger.MergerTestTools; import com.android.jack.tools.merger.MethodIdOverflowException; @@ -31,6 +34,7 @@ import org.junit.BeforeClass; import org.junit.Test; import org.junit.experimental.categories.Category; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; @@ -46,8 +50,10 @@ public class MergerTest011 extends MergerTestTools { private static int fileCount = 655; - private static final String expectedExceptionMessage = - "Index overflow while merging dex files. Try using multidex"; + @Nonnull + private static final String EXPECTED_MESSAGE = + "Error during the dex writing phase: classes.dex has too many IDs. Try using multi-dex"; + @BeforeClass public static void setUpClass() { @@ -64,13 +70,18 @@ public class MergerTest011 extends MergerTestTools { } generateJavaFileWithMethods(srcFolder, fileCount, 36); + ByteArrayOutputStream err = new ByteArrayOutputStream(); + try { - buildOneDexPerType(TestTools.getDefaultBootclasspathString(), srcFolder, false /* withDebug */); + buildOneDexPerType(TestTools.getDefaultBootclasspathString(), srcFolder, + /* withDebug = */false, /* out = */ null, err); Assert.fail(); - } catch (JackUserException e) { - Assert.assertEquals(expectedExceptionMessage, e.getMessage()); + } catch (JackAbortException e) { Throwable cause = e.getCause(); - Assert.assertTrue(cause instanceof MethodIdOverflowException); + Assert.assertTrue(cause instanceof DexWritingException); + Assert.assertTrue(cause.getCause() instanceof SingleDexOverflowException); + Assert.assertTrue(cause.getCause().getCause() instanceof MethodIdOverflowException); + Assert.assertTrue(err.toString().contains(EXPECTED_MESSAGE)); } } @@ -83,13 +94,18 @@ public class MergerTest011 extends MergerTestTools { } generateJavaFileWithFields(srcFolder, fileCount, 37); + ByteArrayOutputStream err = new ByteArrayOutputStream(); + try { - buildOneDexPerType(TestTools.getDefaultBootclasspathString(), srcFolder, false /* withDebug */); + buildOneDexPerType(TestTools.getDefaultBootclasspathString(), srcFolder, + /* withDebug = */false, /* out = */ null, err); Assert.fail(); - } catch (JackUserException e) { - Assert.assertEquals(expectedExceptionMessage, e.getMessage()); + } catch (JackAbortException e) { Throwable cause = e.getCause(); - Assert.assertTrue(cause instanceof FieldIdOverflowException); + Assert.assertTrue(cause instanceof DexWritingException); + Assert.assertTrue(cause.getCause() instanceof SingleDexOverflowException); + Assert.assertTrue(cause.getCause().getCause() instanceof FieldIdOverflowException); + Assert.assertTrue(err.toString().contains(EXPECTED_MESSAGE)); } } @@ -103,13 +119,18 @@ public class MergerTest011 extends MergerTestTools { } generateJavaFileWithTypes(srcFolder, fileCount, 36); + ByteArrayOutputStream err = new ByteArrayOutputStream(); + try { - buildOneDexPerType(TestTools.getDefaultBootclasspathString(), srcFolder, false /* withDebug */); + buildOneDexPerType(TestTools.getDefaultBootclasspathString(), srcFolder, + /* withDebug = */false, /* out = */ null, err); Assert.fail(); - } catch (JackUserException e) { - Assert.assertEquals(expectedExceptionMessage, e.getMessage()); + } catch (JackAbortException e) { Throwable cause = e.getCause(); - Assert.assertTrue(cause instanceof TypeIdOverflowException); + Assert.assertTrue(cause instanceof DexWritingException); + Assert.assertTrue(cause.getCause() instanceof SingleDexOverflowException); + Assert.assertTrue(cause.getCause().getCause() instanceof TypeIdOverflowException); + Assert.assertTrue(err.toString().contains(EXPECTED_MESSAGE)); } } diff --git a/jack-tests/tests/com/android/jack/trycatch/TrycatchTests.java b/jack-tests/tests/com/android/jack/trycatch/TrycatchTests.java new file mode 100644 index 00000000..98694c8d --- /dev/null +++ b/jack-tests/tests/com/android/jack/trycatch/TrycatchTests.java @@ -0,0 +1,128 @@ +/* +* 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.trycatch; + +import com.android.jack.Options; +import com.android.jack.TestTools; +import com.android.jack.test.category.RuntimeRegressionTest; +import com.android.jack.test.helper.RuntimeTestHelper; +import com.android.jack.test.runtime.RuntimeTest; +import com.android.jack.test.runtime.RuntimeTestInfo; +import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.IToolchain; + +import junit.framework.Assert; + +import org.jf.dexlib.CodeItem; +import org.jf.dexlib.DexFile; +import org.jf.dexlib.Code.Instruction; +import org.jf.dexlib.Code.Opcode; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import java.io.File; + +import javax.annotation.Nonnull; + +public class TrycatchTests extends RuntimeTest { + + private RuntimeTestInfo TEST001 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.trycatch.test001"), + "com.android.jack.trycatch.test001.dx.Tests"); + + private RuntimeTestInfo TEST002 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.trycatch.test002"), + "com.android.jack.trycatch.test002.dx.Tests"); + + private RuntimeTestInfo TEST003 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.trycatch.test003"), + "com.android.jack.trycatch.test003.dx.Tests"); + + private RuntimeTestInfo TEST005 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.trycatch.test005"), + "com.android.jack.trycatch.test005.dx.Tests"); + + @BeforeClass + public static void setUpClass() { + TrycatchTests.class.getClassLoader().setDefaultAssertionStatus(true); + } + @Test + @Category(RuntimeRegressionTest.class) + public void test001() throws Exception { + new RuntimeTestHelper(TEST001).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test002() throws Exception { + new RuntimeTestHelper(TEST002).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test003() throws Exception { + new RuntimeTestHelper(TEST003).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test005() throws Exception { + new RuntimeTestHelper(TEST005).compileAndRunTest(); + } + + /** + * Verify that generated dex does not contains useless 'mov' instructions. + */ + @Test + @Ignore("Generated dex contains useless 'mov' instructions") + public void uselessMovInstructions() throws Exception { + File out = AbstractTestTools.createTempFile("uselessMovInstructions", ".dex"); + IToolchain toolchain = + AbstractTestTools.getCandidateToolchain(); + toolchain.srcToExe( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + out, + /* zipFile = */ false, + AbstractTestTools.getTestRootDir("com.android.jack.trycatch.test004")); + + DexFile dexFile = new DexFile(out); + CodeItem ci = + TestTools.getEncodedMethod(dexFile, "Lcom/android/jack/trycatch/test004/jack/TryCatch;", + "setIconAndText", "(IIILjava/lang/String;II)V").codeItem; + + Assert.assertFalse(hasOpcode(ci, Opcode.MOVE_OBJECT)); + } + + private boolean hasOpcode(@Nonnull CodeItem codeItem, @Nonnull Opcode opcode) { + for (Instruction inst : codeItem.getInstructions()) { + if (inst.opcode == opcode) { + return true; + } + } + return false; + } + + @Override + protected void fillRtTestInfos() { + rtTestInfos.add(TEST001); + rtTestInfos.add(TEST002); + rtTestInfos.add(TEST003); + rtTestInfos.add(TEST005); + } +} diff --git a/jack-tests/tests/com/android/jack/tryfinally/TryfinallyTests.java b/jack-tests/tests/com/android/jack/tryfinally/TryfinallyTests.java new file mode 100644 index 00000000..15357063 --- /dev/null +++ b/jack-tests/tests/com/android/jack/tryfinally/TryfinallyTests.java @@ -0,0 +1,82 @@ +/* +* 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.tryfinally; + +import com.android.jack.test.category.RuntimeRegressionTest; +import com.android.jack.test.helper.RuntimeTestHelper; +import com.android.jack.test.runtime.RuntimeTest; +import com.android.jack.test.runtime.RuntimeTestInfo; +import com.android.jack.test.toolchain.AbstractTestTools; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +public class TryfinallyTests extends RuntimeTest { + + private RuntimeTestInfo FINALLY002 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.tryfinally.finally002"), + "com.android.jack.tryfinally.finally002.dx.Tests"); + + private RuntimeTestInfo FINALLY003 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.tryfinally.finally003"), + "com.android.jack.tryfinally.finally003.dx.Tests"); + + private RuntimeTestInfo FINALLY004 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.tryfinally.finally004"), + "com.android.jack.tryfinally.finally004.dx.Tests"); + + private RuntimeTestInfo FINALLYBLOCK = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.tryfinally.finallyblock"), + "com.android.jack.tryfinally.finallyblock.dx.Tests"); + + @BeforeClass + public static void setUpClass() { + TryfinallyTests.class.getClassLoader().setDefaultAssertionStatus(true); + } + @Test + @Category(RuntimeRegressionTest.class) + public void finally002() throws Exception { + new RuntimeTestHelper(FINALLY002).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void finally003() throws Exception { + new RuntimeTestHelper(FINALLY003).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void finally004() throws Exception { + new RuntimeTestHelper(FINALLY004).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void finallyblock() throws Exception { + new RuntimeTestHelper(FINALLYBLOCK).compileAndRunTest(); + } + + @Override + protected void fillRtTestInfos() { + rtTestInfos.add(FINALLY002); + rtTestInfos.add(FINALLY003); + rtTestInfos.add(FINALLY004); + rtTestInfos.add(FINALLYBLOCK); + } +} diff --git a/jack-tests/tests/com/android/jack/type/TypeTests.java b/jack-tests/tests/com/android/jack/type/TypeTests.java new file mode 100644 index 00000000..f908532e --- /dev/null +++ b/jack-tests/tests/com/android/jack/type/TypeTests.java @@ -0,0 +1,60 @@ +/* +* 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.type; + +import com.android.jack.test.category.RuntimeRegressionTest; +import com.android.jack.test.helper.RuntimeTestHelper; +import com.android.jack.test.runtime.RuntimeTest; +import com.android.jack.test.runtime.RuntimeTestInfo; +import com.android.jack.test.toolchain.AbstractTestTools; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +public class TypeTests extends RuntimeTest { + + private RuntimeTestInfo TEST001 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.type.test001"), + "com.android.jack.type.test001.dx.Tests"); + + private RuntimeTestInfo TEST002 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.type.test002"), + "com.android.jack.type.test002.dx.Tests"); + + @BeforeClass + public static void setUpClass() { + TypeTests.class.getClassLoader().setDefaultAssertionStatus(true); + } + @Test + @Category(RuntimeRegressionTest.class) + public void test001() throws Exception { + new RuntimeTestHelper(TEST001).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test002() throws Exception { + new RuntimeTestHelper(TEST002).compileAndRunTest(); + } + + @Override + protected void fillRtTestInfos() { + rtTestInfos.add(TEST001); + rtTestInfos.add(TEST002); + } +} diff --git a/jack-tests/tests/com/android/jack/unary/UnaryTests.java b/jack-tests/tests/com/android/jack/unary/UnaryTests.java new file mode 100644 index 00000000..2f1485e1 --- /dev/null +++ b/jack-tests/tests/com/android/jack/unary/UnaryTests.java @@ -0,0 +1,82 @@ +/* +* 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.unary; + +import com.android.jack.test.category.RuntimeRegressionTest; +import com.android.jack.test.helper.RuntimeTestHelper; +import com.android.jack.test.runtime.RuntimeTest; +import com.android.jack.test.runtime.RuntimeTestInfo; +import com.android.jack.test.toolchain.AbstractTestTools; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +public class UnaryTests extends RuntimeTest { + + private RuntimeTestInfo TEST001 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.unary.test001"), + "com.android.jack.unary.test001.dx.Tests"); + + private RuntimeTestInfo TEST002 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.unary.test002"), + "com.android.jack.unary.test002.dx.Tests"); + + private RuntimeTestInfo TEST003 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.unary.test003"), + "com.android.jack.unary.test003.dx.Tests"); + + private RuntimeTestInfo TEST004 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.unary.test004"), + "com.android.jack.unary.test004.dx.Tests"); + + @BeforeClass + public static void setUpClass() { + UnaryTests.class.getClassLoader().setDefaultAssertionStatus(true); + } + @Test + @Category(RuntimeRegressionTest.class) + public void test001() throws Exception { + new RuntimeTestHelper(TEST001).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test002() throws Exception { + new RuntimeTestHelper(TEST002).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test003() throws Exception { + new RuntimeTestHelper(TEST003).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) + public void test004() throws Exception { + new RuntimeTestHelper(TEST004).compileAndRunTest(); + } + + @Override + protected void fillRtTestInfos() { + rtTestInfos.add(TEST001); + rtTestInfos.add(TEST002); + rtTestInfos.add(TEST003); + rtTestInfos.add(TEST004); + } +} diff --git a/jack-tests/tests/com/android/jack/verify/VerifyTests.java b/jack-tests/tests/com/android/jack/verify/VerifyTests.java new file mode 100644 index 00000000..12c0cfb9 --- /dev/null +++ b/jack-tests/tests/com/android/jack/verify/VerifyTests.java @@ -0,0 +1,49 @@ +/* +* 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.verify; + +import com.android.jack.test.category.RuntimeRegressionTest; +import com.android.jack.test.helper.RuntimeTestHelper; +import com.android.jack.test.runtime.RuntimeTest; +import com.android.jack.test.runtime.RuntimeTestInfo; +import com.android.jack.test.toolchain.AbstractTestTools; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +public class VerifyTests extends RuntimeTest { + + private RuntimeTestInfo TEST001 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.verify.test001"), + "com.android.jack.verify.test001.dx.Tests"); + + @BeforeClass + public static void setUpClass() { + VerifyTests.class.getClassLoader().setDefaultAssertionStatus(true); + } + @Test + @Category(RuntimeRegressionTest.class) + public void test001() throws Exception { + new RuntimeTestHelper(TEST001).compileAndRunTest(); + } + + @Override + protected void fillRtTestInfos() { + rtTestInfos.add(TEST001); + } +} diff --git a/jack-tests/tests/com/android/jack/withphantom/WithPhantomTests.java b/jack-tests/tests/com/android/jack/withphantom/WithPhantomTests.java new file mode 100644 index 00000000..fbf946c2 --- /dev/null +++ b/jack-tests/tests/com/android/jack/withphantom/WithPhantomTests.java @@ -0,0 +1,208 @@ +/* + * 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.withphantom; + +import com.android.jack.ProguardFlags; +import com.android.jack.test.category.KnownBugs; +import com.android.jack.library.FileType; +import com.android.jack.test.toolchain.AbstractTestTools; +import com.android.jack.test.toolchain.JackBasedToolchain; + +import junit.framework.Assert; + +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import java.io.File; +import java.io.FilenameFilter; + +import javax.annotation.Nonnull; + +/** + * Test compilation involving phantoms. + */ +public class WithPhantomTests { + + @Nonnull + private static final String TEST001 = "com.android.jack.withphantom.test001"; + @Nonnull + private static final String TEST001_JACK = TEST001 + ".jack"; + @Nonnull + private static final String TEST002 = "com.android.jack.withphantom.test002"; + @Nonnull + private static final String TEST002_JACK = TEST002 + ".jack"; + + @Nonnull + private static String fixPath(@Nonnull String unixPath) { + return unixPath.replace('/', File.separatorChar); + } + + @Test + public void testPhantomOuter() throws Exception { + File tempJackFolder = AbstractTestTools.createTempDir(); + JackBasedToolchain toolchain = + AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class); + toolchain.srcToLib( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + tempJackFolder, + /* zipFiles = */ false, + AbstractTestTools.getTestRootDir(TEST001_JACK)); + + boolean deleted = + new File(tempJackFolder, FileType.JAYCE.getPrefix() + File.separatorChar + + fixPath("com/android/jack/withphantom/test001/jack/A.jayce")).delete(); + Assert.assertTrue(deleted); + + File testFolder = AbstractTestTools.getTestRootDir(TEST001); + + File tempOut1 = AbstractTestTools.createTempDir(); + toolchain = AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class); + toolchain.addProguardFlags(new ProguardFlags(testFolder, "shrink1.flags")) + .libToLib(tempJackFolder, tempOut1, /* zipFiles = */ false); + + File tempOut2 = AbstractTestTools.createTempDir(); + toolchain = AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class); + toolchain.addProguardFlags(new ProguardFlags(testFolder, "shrink2.flags")) + .libToLib(tempJackFolder, tempOut2, /* zipFiles = */ false); + + File tempOut3 = AbstractTestTools.createTempDir(); + toolchain = AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class); + toolchain.addProguardFlags(new ProguardFlags(testFolder, "obf1.flags")) + .libToLib(tempJackFolder, tempOut3, /* zipFiles = */ false); + + File tempOut4 = AbstractTestTools.createTempDir(); + toolchain = AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class); + toolchain.addProguardFlags(new ProguardFlags(testFolder, "obf2.flags")) + .libToLib(tempJackFolder, tempOut4, /* zipFiles = */ false); + + File tempOut5 = AbstractTestTools.createTempDir(); + toolchain = AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class); + toolchain.libToExe(tempJackFolder, tempOut5, /* zipFile = */ false); + } + + @Test + public void testPhantomInner() throws Exception { + File tempJackFolder = AbstractTestTools.createTempDir(); + JackBasedToolchain toolchain = + AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class); + toolchain.srcToLib( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + tempJackFolder, + /* zipFiles = */ false, + AbstractTestTools.getTestRootDir(TEST001_JACK)); + + boolean deleted = + new File(tempJackFolder, fixPath(FileType.JAYCE.getPrefix() + File.separatorChar + + "com/android/jack/withphantom/test001/jack/A$Inner1.jayce")).delete(); + Assert.assertTrue(deleted); + deleted = + new File(tempJackFolder, fixPath(FileType.DEX.getPrefix() + File.separatorChar + + "com/android/jack/withphantom/test001/jack/A$Inner1.dex")).delete(); + Assert.assertTrue(deleted); + + File testFolder = AbstractTestTools.getTestRootDir(TEST001); + + File tempOut1 = AbstractTestTools.createTempDir(); + toolchain = AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class); + toolchain.addProguardFlags(new ProguardFlags(testFolder, "shrink1.flags")) + .libToLib(tempJackFolder, tempOut1, /* zipFiles = */ false); + + File tempOut2 = AbstractTestTools.createTempDir(); + toolchain = AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class); + toolchain.addProguardFlags(new ProguardFlags(testFolder, "shrink2.flags")) + .libToLib(tempJackFolder, tempOut2, /* zipFiles = */ false); + + File tempOut3 = AbstractTestTools.createTempDir(); + toolchain = AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class); + toolchain.addProguardFlags(new ProguardFlags(testFolder, "obf1.flags")) + .libToLib(tempJackFolder, tempOut3, /* zipFiles = */ false); + + File tempOut4 = AbstractTestTools.createTempDir(); + toolchain = AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class); + toolchain.addProguardFlags(new ProguardFlags(testFolder, "obf2.flags")) + .libToLib(tempJackFolder, tempOut4, /* zipFiles = */ false); + + File tempOutFolder = AbstractTestTools.createTempDir(); + toolchain = AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class); + toolchain.libToExe(tempJackFolder, tempOutFolder, /* zipFile = */ false); + } + + @Category(KnownBugs.class) + @Test + public void testPhantomLocal() throws Exception { + File tempJackFolder = AbstractTestTools.createTempDir(); + JackBasedToolchain toolchain = + AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class); + toolchain.srcToLib( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + tempJackFolder, + /* zipFiles = */ false, + AbstractTestTools.getTestRootDir(TEST002_JACK)); + + File[] inners = + new File(tempJackFolder, fixPath(FileType.JAYCE.getPrefix() + File.separatorChar + + "com/android/jack/withphantom/test002/jack/")).listFiles(new FilenameFilter() { + @Override + public boolean accept(File dir, String name) { + return name.startsWith("A$"); + } + }); + for (File file : inners) { + Assert.assertTrue(file.delete()); + } + + File testFolder = AbstractTestTools.getTestRootDir(TEST002); + + File tempOut1 = AbstractTestTools.createTempDir(); + toolchain = AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class); + toolchain.addProguardFlags(new ProguardFlags(testFolder, "obf1.flags")) + .libToLib(tempJackFolder, tempOut1, /* zipFiles = */ false); + + File tempOutFolder = AbstractTestTools.createTempDir(); + toolchain = AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class); + toolchain.libToExe(tempJackFolder, tempOutFolder, /* zipFile = */ false); + } + + @Test + public void testPhantomLocalOuter() throws Exception { + File tempJackFolder = AbstractTestTools.createTempDir(); + JackBasedToolchain toolchain = + AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class); + toolchain.srcToLib( + AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()), + tempJackFolder, + /* zipFiles = */ false, + AbstractTestTools.getTestRootDir(TEST002_JACK)); + + boolean deleted = + new File(tempJackFolder, fixPath(FileType.JAYCE.getPrefix() + File.separatorChar + + "com/android/jack/withphantom/test002/jack/A.jayce")).delete(); + Assert.assertTrue(deleted); + + File testFolder = AbstractTestTools.getTestRootDir(TEST002); + + File tempOut1 = AbstractTestTools.createTempDir(); + AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class) + .addProguardFlags(new ProguardFlags(testFolder, "obf1.flags")) + .libToLib(tempJackFolder, tempOut1, /* zipFiles = */ false); + + File tempOutFolder = AbstractTestTools.createTempDir(); + AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class) + .libToExe(tempJackFolder, tempOutFolder, /* zipFile = */ false); + } + +} diff --git a/jack/run-jack-unit-tests b/jack/run-jack-unit-tests index 966e3a86..0005fafe 100755 --- a/jack/run-jack-unit-tests +++ b/jack/run-jack-unit-tests @@ -23,5 +23,5 @@ then fi REF_JAVA_COMPILER='javac' \ -java -cp ${ANDROID_BUILD_TOP}/out/host/linux-x86/framework/libjackunittests.jar \ +java -cp ${ANDROID_BUILD_TOP}/toolchain/jack/jack/dist/jackunittests.jar \ org.junit.runner.JUnitCore $1 diff --git a/jack/src/com/android/jack/Options.java b/jack/src/com/android/jack/Options.java index 001c6d5a..084714e7 100644 --- a/jack/src/com/android/jack/Options.java +++ b/jack/src/com/android/jack/Options.java @@ -281,7 +281,10 @@ public class Options { @Option(name = "-g", usage = "emit debug infos") protected boolean emitLocalDebugInfo = false; - enum MultiDexKind { + /** + * Available mode for the multidex feature + */ + public enum MultiDexKind { NONE, NATIVE, LEGACY diff --git a/jack/tests/com/android/jack/AllTests.java b/jack/tests/com/android/jack/AllTests.java index 7624b6c5..68d67592 100644 --- a/jack/tests/com/android/jack/AllTests.java +++ b/jack/tests/com/android/jack/AllTests.java @@ -16,22 +16,14 @@ package com.android.jack; -import com.android.jack.analysis.dfa.reachingdefs.ReachingDefsTest; import com.android.jack.backend.dex.rop.RopRegisterManagerTest; -import com.android.jack.errorhandling.ErrorHandlingAllTests; -import com.android.jack.experimental.incremental.DependencyAllTests; import com.android.jack.ir.ast.MarkerCollectorTest; import com.android.jack.jayce.v0002.io.EscapeStringTest; -import com.android.jack.multidex.MultiDexOverflowTests; -import com.android.jack.multidex.MultiDexTests; import com.android.jack.optimizations.ExpressionSimplifierTest; -import com.android.jack.optimizations.UselessVariableCopyTest; import com.android.jack.preprocessor.PreProcessorTest; -import com.android.jack.tools.merger.MergerAllTests; import com.android.jack.tracer.TracingTest; import com.android.jack.transformations.ast.string.StringSplittingTest; import com.android.jack.transformations.cast.UselessCastRemoverTest; -import com.android.jack.transformations.flow.CompileFlowTest; import org.junit.runner.RunWith; import org.junit.runners.Suite; @@ -43,77 +35,34 @@ import org.junit.runners.Suite.SuiteClasses; */ @RunWith(Suite.class) @SuiteClasses(value = { - AnnotationTest.class, - ArithmeticTest.class, - ArrayTest.class, - AssertionTest.class, - AssignmentTest.class, - BoxTest.class, - BridgeTest.class, - CastTest.class, com.android.jack.cfg.AllTests.class, com.android.jack.compile.androidtree.AllTests.class, com.android.jack.compile.androidtree.dalvik.AllTests.class, com.android.jack.frontend.AllTests.class, com.android.jack.gwt.AllTests.class, - com.android.jack.java7.AllTest.class, com.android.jack.shrob.AllTests.class, com.android.jack.transformations.ast.AllTests.class, - ComparisonTest.class, - CompileFlowTest.class, - CompileTimeTest.class, - ConcatTest.class, ConditionalTest.class, - ConstantTest.class, - DependencyAllTests.class, - DxTest.class, - EnumTest.class, - ErrorTest.class, - ErrorHandlingAllTests.class, EscapeStringTest.class, ExpressionSimplifierTest.class, FibonacciThreeAddressTest.class, - FieldAccessTest.class, - FieldTest.class, - FileConflictTest.class, FinallyTest.class, - FlowTest.class, - GenericTest.class, - IfTest.class, - ImplicitCastTest.class, - ImportTest.class, - InnerTest.class, - InvokesTest.class, JarjarTest.class, - LookupTest.class, MainTest.class, MarkerCollectorTest.class, - MergerAllTests.class, - MultiDexOverflowTests.class, - MultiDexTests.class, + /* MultiDexOverflowTests.class, */ + /* MultiDexTests.class, */ NoClasspathTest.class, - NoPackageTest.class, - OpcodesTest.class, - OrderTest.class, PreProcessorTest.class, - ReachingDefsTest.class, - ResourceTest.class, - ReturnTest.class, +// ReachingDefsTest.class, RopRegisterManagerTest.class, StaticValuesTest.class, StringSplittingTest.class, - SwitchesTest.class, - SynchronizeTest.class, - ThreeAddressTest.class, - ThrowsTest.class, ToolchainTest.class, - TryCatchTest.class, Types.class, UnaryTest.class, UselessCastRemoverTest.class, - UselessVariableCopyTest.class, WithPhantomTest.class, - ClasspathTest.class, TracingTest.class}) public class AllTests { } diff --git a/jack/tests/com/android/jack/AnnotationTest.java b/jack/tests/com/android/jack/AnnotationTest.java deleted file mode 100644 index cc21ce9a..00000000 --- a/jack/tests/com/android/jack/AnnotationTest.java +++ /dev/null @@ -1,220 +0,0 @@ -/* - * Copyright (C) 2012 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; - -import com.android.jack.category.RedundantTests; - -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import java.io.File; - -/** - * JUnit test for compilation of annotation. - */ -public class AnnotationTest { - - private static final File[] BOOTCLASSPATH = TestTools.getDefaultBootclasspath(); - private static final File ANNOTATION001_PATH = - TestTools.getJackTestsWithJackFolder("annotation/test001"); - - @BeforeClass - public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); - } - - @Test - @Category(RedundantTests.class) - public void test001() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - ANNOTATION001_PATH)); - } - - @Test - public void test001_2() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - new File(ANNOTATION001_PATH, "Annotation2.java"))); - } - - @Test - public void test001_3() throws Exception { - TestTools.checkStructure(BOOTCLASSPATH, null, - new File(ANNOTATION001_PATH, "Annotation2.java"), false /*withDebugInfo*/); - } - - @Test - public void test001_4() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(new File[] { - new File(ANNOTATION001_PATH, "Annotation8.java"), - new File(ANNOTATION001_PATH, "Annotated2.java")})); - } - - @Test - public void test001_5() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(new File[] { - new File(ANNOTATION001_PATH, "Annotation7.java"), - new File(ANNOTATION001_PATH, "Annotated3.java")})); - } - - @Test - public void test001_13() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - new File(ANNOTATION001_PATH, "Annotation13.java"))); - } - - @Test - public void test001_OneEnum() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - new File(ANNOTATION001_PATH, "OneEnum.java"))); - } - - /** - * Verifies that the test source can compiled from source to dex file. - */ - @Test - @Category(RedundantTests.class) - public void test002() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("annotation/test002"))); - } - - @Test - @Category(RedundantTests.class) - public void test003() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("annotation/test003"))); - } - - @Test - @Category(RedundantTests.class) - public void test004() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("annotation/test004"))); - } - - @Test - @Category(RedundantTests.class) - public void test005() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("annotation/test005"))); - } - - @Test - @Category(RedundantTests.class) - public void test006() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("annotation/test006"))); - } - - @Test - @Category(RedundantTests.class) - public void test007() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("annotation/test007"))); - } - - @Test - @Category(RedundantTests.class) - public void test008() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("annotation/test008"))); - } - - @Test - @Category(RedundantTests.class) - public void test009() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("annotation/test009"))); - } - - /** - * Compares annotations in dex file to a reference. - */ - - @Test - public void test001Structure() throws Exception { - AnnotationTestTools.checkStructure(BOOTCLASSPATH, - null, - ANNOTATION001_PATH, - null); - } - - @Test - public void test002Structure() throws Exception { - AnnotationTestTools.checkStructure(BOOTCLASSPATH, - null, - TestTools.getJackTestsWithJackFolder("annotation/test002"), - null); - } - - @Test - public void test003Structure() throws Exception { - AnnotationTestTools.checkStructure(BOOTCLASSPATH, - null, - TestTools.getJackTestsWithJackFolder("annotation/test003"), - null); - } - - @Test - public void test004Structure() throws Exception { - AnnotationTestTools.checkStructure(BOOTCLASSPATH, - null, - TestTools.getJackTestsWithJackFolder("annotation/test004"), - null); - } - - @Test - public void test005Structure() throws Exception { - AnnotationTestTools.checkStructure(BOOTCLASSPATH, - null, - TestTools.getJackTestsWithJackFolder("annotation/test005"), - null); - } - - @Test - public void test006Structure() throws Exception { - AnnotationTestTools.checkStructure(BOOTCLASSPATH, - null, - TestTools.getJackTestsWithJackFolder("annotation/test006"), - null); - } - - @Test - public void test007Structure() throws Exception { - AnnotationTestTools.checkStructure(BOOTCLASSPATH, - null, - TestTools.getJackTestsWithJackFolder("annotation/test007"), - null); - } - - @Test - public void test008Structure() throws Exception { - AnnotationTestTools.checkStructure(BOOTCLASSPATH, - null, - TestTools.getJackTestsWithJackFolder("annotation/test008"), - null); - } - - @Test - public void test009Structure() throws Exception { - AnnotationTestTools.checkStructure(BOOTCLASSPATH, - null, - TestTools.getJackTestsWithJackFolder("annotation/test009"), - null); - } -} diff --git a/jack/tests/com/android/jack/AnnotationTestTools.java b/jack/tests/com/android/jack/AnnotationTestTools.java deleted file mode 100644 index 6501b062..00000000 --- a/jack/tests/com/android/jack/AnnotationTestTools.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * 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; - -import com.android.jack.backend.dex.DexFileWriter; - -import java.io.File; -import java.io.IOException; - -import javax.annotation.CheckForNull; -import javax.annotation.Nonnull; - -/** - * Tools for annotation tests - */ -public class AnnotationTestTools { - - public static void checkStructure(@CheckForNull File[] bootclasspath, - @CheckForNull File[] classpath, @Nonnull File fileOrSourceList, - ProguardFlags[] proguardFlags) throws Exception { - - String classpathStr = TestTools.getClasspathsAsString(bootclasspath, classpath); - - File jackDex = TestTools.createTempDir("jack", "dex"); - - boolean useEcjAsRefCompiler = false; - - TestTools.compileSourceToDex(new Options(), - fileOrSourceList, - classpathStr, - jackDex, - false /* zip */, - null /* jarjarRules */, - proguardFlags, - false /* withDebugInfo */); - - Options refOptions = TestTools.buildCommandLineArgs(bootclasspath, classpath, fileOrSourceList); - - compareDexToReference(jackDex, - refOptions, - proguardFlags, - bootclasspath, - classpath, - useEcjAsRefCompiler, - null); - } - - private static void compareDexToReference(@Nonnull File jackDexFolder, - @Nonnull Options compilerArgs, - @CheckForNull ProguardFlags[] proguardFlags, - @CheckForNull File[] bootclasspath, - @CheckForNull File[] classpath, - boolean useEcjAsRefCompiler, - @CheckForNull JarJarRules jarjarRules) - throws IOException, InterruptedException, DifferenceFoundException { - - // Prepare files and directories - File testDir = TestTools.createTempDir("jacktest", null); - - File refDex = TestTools.createReferenceCompilerFiles(testDir, - compilerArgs, - proguardFlags, - bootclasspath, - classpath, - false /* withDebugInfo */, - useEcjAsRefCompiler, - jarjarRules).dexFile; - - // Compare Jack Dex file to reference - DexAnnotationsComparator comparator = new DexAnnotationsComparator(); - comparator.compare(refDex, new File(jackDexFolder, DexFileWriter.DEX_FILENAME)); - } -} diff --git a/jack/tests/com/android/jack/ArithmeticTest.java b/jack/tests/com/android/jack/ArithmeticTest.java deleted file mode 100644 index 5f64099d..00000000 --- a/jack/tests/com/android/jack/ArithmeticTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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; - -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * JUnit test for compilation of arithmetic. - */ -public class ArithmeticTest { - - @BeforeClass - public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); - } - - @Test - public void testNew001() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools - .getJackTestsWithJackFolder("arithmetic/test001"))); - } - - @Test - public void testNew002() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools - .getJackTestsWithJackFolder("arithmetic/test002"))); - } - - @Test - public void testNew003() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools - .getJackTestsWithJackFolder("arithmetic/test003"))); - } - - @Test - public void testNew004() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools - .getJackTestsWithJackFolder("arithmetic/test004"))); - } -} diff --git a/jack/tests/com/android/jack/ArrayTest.java b/jack/tests/com/android/jack/ArrayTest.java deleted file mode 100644 index 9ecd72a7..00000000 --- a/jack/tests/com/android/jack/ArrayTest.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (C) 2012 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; - -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * JUnit test for compilation of field access. - */ -public class ArrayTest { - - @BeforeClass - public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); - } - - /** - * Verifies that a source containing new array can compile to dex file. - */ - @Test - public void testNew001() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools - .getJackTestsWithJackFolder("newarray/test001"))); - } - - /** - * Verifies that a source containing new array can compile to dex file. - */ - @Test - public void testNew002() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools - .getJackTestsWithJackFolder("newarray/test002"))); - } - - /** - * Verifies that a source containing new array can compile to dex file. - */ - @Test - public void testNew003() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools - .getJackTestsWithJackFolder("newarray/test003"))); - } - - /** - * Verifies that a source containing new array can compile to dex file. - */ - @Test - public void testNew004() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools - .getJackTestsWithJackFolder("newarray/test004"))); - } - - @Test - public void testNew005() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools - .getJackTestsWithJackFolder("newarray/test005"))); - } - - @Test - public void testArray001() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools - .getJackTestsWithJackFolder("array/test001"))); - } -} diff --git a/jack/tests/com/android/jack/AssertionTest.java b/jack/tests/com/android/jack/AssertionTest.java deleted file mode 100644 index 45b41397..00000000 --- a/jack/tests/com/android/jack/AssertionTest.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2012 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; - -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * JUnit test for compilation of static field access. - */ -public class AssertionTest { - - @BeforeClass - public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); - } - - /** - * Verifies that the test source can be compiled from source to dex file. - */ - @Test - public void testCompile() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("assertion/test001"))); - } - - /** - * Verifies that the test source can be compiled from source to dex file. - */ - @Test - public void testCompile2() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("assertion/test002"))); - } - - /** - * Verifies that the test source can be compiled from source to dex file. - */ - @Test - public void testCompile3() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("assertion/test003"))); - } -} diff --git a/jack/tests/com/android/jack/AssignmentTest.java b/jack/tests/com/android/jack/AssignmentTest.java deleted file mode 100644 index a234c152..00000000 --- a/jack/tests/com/android/jack/AssignmentTest.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2012 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; - -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * JUnit test for compilation of assignments tests. - */ -public class AssignmentTest { - - @BeforeClass - public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); - } - - /** - * Verifies that the test source can compiled from source to dex file. - */ - @Test - public void testCompile() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("assign"))); - } -} diff --git a/jack/tests/com/android/jack/BoxTest.java b/jack/tests/com/android/jack/BoxTest.java deleted file mode 100644 index c7ba3596..00000000 --- a/jack/tests/com/android/jack/BoxTest.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2012 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; - -import org.junit.BeforeClass; -import org.junit.Test; - -public class BoxTest { - - @BeforeClass - public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); - } - - @Test - public void test001() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("box/test001"))); - } - -} diff --git a/jack/tests/com/android/jack/BridgeTest.java b/jack/tests/com/android/jack/BridgeTest.java deleted file mode 100644 index 2c4577d5..00000000 --- a/jack/tests/com/android/jack/BridgeTest.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright (C) 2012 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; - -import com.android.jack.category.ExtraTests; - -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import java.io.File; -import java.util.ArrayList; - -/** - * JUnit test for compilation of bridges. - */ -public class BridgeTest { - - @BeforeClass - public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); - } - - /** - * Verifies that the test source can compiled from source to dex file. - */ - @Test - public void test001() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("bridge/test001"))); - } - - /** - * Verifies that the test source can compiled from source to dex file. - */ - @Ignore("Tree") - @Test - public void test002() throws Exception { - File[] bootclasspath = new File[]{TestTools.getFromAndroidTree( - "out/target/common/obj/JAVA_LIBRARIES/core-libart_intermediates/classes.zip"), - TestTools.getFromAndroidTree( - "out/host/common/obj/JAVA_LIBRARIES/junit4-hostdex-jack_intermediates/classes.zip")}; - TestTools.runCompilation(TestTools.buildCommandLineArgs(bootclasspath, null, - TestTools.getJackTestsWithJackFolder("bridge/test002"))); - } - - /** - * Verifies that the test source can compiled from source to dex file. - */ - @Test - public void test003() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("bridge/test003"))); - } - - /** - * Verifies that the test source can compiled from source to dex file. - */ - @Test - public void test004() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("bridge/test004"))); - } - - /** - * Verifies that the test source can compiled from source to dex file. - */ - @Test - public void test005() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("bridge/test005"))); - } - - /** - * Verifies that the test source can compiled from source to dex file. - */ - @Test - public void test006() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("bridge/test006"))); - } - - /** - * Verifies that the test source can compiled from source to dex file. - */ - @Test - @Category(ExtraTests.class) - public void test007() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("bridge/test007"))); - } - - @Test - public void test008() throws Exception { - Options options = new Options(); - File srcFolder = TestTools.getJackTestsWithJackFolder("bridge/test008"); - File jackZipOfGenericPackageProtected = TestTools.createTempFile("tmpBridge", ".zip"); - - // Build jack file from GenericPackageProtected.java - TestTools.compileSourceToJack(options, new File(srcFolder, "sub/GenericPackageProtected.java"), - TestTools.getDefaultBootclasspathString(), jackZipOfGenericPackageProtected, true /* zip */ - ); - - // Build jack file from PublicExtendsGeneric.java - File jackZipOfPublicExtendsGeneric = TestTools.createTempFile("tmpBridge", ".zip"); - TestTools.compileSourceToJack(options, new File(srcFolder, "sub/PublicExtendsGeneric.java"), - TestTools.getDefaultBootclasspathString() + File.pathSeparator - + jackZipOfGenericPackageProtected.getAbsolutePath(), jackZipOfPublicExtendsGeneric, true /* zip */ - ); - - // Build dex file representing Caller.java - options = new Options(); - options.jayceImport = new ArrayList<File>(1); - options.jayceImport.add(jackZipOfPublicExtendsGeneric); - File outDexFolder = TestTools.createTempDir("tmpBridge", "dex"); - TestTools.compileSourceToDex(options, new File(srcFolder, "Caller.java"), - TestTools.getDefaultBootclasspathString(), outDexFolder, false /* zip */); - } - - @Test - public void test009() throws Exception { - TestTools.compileSourceToDex( - new Options(), - TestTools.getJackTestsWithJackFolder("bridge/test009"), - TestTools.getDefaultBootclasspathString(), - TestTools.createTempFile("bridge009", ".zip"), - true /* zip */); - } -} diff --git a/jack/tests/com/android/jack/CastTest.java b/jack/tests/com/android/jack/CastTest.java deleted file mode 100644 index 60eb9a41..00000000 --- a/jack/tests/com/android/jack/CastTest.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2012 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; - -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * JUnit test for compilation of casts. - */ -public class CastTest { - - @BeforeClass - public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); - } - - /** - * Verifies that the test source can compiled from source to dex file. - */ - @Test - public void testCompile() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("cast/explicit001"))); - } - - @Test - public void implicitCast001() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("cast/implicit001"))); - } - - @Test - public void implicitCast004() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("cast/implicit004"))); - } - - @Test - public void implicitCast005() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("cast/implicit005"))); - } -} diff --git a/jack/tests/com/android/jack/ClasspathTest.java b/jack/tests/com/android/jack/ClasspathTest.java deleted file mode 100644 index 021c81e5..00000000 --- a/jack/tests/com/android/jack/ClasspathTest.java +++ /dev/null @@ -1,210 +0,0 @@ -/* - * Copyright (C) 2012 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; - -import com.android.jack.library.FileType; -import com.android.jack.library.LibraryReadingException; - -import junit.framework.Assert; - -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.File; -import java.io.IOException; - -public class ClasspathTest { - - @BeforeClass - public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); - } - - @Test - public void test001() throws Exception { - File libOut = TestTools.createTempDir("ClasspathTest", "lib"); - - Options libOptions = TestTools.buildCommandLineArgs( - TestTools.getJackTestLibFolder("classpath/test001")); - libOptions.setJayceOutputDir(libOut); - TestTools.runCompilation(libOptions); - - File testOut = TestTools.createTempDir("ClasspathTest", "test"); - Options testOptions = TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("classpath/test001")); - testOptions.setJayceOutputDir(testOut); - testOptions.setClasspath(libOut.getAbsolutePath()); - TestTools.runCompilation(testOptions); - } - - @Test - public void test002() throws Exception { - File testFolder = TestTools.getJackTestFolder("classpath/test002"); - File outFolder = TestTools.createTempDir("ClasspathTest2", "2"); - - File lib1Out = new File(outFolder, "lib1"); - { - if (!lib1Out.mkdir()) { - throw new AssertionError("Failed to create dir " + lib1Out.getAbsolutePath()); - } - Options lib1Options = TestTools.buildCommandLineArgs(new File(testFolder, "lib1")); - lib1Options.setJayceOutputDir(lib1Out); - TestTools.runCompilation(lib1Options); - } - - File lib1BisOut = new File(outFolder, "lib1override"); - { - if (!lib1BisOut.mkdir()) { - throw new AssertionError("Failed to create dir " + lib1BisOut.getAbsolutePath()); - } - Options lib1BisOptions = TestTools.buildCommandLineArgs(new File(testFolder, "lib1override")); - lib1BisOptions.setJayceOutputDir(lib1BisOut); - TestTools.runCompilation(lib1BisOptions); - } - - File lib2Out = new File(outFolder, "lib2"); - { - if (!lib2Out.mkdir()) { - throw new AssertionError("Failed to create dir " + lib2Out.getAbsolutePath()); - } - Options lib2Options = TestTools.buildCommandLineArgs(new File(testFolder, "lib2")); - lib2Options.setJayceOutputDir(lib2Out); - lib2Options.setClasspath(lib1Out.getAbsolutePath()); - TestTools.runCompilation(lib2Options); - } - - { - Options testOptions = TestTools.buildCommandLineArgs(new File(testFolder, "jack")); - testOptions.setOutputDir(outFolder); - testOptions.addJayceImport(lib2Out); - testOptions.setClasspath(lib1BisOut.getAbsolutePath()); - TestTools.runCompilation(testOptions); - } - } - - @Test - public void test003() throws Exception { - File libOut = TestTools.createTempDir("ClasspathTest", "lib"); - - Options libOptions = TestTools.buildCommandLineArgs( - TestTools.getJackTestLibFolder("classpath/test003")); - libOptions.setJayceOutputDir(libOut); - TestTools.runCompilation(libOptions); - - { - // reference compilation - File testOut = TestTools.createTempDir("ClasspathTest", "test"); - Options testOptions = TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("classpath/test003")); - testOptions.setJayceOutputDir(testOut); - testOptions.setClasspath(libOut.getAbsolutePath()); - TestTools.runCompilation(testOptions); - } - - { - // delete unused inner in classpath and check we can still compile with it - boolean deleted = - new File(libOut, FileType.JAYCE.getPrefix() - + "/com/android/jack/classpath/test003/lib/HasInnersClasses$InnerToDelete.jayce") - .delete(); - Assert.assertTrue(deleted); - File testOut = TestTools.createTempDir("ClasspathTest", "test"); - Options testOptions = TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("classpath/test003")); - testOptions.setJayceOutputDir(testOut); - testOptions.setClasspath(libOut.getAbsolutePath()); - TestTools.runCompilation(testOptions); - } - } - - @Test - public void libOfLib() throws Exception { - - String defaultClasspath = TestTools.getDefaultBootclasspathString(); - File libOfLibOut = TestTools.createTempFile("libOfLibOut", ".zip"); - String testName = "liboflib/lib2"; - File sourceDir = TestTools.getJackTestsWithJackFolder(testName); - TestTools.compileSourceToJack( - new Options(), sourceDir, defaultClasspath, libOfLibOut, true); - - File libOut = TestTools.createTempFile("libOut", ".zip"); - String testName2 = "liboflib/lib"; - String classpath = defaultClasspath + File.pathSeparatorChar + libOfLibOut.getAbsolutePath(); - File sourceDir2 = TestTools.getJackTestsWithJackFolder(testName2); - TestTools.compileSourceToJack( - new Options(), sourceDir2, classpath, libOut, true); - - File mainOut = TestTools.createTempFile("mainOut", ".zip"); - String testName3 = "liboflib/main"; - classpath = defaultClasspath + File.pathSeparatorChar + libOut.getAbsolutePath(); - File sourceDir3 = TestTools.getJackTestsWithJackFolder(testName3); - TestTools.compileSourceToJack( - new Options(), sourceDir3, classpath, mainOut, true); - } - - @Test - public void testMissingClasspathEntry() throws Exception { - String defaultClasspath = TestTools.getDefaultBootclasspathString(); - File srcDir = TestTools.getJackTestsWithJackFolder("classpath/test004"); - String classpathWithMissingEntry = defaultClasspath + File.pathSeparator + - new File(srcDir, "missing.jack").getAbsolutePath(); - - File testOut = TestTools.createTempFile("ClasspathTest", "missing"); - TestTools.compileSourceToJack(new Options(), srcDir, classpathWithMissingEntry, - testOut, true); - - Options strict = new Options(); - strict.addProperty(Jack.STRICT_CLASSPATH.getName(), "true"); - try { - TestTools.compileSourceToJack(strict, srcDir, classpathWithMissingEntry, - testOut, true); - Assert.fail(); - } catch (JackAbortException e) { - Assert.assertTrue(e.getCause() instanceof LibraryReadingException); - } - } - - @Test - public void testInvalidClasspathEntry() throws Exception { - File srcDir = TestTools.getJackTestsWithJackFolder("classpath/test004"); - compileWithInvalidClasspathEntry(srcDir, new File(srcDir, "Classpath004.java")); - compileWithInvalidClasspathEntry(srcDir, new File(srcDir, "invalid.jack")); - compileWithInvalidClasspathEntry(srcDir, new File(srcDir, "notjack.zip")); - } - - private void compileWithInvalidClasspathEntry(File srcDir, File invalidJack) throws IOException, - Exception { - Assert.assertTrue(invalidJack.isFile()); - String classpathWithInvalidEntry = TestTools.getDefaultBootclasspathString() + - File.pathSeparator + invalidJack.getAbsolutePath(); - - File testOut = TestTools.createTempFile("ClasspathTest", "invalid"); - TestTools.compileSourceToJack(new Options(), srcDir, classpathWithInvalidEntry, - testOut, true); - - Options strict = new Options(); - strict.addProperty(Jack.STRICT_CLASSPATH.getName(), "true"); - try { - TestTools.compileSourceToJack(strict, srcDir, classpathWithInvalidEntry, - testOut, true); - Assert.fail(); - } catch (JackAbortException e) { - Assert.assertTrue(e.getCause() instanceof LibraryReadingException); - } - } - -} diff --git a/jack/tests/com/android/jack/ComparisonTest.java b/jack/tests/com/android/jack/ComparisonTest.java deleted file mode 100644 index e5d16e85..00000000 --- a/jack/tests/com/android/jack/ComparisonTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2012 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; - -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; - -import java.io.File; - -/** - * JUnit test for compilation of comparisons. - */ -@Ignore("Tree") -public class ComparisonTest { - - @BeforeClass - public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); - } - - /** - * Verifies that the test source can compile to dex file. - */ - @Test - public void testCompile() throws Exception { - File[] bootclasspath = new File[]{TestTools.getFromAndroidTree( - "out/target/common/obj/JAVA_LIBRARIES/core-libart_intermediates/classes.zip"), - TestTools.getFromAndroidTree( - "out/host/common/obj/JAVA_LIBRARIES/junit4-hostdex-jack_intermediates/classes.zip")}; - TestTools.runCompilation(TestTools.buildCommandLineArgs(bootclasspath, null, - TestTools.getJackTestsWithJackFolder("comparison/test001"))); - } -} diff --git a/jack/tests/com/android/jack/CompileTimeTest.java b/jack/tests/com/android/jack/CompileTimeTest.java deleted file mode 100644 index 6b96de43..00000000 --- a/jack/tests/com/android/jack/CompileTimeTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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; - -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * JUnit test compiling big class. - */ -public class CompileTimeTest { - - @BeforeClass - public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); - } - - @Test - public void testCompileClassWithALotOfFields() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("compiletime/test001"))); - } - - @Test - public void testCompileClassWithALotOfMethods() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("compiletime/test002"))); - } -} diff --git a/jack/tests/com/android/jack/ConcatTest.java b/jack/tests/com/android/jack/ConcatTest.java deleted file mode 100644 index df156fc0..00000000 --- a/jack/tests/com/android/jack/ConcatTest.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2012 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; - -import org.junit.BeforeClass; -import org.junit.Test; - -public class ConcatTest { - - @BeforeClass - public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); - } - - @Test - public void testCompile001() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("string/concat001"))); - } - - @Test - public void testCompile002() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("string/concat002"))); - } - - @Test - public void testCompile003() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("string/concat003"))); - } -} diff --git a/jack/tests/com/android/jack/ConditionalTest.java b/jack/tests/com/android/jack/ConditionalTest.java index 8155554d..1efc659a 100644 --- a/jack/tests/com/android/jack/ConditionalTest.java +++ b/jack/tests/com/android/jack/ConditionalTest.java @@ -49,45 +49,6 @@ public class ConditionalTest { ThreadConfig.setConfig(options.getConfig()); } - /** - * Verifies that the test source can compiled from source to dex file. - */ - @Test - public void testCompile() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("conditional/test001"))); - } - - /** - * Verifies that the test source can compiled from source to dex file. - */ - @Test - public void testCompile2() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("conditional/test002"))); - } - - /** - * Verifies that the test source can compiled from source to dex file. - */ - @Test - public void testCompile3() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("conditional/test003"))); - } - - @Test - public void testCompile4() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("conditional/test004"))); - } - - @Test - public void testCompile5() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("conditional/test005"))); - } - @Test public void testCompile6() throws Exception { Options options = new Options(); diff --git a/jack/tests/com/android/jack/ConstantTest.java b/jack/tests/com/android/jack/ConstantTest.java deleted file mode 100644 index bfb74046..00000000 --- a/jack/tests/com/android/jack/ConstantTest.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (C) 2012 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; - -import com.android.jack.backend.dex.DexFileWriter; - -import junit.framework.Assert; - -import org.jf.dexlib.CodeItem; -import org.jf.dexlib.DexFile; -import org.jf.dexlib.Code.Instruction; -import org.jf.dexlib.Code.Opcode; -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.File; - -import javax.annotation.Nonnegative; -import javax.annotation.Nonnull; - -public class ConstantTest { - - @Nonnull - private static final File[] BOOTCLASSPATH = TestTools.getDefaultBootclasspath(); - - @BeforeClass - public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); - } - - @Test - public void testClazz() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("constant/clazz"))); - } - - @Test - public void test001() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("constant/test001"))); - } - - @Test - public void test002() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("constant/test002"))); - } - - @Test - public void test003() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("constant/test003"))); - } - - @Test - public void test004() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("constant/test004"))); - } - - @Test - public void test005() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools - .getJackTestsWithJackFolder("constant/test005"))); - - File outFolder = TestTools.createTempDir("uselessConstantInstructions", "dex"); - File out = new File(outFolder, DexFileWriter.DEX_FILENAME); - TestTools.compileSourceToDex(new Options(), - TestTools.getJackTestsWithJackFolder("constant/test005"), - TestTools.getClasspathAsString(BOOTCLASSPATH), outFolder, false); - - DexFile dexFile = new DexFile(out); - CodeItem ci = - TestTools.getEncodedMethod(dexFile, "Lcom/android/jack/constant/test005/jack/Constant005;", - "test", "()I").codeItem; - - Assert.assertEquals(7, countOpcode(ci, Opcode.CONST_4)); - } - - @Nonnegative - private int countOpcode(@Nonnull CodeItem codeItem, @Nonnull Opcode opcode) { - int countOpcode = 0; - for (Instruction inst : codeItem.getInstructions()) { - if (inst.opcode == opcode) { - countOpcode++; - } - } - return countOpcode; - } - - @Test - public void test006() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("constant/test006"))); - } - - @Test - public void test007() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("constant/test007"))); - } - - @Test - public void test008() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("constant/test008"))); - } -} diff --git a/jack/tests/com/android/jack/DebugTest.java b/jack/tests/com/android/jack/DebugTest.java deleted file mode 100644 index fccc1c6d..00000000 --- a/jack/tests/com/android/jack/DebugTest.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright (C) 2012 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; - -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; - -public class DebugTest { - @BeforeClass - public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); - } - - @Test - public void test001() throws Exception { - TestTools.checkStructure( - null, null, TestTools.getJackTestsWithJackFolder("debug/test001"), true); - } - - @Test - public void test002() throws Exception { - TestTools.checkStructure( - null, null, TestTools.getJackTestsWithJackFolder("debug/test002"), true); - } - - @Test - public void test003_1() throws Exception { - Options compilerArgs = - TestTools.buildCommandLineArgs(TestTools.getJackTestsWithJackFolder("debug/test003")); - compilerArgs.emitLocalDebugInfo = true; - TestTools.runCompilation(compilerArgs); - } - - @Test - public void test003_2() throws Exception { - TestTools.checkStructure( - null, null, TestTools.getJackTestsWithJackFolder("debug/test003"), true); - } - - @Test - public void test004_1() throws Exception { - Options compilerArgs = - TestTools.buildCommandLineArgs(TestTools.getJackTestsWithJackFolder("debug/test004")); - compilerArgs.emitLocalDebugInfo = true; - TestTools.runCompilation(compilerArgs); - } - - @Test - public void test004_2() throws Exception { - TestTools.checkStructure( - null, null, TestTools.getJackTestsWithJackFolder("debug/test004"), true); - } - - @Test - public void test005() throws Exception { - TestTools.checkStructure( - null, null, TestTools.getJackTestsWithJackFolder("debug/test005"), true); - } - - @Test - @Ignore() - public void test006() throws Exception { - TestTools.checkStructure( - null, null, TestTools.getJackTestsWithJackFolder("debug/test006"), true); - } - - @Test - public void test007() throws Exception { - TestTools.checkStructure( - null, null, TestTools.getJackTestsWithJackFolder("debug/test007"), true); - } - - @Test - public void test008() throws Exception { - TestTools.checkStructure( - null, null, TestTools.getJackTestsWithJackFolder("debug/test008"), true); - } - - @Test - public void test009() throws Exception { - TestTools.checkStructure( - null, null, TestTools.getJackTestsWithJackFolder("debug/test009"), true); - } - - @Test - public void test010() throws Exception { - TestTools.checkStructure( - null, null, TestTools.getJackTestsWithJackFolder("debug/test010"), true); - } - - @Test - public void test011() throws Exception { - TestTools.checkStructure( - null, null, TestTools.getJackTestsWithJackFolder("debug/test011"), true); - } - - @Test - public void test012() throws Exception { - TestTools.checkStructure( - null, null, TestTools.getJackTestsWithJackFolder("debug/test012"), true); - } - - @Test - public void test013() throws Exception { - TestTools.checkStructure( - null, null, TestTools.getJackTestsWithJackFolder("debug/test013"), true); - } - - @Test - public void test014() throws Exception { - TestTools.checkStructure( - null, null, TestTools.getJackTestsWithJackFolder("debug/test014"), true); - } - - @Test - @Ignore("Debug comparison fails because of local variable default initialization") - public void test019() throws Exception { - TestTools.checkStructure( - null, null, TestTools.getJackTestsWithJackFolder("debug/test019"), true); - } -} diff --git a/jack/tests/com/android/jack/DxTest.java b/jack/tests/com/android/jack/DxTest.java deleted file mode 100644 index aaa875f6..00000000 --- a/jack/tests/com/android/jack/DxTest.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright (C) 2012 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; - -import com.android.jack.backend.dex.DexFileWriter; - -import junit.framework.Assert; - -import org.jf.dexlib.ClassDataItem.EncodedMethod; -import org.jf.dexlib.CodeItem; -import org.jf.dexlib.DexFile; -import org.jf.dexlib.Code.Instruction; -import org.jf.dexlib.Code.Opcode; -import org.jf.dexlib.Code.Analysis.AnalyzedInstruction; -import org.jf.dexlib.Code.Analysis.MethodAnalyzer; -import org.jf.dexlib.Code.Format.Instruction23x; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; - -import java.io.File; - -import javax.annotation.Nonnull; - -/** - * Junit tests related to dx. - */ -public class DxTest { - - @Nonnull - private static final File[] BOOTCLASSPATH = TestTools.getDefaultBootclasspath(); - - @BeforeClass - public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); - } - - /** - * Verifies that the test source can compiled from source to dex file. - */ - @Test - public void test() throws Exception { - TestTools.runCompilation(TestTools - .buildCommandLineArgs(TestTools.getJackTestsWithJackFolder("dx/compiler"))); - } - - /** - * Verifies that the test source can compiled from source to dex file. - */ - @Test - public void testDxOptimizer() throws Exception { - TestTools.runCompilation(TestTools - .buildCommandLineArgs(TestTools.getJackTestsWithJackFolder("dx/optimizer"))); - } - - /** - * Verify that generated dex that not contains register overlapping. - */ - @Test - public void testRegisterOverlapping002() throws Exception { - File outFolder = TestTools.createTempDir("registerOverlapping", "dex"); - File out = new File(outFolder, DexFileWriter.DEX_FILENAME); - TestTools.compileSourceToDex(new Options(), - TestTools.getJackTestsWithJackFolder("dx/overlapping"), - TestTools.getClasspathAsString(BOOTCLASSPATH), outFolder, false); - - DexFile dexFile = new DexFile(out); - EncodedMethod em = - TestTools.getEncodedMethod(dexFile, - "Lcom/android/jack/dx/overlapping/jack/Data;", "test002", - "(IJJ)J"); - - checkThatRegistersDoesNotOverlap(em); - } - - /** - * Verify that generated dex that not contains register overlapping. - */ - @Test - public void testRegisterOverlapping001() throws Exception { - File outFolder = TestTools.createTempDir("registerOverlapping", "dex"); - File out = new File(outFolder, DexFileWriter.DEX_FILENAME); - TestTools.compileSourceToDex(new Options(), - TestTools.getJackTestsWithJackFolder("dx/overlapping"), - TestTools.getClasspathAsString(BOOTCLASSPATH), outFolder, false); - - DexFile dexFile = new DexFile(out); - EncodedMethod em = - TestTools.getEncodedMethod(dexFile, - "Lcom/android/jack/dx/overlapping/jack/Data;", "test001", - "(IJJ)J"); - - checkThatRegistersDoesNotOverlap(em); - } - - /** - * Verify that generated dex contains div_int_2addr. - */ - @Test - @Ignore("Dx register allocator use div_int instead of div_int_2addr in some cases.") - public void testRegallocator() throws Exception { - File out = TestTools.createTempFile("core", ".dex"); - TestTools.compileSourceToDex(new Options(), - TestTools.getJackTestsWithJackFolder("dx/regallocator"), - TestTools.getClasspathAsString(BOOTCLASSPATH), out, false); - - DexFile dexFile = new DexFile(out); - - CodeItem ci = - TestTools.getEncodedMethod(dexFile, "Lcom/android/jack/dx/regallocator/jack/Data;", - "compute1", "(I)I").codeItem; - Assert.assertTrue(hasOpcode(ci, Opcode.DIV_INT_2ADDR)); - ci = - TestTools.getEncodedMethod(dexFile, "Lcom/android/jack/dx/regallocator/jack/Data;", - "compute2", "(I)I").codeItem; - Assert.assertTrue(hasOpcode(ci, Opcode.DIV_INT_2ADDR)); - } - - private boolean hasOpcode(@Nonnull CodeItem codeItem, @Nonnull Opcode opcode) { - for (Instruction inst : codeItem.getInstructions()) { - if (inst.opcode == opcode) { - return true; - } - } - return false; - } - - private void checkThatRegistersDoesNotOverlap(@Nonnull EncodedMethod em) { - MethodAnalyzer ma = new MethodAnalyzer(em, false, null); - for (AnalyzedInstruction ai : ma.getInstructions()) { - if (ai.getInstruction() instanceof Instruction23x) { - Instruction23x inst = (Instruction23x) ai.getInstruction(); - // Register overlaps in the following cases - // v0, v1 = ..., v1, v2 - // v0, v1 = v1, v2, ... - // v1, v2 = ..., v0, v1 - // v1, v2 = v0, v1, ... - if (inst.getRegisterA() + 1 == inst.getRegisterC() - || inst.getRegisterA() + 1 == inst.getRegisterB() - || inst.getRegisterA() == inst.getRegisterC() + 1 - || inst.getRegisterA() == inst.getRegisterB() + 1) { - Assert.fail("Register overlapping"); - } - } - } - } -} diff --git a/jack/tests/com/android/jack/EnumTest.java b/jack/tests/com/android/jack/EnumTest.java deleted file mode 100644 index 69da4b46..00000000 --- a/jack/tests/com/android/jack/EnumTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) 2012 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; - -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * JUnit test for compilation of enums. - */ -public class EnumTest { - - @BeforeClass - public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); - } - - /** - * Verifies that the test source can compile from source to dex file. - */ - @Test - public void testCompile001() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("enums/test001"))); - } - /** - * Verifies that the test source can compile from source to dex file. - */ - @Test - public void testCompile002() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("enums/test002"))); - } - /** - * Verifies that the test source can compile from source to dex file. - */ - @Test - public void testCompile003() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("enums/test003"))); - } -} diff --git a/jack/tests/com/android/jack/FibonacciThreeAddressTest.java b/jack/tests/com/android/jack/FibonacciThreeAddressTest.java index d765c05b..7f188a5f 100644 --- a/jack/tests/com/android/jack/FibonacciThreeAddressTest.java +++ b/jack/tests/com/android/jack/FibonacciThreeAddressTest.java @@ -16,14 +16,12 @@ package com.android.jack; -import com.android.jack.backend.dex.DexFileWriter; import com.android.jack.dx.dex.DexOptions; import com.android.jack.dx.dex.file.ClassDefItem; import com.android.jack.dx.dex.file.DexFile; import com.android.jack.ir.ast.JDefinedClassOrInterface; import com.android.jack.ir.ast.JSession; import com.android.jack.scheduling.marker.ClassDefItemMarker; -import com.android.sched.util.file.FileUtils; import junit.framework.Assert; @@ -37,9 +35,7 @@ import java.io.File; */ public class FibonacciThreeAddressTest { - private static final File[] BOOTCLASSPATH = TestTools.getDefaultBootclasspath(); - - private static final String CLASS_BINARY_NAME = "com/android/jack/fibonacci/jack/FibonacciThreeAddress"; + private static final String CLASS_BINARY_NAME = "com/android/jack/fibonacci/test001/jack/FibonacciThreeAddress"; private static final String CLASS_SIGNATURE = "L" + CLASS_BINARY_NAME + ";"; private static final String JAVA_FILENAME = "FibonacciThreeAddress.java"; private static final File JAVA_FILEPATH = TestTools.getJackTestFromBinaryName(CLASS_BINARY_NAME); @@ -89,40 +85,4 @@ public class FibonacciThreeAddressTest { Assert.assertEquals(JAVA_FILENAME, sourceFilename); } - /** - * Compiles FibonacciThreeAddress into a {@code DexFile} and compares it to a dex file created - * using a reference compiler and {@code dx}. - * @throws Exception - */ - @Test - public void testCompareFiboDexFile() throws Exception { - TestTools.checkStructure(BOOTCLASSPATH, null, JAVA_FILEPATH, false /*withDebugInfo*/); - } - - /** - * Verifies that FibonacciThreeAddress can be written to a dex file. - */ - @Test - public void testWriteFiboDexFile() throws Exception { - - File outputDir = FileUtils.getWorkingDirectory(); - Options fiboArgs = TestTools.buildCommandLineArgs(JAVA_FILEPATH); - fiboArgs.setOutputDir(outputDir); - File outputFile = new File(outputDir, DexFileWriter.DEX_FILENAME); - File outputDirectory = outputFile.getParentFile(); - FileUtils.createIfNotExists(outputDirectory); - - Jack.run(fiboArgs); - - Assert.assertTrue(outputFile.exists()); - Assert.assertTrue(outputFile.length() > 0); - } - - /** - * Verifies that FibonacciThreeAddress can compiled from source to dex file. - */ - @Test - public void testCompileFibo() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(JAVA_FILEPATH)); - } } diff --git a/jack/tests/com/android/jack/FieldAccessTest.java b/jack/tests/com/android/jack/FieldAccessTest.java deleted file mode 100644 index 2cabff5d..00000000 --- a/jack/tests/com/android/jack/FieldAccessTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2012 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; - -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * JUnit test for compilation of field access. - */ -public class FieldAccessTest { - - @BeforeClass - public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); - } - - /** - * Verifies that a source containing static field access can compile to dex file. - */ - @Test - public void testStatic() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("field/static001"))); - } - - /** - * Verifies that a source containing static field access can compile to dex file. - */ - @Test - public void testStatic2() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("field/static002"))); - } - - /** - * Verifies that a source containing static field access can compile to dex file. - */ - @Test - public void testInstance() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("field/instance001"))); - } - -} diff --git a/jack/tests/com/android/jack/FieldTest.java b/jack/tests/com/android/jack/FieldTest.java deleted file mode 100644 index 910084b8..00000000 --- a/jack/tests/com/android/jack/FieldTest.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (C) 2012 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; - -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.File; - -/** - * JUnit test for compilation of fields. - */ -public class FieldTest { - - private static final File[] BOOTCLASSPATH = TestTools.getDefaultBootclasspath(); - - @BeforeClass - public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); - } - - @Test - public void testCompileInstance2() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("field/instance001"))); - } - - @Test - public void testCompileInstance3() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("field/instance002"))); - } - - @Test - public void testCompileInstance4() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("field/instance003"))); - } - - @Test - public void testCompileInstance5() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("field/instance004"))); - } - - @Test - public void testCompileInstance6() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("field/instance005"))); - } - - @Test - public void testCompileStatic() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("field/static003"))); - } - - /** - * Compiles StaticField.java into a {@code DexFile} and compares it to a dex file created - * using a reference compiler and {@code dx}. - */ - @Test - public void testStatic() throws Exception { - TestTools.checkStructure(BOOTCLASSPATH, null, - TestTools.getJackTestsWithJackFolder("field/static003"), false /*withDebugInfo*/); - } - - /** - * Compiles InstanceField.java into a {@code DexFile} and compares it to a dex file created - * using a reference compiler and {@code dx}. - */ - @Test - public void testInstance() throws Exception { - TestTools.checkStructure(BOOTCLASSPATH, null, - TestTools.getJackTestsWithJackFolder("field/instance005"), false /*withDebugInfo*/); - } -} diff --git a/jack/tests/com/android/jack/FinallyTest.java b/jack/tests/com/android/jack/FinallyTest.java index 900a90b2..479adba1 100644 --- a/jack/tests/com/android/jack/FinallyTest.java +++ b/jack/tests/com/android/jack/FinallyTest.java @@ -46,50 +46,6 @@ public class FinallyTest { } @Test - public void testCompileBranching() throws Exception { - TestTools.runCompilation( - TestTools.buildCommandLineArgs(new File[] { - new File(PATH, "B.java"), - new File(PATH, "Branching.java")})); - } - - @Test - public void testCompileCatch() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - new File(PATH, "Catch.java"))); - } - - @Test - public void testCompileEmptyBlocks() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - new File(PATH, "EmptyBlocks.java"))); - } - - @Test - public void testCompileNested() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - new File(PATH, "Nested.java"))); - } - - @Test - public void testCompile002() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("tryfinally/finally002"))); - } - - @Test - public void testCompile003() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("tryfinally/finally003"))); - } - - @Test - public void testCompile004() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("tryfinally/finally004"))); - } - - @Test public void testCompile005() throws Exception { String classBinaryName = "com/android/jack/tryfinally/finally005/jack/Finally005"; String methodSignature = "get()V"; diff --git a/jack/tests/com/android/jack/FlowTest.java b/jack/tests/com/android/jack/FlowTest.java deleted file mode 100644 index a757013a..00000000 --- a/jack/tests/com/android/jack/FlowTest.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2013 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; - -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * JUnit test for compilation of flow tests. - */ -public class FlowTest { - - @BeforeClass - public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); - } - - @Test - public void testCfg001() throws Exception { - TestTools.runCompilation( - TestTools.buildCommandLineArgs(TestTools.getJackTestsWithJackFolder("flow/cfg001"))); - } -} diff --git a/jack/tests/com/android/jack/IfTest.java b/jack/tests/com/android/jack/IfTest.java deleted file mode 100644 index 1839bbfe..00000000 --- a/jack/tests/com/android/jack/IfTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2012 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; - -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * JUnit test for compilation of if statements. - */ -public class IfTest { - - @BeforeClass - public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); - } - - @Test - public void testCompileSimple() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools - .getJackTestsWithJackFolder("ifstatement/simpleTest"))); - } - - @Test - public void testCompileAdvanced() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools - .getJackTestsWithJackFolder("ifstatement/advancedTest"))); - } - - @Test - public void testCompileCfg() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools - .getJackTestsWithJackFolder("ifstatement/cfgTest"))); - } - - @Test - public void testFastPath() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools - .getJackTestsWithJackFolder("ifstatement/fastpath"))); - } -} diff --git a/jack/tests/com/android/jack/ImplicitCastTest.java b/jack/tests/com/android/jack/ImplicitCastTest.java deleted file mode 100644 index a9d34d08..00000000 --- a/jack/tests/com/android/jack/ImplicitCastTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (C) 2012 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; - -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * JUnit test for compilation of static field access. - */ -public class ImplicitCastTest { - - @BeforeClass - public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); - } - - /** - * Verifies that the test source can compile from source to dex file. - */ - @Test - public void testCompile001() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("cast/implicit001"))); - } - /** - * Verifies that the test source can compile from source to dex file. - */ - @Test - public void testCompile002() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("cast/implicit002"))); - } - /** - * Verifies that the test source can compile from source to dex file. - */ - @Test - public void testCompile003() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("cast/implicit003"))); - } - /** - * Verifies that the test source can compile from source to dex file. - */ - @Test - public void testCompile004() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("cast/implicit004"))); - } - /** - * Verifies that the test source can compile from source to dex file. - */ - @Test - public void testCompile006() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("cast/implicit006"))); - } -} diff --git a/jack/tests/com/android/jack/ImportTest.java b/jack/tests/com/android/jack/ImportTest.java deleted file mode 100644 index ca93858e..00000000 --- a/jack/tests/com/android/jack/ImportTest.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * 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; - -import com.android.jack.backend.jayce.ImportConflictException; -import com.android.jack.backend.jayce.JayceFileImporter; -import com.android.jack.backend.jayce.TypeImportConflictException; - -import junit.framework.Assert; - -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.File; - -public class ImportTest { - - @BeforeClass - public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); - } - - @Test - public void testCompileNonConflictingSourceAndImport() throws Exception { - File jackOut = TestTools.createTempDir("importtest", "dir"); - Options options = - TestTools.buildCommandLineArgs(TestTools.getJackTestsWithJackFolder("fibonacci")); - options.libraryOutDir = jackOut; - TestTools.runCompilation(options); - - Options importOptions = - TestTools.buildCommandLineArgs(TestTools.getJackTestsWithJackFolder("threeaddress")); - importOptions.jayceImport.add(jackOut); - TestTools.runCompilation(importOptions); - } - - @Test - public void testCompileConflictingSourceAndImport() throws Exception { - File jackOut = TestTools.createTempDir("importtest", "dir"); - Options options = - TestTools.buildCommandLineArgs(TestTools.getJackTestsWithJackFolder("fibonacci")); - options.libraryOutDir = jackOut; - TestTools.runCompilation(options); - - Options conflictOptions = - TestTools.buildCommandLineArgs(TestTools.getJackTestsWithJackFolder("fibonacci")); - conflictOptions.jayceImport.add(jackOut); - try { - TestTools.runCompilation(conflictOptions); - Assert.fail(); - } catch (ImportConflictException e) { - // expected - } - } - - @Test - public void testConflictingImport() throws Exception { - String testName = "inner/test015"; - File lib = TestTools.createTempDir("inner15Lib", ""); - TestTools.compileSourceToJack( - new Options(), - TestTools.getJackTestLibFolder(testName), - TestTools.getDefaultBootclasspathString(), - lib, - false); - - Options options = new Options(); - options.addJayceImport(lib); - // import twice the same lib - options.addJayceImport(lib); - - options.addProperty(JayceFileImporter.COLLISION_POLICY.getName(), "keep-first"); - TestTools.compileSourceToDex( - options, - TestTools.getJackTestsWithJackFolder(testName), - TestTools.getDefaultBootclasspathString(), - TestTools.createTempFile("inner15", ".zip"), true); - - } - - @Test - public void testConflictingImportWithFailPolicy1() throws Exception { - String testName = "inner/test015"; - File lib = TestTools.createTempDir("inner15Lib", ""); - TestTools.compileSourceToJack( - new Options(), - TestTools.getJackTestLibFolder(testName), - TestTools.getDefaultBootclasspathString(), - lib, - false); - - Options options = new Options(); - options.addJayceImport(lib); - // import twice the same lib - options.addJayceImport(lib); - - options.addProperty(JayceFileImporter.COLLISION_POLICY.getName(), "fail"); - - try { - TestTools.compileSourceToDex(options, TestTools.getJackTestsWithJackFolder(testName), - TestTools.getDefaultBootclasspathString(), TestTools.createTempFile("inner15", ".zip"), - true); - Assert.fail(); - } catch (TypeImportConflictException e) { - // Exception is ok - } - } - - @Test - public void testConflictingImportWithFailPolicy2() throws Exception { - String testName = "inner/test015"; - File lib1 = TestTools.createTempDir("inner15Lib1", ""); - TestTools.compileSourceToJack( - new Options(), - TestTools.getJackTestLibFolder(testName), - TestTools.getDefaultBootclasspathString(), - lib1, - false); - - File lib2 = TestTools.createTempDir("inner15Lib2", ""); - TestTools.compileSourceToJack( - new Options(), - TestTools.getJackTestLibFolder(testName), - TestTools.getDefaultBootclasspathString(), - lib2, - false); - - Options options = new Options(); - options.addJayceImport(lib1); - // import twice the same lib - options.addJayceImport(lib2); - - options.addProperty(JayceFileImporter.COLLISION_POLICY.getName(), "fail"); - - try { - TestTools.compileSourceToDex(options, TestTools.getJackTestsWithJackFolder(testName), - TestTools.getDefaultBootclasspathString(), TestTools.createTempFile("inner15", ".zip"), - true); - Assert.fail(); - } catch (TypeImportConflictException e) { - // Exception is ok - } - } -} diff --git a/jack/tests/com/android/jack/InnerTest.java b/jack/tests/com/android/jack/InnerTest.java deleted file mode 100644 index 5362c39e..00000000 --- a/jack/tests/com/android/jack/InnerTest.java +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Copyright (C) 2012 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; - -import com.android.jack.category.RedundantTests; - -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import java.io.File; - -public class InnerTest { - - private static final File[] BOOTCLASSPATH = TestTools.getDefaultBootclasspath(); - - @BeforeClass - public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); - } - - @Test - public void testCompile() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("inner/test001"))); - } - - @Test - public void testCompile2() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("inner/test002"))); - } - - @Test - public void testCompile3() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("inner/test003"))); - } - - @Test - public void testCompile4() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("inner/test004"))); - } - - @Test - public void testCompile5() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("inner/test005"))); - } - - @Test - public void testCompile6() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("inner/test006"))); - } - - @Test - public void testCompile7() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("inner/test007"))); - } - - @Test - public void testCompile8() throws Exception { - String testName = "inner/test008"; - TestTools.runCompilation(TestTools.buildCommandLineArgs(new File[] { - TestTools.getJackTestsWithJackFolder(testName), - TestTools.getJackTestLibFolder(testName)})); - } - - @Test - public void testCompile9() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("inner/test009"))); - } - - @Test - public void testCompile10() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("inner/test010"))); - } - - @Test - public void testCompile11() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("inner/test011"))); - } - - @Test - public void testCompile12() throws Exception { - String testName = "inner/test012"; - TestTools.runCompilation(TestTools.buildCommandLineArgs(new File[] { - TestTools.getJackTestsWithJackFolder(testName), - TestTools.getJackTestLibFolder(testName)})); - } - - @Test - public void testCompile13() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("inner/test013"))); - } - - @Test - public void testCompile14() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("inner/test014"))); - } - - @Test - public void testCompile15() throws Exception { - String testName = "inner/test015"; - TestTools.runCompilation(TestTools.buildCommandLineArgs(new File[] { - TestTools.getJackTestsWithJackFolder(testName), - TestTools.getJackTestLibFolder(testName)})); - } - - @Test - public void testCompile16() throws Exception { - String testName = "inner/test016"; - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder(testName))); - } - - @Test - public void testCompile17() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("inner/test017"))); - } - - @Test - public void testCompile18() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("inner/test018"))); - } - - @Test - public void testCompile19() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("inner/test019"))); - } - - @Test - @Category(RedundantTests.class) - public void testCompile20() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("inner/test020"))); - } - - @Test - public void testCheckStructure20() throws Exception { - //TODO: find out why debug info check fails - TestTools.checkStructure(BOOTCLASSPATH, null, - TestTools.getJackTestsWithJackFolder("inner/test020"), false /*withDebugInfo*/); - } - - @Test - @Category(RedundantTests.class) - public void testCompile21() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("inner/test021"))); - } - - @Test - public void testCheckStructure21() throws Exception { - TestTools.checkStructure(BOOTCLASSPATH, null, - TestTools.getJackTestsWithJackFolder("inner/test021"), false /*withDebugInfo*/); - } - - @Test - public void testCompile22() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("inner/test022"))); - } - - @Test - public void testCompile23() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("inner/test023"))); - } - - @Test - public void testCompile24() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("inner/test024"))); - } - - @Test - public void testCompile25() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("inner/test025"))); - } -} diff --git a/jack/tests/com/android/jack/InvokesTest.java b/jack/tests/com/android/jack/InvokesTest.java deleted file mode 100644 index 1c18e571..00000000 --- a/jack/tests/com/android/jack/InvokesTest.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (C) 2012 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; - -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.File; - -/** - * JUnit test for compilation of invoke tests. - */ -public class InvokesTest { - - @BeforeClass - public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); - } - - /** - * Verifies that the test source can compiled from source to dex file. - */ - @Test - public void testCompile() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("invoke/test001"))); - } - - @Test - public void testCompile002() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("invoke/test002"))); - } - - @Test - public void testCompile003() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("invoke/test003"))); - } - - @Test - public void testCompile004() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("invoke/test004"))); - } - - @Test - public void testCompile005() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(new File[] { - TestTools.getJackTestsWithJackFolder("invoke/test005"), - TestTools.getJackTestLibFolder("invoke/test005")})); - } - - @Test - public void testCompile006() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("invoke/test006"))); - } - - @Test - public void testCompile007() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("invoke/test007"))); - } -} diff --git a/jack/tests/com/android/jack/JarjarTest.java b/jack/tests/com/android/jack/JarjarTest.java index df45adab..0ca1b4c6 100644 --- a/jack/tests/com/android/jack/JarjarTest.java +++ b/jack/tests/com/android/jack/JarjarTest.java @@ -16,7 +16,6 @@ package com.android.jack; -import com.android.jack.category.RedundantTests; import com.tonicsystems.jarjar.PackageRemapper; import com.tonicsystems.jarjar.PatternElement; import com.tonicsystems.jarjar.Rule; @@ -26,9 +25,7 @@ import junit.framework.Assert; import org.junit.BeforeClass; import org.junit.Test; -import org.junit.experimental.categories.Category; -import java.io.File; import java.util.Collections; import javax.annotation.Nonnull; @@ -51,42 +48,6 @@ public class JarjarTest { } @Test - public void test001() throws Exception { - String testName = "jarjar/test001"; - Options ecjArgs = TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder(testName), - new File(TestTools.getJackTestFolder(testName), "jarjar-rules.txt")); - TestTools.runCompilation(ecjArgs); - } - - @Test - @Category(RedundantTests.class) - public void test003() throws Exception { - String testName = "jarjar/test003"; - Options ecjArgs = TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder(testName), - new File(TestTools.getJackTestFolder(testName), "jarjar-rules.txt")); - TestTools.runCompilation(ecjArgs); - } - - @Test - public void test003_1() throws Exception { - String testName = "jarjar/test003"; - Options options = new Options(); - options.jarjarRulesFile = new File(TestTools.getJackTestFolder(testName), "jarjar-rules.txt"); - File lib = TestTools.createTempFile("jarjarTest003Jack", ".zip"); - TestTools.compileSourceToJack(options, TestTools.getJackTestsWithJackFolder(testName), - TestTools.getDefaultBootclasspathString(), lib, true); - TestTools.compileSourceToJack(new Options(), - new File(TestTools.getJackTestFolder(testName), - "dontcompile/TestWithRelocatedReference.java"), - TestTools.getDefaultBootclasspathString() + File.pathSeparator + lib.getAbsolutePath(), - TestTools.createTempFile("jarjarTest003dx", ".zip"), - true); - - } - - @Test public void testMapValue() { assertUnchangedValue("[^\\s;/@&=,.?:+$]"); assertUnchangedValue("[Ljava/lang/Object;"); diff --git a/jack/tests/com/android/jack/LookupTest.java b/jack/tests/com/android/jack/LookupTest.java deleted file mode 100644 index 283510e9..00000000 --- a/jack/tests/com/android/jack/LookupTest.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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; - -import org.junit.Test; - -import java.io.File; - -public class LookupTest { - - @Test - public void test001() throws Exception { - File lib = TestTools.createTempDir("Lookup001Lib", ""); - TestTools.compileSourceToJack( - new Options(), - TestTools.getJackTestLibFolder("lookup/test001"), - TestTools.getDefaultBootclasspathString(), - lib, - false); - - File libOverride = TestTools.createTempDir("Lookup001LibOverride", ""); - TestTools.compileSourceToJack( - new Options(), - new File(TestTools.getJackTestFolder("lookup/test001"), "liboverride"), - TestTools.getDefaultBootclasspathString(), - libOverride, - false); - - File jacks = TestTools.createTempDir("Lookup001Jacks", ""); - TestTools.compileSourceToJack( - new Options(), - TestTools.getJackTestsWithJackFolder("lookup/test001"), - TestTools.getDefaultBootclasspathString() + File.pathSeparator + lib.getAbsolutePath(), - jacks, - false); - - Options options = new Options(); - options.addJayceImport(jacks); - options.addJayceImport(libOverride); - options.outZip = TestTools.createTempFile("Lookup001", ".zip"); - Jack.run(options); - } - -} diff --git a/jack/tests/com/android/jack/MainTest.java b/jack/tests/com/android/jack/MainTest.java index 625aea3a..0750edf6 100644 --- a/jack/tests/com/android/jack/MainTest.java +++ b/jack/tests/com/android/jack/MainTest.java @@ -29,7 +29,7 @@ import org.junit.Test; */ public class MainTest { - private static final String CLASS_BINARY_NAME = "com/android/jack/fibonacci/jack/Fibo"; + private static final String CLASS_BINARY_NAME = "com/android/jack/fibonacci/test001/jack/Fibo"; private static final String CLASS_SIGNATURE = "L" + CLASS_BINARY_NAME + ";"; @BeforeClass @@ -39,16 +39,6 @@ public class MainTest { } /** - * Verifies that a call to {link Main#runCompilation(String[])} complete - * without throwing exception. - */ - @Test - public void testRunCompilation() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestFromBinaryName(CLASS_BINARY_NAME))); - } - - /** * Verifies that Fibo can be loaded in J-AST. */ @Test diff --git a/jack/tests/com/android/jack/NoPackageTest.java b/jack/tests/com/android/jack/NoPackageTest.java deleted file mode 100644 index 56ba35e3..00000000 --- a/jack/tests/com/android/jack/NoPackageTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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; - -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.File; - -public class NoPackageTest { - - @BeforeClass - public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); - } - - @Test - public void test001() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("nopackage"))); - } - - @Test - public void test001_throughJayce() throws Exception { - File tmpDir = TestTools.createTempDir("NoPackageTest", "dir"); - - String testName = "nopackage"; - String classpath = TestTools.getDefaultBootclasspathString(); - File sourceDir = TestTools.getJackTestsWithJackFolder(testName); - TestTools.compileSourceToJack( - new Options(), sourceDir, classpath, tmpDir, false); - File tmpDexFolder = TestTools.createTempDir("NoPackageTest", "dex"); - TestTools.compileJackToDex(new Options(), tmpDir, tmpDexFolder, false); - } - -} diff --git a/jack/tests/com/android/jack/OpcodesTest.java b/jack/tests/com/android/jack/OpcodesTest.java deleted file mode 100644 index 25ae4c43..00000000 --- a/jack/tests/com/android/jack/OpcodesTest.java +++ /dev/null @@ -1,558 +0,0 @@ -/* - * Copyright (C) 2012 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; -import org.junit.BeforeClass; -import org.junit.Test; -/** - * JUnit test for compilation of arithmetic tests. - */ -public class OpcodesTest { - @BeforeClass - public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); - } - - @Test - public void testCompile_add_double() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("add_double"))); - } - - @Test - public void testCompile_float_to_long() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("float_to_long"))); - } - - @Test - public void testCompile_array_length() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("array_length"))); - } - - @Test - public void testCompile_sub_double() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("sub_double"))); - } - - @Test - public void testCompile_int_to_short() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("int_to_short"))); - } - - @Test - public void testCompile_aput() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("aput"))); - } - - @Test - public void testCompile_if_gez() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("if_gez"))); - } - - @Test - public void testCompile_check_cast() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("check_cast"))); - } - - @Test - public void testCompile_cmpl_double() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("cmpl_double"))); - } - - @Test - public void testCompile_double_to_int() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("double_to_int"))); - } - - @Test - public void testCompile_int_to_byte() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("int_to_byte"))); - } - - @Test - public void testCompile_shl_int() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("shl_int"))); - } - - @Test - public void testCompile_long_to_double() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("long_to_double"))); - } - - @Test - public void testCompile_if_ge() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("if_ge"))); - } - - @Test - public void testCompile_opc_new() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("opc_new"))); - } - - @Test - public void testCompile_add_float() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("add_float"))); - } - - @Test - public void testCompile_cmp_long() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("cmp_long"))); - } - - @Test - public void testCompile_opc_instanceof() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("opc_instanceof"))); - } - - @Test - public void testCompile_int_to_char() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("int_to_char"))); - } - - @Test - public void testCompile_aget_short() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("aget_short"))); - } - - @Test - public void testCompile_and_int() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("and_int"))); - } - - @Test - public void testCompile_if_eqz() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("if_eqz"))); - } - - @Test - public void testCompile_opc_goto() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("opc_goto"))); - } - - @Test - public void testCompile_if_gtz() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("if_gtz"))); - } - - @Test - public void testCompile_or_int() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("or_int"))); - } - - @Test - public void testCompile_int_to_double() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("int_to_double"))); - } - - @Test - public void testCompile_xor_long() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("xor_long"))); - } - - @Test - public void testCompile_rem_int() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("rem_int"))); - } - - @Test - public void testCompile_opc_throw() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("opc_throw"))); - } - - @Test - public void testCompile_shr_long() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("shr_long"))); - } - - @Test - public void testCompile_cmpg_double() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("cmpg_double"))); - } - - @Test - public void testCompile_mul_double() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("mul_double"))); - } - - @Test - public void testCompile_cmpg_float() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("cmpg_float"))); - } - - @Test - public void testCompile_mul_int() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("mul_int"))); - } - - @Test - public void testCompile_neg_float() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("neg_float"))); - } - - @Test - public void testCompile_div_double() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("div_double"))); - } - - @Test - public void testCompile_monitor_enter() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("monitor_enter"))); - } - - @Test - public void testCompile_and_long() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("and_long"))); - } - - @Test - public void testCompile_if_ltz() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("if_ltz"))); - } - - @Test - public void testCompile_sparse_switch() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("sparse_switch"))); - } - - @Test - public void testCompile_sget() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("sget"))); - } - - @Test - public void testCompile_ushr_long() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("ushr_long"))); - } - - @Test - public void testCompile_const_wide() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("const_wide"))); - } - - @Test - public void testCompile_aget() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("aget"))); - } - - @Test - public void testCompile_iput() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("iput"))); - } - - @Test - public void testCompile_sput() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("sput"))); - } - - @Test - public void testCompile_return_object() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("return_object"))); - } - - @Test - public void testCompile_invoke_virtual() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("invoke_virtual"))); - } - - @Test - public void testCompile_aget_object() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("aget_object"))); - } - - @Test - public void testCompile_neg_double() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("neg_double"))); - } - - @Test - public void testCompile_int_to_float() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("int_to_float"))); - } - - @Test - public void testCompile_invoke_static() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("invoke_static"))); - } - - @Test - public void testCompile_rem_long() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("rem_long"))); - } - - @Test - public void testCompile_aget_wide() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("aget_wide"))); - } - - @Test - public void testCompile_float_to_double() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("float_to_double"))); - } - - @Test - public void testCompile_if_lt() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("if_lt"))); - } - - @Test - public void testCompile_double_to_float() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("double_to_float"))); - } - - @Test - public void testCompile_double_to_long() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("double_to_long"))); - } - - @Test - public void testCompile_return_wide() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("return_wide"))); - } - - @Test - public void testCompile_add_long() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("add_long"))); - } - - @Test - public void testCompile_shl_long() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("shl_long"))); - } - - @Test - public void testCompile_aput_byte() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("aput_byte"))); - } - - @Test - public void testCompile_aget_char() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("aget_char"))); - } - - @Test - public void testCompile_const4_16() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("const4_16"))); - } - - @Test - public void testCompile_sub_int() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("sub_int"))); - } - - @Test - public void testCompile_neg_long() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("neg_long"))); - } - - @Test - public void testCompile_opc_return() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("opc_return"))); - } - - @Test - public void testCompile_sub_long() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("sub_long"))); - } - - @Test - public void testCompile_long_to_float() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("long_to_float"))); - } - - @Test - public void testCompile_if_le() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("if_le"))); - } - - @Test - public void testCompile_aget_byte() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("aget_byte"))); - } - - @Test - public void testCompile_iget() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("iget"))); - } - - @Test - public void testCompile_aput_char() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("aput_char"))); - } - - @Test - public void testCompile_int_to_long() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("int_to_long"))); - } - - @Test - public void testCompile_div_float() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("div_float"))); - } - - @Test - public void testCompile_if_nez() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("if_nez"))); - } - - @Test - public void testCompile_div_int() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("div_int"))); - } - - @Test - public void testCompile_float_to_int() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("float_to_int"))); - } - - @Test - public void testCompile_long_to_int() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("long_to_int"))); - } - - @Test - public void testCompile_cmpl_float() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("cmpl_float"))); - } - - @Test - public void testCompile_shr_int() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("shr_int"))); - } - - @Test - public void testCompile_if_eq() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("if_eq"))); - } - - @Test - public void testCompile_add_int() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("add_int"))); - } - - @Test - public void testCompile_or_long() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("or_long"))); - } - - @Test - public void testCompile_mul_long() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("mul_long"))); - } - - @Test - public void testCompile_if_lez() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("if_lez"))); - } - - @Test - public void testCompile_sub_float() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("sub_float"))); - } - - @Test - public void testCompile_rem_double() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("rem_double"))); - } - - @Test - public void testCompile_neg_int() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("neg_int"))); - } - - @Test - public void testCompile_aput_wide() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("aput_wide"))); - } - - @Test - public void testCompile_div_long() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("div_long"))); - } - - @Test - public void testCompile_xor_int() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("xor_int"))); - } - - @Test - public void testCompile_aput_object() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("aput_object"))); - } - - @Test - public void testCompile_new_array() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("new_array"))); - } - - @Test - public void testCompile_aput_short() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("aput_short"))); - } - - @Test - public void testCompile_invoke_direct() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("invoke_direct"))); - } - - @Test - public void testCompile_invoke_super() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("invoke_super"))); - } - - @Test - public void testCompile_if_ne() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("if_ne"))); - } - - @Test - public void testCompile_rem_float() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("rem_float"))); - } - - @Test - public void testCompile_ushr_int() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("ushr_int"))); - } - - @Test - public void testCompile_invoke_interface() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("invoke_interface"))); - } - - @Test - public void testCompile_mul_float() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("mul_float"))); - } - - @Test - public void testCompile_if_gt() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("if_gt"))); - } - - @Test - public void testCompile_packed_switch() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("packed_switch"))); - } - - @Test - public void testCompile_const_string() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("const_string"))); - } - - @Test - public void testCompile_opc_const() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getOpcodeTestFolder("opc_const"))); - } -} diff --git a/jack/tests/com/android/jack/OrderTest.java b/jack/tests/com/android/jack/OrderTest.java deleted file mode 100644 index ca4c8720..00000000 --- a/jack/tests/com/android/jack/OrderTest.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2012 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; - -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * JUnit test for compilation of evaluation order tests. - */ -public class OrderTest { - - @BeforeClass - public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); - } - - /** - * Verifies that the test source can compiled from source to dex file. - */ - @Test - public void testCompile() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getJackTestsWithJackFolder("order"))); - } -} diff --git a/jack/tests/com/android/jack/ReturnTest.java b/jack/tests/com/android/jack/ReturnTest.java deleted file mode 100644 index 3916dbb4..00000000 --- a/jack/tests/com/android/jack/ReturnTest.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2012 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; - -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * JUnit test for compilation of return. - */ -public class ReturnTest { - - @BeforeClass - public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); - } - - /** - * Verifies that the test source can compiled from source to dex file. - */ - @Test - public void testCompileReturnVoid() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools - .getJackTestsWithJackFolder("returnstatement/returnvoid"))); - } - - /** - * Verifies that the test source can compiled from source to dex file. - */ - @Test - public void testCompileReturns() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools - .getJackTestsWithJackFolder("returnstatement/returns"))); - } -} diff --git a/jack/tests/com/android/jack/SwitchesTest.java b/jack/tests/com/android/jack/SwitchesTest.java deleted file mode 100644 index 7e92046a..00000000 --- a/jack/tests/com/android/jack/SwitchesTest.java +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright (C) 2012 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; - -import com.android.jack.backend.dex.DexFileWriter; - -import junit.framework.Assert; - -import org.jf.dexlib.ClassDataItem.EncodedMethod; -import org.jf.dexlib.DexFile; -import org.jf.dexlib.Code.Analysis.AnalyzedInstruction; -import org.jf.dexlib.Code.Analysis.MethodAnalyzer; -import org.jf.dexlib.Code.Format.PackedSwitchDataPseudoInstruction; -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -import javax.annotation.Nonnull; - -/** - * JUnit test for compilation of static field access. - */ -public class SwitchesTest { - - @Nonnull - private static final File[] BOOTCLASSPATH = TestTools.getDefaultBootclasspath(); - - @BeforeClass - public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); - } - - @Test - public void testCompile1() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("switchstatement/test001"))); - } - - @Test - public void testCompile2() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("switchstatement/test002"))); - } - - - @Test - public void testCompile2AsJackThenDex() throws Exception { - File outJackTmp = TestTools.createTempDir("switchstatement2", ".jayce"); - try { - - { - // build as jack - Options options = TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("switchstatement/test002")); - options.setJayceOutputDir(outJackTmp); - TestTools.runCompilation(options); - } - - { - // build dex from jack - - File emptySource = new File("Empty.java"); - if (!emptySource.exists()) { - if (!emptySource.createNewFile()) { - throw new AssertionError("Failed to create " + emptySource.getAbsolutePath()); - } - } - - Options options = TestTools.buildCommandLineArgs(null, null, emptySource); - List<File> l = new ArrayList<File>(); - l.add(outJackTmp); - options.setJayceImports(l); - TestTools.runCompilation(options); - } - } catch (Exception e) { - System.err.println("Not deleting temp files of failed test in " + - outJackTmp.getAbsolutePath()); - throw e; - } - } - - @Test - public void testCompile3() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("switchstatement/test003"))); - } - - @Test - public void testCompile4() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("switchstatement/test004"))); - } - - @Test - public void testCompile7() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("switchstatement/test007"))); - } - - @Test - public void testCompile8() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("switchstatement/test008"))); - } - - /** - * Test allowing to check that 'packed-switch-payload' into generated dex is as small as possible. - */ - @Test - public void testCompile9() throws Exception { - File outFolder = TestTools.createTempDir("packedSwitchPayloadTest", "dex"); - File out = new File(outFolder, DexFileWriter.DEX_FILENAME); - - TestTools.compileSourceToDex(new Options(), - TestTools.getJackTestsWithJackFolder("switchstatement/test009"), - TestTools.getClasspathAsString(BOOTCLASSPATH), outFolder, false); - - DexFile dexFile = new DexFile(out); - EncodedMethod em = - TestTools.getEncodedMethod(dexFile, - "Lcom/android/jack/switchstatement/test009/jack/Switch;", "switch1", - "(Lcom/android/jack/switchstatement/test009/jack/Switch$Num;)Z"); - - MethodAnalyzer ma = new MethodAnalyzer(em, false, null); - boolean packedSwitchDataPseudo = false; - for (AnalyzedInstruction ai : ma.getInstructions()) { - if (ai.getInstruction() instanceof PackedSwitchDataPseudoInstruction) { - packedSwitchDataPseudo = true; - Assert.assertEquals(5, - ((PackedSwitchDataPseudoInstruction) ai.getInstruction()).getTargetCount()); - } - } - - Assert.assertTrue(packedSwitchDataPseudo); - } - - - @Test - public void testCompile10() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("switchstatement/test010"))); - } -} diff --git a/jack/tests/com/android/jack/TestTools.java b/jack/tests/com/android/jack/TestTools.java index dd6393b3..6bfe6f1b 100644 --- a/jack/tests/com/android/jack/TestTools.java +++ b/jack/tests/com/android/jack/TestTools.java @@ -21,7 +21,6 @@ import com.android.jack.Options.VerbosityLevel; import com.android.jack.backend.dex.DexFileWriter; import com.android.jack.backend.dex.IntermediateDexProduct; import com.android.jack.backend.jayce.JayceFormatProduct; -import com.android.jack.dx.dex.file.DexFile; import com.android.jack.ir.ast.JDefinedClassOrInterface; import com.android.jack.ir.ast.JMethod; import com.android.jack.ir.ast.JSession; @@ -1015,9 +1014,10 @@ public class TestTools { private static void compileWithEcj(Options compilerArgs, File out) { List<String> jackEcjArgs = getRefCompilerArguments(compilerArgs); - String[] args = new String[jackEcjArgs.size() + 4]; + String[] args = new String[jackEcjArgs.size() + 5]; int i = 0; args[i++] = "-noExit"; + args[i++] = "-1.6"; args[i++] = "-preserveAllLocals"; for (String compilerArg : jackEcjArgs) { args[i++] = compilerArg; diff --git a/jack/tests/com/android/jack/ThreeAddressTest.java b/jack/tests/com/android/jack/ThreeAddressTest.java deleted file mode 100644 index 8d10c33a..00000000 --- a/jack/tests/com/android/jack/ThreeAddressTest.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2012 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; - -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * JUnit test for compilation of three address tests. - */ -public class ThreeAddressTest { - - @BeforeClass - public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); - } - - /** - * Verifies that the test source can compiled from source to dex file. - */ - @Test - public void testCompile() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs(TestTools.getJackTestsWithJackFolder("threeaddress"))); - } -} diff --git a/jack/tests/com/android/jack/ThrowsTest.java b/jack/tests/com/android/jack/ThrowsTest.java deleted file mode 100644 index c919f69c..00000000 --- a/jack/tests/com/android/jack/ThrowsTest.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2012 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; - -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * JUnit test for compilation of throws. - */ -public class ThrowsTest { - - @BeforeClass - public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); - } - - /** - * Verifies that the test source can compiled from source to dex file. - */ - @Test - public void testCompile() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("throwstatement/test001"))); - } -} diff --git a/jack/tests/com/android/jack/TryCatchTest.java b/jack/tests/com/android/jack/TryCatchTest.java deleted file mode 100644 index 54d3156a..00000000 --- a/jack/tests/com/android/jack/TryCatchTest.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (C) 2012 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; - -import junit.framework.Assert; - -import org.jf.dexlib.CodeItem; -import org.jf.dexlib.DexFile; -import org.jf.dexlib.Code.Instruction; -import org.jf.dexlib.Code.Opcode; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; - -import java.io.File; - -import javax.annotation.Nonnull; - -/** - * JUnit test for compilation of try/catch. - */ -public class TryCatchTest { - - @Nonnull - private static final File[] BOOTCLASSPATH = TestTools.getDefaultBootclasspath(); - - @BeforeClass - public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); - } - - /** - * Verifies that the test source can compiled from source to dex file. - */ - @Test - public void testCompile() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("trycatch/test001"))); - } - - /** - * Verifies that the test source can compiled from source to dex file. - */ - @Test - public void testCompile2() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("trycatch/test002"))); - } - - /** - * Verifies that the test source can compiled from source to dex file. - */ - @Test - public void testCompile3() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("trycatch/test003"))); - } - - @Test - public void testCompile5() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("trycatch/test005"))); - } - - /** - * Verify that generated dex does not contains useless 'mov' instructions. - */ - @Test - @Ignore("Generated dex contains useless 'mov' instructions") - public void uselessMovInstructions() throws Exception { - File out = TestTools.createTempFile("uselessMovInstructions", ".dex"); - TestTools.compileSourceToDex(new Options(), - TestTools.getJackTestsWithJackFolder("trycatch/test004"), - TestTools.getClasspathAsString(BOOTCLASSPATH), out, false); - - DexFile dexFile = new DexFile(out); - CodeItem ci = - TestTools.getEncodedMethod(dexFile, "Lcom/android/jack/trycatch/test004/jack/TryCatch;", - "setIconAndText", "(IIILjava/lang/String;II)V").codeItem; - - Assert.assertFalse(hasOpcode(ci, Opcode.MOVE_OBJECT)); - } - - private boolean hasOpcode(@Nonnull CodeItem codeItem, @Nonnull Opcode opcode) { - for (Instruction inst : codeItem.getInstructions()) { - if (inst.opcode == opcode) { - return true; - } - } - return false; - } -} diff --git a/jack/tests/com/android/jack/TryWithResourcesTest.java b/jack/tests/com/android/jack/TryWithResourcesTest.java deleted file mode 100644 index c3405394..00000000 --- a/jack/tests/com/android/jack/TryWithResourcesTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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; - -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * JUnit test for compilation of try-with-resources. - */ -public class TryWithResourcesTest { - - @BeforeClass - public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); - } - - /** - * Verifies that the test source can compiled from source to dex file. - */ - @Test - public void testCompile() throws Exception { - Options options = TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("java7/trywithresources/test001")); - options.addProperty(Options.JAVA_SOURCE_VERSION.getName(), "1.7"); - TestTools.runCompilation(options); - } - - /** - * Verifies that the test source can compiled from source to dex file. - */ - @Test - public void testCompile2() throws Exception { - Options options = TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("java7/trywithresources/test002")); - options.addProperty(Options.JAVA_SOURCE_VERSION.getName(), "1.7"); - TestTools.runCompilation(options); - } -} diff --git a/jack/tests/com/android/jack/Types.java b/jack/tests/com/android/jack/Types.java index 0306835a..6e0f6d45 100644 --- a/jack/tests/com/android/jack/Types.java +++ b/jack/tests/com/android/jack/Types.java @@ -510,15 +510,4 @@ public class Types { .getType()); } - @Test - public void test001() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("type/test001"))); - } - - @Test - public void test002() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("type/test002"))); - } } diff --git a/jack/tests/com/android/jack/UnaryTest.java b/jack/tests/com/android/jack/UnaryTest.java index 2b04da42..f72342ed 100644 --- a/jack/tests/com/android/jack/UnaryTest.java +++ b/jack/tests/com/android/jack/UnaryTest.java @@ -37,42 +37,6 @@ public class UnaryTest { Main.class.getClassLoader().setDefaultAssertionStatus(true); } - /** - * Verifies that the test source can compiled from source to dex file. - */ - @Test - public void testCompile() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("unary/test001"))); - } - - /** - * Verifies that the test source can compiled from source to dex file. - */ - @Test - public void testCompile2() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("unary/test002"))); - } - - /** - * Verifies that the test source can compiled from source to dex file. - */ - @Test - public void testCompile3() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("unary/test003"))); - } - - /** - * Verifies that the test source can compiled from source to dex file. - */ - @Test - public void testCompile4() throws Exception { - TestTools.runCompilation(TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("unary/test004"))); - } - @Test public void testCompile5() throws Exception { String classBinaryName = "com/android/jack/unary/test005/jack/UnaryNot"; diff --git a/jack/tests/com/android/jack/analysis/dfa/reachingdefs/ReachingDefsTest.java b/jack/tests/com/android/jack/analysis/dfa/reachingdefs/ReachingDefsTest.java index b1765dde..e2d5aaf4 100644 --- a/jack/tests/com/android/jack/analysis/dfa/reachingdefs/ReachingDefsTest.java +++ b/jack/tests/com/android/jack/analysis/dfa/reachingdefs/ReachingDefsTest.java @@ -17,8 +17,6 @@ package com.android.jack.analysis.dfa.reachingdefs; import com.android.jack.Main; -import com.android.jack.Options; -import com.android.jack.TestTools; import com.android.jack.analysis.DefinitionMarker; import com.android.jack.cfg.BasicBlock; import com.android.jack.cfg.ControlFlowGraph; @@ -27,13 +25,11 @@ import com.android.jack.ir.ast.JAsgOperation; import com.android.jack.ir.ast.JIntLiteral; import com.android.jack.ir.ast.JMethod; import com.android.jack.ir.ast.JVariableRef; -import com.android.jack.util.filter.SignatureMethodFilter; import com.android.sched.util.codec.ImplementationName; import junit.framework.Assert; import org.junit.BeforeClass; -import org.junit.Test; import javax.annotation.Nonnull; @@ -78,15 +74,4 @@ public class ReachingDefsTest { } } } - - @Test - public void testDfa001() throws Exception { - Options options = TestTools.buildCommandLineArgs(TestTools - .getJackTestsWithJackFolder("analysis/dfa/reachingdefs/test001")); - options.addProperty(Options.METHOD_FILTER.getName(), "method-with-signature"); - options.addProperty(SignatureMethodFilter.METHOD_SIGNATURE_FILTER.getName(), - "dfaWithSwitch(I)I"); - options.addProperty(ReachingDefinitions.REACHING_DEFS_CHECKER.getName(), "test001Checker"); - TestTools.runCompilation(options); - } } diff --git a/jack/tests/com/android/jack/backend/dex/rop/RopRegisterManagerTest.java b/jack/tests/com/android/jack/backend/dex/rop/RopRegisterManagerTest.java index 6349ff73..05f3bfc8 100644 --- a/jack/tests/com/android/jack/backend/dex/rop/RopRegisterManagerTest.java +++ b/jack/tests/com/android/jack/backend/dex/rop/RopRegisterManagerTest.java @@ -16,8 +16,6 @@ package com.android.jack.backend.dex.rop; -import com.android.jack.Options; -import com.android.jack.TestTools; import com.android.jack.ir.ast.JModifier; import com.android.jack.ir.ast.JParameter; import com.android.jack.ir.ast.JParameterRef; @@ -118,10 +116,4 @@ public class RopRegisterManagerTest { rrm.getRegisterSpec(ref); } - @Test - public void ropBuildMethodWithSameReturnReg() throws Exception { - Options compilerArgs = TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("returnstatement/return001")); - TestTools.runCompilation(compilerArgs); - } } diff --git a/jack/tests/com/android/jack/cfg/BuildCfgErrorTest.java b/jack/tests/com/android/jack/cfg/BuildCfgErrorTest.java index 110602ff..68817fb3 100644 --- a/jack/tests/com/android/jack/cfg/BuildCfgErrorTest.java +++ b/jack/tests/com/android/jack/cfg/BuildCfgErrorTest.java @@ -27,7 +27,7 @@ import org.junit.Test; public class BuildCfgErrorTest { - private static final String CLASS_BINARY_NAME = "com/android/jack/fibonacci/jack/FibonacciThreeAddress"; + private static final String CLASS_BINARY_NAME = "com/android/jack/fibonacci/test001/jack/FibonacciThreeAddress"; @Before public void setUp() throws Exception { diff --git a/jack/tests/com/android/jack/cfg/BuildCfgTest.java b/jack/tests/com/android/jack/cfg/BuildCfgTest.java index 4640658b..07415ded 100644 --- a/jack/tests/com/android/jack/cfg/BuildCfgTest.java +++ b/jack/tests/com/android/jack/cfg/BuildCfgTest.java @@ -37,7 +37,7 @@ import java.util.List; public class BuildCfgTest { private List<BasicBlock> bbCodeOder; - private static final String CLASS_BINARY_NAME = "com/android/jack/fibonacci/jack/FibonacciThreeAddress"; + private static final String CLASS_BINARY_NAME = "com/android/jack/fibonacci/test001/jack/FibonacciThreeAddress"; @Before public void setUp() throws Exception { diff --git a/jack/tests/com/android/jack/errorhandling/AnnotationProcessorErrorTest.java b/jack/tests/com/android/jack/errorhandling/AnnotationProcessorErrorTest.java deleted file mode 100644 index 5c314df2..00000000 --- a/jack/tests/com/android/jack/errorhandling/AnnotationProcessorErrorTest.java +++ /dev/null @@ -1,266 +0,0 @@ -/* - * 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.errorhandling; - -import com.google.common.io.Files; - -import com.android.jack.JackUserException; -import com.android.jack.Main; -import com.android.jack.Options; -import com.android.jack.TestTools; -import com.android.jack.errorhandling.annotationprocessor.ResourceAnnotationProcessor; -import com.android.jack.errorhandling.annotationprocessor.ResourceAnnotationTest; -import com.android.jack.errorhandling.annotationprocessor.SourceAnnotationProcessor; -import com.android.jack.errorhandling.annotationprocessor.SourceAnnotationTest; -import com.android.jack.errorhandling.annotationprocessor.SourceErrorAnnotationTest; -import com.android.jack.frontend.FrontendCompilationException; -import com.android.sched.util.file.FileUtils; - -import junit.framework.Assert; - -import org.jf.dexlib.ClassDefItem; -import org.jf.dexlib.DexFile; -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.File; -import java.io.FileReader; -import java.io.LineNumberReader; -import java.util.ArrayList; -import java.util.List; - -import javax.annotation.Nonnull; - -/** - * JUnit test checking Jack behavior when using annotation processor. - */ -public class AnnotationProcessorErrorTest { - - @BeforeClass - public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); - } - - /** - * Checks that compilation fails correctly when annotation processor is called without specifying - * output folder. - */ - @Test - public void testAnnotationProcessorError001() throws Exception { - TestingEnvironment te = new TestingEnvironment(); - - te.addFile(te.getSourceFolder(),"jack.incremental", "A.java", - "package jack.incremental; \n"+ - "public class A {} \n"); - - Options options = new Options(); - List<String> ecjArgs = new ArrayList<String>(); - ecjArgs.add("-processor"); - ecjArgs.add(ResourceAnnotationProcessor.class.getName()); - ecjArgs.add(te.getSourceFolder().getAbsolutePath()); - options.setEcjArguments(ecjArgs); - options.setClasspath(TestTools.getDefaultBootclasspathString()); - - try { - te.compile(options); - Assert.fail(); - } catch (JackUserException e) { - // Failure is ok since output for annotation processor is not specify. - Assert.assertTrue(e.getMessage().contains("Unknown location")); - } - } - - /** - * Checks that compilation succeed when running annotation processor to generate resource file. - */ - @Test - public void testAnnotationProcessorError002() throws Exception { - runAnnotProcBuildingResource(new TestingEnvironment()); - } - - /** - * Checks that last compilation failed since the resource created by annotation processor already - * exist. - */ - @Test - public void testAnnotationProcessorError003() throws Exception { - TestingEnvironment te = new TestingEnvironment(); - - runAnnotProcBuildingResource(te); - - Options options = new Options(); - List<String> ecjArgs = new ArrayList<String>(); - ecjArgs.add("-d"); - ecjArgs.add(te.getTestingFolder().getAbsolutePath()); - ecjArgs.add("-processor"); - ecjArgs.add(ResourceAnnotationProcessor.class.getName()); - ecjArgs.add(te.getSourceFolder().getAbsolutePath()); - options.setEcjArguments(ecjArgs); - options.setClasspath(TestTools.getDefaultBootclasspathString() + File.pathSeparator - + te.getJackFolder()); - options.setOutputDir(TestTools.createTempDir("annot", "dex")); - - try { - te.startErrRedirection(); - te.compile(options); - Assert.fail(); - } catch (FrontendCompilationException e) { - // Failure is ok since created file already exists - } finally { - Assert.assertTrue(te.endErrRedirection().contains("Resource already created")); - } - } - - /** - * Checks that compilation failed since the source file generated by the annotation processor - * does not compile. - */ - @Test - public void testAnnotationProcessorError004() throws Exception { - TestingEnvironment te = new TestingEnvironment(); - - buildAnnotationRequiredByAnnotationProc(te, new Class<?>[] {SourceAnnotationTest.class, - SourceErrorAnnotationTest.class}); - - te.addFile(te.getSourceFolder(), "jack.incremental", "A.java", "package jack.incremental;\n" - + "import " + SourceErrorAnnotationTest.class.getName() + ";\n" - + "@" + SourceErrorAnnotationTest.class.getSimpleName() + "\n" - + "public class A {}\n"); - - Options options = new Options(); - List<String> ecjArgs = new ArrayList<String>(); - ecjArgs.add("-d"); - ecjArgs.add(te.getTestingFolder().getAbsolutePath()); - ecjArgs.add("-processor"); - ecjArgs.add(SourceAnnotationProcessor.class.getName()); - ecjArgs.add(te.getSourceFolder().getAbsolutePath()); - options.setEcjArguments(ecjArgs); - options.setClasspath(TestTools.getDefaultBootclasspathString() + File.pathSeparator - + te.getJackFolder()); - - try { - te.startErrRedirection(); - te.compile(options); - Assert.fail(); - } catch (FrontendCompilationException ex) { - // Failure is ok since source generated by annotation processor does not compile. - } finally { - Assert.assertTrue(te.endErrRedirection().contains("Syntax error on tokens, delete these tokens")); - } - } - - /** - * Checks that compilation succeed to compile source file generated by the annotation processor. - */ - @Test - public void testAnnotationProcessorError005() throws Exception { - TestingEnvironment te = new TestingEnvironment(); - - buildAnnotationRequiredByAnnotationProc(te, new Class<?>[] {SourceAnnotationTest.class, - SourceErrorAnnotationTest.class}); - - te.addFile(te.getSourceFolder(), "jack.incremental", "A.java", "package jack.incremental;\n" - + "import " + SourceAnnotationTest.class.getName() + ";\n" - + "@" + SourceAnnotationTest.class.getSimpleName() + "\n" - + "public class A {}\n"); - - Options options = new Options(); - List<String> ecjArgs = new ArrayList<String>(); - ecjArgs.add("-d"); - ecjArgs.add(te.getTestingFolder().getAbsolutePath()); - ecjArgs.add("-processor"); - ecjArgs.add(SourceAnnotationProcessor.class.getName()); - ecjArgs.add(te.getSourceFolder().getAbsolutePath()); - options.setEcjArguments(ecjArgs); - options.setClasspath(TestTools.getDefaultBootclasspathString() + File.pathSeparator - + te.getJackFolder()); - - File dexOutput = new File(te.getTestingFolder(), "classes.dex"); - options.setOutputDir(te.getTestingFolder()); - - te.compile(options); - - DexFile dexFile = new DexFile(dexOutput); - List<String> sourceFileInDex = new ArrayList<String>(); - for (ClassDefItem classDef : dexFile.ClassDefsSection.getItems()) { - sourceFileInDex.add(classDef.getSourceFile().getStringValue()); - } - - Assert.assertTrue(sourceFileInDex.contains("ADuplicated.java")); - Assert.assertTrue(sourceFileInDex.contains("A.java")); - } - - private void runAnnotProcBuildingResource(@Nonnull TestingEnvironment te) throws Exception { - - buildAnnotationRequiredByAnnotationProc(te, new Class<?>[] {ResourceAnnotationTest.class}); - - te.addFile(te.getSourceFolder(), "jack.incremental", "A.java", "package jack.incremental;\n" - + "import " + ResourceAnnotationTest.class.getName() + ";\n" - + "@" + ResourceAnnotationTest.class.getSimpleName() + "\n" - + "public class A {}\n"); - - Options options = new Options(); - List<String> ecjArgs = new ArrayList<String>(); - ecjArgs.add("-d"); - ecjArgs.add(te.getTestingFolder().getAbsolutePath()); - ecjArgs.add("-processor"); - ecjArgs.add(ResourceAnnotationProcessor.class.getName()); - ecjArgs.add(te.getSourceFolder().getAbsolutePath()); - options.setEcjArguments(ecjArgs); - options.setClasspath(TestTools.getDefaultBootclasspathString() + File.pathSeparator - + te.getJackFolder()); - options.setOutputDir(TestTools.createTempDir("annot", "dex")); - - te.compile(options); - - File discoverFile = new File(te.getTestingFolder(), ResourceAnnotationProcessor.FILENAME); - Assert.assertTrue(discoverFile.exists()); - LineNumberReader lnr = new LineNumberReader(new FileReader(discoverFile)); - Assert.assertEquals(ResourceAnnotationTest.class.getName(), lnr.readLine()); - Assert.assertEquals("jack.incremental.A", lnr.readLine()); - Assert.assertNull(lnr.readLine()); - lnr.close(); - } - - private void buildAnnotationRequiredByAnnotationProc(@Nonnull TestingEnvironment te, - @Nonnull Class<?>[] annotationClasses) throws Exception { - File targetAnnotationFileFolder = - new File(te.getSourceFolder(), "com/android/jack/errorhandling/annotationprocessor/"); - if (!targetAnnotationFileFolder.mkdirs()) { - Assert.fail("Fail to create folder " + targetAnnotationFileFolder.getAbsolutePath()); - } - - for (Class<?> annotationClass : annotationClasses) { - Files.copy(new File(TestTools.getAndroidTop() - + "/toolchain/jack/jack/tests/com/android/jack/errorhandling/annotationprocessor/" - + annotationClass.getSimpleName() + ".java"), new File( - targetAnnotationFileFolder, annotationClass.getSimpleName() + ".java")); - } - - // Compile annotation to a jack file - Options options = new Options(); - List<String> ecjArgs = new ArrayList<String>(); - ecjArgs.add(te.getSourceFolder().getAbsolutePath()); - options.setEcjArguments(ecjArgs); - options.setClasspath(TestTools.getDefaultBootclasspathString()); - options.setJayceOutputDir(te.getJackFolder()); - - te.compile(options); - - FileUtils.deleteDir(te.getSourceFolder()); - } -} diff --git a/jack/tests/com/android/jack/errorhandling/CommandLineErrorTest.java b/jack/tests/com/android/jack/errorhandling/CommandLineErrorTest.java deleted file mode 100644 index 871bd4e9..00000000 --- a/jack/tests/com/android/jack/errorhandling/CommandLineErrorTest.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * 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.errorhandling; - -import com.android.jack.IllegalOptionsException; -import com.android.jack.Main; -import com.android.jack.NothingToDoException; -import com.android.jack.Options; -import com.android.jack.frontend.FrontendCompilationException; - -import junit.framework.Assert; - -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -/** - * JUnit test checking Jack behavior on exceptions. - */ -public class CommandLineErrorTest { - - @BeforeClass - public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); - } - - /** - * Checks that compilation fails correctly when an unsupported options is passed to ecj. - */ - @Test - public void testCommandLineError001() throws Exception { - TestingEnvironment ite = new TestingEnvironment(); - - Options options = new Options(); - List<String> ecjArgs = new ArrayList<String>(); - ecjArgs.add("-unsupported"); - ecjArgs.add(ite.getTestingFolder().getAbsolutePath()); - options.setEcjArguments(ecjArgs); - - try { - ite.startErrRedirection(); - ite.compile(options); - Assert.fail(); - } catch (IllegalOptionsException e) { - // Failure is ok since a bad options is passed to ecj. - } finally { - Assert.assertEquals("", ite.endErrRedirection()); - } - } - - /** - * Checks that compilation fails correctly when no source files are passed to ecj. - */ - @Test - public void testCommandLineError002() throws Exception { - TestingEnvironment ite = new TestingEnvironment(); - - Options options = new Options(); - options.setEcjArguments(new ArrayList<String>()); - - try { - ite.startErrRedirection(); - ite.startOutRedirection(); - ite.compile(options); - Assert.fail(); - } catch (NothingToDoException e) { - // Failure is ok since there is no source files. - } finally { - Assert.assertEquals("", ite.endErrRedirection()); - Assert.assertTrue(ite.endOutRedirection().contains("Usage:")); - } - } - - /** - * Checks that compilation fails correctly when java.lang.Object does not exist on classpath. - */ - @Test - public void testCommandLineError003() throws Exception { - TestingEnvironment ite = new TestingEnvironment(); - - File sourceFile = ite.addFile(ite.getSourceFolder(),"jack.incremental", "A.java", - "package jack.incremental; \n"+ - "public class A {} \n"); - - Options options = new Options(); - List<String> ecjArgs = new ArrayList<String>(); - ecjArgs.add(sourceFile.getAbsolutePath()); - options.setEcjArguments(ecjArgs); - - try { - ite.startErrRedirection(); - ite.startOutRedirection(); - ite.compile(options); - Assert.fail(); - } catch (FrontendCompilationException e) { - // Failure is ok, since java.lang.Object does not exist. - } finally { - Assert.assertEquals("", ite.endOutRedirection()); - String err = ite.endErrRedirection(); - Assert.assertTrue(err.contains("The type java.lang.Object cannot be found in source files, " - + "imported jack libs or the classpath")); - } - } -} diff --git a/jack/tests/com/android/jack/errorhandling/FileAccessErrorTest.java b/jack/tests/com/android/jack/errorhandling/FileAccessErrorTest.java deleted file mode 100644 index ecd4d31b..00000000 --- a/jack/tests/com/android/jack/errorhandling/FileAccessErrorTest.java +++ /dev/null @@ -1,249 +0,0 @@ -/* - * 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.errorhandling; - -import com.android.jack.JackAbortException; -import com.android.jack.JackUserException; -import com.android.jack.Main; -import com.android.jack.Options; -import com.android.jack.TestTools; -import com.android.jack.frontend.FrontendCompilationException; -import com.android.jack.library.LibraryIOException; -import com.android.jack.library.LibraryReadingException; -import com.android.sched.util.config.PropertyIdException; -import com.android.sched.util.file.WrongPermissionException; - -import junit.framework.Assert; - -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -/** - * JUnit test checking Jack behavior on file access error. - */ -public class FileAccessErrorTest { - - @BeforeClass - public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); - } - - /** - * Checks that compilation fails correctly when folder to generate jack files is not readable. - */ - @Test - public void testFileAccessError001() throws Exception { - TestingEnvironment te = new TestingEnvironment(); - - te.addFile(te.getSourceFolder(), "jack.incremental", "A.java", - "package jack.incremental; \n"+ - "public class A {} \n"); - - Options options = new Options(); - List<String> ecjArgs = new ArrayList<String>(); - ecjArgs.add(te.getTestingFolder().getAbsolutePath()); - options.setEcjArguments(ecjArgs); - options.setClasspath(TestTools.getDefaultBootclasspathString()); - File jackOutputFile = TestTools.createTempDir("ErrorHandlingTest_", "001"); - options.setJayceOutputDir(jackOutputFile); - if (!jackOutputFile.setReadable(false)) { - Assert.fail("Fails to change file permissions of " + jackOutputFile.getAbsolutePath()); - } - - try { - te.compile(options); - Assert.fail(); - } catch (PropertyIdException e) { - // Failure is ok since jack output folder is not readable - } finally { - if (!jackOutputFile.setReadable(true)) { - Assert.fail("Fails to change file permissions of " + jackOutputFile.getAbsolutePath()); - } - } - } - - /** - * Checks that compilation fails correctly when folder containing jack files is not readable. - */ - @Test - public void testFileAccessError002() throws Exception { - TestingEnvironment te = new TestingEnvironment(); - - te.addFile(te.getSourceFolder(), "jack.incremental", "A.java", - "package jack.incremental; \n"+ - "public class A {} \n"); - - Options options = new Options(); - List<String> ecjArgs = new ArrayList<String>(); - ecjArgs.add(te.getTestingFolder().getAbsolutePath()); - options.setEcjArguments(ecjArgs); - options.setClasspath(TestTools.getDefaultBootclasspathString()); - File jackOutputFile = TestTools.createTempDir("ErrorHandlingTest_", "001"); - options.setJayceOutputDir(jackOutputFile); - - te.compile(options); - - te.deleteJavaFile(te.getSourceFolder(), "jack.incremental", "A.java"); - te.addFile(te.getSourceFolder(), "jack.incremental", "B.java", - "package jack.incremental; \n"+ - "public class B extends A {} \n"); - - options = new Options(); - ecjArgs = new ArrayList<String>(); - ecjArgs.add(te.getTestingFolder().getAbsolutePath()); - options.setEcjArguments(ecjArgs); - options.setClasspath(TestTools.getDefaultBootclasspathString()); - options.addJayceImport(jackOutputFile); - - // Modify read permission of folder containing jack files - if (!jackOutputFile.setReadable(false)) { - Assert.fail("Fails to change file permissions of " + jackOutputFile.getAbsolutePath()); - } - try { - te.startErrRedirection(); - te.compile(options); - Assert.fail(); - } catch (JackAbortException e) { - // Failure is ok since Jack file could not be imported since folder is not readable - Assert.assertTrue(e.getCause() instanceof LibraryReadingException); - Assert.assertTrue(e.getCause().getCause() instanceof WrongPermissionException); - } finally { - Assert.assertTrue("", te.endErrRedirection().contains("is not readable")); - if (!jackOutputFile.setReadable(true)) { - Assert.fail("Fails to change file permissions of " + jackOutputFile.getAbsolutePath()); - } - } - } - - /** - * Checks that compilation fails correctly when source file is not readable. - */ - @Test - public void testFileAccessError003() throws Exception { - TestingEnvironment te = new TestingEnvironment(); - - File a = te.addFile(te.getSourceFolder(), "jack.incremental", "A.java", - "package jack.incremental; \n"+ - "public class A {} \n"); - if (!a.setReadable(false)) { - Assert.fail("Fails to change file permissions of " + a.getAbsolutePath()); - } - - Options options = new Options(); - List<String> ecjArgs = new ArrayList<String>(); - ecjArgs.add(te.getTestingFolder().getAbsolutePath()); - options.setEcjArguments(ecjArgs); - options.setClasspath(TestTools.getDefaultBootclasspathString()); - - try { - te.startErrRedirection(); - te.compile(options); - Assert.fail(); - } catch (FrontendCompilationException e) { - // Failure is ok since source file is not readable - } finally { - if (!a.setReadable(true)) { - Assert.fail("Fails to change file permissions of " + a.getAbsolutePath()); - } - Assert.assertTrue(te.endErrRedirection().contains("Permission denied")); - } - } - - /** - * Checks that compilation fails correctly when jack file is not readable. - */ - @Test - public void testFileAccessError004() throws Exception { - TestingEnvironment te = new TestingEnvironment(); - - te.addFile(te.getSourceFolder(), "jack.incremental", "A.java", - "package jack.incremental; \n"+ - "public class A {} \n"); - - Options options = new Options(); - List<String> ecjArgs = new ArrayList<String>(); - ecjArgs.add(te.getTestingFolder().getAbsolutePath()); - options.setEcjArguments(ecjArgs); - options.setClasspath(TestTools.getDefaultBootclasspathString()); - options.setJayceOutputDir(te.getJackFolder()); - - te.compile(options); - - te.deleteJavaFile(te.getSourceFolder(), "jack.incremental", "A.java"); - - te.addFile(te.getSourceFolder(),"jack.incremental", "B.java", - "package jack.incremental; \n"+ - "public class B extends A {} \n"); - - options = new Options(); - ecjArgs = new ArrayList<String>(); - ecjArgs.add(te.getTestingFolder().getAbsolutePath()); - options.setEcjArguments(ecjArgs); - options.setClasspath( - TestTools.getDefaultBootclasspathString() + File.pathSeparator + te.getJackFolder()); - - try { - for (File jackFile : te.getJackFiles(te.getJackFolder())) { - if (!jackFile.setReadable(false)) { - Assert.fail("Fails to change file permissions of " + jackFile.getAbsolutePath()); - } - } - te.startErrRedirection(); - te.compile(options); - Assert.fail(); - } catch (JackAbortException e) { - Assert.assertTrue(e.getCause() instanceof LibraryReadingException); - Assert.assertTrue(e.getCause().getCause() instanceof LibraryIOException); - } finally { - String errOutput = te.endErrRedirection(); - Assert.assertTrue(errOutput.contains("is an invalid library")); - Assert.assertTrue(errOutput.contains("is not readable")); - for (File jackFile : te.getJackFiles(te.getJackFolder())) { - if (!jackFile.setReadable(true)) { - Assert.fail("Fails to change file permissions of " + jackFile.getAbsolutePath()); - } - } - } - } - - /** - * Checks that compilation fails correctly when source file does not exist. - */ - @Test - public void testFileAccessError005() throws Exception { - TestingEnvironment te = new TestingEnvironment(); - - Options options = new Options(); - List<String> ecjArgs = new ArrayList<String>(); - ecjArgs.add(te.getSourceFolder() + File.separator + "A.java"); - options.setEcjArguments(ecjArgs); - options.setClasspath(TestTools.getDefaultBootclasspathString()); - - try { - te.startErrRedirection(); - te.compile(options); - Assert.fail(); - } catch (JackUserException e) { - // Failure is ok since source file is not readable - Assert.assertTrue(e.getMessage().contains("A.java is missing")); - } - } -} diff --git a/jack/tests/com/android/jack/errorhandling/JackFormatErrorTest.java b/jack/tests/com/android/jack/errorhandling/JackFormatErrorTest.java deleted file mode 100644 index 0cf9495f..00000000 --- a/jack/tests/com/android/jack/errorhandling/JackFormatErrorTest.java +++ /dev/null @@ -1,184 +0,0 @@ -/* - * 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.errorhandling; - -import com.android.jack.JackAbortException; -import com.android.jack.Main; -import com.android.jack.Options; -import com.android.jack.Options.VerbosityLevel; -import com.android.jack.TestTools; -import com.android.jack.jayce.JayceProperties; -import com.android.jack.library.FileType; -import com.android.jack.library.JackLibrary; -import com.android.jack.library.JackLibraryFactory; -import com.android.jack.library.LibraryFormatException; -import com.android.jack.library.LibraryReadingException; -import com.android.jack.library.v0001.Version; - -import junit.framework.Assert; - -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -/** - * JUnit test checking Jack behavior on exceptions. - */ -public class JackFormatErrorTest { - - @BeforeClass - public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); - } - - /** - * Checks that compilation fails correctly when jayce file is corrupted. - */ - @Test - public void testJackFormatError001() throws Exception { - TestingEnvironment ite = new TestingEnvironment(); - - ite.addFile(new File(ite.getJackFolder(), FileType.JAYCE.getPrefix()), "jack.incremental", - "A.jayce", "jayce(" + JackLibraryFactory.DEFAULT_MAJOR_VERSION + "." + Version.MINOR - + ")Corrupted"); - ite.addFile(ite.getJackFolder(), "", "jack.properties", - JackLibrary.KEY_LIB_EMITTER + "=unknown\n" - + JackLibrary.KEY_LIB_EMITTER_VERSION + "=0\n" - + JackLibrary.KEY_LIB_MAJOR_VERSION + "=" + Version.MAJOR + "\n" - + JackLibrary.KEY_LIB_MINOR_VERSION + "=" + Version.MINOR + "\n" - + FileType.JAYCE.buildPropertyName(null /*suffix*/) + "=true\n" - + JayceProperties.KEY_JAYCE_MAJOR_VERSION + "=2\n" - + JayceProperties.KEY_JAYCE_MINOR_VERSION + "=14\n"); - - ite.addFile(ite.getSourceFolder(),"jack.incremental", "B.java", - "package jack.incremental; \n"+ - "public class B extends A {} \n"); - - Options options = new Options(); - options.setVerbosityLevel(VerbosityLevel.DEBUG); - List<String> ecjArgs = new ArrayList<String>(); - ecjArgs.add(ite.getTestingFolder().getAbsolutePath()); - options.setEcjArguments(ecjArgs); - options.setClasspath( - TestTools.getDefaultBootclasspathString() + File.pathSeparator + ite.getJackFolder()); - - try { - ite.startErrRedirection(); - ite.compile(options); - Assert.fail(); - } catch (JackAbortException e) { - // Failure is ok since jack file is corrupted. - Assert.assertTrue(e.getCause() instanceof LibraryReadingException); - Assert.assertTrue(e.getCause().getCause() instanceof LibraryFormatException); - } finally { - Assert.assertTrue(ite.endErrRedirection().contains("is an invalid library")); - Assert.assertTrue(ite.endErrRedirection().contains( - "Unexpected node NForStatement, NDeclaredType was expected")); - } - } - - /** - * Checks that compilation fails correctly when jack file header is corrupted. - */ - @Test - public void testJackFormatError002() throws Exception { - TestingEnvironment ite = new TestingEnvironment(); - - ite.addFile(new File(ite.getJackFolder(), FileType.JAYCE.getPrefix()), "jack.incremental", - "A.jayce", "jayce()"); - ite.addFile(ite.getJackFolder(), "", "jack.properties", - JackLibrary.KEY_LIB_EMITTER + "=unknown\n" - + JackLibrary.KEY_LIB_EMITTER_VERSION + "=0\n" - + JackLibrary.KEY_LIB_MAJOR_VERSION + "=" + Version.MAJOR + "\n" - + JackLibrary.KEY_LIB_MINOR_VERSION + "=" + Version.MINOR + "\n" - + FileType.JAYCE.buildPropertyName(null /*suffix*/) + "=true\n" - + JayceProperties.KEY_JAYCE_MAJOR_VERSION + "=2\n" - + JayceProperties.KEY_JAYCE_MINOR_VERSION + "=14\n"); - - ite.addFile(ite.getSourceFolder(),"jack.incremental", "B.java", - "package jack.incremental; \n"+ - "public class B extends A {} \n"); - - Options options = new Options(); - options.setVerbosityLevel(VerbosityLevel.DEBUG); - List<String> ecjArgs = new ArrayList<String>(); - ecjArgs.add(ite.getTestingFolder().getAbsolutePath()); - options.setEcjArguments(ecjArgs); - options.setClasspath( - TestTools.getDefaultBootclasspathString() + File.pathSeparator + ite.getJackFolder()); - - try { - ite.startErrRedirection(); - ite.compile(options); - Assert.fail(); - } catch (JackAbortException e) { - // Failure is ok since jack file header is corrupted. - Assert.assertTrue(e.getCause() instanceof LibraryReadingException); - Assert.assertTrue(e.getCause().getCause() instanceof LibraryFormatException); - } finally { - Assert.assertTrue(ite.endErrRedirection().contains("is an invalid library")); - Assert.assertTrue(ite.endErrRedirection().contains("Invalid Jayce header")); - } - } - - /** - * Checks that compilation fails correctly when jack file is not longer supported. - */ - @Test - public void testJackFormatError003() throws Exception { - TestingEnvironment ite = new TestingEnvironment(); - - ite.addFile(new File(ite.getJackFolder(), FileType.JAYCE.getPrefix()), "jack.incremental", - "A.jayce", "jayce()"); - ite.addFile(ite.getJackFolder(), "", "jack.properties", - JackLibrary.KEY_LIB_EMITTER + "=unknown\n" - + JackLibrary.KEY_LIB_EMITTER_VERSION + "=0\n" - + JackLibrary.KEY_LIB_MAJOR_VERSION + "=" + Version.MAJOR + "\n" - + JackLibrary.KEY_LIB_MINOR_VERSION + "=" + Version.MINOR + "\n" - + FileType.JAYCE.buildPropertyName(null /*suffix*/) + "=true\n" - + JayceProperties.KEY_JAYCE_MAJOR_VERSION + "=0\n" - + JayceProperties.KEY_JAYCE_MINOR_VERSION + "=0\n"); - - ite.addFile(ite.getSourceFolder(),"jack.incremental", "B.java", - "package jack.incremental; \n"+ - "public class B extends A {} \n"); - - Options options = new Options(); - options.setVerbosityLevel(VerbosityLevel.DEBUG); - List<String> ecjArgs = new ArrayList<String>(); - ecjArgs.add(ite.getTestingFolder().getAbsolutePath()); - options.setEcjArguments(ecjArgs); - options.setClasspath( - TestTools.getDefaultBootclasspathString() + File.pathSeparator + ite.getJackFolder()); - - try { - ite.startErrRedirection(); - ite.compile(options); - Assert.fail(); - } catch (JackAbortException e) { - // Failure is ok since jack file header is corrupted. - Assert.assertTrue(e.getCause() instanceof LibraryReadingException); - Assert.assertTrue(e.getCause().getCause() instanceof LibraryFormatException); - } finally { - Assert.assertTrue(ite.endErrRedirection().contains("is an invalid library")); - Assert.assertTrue(ite.endErrRedirection().contains("Jayce version 0 not supported")); - } - } -} diff --git a/jack/tests/com/android/jack/errorhandling/SourceErrorTest.java b/jack/tests/com/android/jack/errorhandling/SourceErrorTest.java deleted file mode 100644 index 165b49d7..00000000 --- a/jack/tests/com/android/jack/errorhandling/SourceErrorTest.java +++ /dev/null @@ -1,341 +0,0 @@ -/* - * 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.errorhandling; - -import com.android.jack.Options; -import com.android.jack.TestTools; -import com.android.jack.frontend.FrontendCompilationException; - -import org.junit.Assert; -import org.junit.Test; - -import java.util.ArrayList; -import java.util.List; - -import javax.annotation.Nonnull; - -/** - * JUnit test checking Jack behavior with source errors. - */ -public class SourceErrorTest { - - /** - * Checks that compilation fails because of invalid "class" keyword. - * parsingErrorId = syntaxCategory + internalCategory + 204 - */ - @Test - public void testInvalidSource001() throws Exception { - TestingEnvironment te = new TestingEnvironment(); - - te.addFile(te.getSourceFolder(), "jack.invalidsource", "A.java", "package jack.invalidsource;\n" - + "public clas A {}\n"); - - try { - te.startOutRedirection(); - te.startErrRedirection(); - te.compile(getOptions(te)); - Assert.fail(); - } catch (FrontendCompilationException ex) { - // Failure is ok since source does not compile. - } finally { - Assert.assertEquals("", te.endOutRedirection()); - Assert.assertTrue( - te.endErrRedirection().contains("Syntax error on token \"clas\", class expected")); - } - } - - /** - * Checks that compilation fails because of invalid "public" keyword. - * parsingErrorId = syntaxCategory + internalCategory + 204 - */ - @Test - public void testInvalidSource002() throws Exception { - TestingEnvironment te = new TestingEnvironment(); - - te.addFile(te.getSourceFolder(), "jack.invalidsource", "A.java", "package jack.invalidsource;\n" - + "publi class A {}\n"); - - try { - te.startOutRedirection(); - te.startErrRedirection(); - te.compile(getOptions(te)); - Assert.fail(); - } catch (FrontendCompilationException ex) { - // Failure is ok since source does not compile. - } finally { - Assert.assertEquals("", te.endOutRedirection()); - Assert.assertTrue( - te.endErrRedirection().contains("Syntax error on token \"publi\", public expected")); - } - } - - /** - * Checks that compilation fails because of a class name that does not match the file name. - * publicClassMustMatchFileNameId = typeRelatedCategory + 325 - */ - @Test - public void testInvalidSource003() throws Exception { - TestingEnvironment te = new TestingEnvironment(); - - te.addFile(te.getSourceFolder(), "jack.invalidsource", "A.java", "package jack.invalidsource;\n" - + "public class B {}\n"); - - try { - te.startOutRedirection(); - te.startErrRedirection(); - te.compile(getOptions(te)); - Assert.fail(); - } catch (FrontendCompilationException ex) { - // Failure is ok since source does not compile. - } finally { - Assert.assertEquals("", te.endOutRedirection()); - Assert.assertTrue( - te.endErrRedirection().contains("The public type B must be defined in its own file")); - } - } - - /** - * Checks that compilation fails because of an import of a class that is not on classpath. - * importNotFoundId = importRelatedCategory + 390 - */ - @Test - public void testInvalidSource004() throws Exception { - TestingEnvironment te = new TestingEnvironment(); - - te.addFile(te.getSourceFolder(), "jack.invalidsource", "A.java", "package jack.invalidsource;\n" - + "import jack.invalidsource.B;\n" - + "public class A {}\n"); - - try { - te.startOutRedirection(); - te.startErrRedirection(); - te.compile(getOptions(te)); - Assert.fail(); - } catch (FrontendCompilationException ex) { - // Failure is ok since source does not compile. - } finally { - Assert.assertEquals("", te.endOutRedirection()); - Assert.assertTrue( - te.endErrRedirection().contains("The import jack.invalidsource.B cannot be resolved")); - } - } - - /** - * Checks that compilation fails because there are too many methods in a single class. - * tooManyMethodsId = internalCategory + 433 - */ - @Test - public void testInvalidSource005() throws Exception { - TestingEnvironment te = new TestingEnvironment(); - - int methodCount = 65536; - StringBuilder content = - new StringBuilder("public class A {"); - // -1 due to implicit init method - for (int mthIdx = 0; mthIdx < methodCount - 1; mthIdx++) { - content.append("public void m" + mthIdx + "() {} \n"); - } - content.append("} \n"); - - te.addFile(te.getSourceFolder(), "jack.overflow", "A.java", - "package jack.overflow; \n" + content.toString()); - - try { - te.startErrRedirection(); - te.startOutRedirection(); - te.compile(getOptions(te)); - Assert.fail(); - } catch (FrontendCompilationException e) { - // Failure is ok, since there are too many methods. - } finally { - Assert.assertEquals("", te.endOutRedirection()); - Assert.assertTrue( - te.endErrRedirection().contains("Too many methods for type A. Maximum is 65535")); - } - } - - /** - * Checks that compilation fails because of several source errors. - */ - @Test - public void testInvalidSource006() throws Exception { - TestingEnvironment te = new TestingEnvironment(); - - te.addFile(te.getSourceFolder(), "jack.invalidsource", "A.java", "package jack.invalidsource;\n" - + "public class A { private voi m() {} } \n"); - te.addFile(te.getSourceFolder(), "jack.invalidsource", "B.java", "package jack.invalidsource;\n" - + "public class B { private void m(in a) {}; \n private void n(int a) {re}; } \n"); - - try { - te.startOutRedirection(); - te.startErrRedirection(); - te.compile(getOptions(te)); - Assert.fail(); - } catch (FrontendCompilationException ex) { - // Failure is ok since source does not compile. - } finally { - Assert.assertEquals("", te.endOutRedirection()); - String errorString = te.endErrRedirection(); - Assert.assertTrue(errorString.contains("in cannot be resolved to a type")); - Assert.assertTrue(errorString.contains( - "Syntax error, insert \"VariableDeclarators\" to complete LocalVariableDeclaration")); - Assert.assertTrue( - errorString.contains("Syntax error, insert \";\" to complete BlockStatements")); - Assert.assertTrue(errorString.contains("voi cannot be resolved to a type")); - } - } - - /** - * Checks that compilation fails because of a source error, with also some warnings. - */ - @Test - public void testInvalidSource007() throws Exception { - TestingEnvironment te = new TestingEnvironment(); - - te.addFile(te.getSourceFolder(), "jack.invalidsource", "A.java", "package jack.invalidsource;\n" - + "public class A { private void m() {} } \n"); - te.addFile(te.getSourceFolder(), "jack.invalidsource", "B.java", "package jack.invalidsource;\n" - + "public class B { private void m(in a) {}; \n private void n(int a) {}; } \n"); - - try { - te.startOutRedirection(); - te.startErrRedirection(); - te.compile(getOptions(te)); - Assert.fail(); - } catch (FrontendCompilationException ex) { - // Failure is ok since source does not compile. - } finally { - Assert.assertEquals("", te.endOutRedirection()); - Assert.assertTrue(te.endErrRedirection().contains("in cannot be resolved to a type")); - Assert.assertTrue(te.endErrRedirection().contains( - "The method n(int) from the type B is never used locally")); - Assert.assertTrue( - te.endErrRedirection().contains("The method m() from the type A is never used locally")); - } - } - - /** - * Checks that compilation succeeds but prints several warnings. - */ - @Test - public void testInvalidSource008() throws Exception { - TestingEnvironment te = new TestingEnvironment(); - - te.addFile(te.getSourceFolder(), "jack.invalidsource", "A.java", "package jack.invalidsource;\n" - + "public class A { private void m() {} } \n"); - te.addFile(te.getSourceFolder(), "jack.invalidsource", "B.java", "package jack.invalidsource;\n" - + "public class B { private void m(int a) {}; \n private void n(int a) {}; } \n"); - - try { - te.startOutRedirection(); - te.startErrRedirection(); - te.compile(getOptions(te)); - } finally { - Assert.assertEquals("", te.endOutRedirection()); - Assert.assertTrue(te.endErrRedirection().contains( - "The method m(int) from the type B is never used locally")); - Assert.assertTrue(te.endErrRedirection().contains( - "The method n(int) from the type B is never used locally")); - Assert.assertTrue( - te.endErrRedirection().contains("The method m() from the type A is never used locally")); - } - } - - /** - * Checks that compilation fails because of an invalid type. - * undefinedTypeId = typeRelatedCategory + 2 - */ - @Test - public void testInvalidSource009() throws Exception { - TestingEnvironment te = new TestingEnvironment(); - - te.addFile(te.getSourceFolder(), "jack.invalidsource", "A.java", "package jack.invalidsource;\n" - + "public class A { private void m(in a) {}; } \n"); - - try { - te.startOutRedirection(); - te.startErrRedirection(); - te.compile(getOptions(te)); - Assert.fail(); - } catch (FrontendCompilationException ex) { - // Failure is ok since source does not compile. - } finally { - Assert.assertEquals("", te.endOutRedirection()); - Assert.assertTrue( - te.endErrRedirection().contains("in cannot be resolved to a type")); - } - } - - /** - * Checks that compilation fails because of a parsing error. - * parsingErrorInsertToCompleteId = syntaxCategory + internalCategory + 240 - */ - @Test - public void testInvalidSource010() throws Exception { - TestingEnvironment te = new TestingEnvironment(); - - te.addFile(te.getSourceFolder(), "jack.invalidsource", "A.java", "package jack.invalidsource;\n" - + "public class A { private void n(int a) {re;} } \n"); - - try { - te.startOutRedirection(); - te.startErrRedirection(); - te.compile(getOptions(te)); - Assert.fail(); - } catch (FrontendCompilationException ex) { - // Failure is ok since source does not compile. - } finally { - Assert.assertEquals("", te.endOutRedirection()); - Assert.assertTrue(te.endErrRedirection().contains( - "Syntax error, insert \"VariableDeclarators\" to complete LocalVariableDeclaration")); - } - } - - /** - * Checks that compilation succeeds but raises a warning because of an unused private method. - * unusedPrivateMethodId = internalCategory + methodRelatedCategory + 118 - */ - @Test - public void testInvalidSource011() throws Exception { - TestingEnvironment te = new TestingEnvironment(); - - te.addFile(te.getSourceFolder(), "jack.invalidsource", "A.java", "package jack.invalidsource;\n" - + "public class A { private void m() {} } \n"); - - try { - te.startOutRedirection(); - te.startErrRedirection(); - te.compile(getOptions(te)); - } finally { - Assert.assertEquals("", te.endOutRedirection()); - Assert.assertTrue( - te.endErrRedirection().contains("The method m() from the type A is never used locally")); - } - } - - @Nonnull - private Options getOptions(@Nonnull TestingEnvironment te) { - Options options = new Options(); - List<String> ecjArgs = new ArrayList<String>(); - ecjArgs.add(te.getSourceFolder().getAbsolutePath()); - options.setEcjArguments(ecjArgs); - options.setClasspath(TestTools.getDefaultBootclasspathString()); - options.setOutputDir(te.getTestingFolder()); - return options; - } - -} diff --git a/jack/tests/com/android/jack/errorhandling/TestingEnvironment.java b/jack/tests/com/android/jack/errorhandling/TestingEnvironment.java deleted file mode 100644 index 36086d42..00000000 --- a/jack/tests/com/android/jack/errorhandling/TestingEnvironment.java +++ /dev/null @@ -1,183 +0,0 @@ -/* - * 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.errorhandling; - -import com.android.jack.IllegalOptionsException; -import com.android.jack.Jack; -import com.android.jack.JackUserException; -import com.android.jack.NothingToDoException; -import com.android.jack.Options; -import com.android.jack.TestTools; -import com.android.jack.backend.jayce.JayceFileImporter; -import com.android.jack.util.NamingTools; -import com.android.sched.util.config.ConfigurationException; - -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileDescriptor; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.ArrayList; -import java.util.List; - -import javax.annotation.CheckForNull; -import javax.annotation.Nonnull; - -public class TestingEnvironment { - - @CheckForNull - ByteArrayOutputStream baosOut = null; - - @CheckForNull - PrintStream outRedirectStream = null; - - @CheckForNull - ByteArrayOutputStream baosErr = null; - - @CheckForNull - PrintStream errRedirectStream = null; - - @Nonnull - private final File testingFolder; - - @Nonnull - private final File sourceFolder; - - @Nonnull - private final File jackFolder; - - public TestingEnvironment() throws IOException { - this.testingFolder = TestTools.createTempDir("ErrorHandlingTest_", ""); - this.sourceFolder = new File(testingFolder, "src"); - if (!this.sourceFolder.mkdirs()) { - throw new IOException("Failed to create folder " + this.sourceFolder.getAbsolutePath()); - } - this.jackFolder = new File(testingFolder, "jack"); - if (!this.jackFolder.mkdirs()) { - throw new IOException("Failed to create folder " + this.jackFolder.getAbsolutePath()); - } - } - - @Nonnull - public File getSourceFolder() { - return sourceFolder; - } - - @Nonnull - public File getJackFolder() { - return jackFolder; - } - - @Nonnull - public File getTestingFolder() { - return testingFolder; - } - - public void compile(@Nonnull Options options) - throws ConfigurationException, - IllegalOptionsException, - NothingToDoException, JackUserException { - Jack.run(options); - } - - @Nonnull - public File addFile(@Nonnull File folder, @Nonnull String packageName, @Nonnull String fileName, - @Nonnull String fileContent) throws IOException { - File packageFolder = new File(folder, packageName.replace('.', File.separatorChar)); - if (!packageFolder.exists() && !packageFolder.mkdirs()) { - throw new IOException("Failed to create folder " + packageFolder.getAbsolutePath()); - } - File javaFile = new File(packageFolder, fileName); - if (javaFile.exists() && !javaFile.delete()) { - throw new IOException("Failed to delete file " + javaFile.getAbsolutePath()); - } - if (!javaFile.createNewFile()) { - throw new IOException("Failed to create file " + javaFile.getAbsolutePath()); - } - FileOutputStream fos = null; - try { - fos = new FileOutputStream(javaFile); - fos.write(fileContent.getBytes()); - } finally { - if (fos != null) { - fos.close(); - } - } - - return javaFile; - } - - public void deleteJavaFile(@Nonnull File folder, @Nonnull String packageName, @Nonnull String fileName) - throws IOException { - File packageFolder = new File(folder, NamingTools.getBinaryName(packageName)); - File javaFile = new File(packageFolder, fileName); - if (!javaFile.delete()) { - throw new IOException("Failed to delete file " + javaFile.getAbsolutePath()); - } - } - - public void startErrRedirection() { - baosErr = new ByteArrayOutputStream(); - errRedirectStream = new PrintStream(baosErr); - System.setErr(errRedirectStream); - } - - @Nonnull - public String endErrRedirection() { - assert baosErr != null; - String err = baosErr.toString(); - assert errRedirectStream != null; - errRedirectStream.close(); - System.setErr(new PrintStream(new FileOutputStream(FileDescriptor.err))); - return err; - } - - public void startOutRedirection() { - baosOut = new ByteArrayOutputStream(); - outRedirectStream = new PrintStream(baosOut); - System.setOut(outRedirectStream); - } - - @Nonnull - public String endOutRedirection() { - assert baosOut != null; - String out = baosOut.toString(); - assert outRedirectStream != null; - outRedirectStream.close(); - System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out))); - return out; - } - - @Nonnull - public List<File> getJackFiles(@Nonnull File folder) { - assert folder.isDirectory(); - List<File> jackFiles = new ArrayList<File>(); - fillJackFiles(folder, jackFiles); - return jackFiles; - } - - private void fillJackFiles(@Nonnull File file, @Nonnull List<File> jackFiles) { - if (file.isDirectory()) { - for (File subFile : file.listFiles()) { - fillJackFiles(subFile, jackFiles); - } - } else if (file.getName().endsWith(JayceFileImporter.JAYCE_FILE_EXTENSION)) { - jackFiles.add(file); - } - } -} diff --git a/jack/tests/com/android/jack/frontend/AllTests.java b/jack/tests/com/android/jack/frontend/AllTests.java index c3041fa8..b681ddfc 100644 --- a/jack/tests/com/android/jack/frontend/AllTests.java +++ b/jack/tests/com/android/jack/frontend/AllTests.java @@ -25,12 +25,8 @@ import org.junit.runners.Suite.SuiteClasses; TypeModifierTest.class, FieldModifierTest.class, MethodModifierTest.class, - MissingClassTest.class, ClinitTest.class, InitTest.class, - InstanceTest.class, - LabelTest.class, - StringTest.class, GotoTest.class, SwitchTest.class, SynchronizedTest.class}) diff --git a/jack/tests/com/android/jack/frontend/ClinitTest.java b/jack/tests/com/android/jack/frontend/ClinitTest.java index 22037168..f66a8dff 100644 --- a/jack/tests/com/android/jack/frontend/ClinitTest.java +++ b/jack/tests/com/android/jack/frontend/ClinitTest.java @@ -17,7 +17,6 @@ package com.android.jack.frontend; import com.android.jack.Main; -import com.android.jack.Options; import com.android.jack.TestTools; import com.android.jack.ir.ast.JAsgOperation; import com.android.jack.ir.ast.JBlock; @@ -66,13 +65,6 @@ public class ClinitTest { } @Test - public void testCompileWithClinit() throws Exception { - Options compilerArgs = TestTools.buildCommandLineArgs( - TestTools.getJackTestFromBinaryName(CLASS_WITH_VARIABLE_INIT_BINARY_NAME)); - TestTools.runCompilation(compilerArgs); - } - - @Test public void searchEmptyStaticInit() throws Exception { JMethod clinit = TestTools.getJMethodWithRejectAllFilter( TestTools.getJackTestFromBinaryName(CLASS_BINARY_NAME), diff --git a/jack/tests/com/android/jack/frontend/InitTest.java b/jack/tests/com/android/jack/frontend/InitTest.java index b32790df..db60fbb3 100644 --- a/jack/tests/com/android/jack/frontend/InitTest.java +++ b/jack/tests/com/android/jack/frontend/InitTest.java @@ -16,7 +16,6 @@ package com.android.jack.frontend; -import com.android.jack.Options; import com.android.jack.TestTools; import com.android.jack.ir.ast.JMethod; import com.android.jack.util.NamingTools; @@ -35,7 +34,7 @@ public class InitTest { @Test public void searchInit() throws Exception { - String binaryName = "com/android/jack/fibonacci/jack/Fibo"; + String binaryName = "com/android/jack/fibonacci/test001/jack/Fibo"; JMethod init = TestTools.getJMethodWithRejectAllFilter( TestTools.getJackTestFromBinaryName(binaryName), "L" + binaryName + ";", @@ -44,17 +43,4 @@ public class InitTest { Assert.assertNotNull(init); } - @Test - public void testCompileEmptyConstructor() throws Exception { - Options compilerArgs = TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("init/test001")); - TestTools.runCompilation(compilerArgs); - } - - @Test - public void testVariableInit() throws Exception { - Options compilerArgs = TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("init/test002")); - TestTools.runCompilation(compilerArgs); - } }
\ No newline at end of file diff --git a/jack/tests/com/android/jack/frontend/MissingClassTest.java b/jack/tests/com/android/jack/frontend/MissingClassTest.java deleted file mode 100644 index 2d697ac6..00000000 --- a/jack/tests/com/android/jack/frontend/MissingClassTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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.frontend; - -import com.android.jack.Options; -import com.android.jack.TestTools; -import com.android.jack.category.KnownBugs; - -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import java.io.File; - -public class MissingClassTest { - - @Test - @Category(KnownBugs.class) - public void test001() throws Exception { - File outJackTmpMissing = TestTools.createTempDir("MissingClassTest001-missing", ".jayce"); - File outJackTmpSuper = TestTools.createTempDir("MissingClassTest001-super", ".jayce"); - File outJackTmpTest = TestTools.createTempDir("MissingClassTest001-test", ".jayce"); - - TestTools.compileSourceToJack(new Options(), - new File(TestTools.getJackTestsWithJackFolder("frontend/test001"), "missing"), - TestTools.getDefaultBootclasspathString(), outJackTmpMissing, false /* zip */); - - TestTools.compileSourceToJack(new Options(), - new File(TestTools.getJackTestsWithJackFolder("frontend/test001"), "sub2"), - TestTools.getDefaultBootclasspathString() + File.pathSeparator - + outJackTmpMissing.getPath(), outJackTmpSuper, false /* zip */); - - TestTools.compileSourceToJack(new Options(), - new File(TestTools.getJackTestsWithJackFolder("frontend/test001"), "test"), - TestTools.getDefaultBootclasspathString() + File.pathSeparator + outJackTmpSuper.getPath(), - outJackTmpTest, false /* zip */); - - } - -} diff --git a/jack/tests/com/android/jack/frontend/StringTest.java b/jack/tests/com/android/jack/frontend/StringTest.java deleted file mode 100644 index cd9e8893..00000000 --- a/jack/tests/com/android/jack/frontend/StringTest.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2012 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.frontend; - -import com.android.jack.Options; -import com.android.jack.TestTools; - -import org.junit.Before; -import org.junit.Test; - -public class StringTest { - - @Before - public void setUp() throws Exception { - StringTest.class.getClassLoader().setDefaultAssertionStatus(true); - } - - @Test - public void testCompileNewString() throws Exception { - Options compilerArgs = TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("string001")); - TestTools.runCompilation(compilerArgs); - } -} diff --git a/jack/tests/com/android/jack/frontend/SwitchTest.java b/jack/tests/com/android/jack/frontend/SwitchTest.java index fd349536..d4598afc 100644 --- a/jack/tests/com/android/jack/frontend/SwitchTest.java +++ b/jack/tests/com/android/jack/frontend/SwitchTest.java @@ -46,7 +46,7 @@ public class SwitchTest { @Before public void setUp() throws Exception { - StringTest.class.getClassLoader().setDefaultAssertionStatus(true); + SwitchTest.class.getClassLoader().setDefaultAssertionStatus(true); } @Test diff --git a/jack/tests/com/android/jack/frontend/SynchronizedTest.java b/jack/tests/com/android/jack/frontend/SynchronizedTest.java index 0637072d..9d271771 100644 --- a/jack/tests/com/android/jack/frontend/SynchronizedTest.java +++ b/jack/tests/com/android/jack/frontend/SynchronizedTest.java @@ -23,8 +23,8 @@ import com.android.jack.ir.ast.JClassLiteral; import com.android.jack.ir.ast.JLock; import com.android.jack.ir.ast.JMethod; import com.android.jack.ir.ast.JMethodBody; -import com.android.jack.ir.ast.JSession; import com.android.jack.ir.ast.JReturnStatement; +import com.android.jack.ir.ast.JSession; import com.android.jack.ir.ast.JStatement; import com.android.jack.ir.ast.JSynchronizedBlock; import com.android.jack.ir.ast.JUnlock; @@ -54,7 +54,7 @@ public class SynchronizedTest { @Before public void setUp() throws Exception { - StringTest.class.getClassLoader().setDefaultAssertionStatus(true); + SynchronizedTest.class.getClassLoader().setDefaultAssertionStatus(true); } @Test diff --git a/jack/tests/com/android/jack/gwt/BinaryLookup.java b/jack/tests/com/android/jack/gwt/BinaryLookup.java index 8d4c44bf..5eda4722 100644 --- a/jack/tests/com/android/jack/gwt/BinaryLookup.java +++ b/jack/tests/com/android/jack/gwt/BinaryLookup.java @@ -51,7 +51,7 @@ public class BinaryLookup { Main.class.getClassLoader().setDefaultAssertionStatus(true); Options fiboArgs = TestTools.buildCommandLineArgs( - TestTools.getJackTestFromBinaryName("com/android/jack/fibonacci/jack/Fibo")); + TestTools.getJackTestFromBinaryName("com/android/jack/fibonacci/test001/jack/Fibo")); fiboArgs.addProperty(Options.METHOD_FILTER.getName(), "reject-all-methods"); hooks = new RunnableHooks(); session = TestTools.buildSession(fiboArgs, hooks); diff --git a/jack/tests/com/android/jack/java7/ExceptionsTest.java b/jack/tests/com/android/jack/java7/ExceptionsTest.java deleted file mode 100644 index 1339bee2..00000000 --- a/jack/tests/com/android/jack/java7/ExceptionsTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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.java7; - -import com.android.jack.Main; -import com.android.jack.Options; -import com.android.jack.TestTools; - -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * JUnit test for compilation of Java 7 features - */ -public class ExceptionsTest { - - @BeforeClass - public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); - } - - @Test - public void java7Exception001() throws Exception { - Options options = TestTools.buildCommandLineArgs(TestTools - .getJackTestsWithJackFolder("java7/exceptions/test001")); - options.addProperty(Options.JAVA_SOURCE_VERSION.getName(), "1.7"); - TestTools.runCompilation(options); - } - - @Test - public void java7Exception002() throws Exception { - Options options = TestTools.buildCommandLineArgs(TestTools - .getJackTestsWithJackFolder("java7/exceptions/test002")); - options.addProperty(Options.JAVA_SOURCE_VERSION.getName(), "1.7"); - TestTools.runCompilation(options); - } - - @Test - public void java7Exception003() throws Exception { - Options options = TestTools.buildCommandLineArgs(TestTools - .getJackTestsWithJackFolder("java7/exceptions/test003")); - options.addProperty(Options.JAVA_SOURCE_VERSION.getName(), "1.7"); - TestTools.runCompilation(options); - } - - @Test - public void java7Exception004() throws Exception { - Options options = TestTools.buildCommandLineArgs(TestTools - .getJackTestsWithJackFolder("java7/exceptions/test004")); - options.addProperty(Options.JAVA_SOURCE_VERSION.getName(), "1.7"); - TestTools.runCompilation(options); - } - - @Test - public void java7Exception005() throws Exception { - Options options = TestTools.buildCommandLineArgs(TestTools - .getJackTestsWithJackFolder("java7/exceptions/test005")); - options.addProperty(Options.JAVA_SOURCE_VERSION.getName(), "1.7"); - TestTools.runCompilation(options); - } -} diff --git a/jack/tests/com/android/jack/java7/SwitchesTest.java b/jack/tests/com/android/jack/java7/SwitchesTest.java deleted file mode 100644 index 6474af18..00000000 --- a/jack/tests/com/android/jack/java7/SwitchesTest.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * 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.java7; - -import com.android.jack.Main; -import com.android.jack.Options; -import com.android.jack.TestTools; - -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -/** - * JUnit test for compilation of Java 7 features - */ -public class SwitchesTest { - - @BeforeClass - public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); - } - - @Test - public void java7Switches001() throws Exception { - Options options = TestTools.buildCommandLineArgs(TestTools - .getJackTestsWithJackFolder("java7/switches/test001")); - options.addProperty(Options.JAVA_SOURCE_VERSION.getName(), "1.7"); - TestTools.runCompilation(options); - } - - @Test - public void java7Switches002() throws Exception { - Options options = TestTools.buildCommandLineArgs(TestTools - .getJackTestsWithJackFolder("java7/switches/test002")); - options.addProperty(Options.JAVA_SOURCE_VERSION.getName(), "1.7"); - TestTools.runCompilation(options); - } - - @Test - public void java7Switches003() throws Exception { - Options options = TestTools.buildCommandLineArgs(TestTools - .getJackTestsWithJackFolder("java7/switches/test003")); - options.addProperty(Options.JAVA_SOURCE_VERSION.getName(), "1.7"); - TestTools.runCompilation(options); - } - - @Test - public void java7Switches004() throws Exception { - File jackZipFile = TestTools.createTempFile("tmp", ".zip"); - - Options options = new Options(); - options.addProperty(Options.JAVA_SOURCE_VERSION.getName(), "1.7"); - - TestTools.compileSourceToJack(options, - TestTools.getJackTestsWithJackFolder("java7/switches/test001"), - TestTools.getDefaultBootclasspathString(), jackZipFile, true /* zip */ - ); - - options = new Options(); - List<File> imports = new ArrayList<File>(1); - imports.add(jackZipFile); - options.setJayceImports(imports); - File outDexFolder = TestTools.createTempDir("tmp", "dex"); - TestTools.compileJackToDex(options, jackZipFile, outDexFolder, false /* zip */); - } -} diff --git a/jack/tests/com/android/jack/preprocessor/PreProcessorTest.java b/jack/tests/com/android/jack/preprocessor/PreProcessorTest.java index f03e8c41..3a600ec3 100644 --- a/jack/tests/com/android/jack/preprocessor/PreProcessorTest.java +++ b/jack/tests/com/android/jack/preprocessor/PreProcessorTest.java @@ -89,59 +89,4 @@ public class PreProcessorTest { hooks.runHooks(); } - - @Test - public void test001_002() throws Exception { - File testDir = TestTools.getJackTestsWithJackFolder("preprocessor/test001"); - Options options = TestTools.buildCommandLineArgs(testDir); - options.addProperty(PreProcessor.ENABLE.getName(), "true"); - options.addProperty(PreProcessor.FILE.getName(), - new File(testDir, "config.jpp").getAbsolutePath()); - TestTools.compileSourceToDex(options, testDir, TestTools.getDefaultBootclasspathString(), - TestTools.createTempFile("annotationAdderTest", ".out.zip"), true); - } - - @Test - public void test001_001() throws Exception { - File testDir = TestTools.getJackTestsWithJackFolder("preprocessor/test001"); - File tempDir = TestTools.createTempDir("preprocessor", "test"); - TestTools.compileSourceToJack(new Options(), testDir, - TestTools.getDefaultBootclasspathString(), tempDir, false); - - Options args = TestTools.buildCommandLineArgs( - new File(testDir, "app1/ApplicationActivity1.java")); - args.setClasspath(tempDir.getPath()); - RunnableHooks hooks = new RunnableHooks(); - JSession session = TestTools.buildSession(args, hooks); - ANTLRFileStream in = new ANTLRFileStream(new File(testDir, "config.jpp").getAbsolutePath()); - PreProcessorLexer lexer = new PreProcessorLexer(in); - CommonTokenStream tokens = new CommonTokenStream(lexer); - PreProcessorParser parser = new PreProcessorParser(tokens); - Collection<Rule> rules = parser.rules(session); - Scope scope = new TypeToEmitScope(session); - for (Rule rule : rules) { - Context context = new Context(); - if (!rule.getSet().eval(scope, context).isEmpty()) { - context.getRequest(session).commit(); - } - } - - JAnnotation installerAnnotation = session.getPhantomLookup().getAnnotation( - "Lcom/android/jack/preprocessor/test001/jack/MultiDexInstaller;"); - JNodeLookup lookup = session.getLookup(); - { - JDefinedClassOrInterface coi = lookup.getClass( - "Lcom/android/jack/preprocessor/test001/jack/app1/ApplicationActivity1;"); - Assert.assertFalse(coi.getAnnotations(installerAnnotation).isEmpty()); - for (JMethod method : coi.getMethods()) { - if (method.getName().equals("noAnnotation")) { - Assert.assertTrue(method.getAnnotations(installerAnnotation).isEmpty()); - } else { - Assert.assertFalse(method.getAnnotations(installerAnnotation).isEmpty()); - } - } - } - - hooks.runHooks(); - } } diff --git a/jack/tests/com/android/jack/shrob/AbstractTest.java b/jack/tests/com/android/jack/shrob/AbstractTest.java deleted file mode 100644 index eb707d0e..00000000 --- a/jack/tests/com/android/jack/shrob/AbstractTest.java +++ /dev/null @@ -1,567 +0,0 @@ -/* - * Copyright (C) 2012 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.shrob; - -import com.android.jack.Main; -import com.android.jack.ProguardFlags; -import com.android.jack.TestTools; -import com.android.jack.category.KnownBugs; -import com.android.jack.category.SlowTests; - -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; - -import javax.annotation.CheckForNull; -import javax.annotation.Nonnull; - -/** - * Abstract class for running shrob tests - */ -public abstract class AbstractTest { - - @Nonnull - static final File[] defaultBootclasspath = TestTools.getDefaultBootclasspath(); - - @BeforeClass - public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); - } - - protected abstract void runTest( - @CheckForNull File[] bootclasspath, - @CheckForNull File[] classpath, - @Nonnull String testNumber, - @Nonnull String flagNumber, - @Nonnull String mappingNumber) - throws Exception; - - protected ProguardFlags generateApplyMapping(@Nonnull File mappingFile) throws IOException { - File applyMapping = TestTools.createTempFile("mapping.flags", null); - BufferedWriter writer = new BufferedWriter(new FileWriter(applyMapping)); - writer.append("-applymapping "); - writer.append(mappingFile.getAbsolutePath()); - writer.close(); - return new ProguardFlags(applyMapping); - } - - protected ProguardFlags generateInjars(@Nonnull File injar) throws IOException { - File injarFlags = TestTools.createTempFile("injars", ".flags"); - BufferedWriter writer = new BufferedWriter(new FileWriter(injarFlags)); - writer.append("-injars "); - writer.append(injar.getAbsolutePath()); - writer.close(); - return new ProguardFlags(injarFlags); - } - - @Test - public void test1_001() throws Exception { - runTest(defaultBootclasspath, null, "001", "001", ""); - } - - @Test - @Category(SlowTests.class) - public void test1_002() throws Exception { - runTest(defaultBootclasspath, null, "001", "002", ""); - } - - @Test - @Category(SlowTests.class) - public void test1_003() throws Exception { - runTest(defaultBootclasspath, null, "001", "003", ""); - } - - @Test - @Category(SlowTests.class) - public void test1_004() throws Exception { - runTest(defaultBootclasspath, null, "001", "004", ""); - } - - @Test - @Category(SlowTests.class) - public void test1_005() throws Exception { - runTest(defaultBootclasspath, null, "001", "005", ""); - } - - @Test - @Category(SlowTests.class) - public void test1_005_002() throws Exception { - runTest(defaultBootclasspath, null, "001", "005", "002"); - } - - @Test - @Category(SlowTests.class) - public void test1_005_003() throws Exception { - runTest(defaultBootclasspath, null, "001", "005", "003"); - } - - @Test - @Category(SlowTests.class) - public void test1_006() throws Exception { - runTest(defaultBootclasspath, null, "001", "006", ""); - } - - @Test - @Category(SlowTests.class) - public void test1_007() throws Exception { - runTest(defaultBootclasspath, null, "001", "007", ""); - } - - @Test - @Category(SlowTests.class) - public void test1_008() throws Exception { - runTest(defaultBootclasspath, null, "001", "008", ""); - } - - @Test - @Category(SlowTests.class) - public void test1_009() throws Exception { - runTest(defaultBootclasspath, null, "001", "009", ""); - } - - @Test - @Category(SlowTests.class) - public void test1_010() throws Exception { - runTest(defaultBootclasspath, null, "001", "010", ""); - } - - @Test - @Category(SlowTests.class) - public void test1_011() throws Exception { - runTest(defaultBootclasspath, null, "001", "011", ""); - } - - @Test - @Category(SlowTests.class) - public void test1_012() throws Exception { - runTest(defaultBootclasspath, null, "001", "012", ""); - } - - @Test - @Category(SlowTests.class) - public void test1_013() throws Exception { - runTest(defaultBootclasspath, null, "001", "013", ""); - } - - @Test - @Category(SlowTests.class) - public void test1_014() throws Exception { - runTest(defaultBootclasspath, null, "001", "014", ""); - } - - @Test - @Category(SlowTests.class) - public void test1_015() throws Exception { - runTest(defaultBootclasspath, null, "001", "015", ""); - } - - @Test - @Category(SlowTests.class) - public void test1_016() throws Exception { - runTest(defaultBootclasspath, null, "001", "016", ""); - } - - @Test - @Category(SlowTests.class) - public void test1_017() throws Exception { - runTest(defaultBootclasspath, null, "001", "017", ""); - } - - @Test - @Category(SlowTests.class) - public void test1_018() throws Exception { - runTest(defaultBootclasspath, null, "001", "018", ""); - } - - @Test - @Category(SlowTests.class) - public void test1_019() throws Exception { - runTest(defaultBootclasspath, null, "001", "019", ""); - } - - @Test - @Category(SlowTests.class) - public void test1_020() throws Exception { - runTest(defaultBootclasspath, null, "001", "020", ""); - } - - @Test - @Category(SlowTests.class) - public void test1_021() throws Exception { - runTest(defaultBootclasspath, null, "001", "021", ""); - } - - @Test - @Category(SlowTests.class) - public void test1_022() throws Exception { - runTest(defaultBootclasspath, null, "001", "022", ""); - } - - @Test - public void test2_001() throws Exception { - runTest(defaultBootclasspath, null, "002", "001", ""); - } - - @Test - @Category(SlowTests.class) - public void test2_002() throws Exception { - runTest(defaultBootclasspath, null, "002", "002", ""); - } - - @Test - @Category(SlowTests.class) - public void test2_003() throws Exception { - runTest(defaultBootclasspath, null, "002", "003", ""); - } - - @Test - public void test4_001() throws Exception { - runTest(defaultBootclasspath, null, "004", "001", ""); - } - - @Test - @Category(SlowTests.class) - public void test4_002() throws Exception { - runTest(defaultBootclasspath, null, "004", "002", ""); - } - - @Test - @Category(SlowTests.class) - public void test4_003() throws Exception { - runTest(defaultBootclasspath, null, "004", "003", ""); - } - - @Test - public void test5_001() throws Exception { - runTest(defaultBootclasspath, null, "005", "001", ""); - } - - @Test - @Category(SlowTests.class) - public void test5_002() throws Exception { - runTest(defaultBootclasspath, null, "005", "002", ""); - } - - @Test - @Category(SlowTests.class) - public void test5_003() throws Exception { - runTest(defaultBootclasspath, null, "005", "003", ""); - } - - @Test - @Category(SlowTests.class) - public void test5_004() throws Exception { - runTest(defaultBootclasspath, null, "005", "004", ""); - } - - @Test - public void test5_005() throws Exception { - runTest(defaultBootclasspath, null, "005", "005", ""); - } - - @Test - @Category(SlowTests.class) - public void test5_006() throws Exception { - runTest(defaultBootclasspath, null, "005", "006", ""); - } - - @Test - @Category(SlowTests.class) - public void test5_007() throws Exception { - runTest(defaultBootclasspath, null, "005", "007", ""); - } - - @Test - @Category(SlowTests.class) - public void test5_008() throws Exception { - runTest(defaultBootclasspath, null, "005", "008", ""); - } - - @Test - public void test6_001() throws Exception { - runTest(defaultBootclasspath, null, "006", "001", ""); - } - - @Test - @Category(SlowTests.class) - public void test6_002() throws Exception { - runTest(defaultBootclasspath, null, "006", "002", ""); - } - - @Test - @Category(SlowTests.class) - public void test6_003() throws Exception { - runTest(defaultBootclasspath, null, "006", "003", ""); - } - - @Test - @Category(SlowTests.class) - public void test6_004() throws Exception { - runTest(defaultBootclasspath, null, "006", "004", ""); - } - - @Test - @Category(SlowTests.class) - public void test6_005() throws Exception { - runTest(defaultBootclasspath, null, "006", "005", ""); - } - - @Test - @Category(SlowTests.class) - public void test6_006() throws Exception { - runTest(defaultBootclasspath, null, "006", "006", ""); - } - - @Test - public void test7_001() throws Exception { - runTest(defaultBootclasspath, null, "007", "001", ""); - } - - @Test - @Category(SlowTests.class) - public void test7_002() throws Exception { - runTest(defaultBootclasspath, null, "007", "002", ""); - } - - @Test - @Category(SlowTests.class) - public void test7_003() throws Exception { - runTest(defaultBootclasspath, null, "007", "003", ""); - } - - @Test - public void test8_001() throws Exception { - runTest(defaultBootclasspath, null, "008", "001", ""); - } - - @Test - @Category(SlowTests.class) - public void test8_002() throws Exception { - runTest(defaultBootclasspath, null, "008", "002", ""); - } - - @Test - @Category(SlowTests.class) - public void test8_003() throws Exception { - runTest(defaultBootclasspath, null, "008", "003", ""); - } - - @Test - @Category(SlowTests.class) - public void test8_004() throws Exception { - runTest(defaultBootclasspath, null, "008", "004", ""); - } - - @Test - public void test9_001() throws Exception { - runTest(defaultBootclasspath, null, "009", "001", ""); - } - - @Test - @Category(SlowTests.class) - public void test9_002() throws Exception { - runTest(defaultBootclasspath, null, "009", "002", ""); - } - - @Test - @Category(SlowTests.class) - public void test9_003() throws Exception { - runTest(defaultBootclasspath, null, "009", "003", ""); - } - - @Test - public void test10_001() throws Exception { - runTest(defaultBootclasspath, null, "010", "001", ""); - } - - @Test - @Category(SlowTests.class) - public void test10_002() throws Exception { - runTest(defaultBootclasspath, null, "010", "002", ""); - } - - @Test - @Category(SlowTests.class) - public void test10_003() throws Exception { - runTest(defaultBootclasspath, null, "010", "003", ""); - } - - @Test - public void test11_001() throws Exception { - runTest(defaultBootclasspath, null, "011", "001", ""); - } - - @Test - @Category(SlowTests.class) - public void test11_002() throws Exception { - runTest(defaultBootclasspath, null, "011", "002", ""); - } - - @Test - public void test12_001() throws Exception { - runTest(defaultBootclasspath, null, "012", "001", ""); - } - - @Test - public void test13_001() throws Exception { - runTest(defaultBootclasspath, null, "013", "001", ""); - } - - @Test - public void test14_001() throws Exception { - runTest(defaultBootclasspath, null, "014", "001", ""); - } - - @Test - public void test15_001() throws Exception { - runTest(defaultBootclasspath, null, "015", "001", ""); - } - - @Test - public void test16_001() throws Exception { - runTest(defaultBootclasspath, null, "016", "001", ""); - } - - @Test - @Category(SlowTests.class) - public void test16_002() throws Exception { - runTest(defaultBootclasspath, null, "016", "002", ""); - } - - @Test - public void test17_001() throws Exception { - runTest(defaultBootclasspath, null, "017", "001", ""); - } - - @Test - public void test18_001() throws Exception { - runTest(defaultBootclasspath, null, "018", "001", ""); - } - - @Test - public void test19_001() throws Exception { - runTest(defaultBootclasspath, null, "019", "001", ""); - } - - @Test - public void test21_001() throws Exception { - runTest(defaultBootclasspath, null, "021", "001", ""); - } - - @Test - public void test22_001() throws Exception { - runTest(defaultBootclasspath, null, "022", "001", ""); - } - - @Test - public void test23_001() throws Exception { - runTest(defaultBootclasspath, null, "023", "001", ""); - } - - @Test - public void test25_001() throws Exception { - runTest(defaultBootclasspath, null, "025", "001", ""); - } - - @Test - public void test26_001() throws Exception { - runTest(defaultBootclasspath, null, "026", "001", ""); - } - - @Test - public void test29_001() throws Exception { - runTest(defaultBootclasspath, null, "029", "001", ""); - } - - @Test - public void test30_001() throws Exception { - runTest(defaultBootclasspath, null, "030", "001", ""); - } - - @Test - public void test31_001() throws Exception { - runTest(defaultBootclasspath, null, "031", "001", ""); - } - - @Test - public void test31_002() throws Exception { - runTest(defaultBootclasspath, null, "031", "002", ""); - } - - @Test - public void test32_001() throws Exception { - runTest(defaultBootclasspath, null, "032", "001", ""); - } - - @Test - public void test33_001() throws Exception { - runTest(defaultBootclasspath, null, "033", "001", ""); - } - - @Test - @Category(SlowTests.class) - public void test33_002() throws Exception { - runTest(defaultBootclasspath, null, "033", "002", ""); - } - - @Test - public void test34_001() throws Exception { - runTest(defaultBootclasspath, null, "034", "001", ""); - } - - @Test - public void test35_001() throws Exception { - runTest(defaultBootclasspath, null, "035", "001", ""); - } - - @Test - public void test36_001() throws Exception { - runTest(defaultBootclasspath, null, "036", "001", ""); - } - - @Test - public void test37_001() throws Exception { - runTest(defaultBootclasspath, null, "037", "001", ""); - } - - @Test - public void test38_001() throws Exception { - runTest(defaultBootclasspath, null, "038", "001", ""); - } - - @Test - public void test39_001() throws Exception { - runTest(defaultBootclasspath, null, "039", "001", ""); - } - - @Test - @Category(SlowTests.class) - public void test40_001() throws Exception { - runTest(defaultBootclasspath, null, "040", "001", ""); - } - - @Test - @Category(KnownBugs.class) - public void test41_001() throws Exception { - runTest(defaultBootclasspath, null, "041", "001", ""); - } -} diff --git a/jack/tests/com/android/jack/shrob/AllTests.java b/jack/tests/com/android/jack/shrob/AllTests.java index e1a7fc3d..2543219e 100644 --- a/jack/tests/com/android/jack/shrob/AllTests.java +++ b/jack/tests/com/android/jack/shrob/AllTests.java @@ -23,16 +23,6 @@ import org.junit.runners.Suite.SuiteClasses; @RunWith(Suite.class) @SuiteClasses(value = { -// AnnotationsTest.class, - ShrinkTest.class, - ShrinkMultiDexTest.class, - ObfuscationWithMappingTest.class, -// ObfuscationWithAttributesTest.class, -// ObfuscationWithDebugInfoTest.class, - ObfuscationWithoutMappingTest.class, - RepackagingTest.class, - FlattenPackageTest.class, - SeedTest.class, TreeTest.class }) public class AllTests { diff --git a/jack/tests/com/android/jack/shrob/ObfuscationWithDebugInfoTest.java b/jack/tests/com/android/jack/shrob/ObfuscationWithDebugInfoTest.java deleted file mode 100644 index 2dba0245..00000000 --- a/jack/tests/com/android/jack/shrob/ObfuscationWithDebugInfoTest.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2012 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.shrob; - -import com.android.jack.ProguardFlags; -import com.android.jack.TestTools; - -import java.io.File; - -import javax.annotation.CheckForNull; -import javax.annotation.Nonnull; - -public class ObfuscationWithDebugInfoTest extends AbstractTest { - - @Override - protected void runTest( - @CheckForNull File[] bootclasspath, - @CheckForNull File[] classpath, - @Nonnull String testNumber, - @Nonnull String flagNumber, - @Nonnull String mappingNumber) - throws Exception { - String testName = "shrob/test" + testNumber; - File testFolder = TestTools.getJackTestFolder(testName); - ProguardFlags[] proguardflagsFiles = new ProguardFlags[] { - generateApplyMapping(new File(testFolder,"proguard.flags" + flagNumber + ".mapping" + mappingNumber)), - new ProguardFlags(TestTools.getJackTestFolder("shrob"),"keepDebugInfo.flags"), - new ProguardFlags(testFolder,"proguard.flags" + flagNumber) - }; - TestTools.checkStructure(null, null, TestTools.getJackTestsWithJackFolder(testName), - true /* withDebuginfo */, proguardflagsFiles); - } -} diff --git a/jack/tests/com/android/jack/shrob/ObfuscationWithoutMappingTest.java b/jack/tests/com/android/jack/shrob/ObfuscationWithoutMappingTest.java deleted file mode 100644 index 36ec6219..00000000 --- a/jack/tests/com/android/jack/shrob/ObfuscationWithoutMappingTest.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (C) 2012 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.shrob; - -import com.android.jack.Options; -import com.android.jack.TestTools; -import com.android.jack.category.KnownBugs; -import com.android.jack.shrob.proguard.GrammarActions; -import com.android.jack.shrob.spec.Flags; - -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import java.io.File; - -import javax.annotation.CheckForNull; -import javax.annotation.Nonnull; - -public class ObfuscationWithoutMappingTest extends AbstractTest { - - @Override - protected void runTest( - @CheckForNull File[] bootclasspath, - @CheckForNull File[] classpath, - @Nonnull String testNumber, - @Nonnull String flagNumber, - @Nonnull String mappingNumber) - throws Exception { - String testName = "shrob/test" + testNumber; - File testFolder = TestTools.getJackTestFolder(testName); - Flags flags = new Flags(); - GrammarActions.parse("proguard.flags" + flagNumber, testFolder.getAbsolutePath(), flags); - File refFolder = new File(testFolder, "refsObfuscationWithoutMapping"); - - File candidateOutputMapping = TestTools.createTempFile("mapping", ".txt"); - File refOutputMapping = new File(refFolder, "expected-" + flagNumber + ".txt"); - flags.setOutputMapping(candidateOutputMapping); - flags.setPrintMapping(true); - - Options jackOptions = new Options(); - jackOptions.setNameProvider("rot13"); - TestTools.runWithFlags(jackOptions, bootclasspath, classpath, - TestTools.getJackTestsWithJackFolder(testName), flags); - ListingComparator.compare(refOutputMapping, candidateOutputMapping); - } - - @Override - @Test - @Category(KnownBugs.class) - public void test33_001() throws Exception { - super.test33_001(); - } - - @Override - @Test - @Category(KnownBugs.class) - public void test34_001() throws Exception { - super.test34_001(); - } - - @Override - @Test - @Category(KnownBugs.class) - public void test35_001() throws Exception { - super.test35_001(); - } -} diff --git a/jack/tests/com/android/jack/shrob/ShrinkMultiDexTest.java b/jack/tests/com/android/jack/shrob/ShrinkMultiDexTest.java deleted file mode 100644 index 4b2fc57a..00000000 --- a/jack/tests/com/android/jack/shrob/ShrinkMultiDexTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (C) 2012 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.shrob; - -import com.android.jack.Main; -import com.android.jack.Options; -import com.android.jack.ProguardFlags; -import com.android.jack.TestTools; -import com.android.jack.backend.dex.DexFileWriter; -import com.android.jack.backend.dex.MultiDexLegacy; -import com.android.jack.preprocessor.PreProcessor; - -import org.junit.BeforeClass; - -import java.io.File; - -import javax.annotation.CheckForNull; -import javax.annotation.Nonnull; - -/** - * Tests for verifying that tracing for MultiDex does not disturb shrinking. - */ -public class ShrinkMultiDexTest extends AbstractTest { - - private static ProguardFlags dontObfuscateFlagFile = - new ProguardFlags(TestTools.getJackTestFolder("shrob"), "dontobfuscate.flags"); - - @BeforeClass - public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); - } - - @Override - protected void runTest( - @CheckForNull File[] bootclasspath, - @CheckForNull File[] classpath, - @Nonnull String testNumber, - @Nonnull String flagNumber, - @Nonnull String mappingNumber) - throws Exception { - String testName = "shrob/test" + testNumber; - File testFolder = TestTools.getJackTestFolder(testName); - ProguardFlags[] proguardflagsFiles = new ProguardFlags[] { - dontObfuscateFlagFile, - new ProguardFlags(TestTools.getJackTestFolder("shrob"),"keepAllAttributes.flags"), - new ProguardFlags(testFolder, "proguard.flags" + flagNumber)}; - File refFolder = new File(testFolder, "refsShrinking"); - Options options = new Options(); - options.addProperty(DexFileWriter.DEX_WRITING_POLICY.getName(), "multidex"); - options.addProperty(MultiDexLegacy.MULTIDEX_LEGACY.getName(), "true"); - options.addProperty(PreProcessor.ENABLE.getName(), "true"); - options.addProperty(PreProcessor.FILE.getName(), new File(TestTools.getJackTestFolder("shrob"), - "legacyMainDexClasses.jpp").getAbsolutePath()); - TestTools.checkListingWhenMultiDex(options, - bootclasspath, - classpath, - TestTools.getJackTestsWithJackFolder(testName), - proguardflagsFiles, - new File(refFolder, "expected-" + flagNumber + ".txt")); - } - -} diff --git a/jack/tests/com/android/jack/shrob/ShrinkTest.java b/jack/tests/com/android/jack/shrob/ShrinkTest.java deleted file mode 100644 index a4bebd29..00000000 --- a/jack/tests/com/android/jack/shrob/ShrinkTest.java +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Copyright (C) 2012 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.shrob; - -import com.android.jack.Main; -import com.android.jack.Options; -import com.android.jack.ProguardFlags; -import com.android.jack.TestTools; -import com.android.jack.util.TextUtils; - -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.File; -import java.util.Collections; - -import javax.annotation.CheckForNull; -import javax.annotation.Nonnull; - -public class ShrinkTest extends AbstractTest { - - private static ProguardFlags dontObfuscateFlagFile = - new ProguardFlags(TestTools.getJackTestFolder("shrob"), "dontobfuscate.flags"); - - @BeforeClass - public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); - } - - @Override - protected void runTest( - @CheckForNull File[] bootclasspath, - @CheckForNull File[] classpath, - @Nonnull String testNumber, - @Nonnull String flagNumber, - @Nonnull String mappingNumber) - throws Exception { - String testName = "shrob/test" + testNumber; - File testFolder = TestTools.getJackTestFolder(testName); - ProguardFlags[] proguardflagsFiles = new ProguardFlags[] { - dontObfuscateFlagFile, - new ProguardFlags(TestTools.getJackTestFolder("shrob"),"keepAllAttributes.flags"), - new ProguardFlags(testFolder, "proguard.flags" + flagNumber)}; - File refFolder = new File(testFolder, "refsShrinking"); - TestTools.checkListing(bootclasspath, - classpath, - TestTools.getJackTestsWithJackFolder(testName), - proguardflagsFiles, - new File(refFolder, "expected-" + flagNumber + ".txt")); - } - - @Test - public void test020() throws Exception { - File libOut = TestTools.createTempDir("ShrinkTest", "lib"); - File testOut = null; - File shrinkOut = null; - - try { - Options libOptions = TestTools.buildCommandLineArgs( - TestTools.getJackTestLibFolder("shrob/test020")); - libOptions.setJayceOutputDir(libOut); - TestTools.runCompilation(libOptions); - - testOut = TestTools.createTempDir("ShrinkTest", "test"); - Options testOptions = TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("shrob/test020")); - testOptions.setJayceOutputDir(testOut); - testOptions.setClasspath(libOut.getAbsolutePath()); - TestTools.runCompilation(testOptions); - - Options shrinkOption = new Options(); - shrinkOption.addProguardFlagsFile(dontObfuscateFlagFile); - shrinkOption.addProguardFlagsFile( - new ProguardFlags(TestTools.getJackTestFolder("shrob/test020"),"proguard.flags")); - - shrinkOut = TestTools.createTempDir("ShrinkTest", "shrink"); - shrinkOption.setJayceOutputDir(shrinkOut); - shrinkOption.addJayceImport(testOut); - TestTools.runCompilation(shrinkOption); - } catch (Exception e) { - String message = "Not deleting temp files of failed test ShrinkTest.test20 in:" + - TextUtils.LINE_SEPARATOR + - "- " + libOut.getAbsolutePath(); - if (testOut != null) { - message += TextUtils.LINE_SEPARATOR + "- " + testOut.getAbsolutePath(); - } - if (shrinkOut != null) { - message += TextUtils.LINE_SEPARATOR + "- " + shrinkOut.getAbsolutePath(); - } - System.err.println(); - System.err.println(message); - throw e; - } - } - - @Test - public void test021() throws Exception { - File jackOut = TestTools.createTempDir("ShrinkTest", "jayce"); - File shrinkOut = null; - File dexOut = null; - - try { - Options libOptions = TestTools.buildCommandLineArgs( - TestTools.getJackTestsWithJackFolder("shrob/test021")); - libOptions.setJayceOutputDir(jackOut); - TestTools.runCompilation(libOptions); - - Options shrinkOption = new Options(); - shrinkOption.addProguardFlagsFile(dontObfuscateFlagFile); - shrinkOption.addProguardFlagsFile( - new ProguardFlags(TestTools.getJackTestFolder("shrob/test021"),"proguard.flags001")); - - shrinkOut = TestTools.createTempDir("ShrinkTest", "test"); - shrinkOption.setJayceOutputDir(shrinkOut); - shrinkOption.addJayceImport(jackOut); - TestTools.runCompilation(shrinkOption); - - dexOut = TestTools.createTempDir("ShrinkTest", "dex"); - Options dxOption = new Options(); - dxOption.addJayceImport(shrinkOut); - dxOption.setOutputDir(dexOut); - TestTools.runCompilation(dxOption); - - } catch (Exception e) { - String message = "Not deleting temp files of failed ShrinkTest.test20 in:\n" + - "- " + jackOut.getAbsolutePath(); - if (shrinkOut != null) { - message += "\n- " + shrinkOut.getAbsolutePath(); - } - if (dexOut != null) { - message += "\n- " + dexOut.getAbsolutePath(); - } - System.err.println(); - System.err.println(message); - throw e; - } - } - - /** - * The only purpose of this test is to use jack shrink capabilities and to have no reference to - * java/lang/Class. This test will make Jack fail if java/lang/Class methods like getField and - * getMethod cannot be looked up (i.e. at the time this test is written, if the structure of - * java/lang/Class has not been preloaded). - */ - @Test - public void test028() throws Exception { - File testFolder = TestTools.getJackTestFolder("shrob/test028"); - File jackar = null; - File shrinkedjackar = null; - jackar = TestTools.createTempFile("jackar", ".zip"); - shrinkedjackar = TestTools.createTempFile("shrinkedjackar", ".zip"); - ProguardFlags flags = new ProguardFlags(testFolder, "proguard.flags001"); - String classpath = TestTools.getDefaultBootclasspathString(); - - TestTools.compileSourceToJack(new Options(), testFolder, classpath, jackar, true); - - TestTools.shrobJackToJack(new Options(), - jackar, - classpath, - shrinkedjackar, - Collections.singletonList(flags), - true); - } - - @Test - public void test42_001() throws Exception { - runTest(defaultBootclasspath, null, "042", "001", ""); - } - - @Test - public void test42_002() throws Exception { - runTest(defaultBootclasspath, null, "042", "002", ""); - } - - @Test - public void test42_003() throws Exception { - runTest(defaultBootclasspath, null, "042", "003", ""); - } -} diff --git a/jack/tests/com/android/jack/tools/merger/MergerTestTools.java b/jack/tests/com/android/jack/tools/merger/MergerTestTools.java deleted file mode 100644 index 31c85f79..00000000 --- a/jack/tests/com/android/jack/tools/merger/MergerTestTools.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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.tools.merger; - -import com.android.jack.Options; -import com.android.jack.TestTools; -import com.android.jack.backend.dex.DexFileWriter; -import com.android.sched.scheduler.ScheduleInstance; - -import java.io.File; - -import javax.annotation.CheckForNull; -import javax.annotation.Nonnull; - -public class MergerTestTools { - - @Nonnull - public File buildOneDexPerType(@CheckForNull String classpath, @Nonnull File sourceFolder, - boolean withDebug) throws Exception { - Options options; - File multiDexFolder = TestTools.createTempDir("multi", "dex"); - File multiDex = new File(multiDexFolder, DexFileWriter.DEX_FILENAME); - File multiDexOnTypePerTypeFolder = TestTools.createTempDir("multiOnDexPerType", "dex"); - options = new Options(); - options.addProperty(Options.EMIT_LINE_NUMBER_DEBUG_INFO.getName(), Boolean.toString(withDebug)); - options.addProperty(ScheduleInstance.DEFAULT_RUNNER.getName(), "single-threaded"); - options.addProperty(Options.INTERMEDIATE_DEX_DIR.getName(), multiDexOnTypePerTypeFolder.getAbsolutePath()); - TestTools - .compileSourceToDex(options, sourceFolder, classpath, - multiDexFolder, false /* zip */, null /* jarjarRules */, null /* flagFiles */, - withDebug /* withDebugInfo */); - - return multiDex; - } -} diff --git a/jack/tests/com/android/jack/tools/merger/test011/MergerTest011.java b/jack/tests/com/android/jack/tools/merger/test011/MergerTest011.java deleted file mode 100644 index f11dfc17..00000000 --- a/jack/tests/com/android/jack/tools/merger/test011/MergerTest011.java +++ /dev/null @@ -1,210 +0,0 @@ -/* - * 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.tools.merger.test011; - -import com.android.jack.JackAbortException; -import com.android.jack.Main; -import com.android.jack.TestTools; -import com.android.jack.backend.dex.DexWritingException; -import com.android.jack.backend.dex.SingleDexOverflowException; -import com.android.jack.category.SlowTests; -import com.android.jack.tools.merger.FieldIdOverflowException; -import com.android.jack.tools.merger.MergerTestTools; -import com.android.jack.tools.merger.MethodIdOverflowException; -import com.android.jack.tools.merger.TypeIdOverflowException; - -import junit.framework.Assert; - -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.PrintStream; - -import javax.annotation.Nonnegative; -import javax.annotation.Nonnull; - -/** - * JUnit test checking that merging can throw overflow exceptions. - */ -public class MergerTest011 extends MergerTestTools { - - private static final int fileCount = 655; - @Nonnull - private static final String EXPECTED_MESSAGE = - "Error during the dex writing phase: classes.dex has too many IDs. Try using multi-dex"; - - @BeforeClass - public static void setUpClass() { - Main.class.getClassLoader().setDefaultAssertionStatus(true); - } - - @Test - public void testMergerWithHighNumberOfMethods() throws Exception { - File srcFolder = TestTools.createTempDir("oneDexPerType", "SrcFolder"); - - // One CstMethodRef is also created for call to object.init() - for (int fileIdx = 0; fileIdx < fileCount; fileIdx++) { - generateJavaFileWithMethods(srcFolder, fileIdx, 100); - } - generateJavaFileWithMethods(srcFolder, fileCount, 36); - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - PrintStream redirectStream = new PrintStream(baos); - System.setErr(redirectStream); - try { - buildOneDexPerType(TestTools.getDefaultBootclasspathString(), srcFolder, false /* withDebug */); - Assert.fail(); - } catch (JackAbortException e) { - Throwable cause = e.getCause(); - Assert.assertTrue(cause instanceof DexWritingException); - Assert.assertTrue(cause.getCause() instanceof SingleDexOverflowException); - Assert.assertTrue(cause.getCause().getCause() instanceof MethodIdOverflowException); - Assert.assertTrue(baos.toString().contains(EXPECTED_MESSAGE)); - } finally { - redirectStream.close(); - } - } - - @Test - public void testMergerWithHighNumberOfFields() throws Exception { - File srcFolder = TestTools.createTempDir("oneDexPerType", "SrcFolder"); - - for (int fileIdx = 0; fileIdx < fileCount; fileIdx++) { - generateJavaFileWithFields(srcFolder, fileIdx, 100); - } - generateJavaFileWithFields(srcFolder, fileCount, 37); - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - PrintStream redirectStream = new PrintStream(baos); - System.setErr(redirectStream); - try { - buildOneDexPerType(TestTools.getDefaultBootclasspathString(), srcFolder, false /* withDebug */); - Assert.fail(); - } catch (JackAbortException e) { - Throwable cause = e.getCause(); - Assert.assertTrue(cause instanceof DexWritingException); - Assert.assertTrue(cause.getCause() instanceof SingleDexOverflowException); - Assert.assertTrue(cause.getCause().getCause() instanceof FieldIdOverflowException); - Assert.assertTrue(baos.toString().contains(EXPECTED_MESSAGE)); - } finally { - redirectStream.close(); - } - } - - @Test - @Category(SlowTests.class) - public void testMergerWithHighNumberOfTypes() throws Exception { - File srcFolder = TestTools.createTempDir("oneDexPerType", "SrcFolder"); - - for (int fileIdx = 0; fileIdx < fileCount; fileIdx++) { - generateJavaFileWithTypes(srcFolder, fileIdx, 100); - } - generateJavaFileWithTypes(srcFolder, fileCount, 36); - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - PrintStream redirectStream = new PrintStream(baos); - System.setErr(redirectStream); - try { - buildOneDexPerType(TestTools.getDefaultBootclasspathString(), srcFolder, false /* withDebug */); - Assert.fail(); - } catch (JackAbortException e) { - Throwable cause = e.getCause(); - Assert.assertTrue(cause instanceof DexWritingException); - Assert.assertTrue(cause.getCause() instanceof SingleDexOverflowException); - Assert.assertTrue(cause.getCause().getCause() instanceof TypeIdOverflowException); - Assert.assertTrue(baos.toString().contains(EXPECTED_MESSAGE)); - } finally { - redirectStream.close(); - } - } - - private void generateJavaFileWithMethods(@Nonnull File srcFolder, @Nonnegative int fileIdx, - @Nonnegative int methodCount) throws IOException, FileNotFoundException { - File javaFile = new File(srcFolder, "A" + fileIdx + ".java"); - if (!javaFile.createNewFile()) { - throw new IOException("Failed to create file " + javaFile.getAbsolutePath()); - } - FileOutputStream fos = null; - try { - fos = new FileOutputStream(javaFile); - StringBuilder content = - new StringBuilder("package jack.merger; \n" + "public class A" + fileIdx+ " {"); - // -1 due to implicit init method - for (int mthIdx = 0; mthIdx < methodCount - 1; mthIdx++) { - content.append("public void m" + mthIdx + "() {}"); - } - content.append("} \n"); - fos.write(content.toString().getBytes()); - } finally { - if (fos != null) { - fos.close(); - } - } - } - - private void generateJavaFileWithFields(@Nonnull File srcFolder, @Nonnegative int fileIdx, - @Nonnegative int fieldCount) throws IOException, FileNotFoundException { - File javaFile = new File(srcFolder, "A" + fileIdx + ".java"); - if (!javaFile.createNewFile()) { - throw new IOException("Failed to create file " + javaFile.getAbsolutePath()); - } - FileOutputStream fos = null; - try { - fos = new FileOutputStream(javaFile); - StringBuilder content = - new StringBuilder("package jack.merger; \n" + "public class A" + fileIdx+ " {"); - for (int fieldIdx = 0; fieldIdx < fieldCount; fieldIdx++) { - content.append("public int f" + fieldIdx + ";"); - } - content.append("} \n"); - fos.write(content.toString().getBytes()); - } finally { - if (fos != null) { - fos.close(); - } - } - } - - private void generateJavaFileWithTypes(@Nonnull File srcFolder, @Nonnegative int fileIdx, - @Nonnegative int typeCount) throws IOException, FileNotFoundException { - File javaFile = new File(srcFolder, "A" + fileIdx + ".java"); - if (!javaFile.createNewFile()) { - throw new IOException("Failed to create file " + javaFile.getAbsolutePath()); - } - FileOutputStream fos = null; - try { - fos = new FileOutputStream(javaFile); - StringBuilder content = - new StringBuilder("package jack.merger; \n" + "public class A" + fileIdx+ " {"); - for (int typeIdx = 0; typeIdx < typeCount; typeIdx++) { - content.append("public class c" + typeIdx + " {}"); - } - content.append("} \n"); - fos.write(content.toString().getBytes()); - } finally { - if (fos != null) { - fos.close(); - } - } - } -} diff --git a/jack/tests/com/android/jack/transformations/cast/UselessCastRemoverTest.java b/jack/tests/com/android/jack/transformations/cast/UselessCastRemoverTest.java index 01cea1a9..79651e82 100644 --- a/jack/tests/com/android/jack/transformations/cast/UselessCastRemoverTest.java +++ b/jack/tests/com/android/jack/transformations/cast/UselessCastRemoverTest.java @@ -17,25 +17,17 @@ package com.android.jack.transformations.cast; -import com.android.jack.Options; import com.android.jack.TestTools; -import com.android.jack.backend.dex.DexFileWriter; import com.android.jack.ir.ast.JCastOperation; import com.android.jack.ir.ast.JMethod; import com.android.jack.ir.ast.JVisitor; import junit.framework.Assert; -import org.jf.dexlib.CodeItem; -import org.jf.dexlib.DexFile; -import org.jf.dexlib.Code.Instruction; -import org.jf.dexlib.Code.Opcode; import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; -import java.io.File; - import javax.annotation.Nonnull; public class UselessCastRemoverTest { @@ -147,70 +139,6 @@ public class UselessCastRemoverTest { buildMethodAndCheckUselessCastRemover(CAST_USELESS003, "nestedAssign()V", true); } - @Test - public void test001() throws Exception { - File outFolder = TestTools.createTempDir("uselessCastInstructions", "dex"); - File out = new File(outFolder, DexFileWriter.DEX_FILENAME); - - TestTools.compileSourceToDex(new Options(), - TestTools.getJackTestsWithJackFolder("cast/test001"), - TestTools.getClasspathAsString(TestTools.getDefaultBootclasspath()), outFolder, false); - - DexFile dexFile = new DexFile(out); - CodeItem ci = - TestTools.getEncodedMethod(dexFile, - "Lcom/android/jack/cast/test001/jack/Test001;", "get", - "(Lcom/android/jack/cast/test001/jack/Test001;)I").codeItem; - - Assert.assertFalse(hasOpcode(ci, Opcode.CHECK_CAST)); - Assert.assertFalse(hasOpcode(ci, Opcode.CHECK_CAST_JUMBO)); - } - - @Test - public void test002() throws Exception { - File outFolder = TestTools.createTempDir("uselessCastInstructions", "dex"); - File out = new File(outFolder, DexFileWriter.DEX_FILENAME); - TestTools.compileSourceToDex(new Options(), - TestTools.getJackTestsWithJackFolder("cast/test002"), - TestTools.getClasspathAsString(TestTools.getDefaultBootclasspath()), outFolder, false); - - DexFile dexFile = new DexFile(out); - CodeItem ci = - TestTools.getEncodedMethod(dexFile, - "Lcom/android/jack/cast/test002/jack/Test002;", "get", - "(Lcom/android/jack/cast/test002/jack/Test002;)I").codeItem; - - Assert.assertFalse(hasOpcode(ci, Opcode.CHECK_CAST)); - Assert.assertFalse(hasOpcode(ci, Opcode.CHECK_CAST_JUMBO)); - } - - @Test - public void test003() throws Exception { - File outFolder = TestTools.createTempDir("uselessCastInstructions", "dex"); - File out = new File(outFolder, DexFileWriter.DEX_FILENAME); - TestTools.compileSourceToDex(new Options(), - TestTools.getJackTestsWithJackFolder("cast/test003"), - TestTools.getClasspathAsString(TestTools.getDefaultBootclasspath()), outFolder, false); - - DexFile dexFile = new DexFile(out); - CodeItem ci = - TestTools.getEncodedMethod(dexFile, - "Lcom/android/jack/cast/test003/jack/Test003;", "get", - "(Lcom/android/jack/cast/test003/jack/A;)I").codeItem; - - Assert.assertFalse(hasOpcode(ci, Opcode.CHECK_CAST)); - Assert.assertFalse(hasOpcode(ci, Opcode.CHECK_CAST_JUMBO)); - } - - private boolean hasOpcode(@Nonnull CodeItem codeItem, @Nonnull Opcode opcode) { - for (Instruction inst : codeItem.getInstructions()) { - if (inst.opcode == opcode) { - return true; - } - } - return false; - } - private static void buildMethodAndCheckUselessCastRemover(@Nonnull String classBinaryName, @Nonnull String methodSignature, boolean castRemoved) throws Exception { JMethod m = |
