Commit 57ea3597 authored by Eric Bruneton's avatar Eric Bruneton

Add a few more tests for the analysis package.

parent 70960d92
Pipeline #496 passed with stage
in 10 minutes and 39 seconds
......@@ -430,6 +430,7 @@ public class BasicVerifier extends BasicInterpreter {
*
* @param objectArrayValue a value corresponding to array of object (or array) references.
* @return the value corresponding to the type of the elements of 'objectArrayValue'.
* @throws AnalyzerException if objectArrayValue does not correspond to an array type.
*/
protected BasicValue getElementValue(final BasicValue objectArrayValue) throws AnalyzerException {
return BasicValue.REFERENCE_VALUE;
......
......@@ -27,6 +27,9 @@
// THE POSSIBILITY OF SUCH DAMAGE.
package org.objectweb.asm.tree.analysis;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.objectweb.asm.ClassReader;
......@@ -41,6 +44,11 @@ import org.objectweb.asm.tree.MethodNode;
*/
public class BasicInterpreterTest extends AsmTest {
@Test
public void testConstructor() {
assertThrows(IllegalStateException.class, () -> new BasicInterpreter() {});
}
/**
* Tests that the precompiled classes can be successfully analyzed with a BasicInterpreter.
*
......
......@@ -27,6 +27,9 @@
// THE POSSIBILITY OF SUCH DAMAGE.
package org.objectweb.asm.tree.analysis;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.objectweb.asm.ClassReader;
......@@ -41,6 +44,11 @@ import org.objectweb.asm.tree.MethodNode;
*/
public class BasicVerifierTest extends AsmTest {
@Test
public void testConstructor() {
assertThrows(IllegalStateException.class, () -> new BasicVerifier() {});
}
/**
* Tests that the precompiled classes can be successfully analyzed with a BasicVerifier.
*
......
......@@ -41,7 +41,7 @@ import java.util.Set;
import org.junit.jupiter.api.Test;
/**
* SmallSet unit tests.
* SmallSet tests.
*
* @author Eric Bruneton
*/
......
......@@ -27,6 +27,9 @@
// THE POSSIBILITY OF SUCH DAMAGE.
package org.objectweb.asm.tree.analysis;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.objectweb.asm.ClassReader;
......@@ -41,6 +44,11 @@ import org.objectweb.asm.tree.MethodNode;
*/
public class SourceInterpreterTest extends AsmTest {
@Test
public void testConstructor() {
assertThrows(IllegalStateException.class, () -> new SourceInterpreter() {});
}
/**
* Tests that the precompiled classes can be successfully analyzed with a SourceInterpreter.
*
......
......@@ -27,12 +27,18 @@
// THE POSSIBILITY OF SUCH DAMAGE.
package org.objectweb.asm.tree.analysis;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.InsnNode;
/**
* BasicValue and SourceValue unit tests.
* BasicValue and SourceValue tests.
*
* @author Eric Bruneton
*/
......@@ -40,16 +46,35 @@ public class ValueTest {
@Test
public void testBasicValue() {
assertTrue(BasicValue.UNINITIALIZED_VALUE.equals(new BasicValue(null)));
assertTrue(BasicValue.INT_VALUE.equals(new BasicValue(Type.INT_TYPE)));
assertTrue(BasicValue.INT_VALUE.equals(BasicValue.INT_VALUE));
assertFalse(BasicValue.INT_VALUE.equals(new Object()));
BasicValue.INT_VALUE.hashCode();
BasicValue.UNINITIALIZED_VALUE.toString();
BasicValue.RETURNADDRESS_VALUE.toString();
BasicValue.REFERENCE_VALUE.toString();
assertTrue(BasicValue.REFERENCE_VALUE.isReference());
assertTrue(new BasicValue(Type.getObjectType("[I")).isReference());
assertFalse(BasicValue.UNINITIALIZED_VALUE.isReference());
assertFalse(BasicValue.INT_VALUE.isReference());
assertEquals(0, BasicValue.UNINITIALIZED_VALUE.hashCode());
assertNotEquals(0, BasicValue.INT_VALUE.hashCode());
assertEquals(".", BasicValue.UNINITIALIZED_VALUE.toString());
assertEquals("A", BasicValue.RETURNADDRESS_VALUE.toString());
assertEquals("R", BasicValue.REFERENCE_VALUE.toString());
assertEquals("LI;", new BasicValue(Type.getObjectType("I")).toString());
}
@Test
public void testSourceValue() {
new SourceValue(1).hashCode();
assertEquals(2, new SourceValue(2).getSize());
assertTrue(new SourceValue(1).equals(new SourceValue(1)));
assertFalse(new SourceValue(1).equals(new SourceValue(1, new InsnNode(Opcodes.NOP))));
assertFalse(new SourceValue(1).equals(new SourceValue(2)));
assertFalse(new SourceValue(1).equals(null));
assertEquals(0, new SourceValue(1).hashCode());
assertNotEquals(0, new SourceValue(1, new InsnNode(Opcodes.NOP)).hashCode());
}
}
......@@ -237,10 +237,18 @@ class AllInstructions {
return f++;
}
public void dup2Instruction(long[] v0, int i, int j) {
v0[i] |= (1L << j);
}
public long dup2X1Instruction() {
return g++;
}
public void dup2X1InstructionVariant(String[] v0, int i, Object o) {
v0[i] += " " + o.toString();
}
public void dupX2Instruction(int[] v0, int[] v1) {
v0[0] = v1[0] = 0;
}
......
......@@ -47,6 +47,7 @@ import org.objectweb.asm.Opcodes;
* <li>the StackMap attribute (which was used for pre-verification in J2ME CLDC 1.1),
* <li>non standard class, field, method and code attributes,
* <li>the nop and swap instructions,
* <li>some variants of the dup_x2 and dup2_x2 instructions,
* <li>several line numbers per bytecode offset.
* </ul>
*
......@@ -118,6 +119,62 @@ public class DumpArtificialStructures implements Opcodes {
methodVisitor.visitMaxs(0, 0);
methodVisitor.visitEnd();
methodVisitor = classWriter.visitMethod(ACC_STATIC, "dup_x2", "(IJ)V", null, null);
methodVisitor.visitCode();
methodVisitor.visitVarInsn(LLOAD, 1);
methodVisitor.visitVarInsn(ILOAD, 0);
methodVisitor.visitInsn(DUP_X2);
methodVisitor.visitInsn(I2L);
methodVisitor.visitInsn(LADD);
methodVisitor.visitMethodInsn(
INVOKESTATIC, "jdk3/ArtificialStructures", "dup_x2", "(IJ)V", false);
methodVisitor.visitInsn(RETURN);
methodVisitor.visitMaxs(0, 0);
methodVisitor.visitEnd();
methodVisitor = classWriter.visitMethod(ACC_STATIC, "dup2_x2", "(IIII)V", null, null);
methodVisitor.visitCode();
methodVisitor.visitVarInsn(ILOAD, 3);
methodVisitor.visitVarInsn(ILOAD, 2);
methodVisitor.visitVarInsn(ILOAD, 1);
methodVisitor.visitVarInsn(ILOAD, 0);
methodVisitor.visitInsn(DUP2_X2);
methodVisitor.visitInsn(IADD);
methodVisitor.visitInsn(IADD);
methodVisitor.visitMethodInsn(
INVOKESTATIC, "jdk3/ArtificialStructures", "dup2_x2", "(IIII)V", false);
methodVisitor.visitInsn(RETURN);
methodVisitor.visitMaxs(0, 0);
methodVisitor.visitEnd();
methodVisitor = classWriter.visitMethod(ACC_STATIC, "dup2_x2", "(IIJ)V", null, null);
methodVisitor.visitCode();
methodVisitor.visitVarInsn(LLOAD, 2);
methodVisitor.visitVarInsn(ILOAD, 1);
methodVisitor.visitVarInsn(ILOAD, 0);
methodVisitor.visitInsn(DUP2_X2);
methodVisitor.visitInsn(IADD);
methodVisitor.visitInsn(I2L);
methodVisitor.visitInsn(LADD);
methodVisitor.visitMethodInsn(
INVOKESTATIC, "jdk3/ArtificialStructures", "dup2_x2", "(IIJ)V", false);
methodVisitor.visitInsn(RETURN);
methodVisitor.visitMaxs(0, 0);
methodVisitor.visitEnd();
methodVisitor = classWriter.visitMethod(ACC_STATIC, "dup2_x2", "(JD)V", null, null);
methodVisitor.visitCode();
methodVisitor.visitVarInsn(DLOAD, 2);
methodVisitor.visitVarInsn(LLOAD, 0);
methodVisitor.visitInsn(DUP2_X2);
methodVisitor.visitInsn(L2D);
methodVisitor.visitInsn(DADD);
methodVisitor.visitMethodInsn(
INVOKESTATIC, "jdk3/ArtificialStructures", "dup2_x2", "(JD)V", false);
methodVisitor.visitInsn(RETURN);
methodVisitor.visitMaxs(0, 0);
methodVisitor.visitEnd();
classWriter.visitEnd();
return classWriter.toByteArray();
}
......
......@@ -50,7 +50,7 @@ subprojects {
ext.requires = [] // The required Gradle projects, e.g. [':asm-test']
ext.depends = [] // The external dependencies, e.g. ['junit:junit:4.12']
ext.runWith = [] // The command line to run this project, if applicable.
ext.coverage = 0.9 // The minimum code fraction that must be covered by tests.
ext.minCodeCoverage = 0.95 // The minimum code coverage fraction.
}
// -----------------------------------------------------------------------------
......@@ -60,7 +60,6 @@ subprojects {
project(':asm') {
description = parent.description
provides = ['org.objectweb.asm', 'org.objectweb.asm.signature']
coverage = 0.95
}
project(':asm-analysis') {
......@@ -74,7 +73,7 @@ project(':asm-commons') {
provides = ['org.objectweb.asm.commons']
requires = [':asm', ':asm-tree', ':asm-analysis']
dependencies { testCompile project(':asm-util') }
coverage = 0.5 // TODO: improve the code coverage of this project.
minCodeCoverage = 0.5 // TODO: improve the code coverage of this project.
}
project(':asm-test') {
......@@ -84,14 +83,12 @@ project(':asm-test') {
'org.junit.jupiter:junit-jupiter-params:5.0.1']
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
coverage = 0.95
}
project(':asm-tree') {
description = "Tree API of ${parent.description}"
provides = ['org.objectweb.asm.tree']
requires = [':asm']
coverage = 0.95
}
project(':asm-util') {
......@@ -99,13 +96,14 @@ project(':asm-util') {
provides = ['org.objectweb.asm.util']
requires = [':asm', ':asm-tree', ':asm-analysis']
dependencies { testCompile 'org.codehaus.janino:janino:3.0.7' }
minCodeCoverage = 0.9
}
project(':asm-xml') {
description = "XML API of ${parent.description}"
provides = ['org.objectweb.asm.xml']
requires = [':asm', ':asm-util']
coverage = 0.8
minCodeCoverage = 0.8
}
project(':benchmarks') {
......@@ -229,7 +227,7 @@ configure(subprojects.findAll { it.provides }) {
violationRules.rule {
limit {
counter = 'INSTRUCTION'
minimum = coverage
minimum = minCodeCoverage
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment