Search in sources :

Example 6 with ComputeClassWriter

use of org.evosuite.runtime.util.ComputeClassWriter in project evosuite by EvoSuite.

the class ComputeClassWriter_ESTest method test4.

@Test
public void test4() throws Throwable {
    ComputeClassWriter computeClassWriter0 = new ComputeClassWriter((-32768));
    // Undeclared exception!
    try {
        computeClassWriter0.getCommonSuperClass("", "37SFrh2");
        fail("Expecting exception: RuntimeException");
    } catch (RuntimeException e) {
        // 
        // Class not found: : shaded.org.evosuite.runtime.mock.java.lang.MockThrowable: Class not found
        // 
        assertThrownBy("org.evosuite.runtime.util.ComputeClassWriter", e);
    }
}
Also used : ComputeClassWriter(org.evosuite.runtime.util.ComputeClassWriter) Test(org.junit.Test)

Example 7 with ComputeClassWriter

use of org.evosuite.runtime.util.ComputeClassWriter in project evosuite by EvoSuite.

the class ComputeClassWriter_ESTest method test0.

@Test
public void test0() throws Throwable {
    ComputeClassWriter computeClassWriter0 = new ComputeClassWriter((-2878));
    String string0 = computeClassWriter0.getCommonSuperClass("java/lang/Class", "java/lang/Throwable");
    assertEquals("java/lang/Object", string0);
}
Also used : ComputeClassWriter(org.evosuite.runtime.util.ComputeClassWriter) Test(org.junit.Test)

Example 8 with ComputeClassWriter

use of org.evosuite.runtime.util.ComputeClassWriter in project evosuite by EvoSuite.

the class RuntimeInstrumentation method transformBytes.

public byte[] transformBytes(ClassLoader classLoader, String className, ClassReader reader, boolean skipInstrumentation) {
    String classNameWithDots = className.replace('/', '.');
    if (!checkIfCanInstrument(classNameWithDots)) {
        throw new IllegalArgumentException("Should not transform a shared class (" + classNameWithDots + ")! Load by parent (JVM) classloader.");
    }
    int asmFlags = ClassWriter.COMPUTE_FRAMES;
    ClassWriter writer = new ComputeClassWriter(asmFlags);
    ClassVisitor cv = writer;
    if (!skipInstrumentation) {
        if (RuntimeSettings.resetStaticState && !retransformingMode) {
            /*
			 * FIXME: currently reset does add a new method, but that does no work
			 * when retransformingMode :(
			 */
            CreateClassResetClassAdapter resetClassAdapter = new CreateClassResetClassAdapter(cv, className, true);
            cv = resetClassAdapter;
        }
        if (RuntimeSettings.isUsingAnyMocking()) {
            cv = new MethodCallReplacementClassAdapter(cv, className, !retransformingMode);
        }
        cv = new KillSwitchClassAdapter(cv);
        cv = new RemoveFinalClassAdapter(cv);
        if (RuntimeSettings.maxNumberOfIterationsPerLoop >= 0) {
            cv = new LoopCounterClassAdapter(cv);
        }
    }
    ClassNode cn = new AnnotatedClassNode();
    int readFlags = ClassReader.SKIP_FRAMES;
    reader.accept(cn, readFlags);
    cv = new JSRInlinerClassVisitor(cv);
    try {
        cn.accept(cv);
    } catch (Throwable ex) {
        logger.error("Error while instrumenting class " + className + ": " + ex.getMessage(), ex);
    }
    return writer.toByteArray();
}
Also used : ClassNode(org.objectweb.asm.tree.ClassNode) ClassVisitor(org.objectweb.asm.ClassVisitor) ClassWriter(org.objectweb.asm.ClassWriter) ComputeClassWriter(org.evosuite.runtime.util.ComputeClassWriter) ComputeClassWriter(org.evosuite.runtime.util.ComputeClassWriter)

Aggregations

ComputeClassWriter (org.evosuite.runtime.util.ComputeClassWriter)8 Test (org.junit.Test)5 ClassVisitor (org.objectweb.asm.ClassVisitor)3 ClassWriter (org.objectweb.asm.ClassWriter)3 ClassNode (org.objectweb.asm.tree.ClassNode)2 PrintWriter (java.io.PrintWriter)1 CheapPurityAnalyzer (org.evosuite.assertion.CheapPurityAnalyzer)1 CFGClassAdapter (org.evosuite.graphs.cfg.CFGClassAdapter)1 ErrorConditionClassAdapter (org.evosuite.instrumentation.error.ErrorConditionClassAdapter)1 BooleanTestabilityTransformation (org.evosuite.instrumentation.testability.BooleanTestabilityTransformation)1 ComparisonTransformation (org.evosuite.instrumentation.testability.ComparisonTransformation)1 ContainerTransformation (org.evosuite.instrumentation.testability.ContainerTransformation)1 StringTransformation (org.evosuite.instrumentation.testability.StringTransformation)1 PrimitiveClassAdapter (org.evosuite.seeding.PrimitiveClassAdapter)1 ClassReader (org.objectweb.asm.ClassReader)1 SerialVersionUIDAdder (org.objectweb.asm.commons.SerialVersionUIDAdder)1 TraceClassVisitor (org.objectweb.asm.util.TraceClassVisitor)1