How to use ExecutionTracer class of org.evomaster.client.java.instrumentation.staticstate package

Best EvoMaster code snippet using org.evomaster.client.java.instrumentation.staticstate.ExecutionTracer

Source:LineCovMethodVisitor.java Github

copy

Full Screen

1package org.evomaster.client.java.instrumentation.coverage;2import org.evomaster.client.java.instrumentation.staticstate.ExecutionTracer;3import org.evomaster.client.java.instrumentation.staticstate.ObjectiveRecorder;4import org.evomaster.client.java.instrumentation.shared.ClassName;5import org.evomaster.client.java.instrumentation.Constants;6import org.evomaster.client.java.instrumentation.shared.ObjectiveNaming;7import org.evomaster.client.java.instrumentation.staticstate.UnitsInfoRecorder;8import org.objectweb.asm.Label;9import org.objectweb.asm.MethodVisitor;10import org.objectweb.asm.Opcodes;11import java.util.Arrays;12import java.util.Collections;13import java.util.HashSet;14import java.util.Set;15public class LineCovMethodVisitor extends MethodVisitor {16 private static final Set<Integer> returnCodes = Collections.unmodifiableSet(17 new HashSet<>(Arrays.asList(18 Opcodes.IRETURN,19 Opcodes.LRETURN,20 Opcodes.FRETURN,21 Opcodes.DRETURN,22 Opcodes.ARETURN,23 Opcodes.RETURN24 ))25 );26 private final String className;27 private final String methodName;28 private final String descriptor;29 private boolean seenAtLeastOneLine;30 public LineCovMethodVisitor(MethodVisitor mv,31 String className,32 String methodName,33 String descriptor) {34 super(Constants.ASM, mv);35 this.className = className;36 this.methodName = methodName;37 this.descriptor = descriptor;38 seenAtLeastOneLine = false;39 }40 @Override41 public void visitLineNumber(int line, Label start) {42 super.visitLineNumber(line, start);43 if (methodName.equals(Constants.CLASS_INIT_METHOD)) {44 return;45 }46 seenAtLeastOneLine = true;47 /*48 After a line, we add our instrumentation to record49 that the line has been just passed/executed.50 Here we push 4 elements on the stack, which51 are used to uniquely identify the line.52 Then, we do a call to ExecutionTracer that53 will pop these 4 elements as input parameters.54 */55 UnitsInfoRecorder.markNewLine();56 ObjectiveRecorder.registerTarget(ObjectiveNaming.lineObjectiveName(className, line));57 this.visitLdcInsn(className);58 this.visitLdcInsn(methodName);59 this.visitLdcInsn(descriptor);60 this.visitLdcInsn(line);61 mv.visitMethodInsn(62 Opcodes.INVOKESTATIC,63 ClassName.get(ExecutionTracer.class).getBytecodeName(),64 ExecutionTracer.EXECUTED_LINE_METHOD_NAME,65 ExecutionTracer.EXECUTED_LINE_DESCRIPTOR,66 ExecutionTracer.class.isInterface()); //false67 }68 public void visitInsn(final int opcode) {69 if (seenAtLeastOneLine && returnCodes.contains(opcode)){70 mv.visitMethodInsn(71 Opcodes.INVOKESTATIC,72 ClassName.get(ExecutionTracer.class).getBytecodeName(),73 ExecutionTracer.COMPLETED_LAST_EXECUTED_STATEMENT_NAME,74 ExecutionTracer.COMPLETED_LAST_EXECUTED_STATEMENT_DESCRIPTOR,75 ExecutionTracer.class.isInterface()); //false76 }77 super.visitInsn(opcode);78 }79 @Override80 public void visitMaxs(int maxStack, int maxLocals) {81 /*82 we pushed 4 values on the stack, so we need to tell ASM83 that this instrumented method should have a frame for at84 least 4 elements.85 Note: as here we are instrumenting lines, it can be assumed86 that the frame is empty (isn't it?), and so we do87 Math.max(maxElementsAddedOnStackFrame, maxStack)88 instead of89 maxElementsAddedOnStackFrame + maxStack...

Full Screen

Full Screen

Source:EmbeddedSutController.java Github

copy

Full Screen

...3import org.evomaster.client.java.controller.api.dto.BootTimeInfoDto;4import org.evomaster.client.java.controller.api.dto.UnitsInfoDto;5import org.evomaster.client.java.controller.internal.SutController;6import org.evomaster.client.java.instrumentation.*;7import org.evomaster.client.java.instrumentation.staticstate.ExecutionTracer;8import org.evomaster.client.java.instrumentation.staticstate.ObjectiveRecorder;9import org.evomaster.client.java.instrumentation.staticstate.UnitsInfoRecorder;10import java.util.Collection;11import java.util.List;12/**13 * <p>14 * Main class used to implement an EvoMaster Driver.15 * A user that wants to use EvoMaster for white-box testing will16 * need to implement this abstract class.17 * </p>18 *19 * <p>20 * For full details on how to implement this class, look at the documentation21 * for <em>Write an EvoMaster Driver for White-Box Testing</em>,22 * currently at23 * <a href=https://github.com/EMResearch/EvoMaster/blob/master/docs/write_driver.md>24 * https://github.com/EMResearch/EvoMaster/blob/master/docs/write_driver.md</a>25 * </p>26 */27public abstract class EmbeddedSutController extends SutController {28 @Override29 public final void setupForGeneratedTest(){30 //In the past, we configured P6Spy here31 }32 @Override33 public final boolean isInstrumentationActivated() {34 return InstrumentingAgent.isActive();35 }36 @Override37 public final void newSearch(){38 InstrumentationController.resetForNewSearch();39 }40 @Override41 public final void newTestSpecificHandler(){42 InstrumentationController.resetForNewTest();43 }44 @Override45 public final List<TargetInfo> getTargetInfos(Collection<Integer> ids){46 return InstrumentationController.getTargetInfos(ids);47 }48 @Override49 public final List<AdditionalInfo> getAdditionalInfoList(){50 return InstrumentationController.getAdditionalInfoList();51 }52 @Override53 public final void newActionSpecificHandler(ActionDto dto){54 ExecutionTracer.setAction(new Action(dto.index, dto.inputVariables));55 }56 @Override57 public final UnitsInfoDto getUnitsInfoDto(){58 return getUnitsInfoDto(UnitsInfoRecorder.getInstance());59 }60 @Override61 public final void setKillSwitch(boolean b) {62 ExecutionTracer.setKillSwitch(b);63 }64 @Override65 public final void setExecutingInitSql(boolean executingInitSql) {66 ExecutionTracer.setExecutingInitSql(executingInitSql);67 }68 @Override69 public final void setExecutingAction(boolean executingAction){70 ExecutionTracer.setExecutingAction(executingAction);71 }72 @Override73 public BootTimeInfoDto getBootTimeInfoDto() {74 return getBootTimeInfoDto(InstrumentationController.getBootTimeObjectiveInfo());75 }76 @Override77 public final String getExecutableFullPath(){78 return null; //not needed for embedded79 }80}...

Full Screen

Full Screen

ExecutionTracer

Using AI Code Generation

copy

Full Screen

1package org.evomaster.client.java.instrumentation.example;2import org.evomaster.client.java.instrumentation.staticstate.ExecutionTracer;3public class 2 {4 public static void main(String[] args) {5 ExecutionTracer.enableTraceCalls();6 System.out.println("Hello World!");7 ExecutionTracer.disableTraceCalls();8 }9}10package org.evomaster.client.java.instrumentation.example;11import org.evomaster.client.java.instrumentation.staticstate.ExecutionTracer;12public class 3 {13 public static void main(String[] args) {14 ExecutionTracer.enableTraceCalls();15 System.out.println("Hello World!");16 ExecutionTracer.disableTraceCalls();17 }18}19package org.evomaster.client.java.instrumentation.example;20import org.evomaster.client.java.instrumentation.staticstate.ExecutionTracer;21public class 4 {22 public static void main(String[] args) {23 ExecutionTracer.enableTraceCalls();24 System.out.println("Hello World!");25 ExecutionTracer.disableTraceCalls();26 }27}28package org.evomaster.client.java.instrumentation.example;29import org.evomaster.client.java.instrumentation.staticstate.ExecutionTracer;30public class 5 {31 public static void main(String[] args) {32 ExecutionTracer.enableTraceCalls();33 System.out.println("Hello World!");34 ExecutionTracer.disableTraceCalls();35 }36}37package org.evomaster.client.java.instrumentation.example;38import org.evomaster.client.java.instrumentation.staticstate.ExecutionTracer;39public class 6 {40 public static void main(String[] args) {41 ExecutionTracer.enableTraceCalls();42 System.out.println("Hello World!");43 ExecutionTracer.disableTraceCalls();44 }45}46package org.evomaster.client.java.instrumentation.example;47import org.evomaster.client.java

Full Screen

Full Screen

ExecutionTracer

Using AI Code Generation

copy

Full Screen

1package org.evomaster.client.java.instrumentation.example;2import org.evomaster.client.java.instrumentation.staticstate.ExecutionTracer;3public class ExampleClass2 {4 public static void main(String[] args) {5 ExecutionTracer.enableTraceCalls();6 ExampleClass1.main(new String[]{});7 System.out.println("Executed tests: " + ExecutionTracer.getNumberOfExecutedTests());8 System.out.println("Executed actions: " + ExecutionTracer.getNumberOfExecutedActions());9 }10}11package org.evomaster.client.java.instrumentation.example;12import org.evomaster.client.java.instrumentation.staticstate.CoverageInfo;13public class ExampleClass3 {14 public static void main(String[] args) {15 CoverageInfo.reset();16 ExampleClass1.main(new String[]{});17 System.out.println("Coverage: " + CoverageInfo.getResults());18 }19}

Full Screen

Full Screen

ExecutionTracer

Using AI Code Generation

copy

Full Screen

1package org.evomaster.client.java.instrumentation.example;2import org.evomaster.client.java.instrumentation.staticstate.ExecutionTracer;3import java.util.HashMap;4public class Main {5 public static void main(String[] args) {6 HashMap<String, String> map = new HashMap<>();7 map.put("a", "A");8 map.put("b", "B");9 map.put("c", "C");10 System.out.println(map);11 ExecutionTracer.markOutputVariable("map", map);12 System.out.println("map.size() = " + map.size());13 ExecutionTracer.markOutputVariable("map.size()", map.size());14 System.out.println("map.get(\"a\") = " + map.get("a"));15 ExecutionTracer.markOutputVariable("map.get(\"a\")", map.get("a"));16 System.out.println("map.containsKey(\"a\") = " + map.containsKey("a"));17 ExecutionTracer.markOutputVariable("map.containsKey(\"a\")", map.containsKey("a"));18 System.out.println("map.containsKey(\"d\") = " + map.containsKey("d"));19 ExecutionTracer.markOutputVariable("map.containsKey(\"d\")", map.containsKey("d"));20 System.out.println("map.remove(\"a\") = " + map.remove("a"));21 ExecutionTracer.markOutputVariable("map.remove(\"a\")", map.remove("a"));22 System.out.println("map.containsKey(\"a\") = " + map.containsKey("a"));23 ExecutionTracer.markOutputVariable("map.containsKey(\"a\")", map.containsKey("a"));24 System.out.println("map.containsKey(\"d\") = " + map.containsKey("d"));25 ExecutionTracer.markOutputVariable("map.containsKey(\"d\")", map.containsKey("d"));26 System.out.println("map.size() = " + map.size());27 ExecutionTracer.markOutputVariable("map.size()", map.size());28 System.out.println(map);29 ExecutionTracer.markOutputVariable("map", map);30 }31}32package org.evomaster.client.java.instrumentation.example;33import org.evomaster.client.java.instrumentation.staticstate.ExecutionTracer;34import java.util.HashMap;35public class Main {36 public static void main(String[] args) {37 HashMap<String, String> map = new HashMap<>();38 map.put("a", "A");39 map.put("b

Full Screen

Full Screen

ExecutionTracer

Using AI Code Generation

copy

Full Screen

1import org.evomaster.client.java.instrumentation.staticstate.ExecutionTracer;2import java.util.*;3import java.util.stream.Collectors;4public class 2 {5 public static void main(String[] args) {6 ExecutionTracer.enableTraceCalls();7 System.out.println("Hello World");8 List<String> actions = ExecutionTracer.getExecutedActions();9 System.out.println("Actions: " + actions);10 }11}12ExecutionTracer.enableTraceCalls();13ExecutionTracer.getExecutedActions();

Full Screen

Full Screen

ExecutionTracer

Using AI Code Generation

copy

Full Screen

1import org.evomaster.client.java.instrumentation.staticstate.ExecutionTracer;2import org.evomaster.client.java.instrumentation.staticstate.ExecutionTracer;3import java.util.List;4import java.util.ArrayList;5import java.util.Arrays;6import java.util.Collections;7import java.util.stream.Collectors;8public class 2 {9 public static void main(String[] args) {10 ExecutionTracer.enableTraceCalls();11 ExecutionTracer.enableTraceCalls();12 ExecutionTracer.enableTraceCalls();13 ExecutionTracer.enableTraceCalls();14 ExecutionTracer.enableTraceCalls();15 ExecutionTracer.enableTraceCalls();16 ExecutionTracer.enableTraceCalls();17 ExecutionTracer.enableTraceCalls();18 ExecutionTracer.enableTraceCalls();19 ExecutionTracer.enableTraceCalls();20 ExecutionTracer.enableTraceCalls();

Full Screen

Full Screen

ExecutionTracer

Using AI Code Generation

copy

Full Screen

1public class 2 {2 public static int foo(int x, int y) {3 int z = 0;4 if (x > y) {5 z = x - y;6 } else if (x < y) {7 z = y - x;8 } else {9 z = 0;10 }11 return z;12 }13 public static void main(String[] args) {14 int x = 10;15 int y = 20;16 int z = foo(x, y);17 System.out.println(z);18 }19}20public class 3 {21 public static int foo(int x, int y) {22 int z = 0;23 if (x > y) {24 z = x - y;25 } else if (x < y) {26 z = y - x;27 } else {28 z = 0;29 }30 return z;31 }32 public static void main(String[] args) {33 int x = 10;34 int y = 20;35 int z = foo(x, y);36 System.out.println(z);37 }38}39public class 4 {40 public static int foo(int x, int y) {41 int z = 0;42 if (x > y) {43 z = x - y;44 } else if (x < y) {45 z = y - x;46 } else {47 z = 0;48 }49 return z;50 }51 public static void main(String[] args) {52 int x = 10;53 int y = 20;54 int z = foo(x, y);55 System.out.println(z);56 }57}

Full Screen

Full Screen

ExecutionTracer

Using AI Code Generation

copy

Full Screen

1import org.evomaster.client.java.instrumentation.staticstate.ExecutionTracer;2import org.evomaster.client.java.controller.api.Controller;3import org.evomaster.client.java.controller.api.dto.SutInfoDto;4import org.evomaster.client.java.controller.api.dto.SutSystemDto;5import org.evomaster.client.java.controller.api.dto.TestResultsDto;6import org.evomaster.client.java.controller.api.dto.database.operations.DatabaseExecutionDto;7import org.evomaster.client.java.controller.api.dto.database.operations.DatabaseInitializationDto;8import org.evomaster.client.java.controller.api.dto.database.operations.DatabaseRowDto;9import org.evomaster.client.java.controller.internal.db.SqlScriptRunner;10import org.evomaster.client.java.controller.internal.db.SqlScriptRunnerException;11import org.evomaster.client.java.controller.internal.db.SqlScriptRunnerImpl;12import org.evomaster.client.java.controller.internal.db.h2.H2Controller;13import org.evomaster.client.java.controller.internal.db.h2.H2Dto;14import org.evomaster.client.java.controller.internal.db.h2.H2Table;15import org.evomaster.client.java.controller.internal.db.h2.H2TableColumn;16import org.evomaster.client.java.controller.internal.db.h2.H2TableIndex;

Full Screen

Full Screen

ExecutionTracer

Using AI Code Generation

copy

Full Screen

1package org.evomaster.client.java.instrumentation.example;2import org.evomaster.client.java.instrumentation.staticstate.ExecutionTracer;3import java.util.List;4public class Main2 {5 public static void main(String[] args) {6 System.out.println("Hello World!");7 List<String> methods = ExecutionTracer.getExecutedMethods();8 for (String m : methods) {9 System.out.println(m);10 }11 }12}13org.evomaster.client.java.instrumentation.example.Main2.main(String[])14org.evomaster.client.java.instrumentation.example.Main2.main(String[])15org.evomaster.client.java.instrumentation.example.Main2.main(String[])16org.evomaster.client.java.instrumentation.example.Main2.main(String[])17package org.evomaster.client.java.instrumentation.example;18import org.evomaster.client.java.instrumentation.staticstate.ExecutionTracer;19import java.util.List;20public class Main3 {21 public static void main(String[]

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful