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 /jack-tests/tests/com/android/jack/cast | |
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
Diffstat (limited to 'jack-tests/tests/com/android/jack/cast')
3 files changed, 269 insertions, 0 deletions
diff --git a/jack-tests/tests/com/android/jack/cast/CastAllTests.java b/jack-tests/tests/com/android/jack/cast/CastAllTests.java new file mode 100644 index 00000000..803546b0 --- /dev/null +++ b/jack-tests/tests/com/android/jack/cast/CastAllTests.java @@ -0,0 +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. + */ +package com.android.jack.cast; + +import org.junit.experimental.categories.Categories; +import org.junit.runner.RunWith; +import org.junit.runners.Suite.SuiteClasses; + +@RunWith(Categories.class) +@SuiteClasses( +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 |