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

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

Source:ExecutionTracer.java Github

copy

Full Screen

...183 }184 public static List<AdditionalInfo> exposeAdditionalInfoList() {185 return additionalInfoList;186 }187 private static AdditionalInfo getCurrentAdditionalInfo() {188 synchronized (lock) {189 return additionalInfoList.get(actionIndex);190 }191 }192 public static void markRawAccessOfHttpBodyPayload() {193 getCurrentAdditionalInfo().setRawAccessOfHttpBodyPayload(true);194 }195 public static void addParsedDtoName(String name) {196 getCurrentAdditionalInfo().addParsedDtoName(name);197 }198 public static void addQueryParameter(String param) {199 getCurrentAdditionalInfo().addQueryParameter(param);200 }201 public static void addHeader(String header) {202 getCurrentAdditionalInfo().addHeader(header);203 }204 public static void addStringSpecialization(String taintInputName, StringSpecializationInfo info) {205 getCurrentAdditionalInfo().addSpecialization(taintInputName, info);206 }207 public static void addSqlInfo(SqlInfo info){208 if (!executingInitSql)209 getCurrentAdditionalInfo().addSqlInfo(info);210 }211 public static void markLastExecutedStatement(String lastLine, String lastMethod) {212 getCurrentAdditionalInfo().pushLastExecutedStatement(lastLine, lastMethod);213 }214 public static final String COMPLETED_LAST_EXECUTED_STATEMENT_NAME = "completedLastExecutedStatement";215 public static final String COMPLETED_LAST_EXECUTED_STATEMENT_DESCRIPTOR = "()V";216 public static void completedLastExecutedStatement() {217 getCurrentAdditionalInfo().popLastExecutedStatement();218 }219 public static Map<String, TargetInfo> getInternalReferenceToObjectiveCoverage() {220 return objectiveCoverage;221 }222 /**223 * @return the number of objectives that have been encountered224 * during the test execution225 */226 public static int getNumberOfObjectives() {227 return objectiveCoverage.size();228 }229 public static int getNumberOfObjectives(String prefix) {230 return (int) objectiveCoverage231 .entrySet().stream()232 .filter(e -> prefix == null || e.getKey().startsWith(prefix))233 .count();234 }235 /**236 * Note: only the objectives encountered so far can have237 * been recorded. So, this is a relative value, not based238 * on the code of the whole SUT (just the parts executed so far).239 * Therefore, it is quite useless for binary values (ie 0 or 1),240 * like current implementation of basic line coverage.241 *242 * @param prefix used for string matching of which objectives types243 * to consider, eg only lines or only branches.244 * Use "" or {@code null} to pick up everything245 * @return246 */247 public static int getNumberOfNonCoveredObjectives(String prefix) {248 return getNonCoveredObjectives(prefix).size();249 }250 public static Set<String> getNonCoveredObjectives(String prefix) {251 return objectiveCoverage252 .entrySet().stream()253 .filter(e -> prefix == null || e.getKey().startsWith(prefix))254 .filter(e -> e.getValue().value < 1)255 .map(e -> e.getKey())256 .collect(Collectors.toSet());257 }258 public static Double getValue(String id) {259 return objectiveCoverage.get(id).value;260 }261 private static void updateObjective(String id, double value) {262 if (value < 0d || value > 1d) {263 throw new IllegalArgumentException("Invalid value " + value + " out of range [0,1]");264 }265 /*266 In the same execution, a target could be reached several times,267 so we should keep track of the best value found so far268 */269 synchronized (lock) {270 if (objectiveCoverage.containsKey(id)) {271 double previous = objectiveCoverage.get(id).value;272 if (value > previous) {273 objectiveCoverage.put(id, new TargetInfo(null, id, value, actionIndex));274 }275 } else {276 objectiveCoverage.put(id, new TargetInfo(null, id, value, actionIndex));277 }278 }279 ObjectiveRecorder.update(id, value, !executingAction);280 }281 public static void executedNumericComparison(String idTemplate, double lt, double eq, double gt) {282 updateObjective(ObjectiveNaming.numericComparisonObjectiveName(idTemplate, -1), lt);283 updateObjective(ObjectiveNaming.numericComparisonObjectiveName(idTemplate, 0), eq);284 updateObjective(ObjectiveNaming.numericComparisonObjectiveName(idTemplate, +1), gt);285 }286 public static void executedReplacedMethod(String idTemplate, ReplacementType type, Truthness t) {287 /*288 Considering the fact that the method has been executed, and so reached, cannot happen289 that any of the heuristic values is 0290 */291 assert t.getOfTrue() != 0 && t.getOfFalse() !=0;292 String idTrue = ObjectiveNaming.methodReplacementObjectiveName(idTemplate, true, type);293 String idFalse = ObjectiveNaming.methodReplacementObjectiveName(idTemplate, false, type);294 updateObjective(idTrue, t.getOfTrue());295 updateObjective(idFalse, t.getOfFalse());296 }297 public static final String EXECUTED_LINE_METHOD_NAME = "executedLine";298 public static final String EXECUTED_LINE_DESCRIPTOR = "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)V";299 /**300 * Report on the fact that a given line has been executed.301 */302 public static void executedLine(String className, String methodName, String descriptor, int line) {303 /*304 This is done to prevent the SUT keep on executing code after a test case is evaluated305 */306 if (isKillSwitch()) {307 /*308 This is tricky... not only if we are in the middle of a class initializer (e.g., a309 static block, or static fields initialization), but also if any ancestor calls are310 a class initializer (in bytecode these are marked as <clinit>).311 For example, assume class X has a static intiliazer "static{ Foo f == new Foo()},312 then, if the kill switch is on while we are executing "Foo()", we must not kill the313 execution, otherwise the class initializer of X would fail, and X would not be usable314 anymore inside the whole SUT.315 To check those cases, we look at the stack trace of the method calls.316 */317 boolean initClass = Arrays.stream(Thread.currentThread().getStackTrace())318 .anyMatch(e -> e.getMethodName().equals("<clinit>"));319 /*320 must NOT stop the initialization of a class, otherwise the SUT will be left in an321 inconsistent state in the following calls322 */323 if (!initClass) {324 throw new KillSwitchException();325 }326 }327 //for targets to cover328 String lineId = ObjectiveNaming.lineObjectiveName(className, line);329 String classId = ObjectiveNaming.classObjectiveName(className);330 updateObjective(lineId, 1d);331 updateObjective(classId, 1d);332 //to calculate last executed line333 String lastLine = className + "_" + line + "_" + methodName;334 String lastMethod = className + "_" + methodName + "_" + descriptor;335 markLastExecutedStatement(lastLine, lastMethod);336 }337 public static final String EXECUTING_METHOD_METHOD_NAME = "executingMethod";338 public static final String EXECUTING_METHOD_DESCRIPTOR = "(Ljava/lang/String;IIZ)V";339 /**340 * Report on whether method calls have been successfully completed.341 * Failures can happen due to thrown exceptions.342 *343 * @param className344 * @param line345 * @param index as there can be many method calls on same line, need to differentiate them346 * @param completed whether the method call was successfully completed.347 */348 public static void executingMethod(String className, int line, int index, boolean completed) {349 String id = ObjectiveNaming.successCallObjectiveName(className, line, index);350 if (completed) {351 updateObjective(id, 1d);352 } else {353 updateObjective(id, 0.5);354 }355 }356 //---- branch-jump methods --------------------------357 private static void updateBranch(String className, int line, int branchId, Truthness t) {358 /*359 Note: when we have360 if(x > 0){}361 the "jump" to "else" branch is done if that is false.362 So, the actual evaluated condition is the negation, ie363 x <= 0364 */365 String forThen = ObjectiveNaming.branchObjectiveName(className, line, branchId, true);366 String forElse = ObjectiveNaming.branchObjectiveName(className, line, branchId, false);367 updateObjective(forElse, t.getOfTrue());368 updateObjective(forThen, t.getOfFalse());369 }370 public static final String EXECUTING_BRANCH_JUMP_METHOD_NAME = "executingBranchJump";371 public static final String JUMP_DESC_1_VALUE = "(IILjava/lang/String;II)V";372 public static void executingBranchJump(373 int value, int opcode, String className, int line, int branchId) {374 Truthness t = HeuristicsForJumps.getForSingleValueJump(value, opcode);375 updateBranch(className, line, branchId, t);376 }377 public static final String JUMP_DESC_2_VALUES = "(IIILjava/lang/String;II)V";378 public static void executingBranchJump(379 int firstValue, int secondValue, int opcode, String className, int line, int branchId) {380 Truthness t = HeuristicsForJumps.getForValueComparison(firstValue, secondValue, opcode);381 updateBranch(className, line, branchId, t);382 }383 public static final String JUMP_DESC_OBJECTS =384 "(Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/String;II)V";385 public static void executingBranchJump(386 Object first, Object second, int opcode, String className, int line, int branchId) {387 Truthness t = HeuristicsForJumps.getForObjectComparison(first, second, opcode);388 updateBranch(className, line, branchId, t);389 }390 public static final String JUMP_DESC_NULL =391 "(Ljava/lang/Object;ILjava/lang/String;II)V";392 public static void executingBranchJump(393 Object obj, int opcode, String className, int line, int branchId) {394 Truthness t = HeuristicsForJumps.getForNullComparison(obj, opcode);395 updateBranch(className, line, branchId, t);396 }397 /**398 * Add the external HTTP/S hostname to the additional info to keep track.399 */400 public static void addExternalServiceHost(ExternalServiceInfo hostInfo) {401 getCurrentAdditionalInfo().addExternalService(hostInfo);402 // here, we only register external info into ObjectiveRecorder if it occurs during the startup403 if (!executingAction)404 ObjectiveRecorder.registerExternalServiceInfoAtSutStartupTime(hostInfo);405 }406}...

Full Screen

Full Screen

getCurrentAdditionalInfo

Using AI Code Generation

copy

Full Screen

1 public static String getCurrentAdditionalInfo() {2 return ExecutionTracer.getCurrentAdditionalInfo();3 }4 public static String getCurrentMethodOrConstructorName() {5 return ExecutionTracer.getCurrentMethodOrConstructorName();6 }7 public static String getCurrentMethodName() {8 return ExecutionTracer.getCurrentMethodName();9 }10 public static String getCurrentClassName() {11 return ExecutionTracer.getCurrentClassName();12 }13 public static String getCurrentTestName() {14 return ExecutionTracer.getCurrentTestName();15 }16 public static String getCurrentTestClassName() {17 return ExecutionTracer.getCurrentTestClassName();18 }19 public static String getCurrentTestExecutionId() {20 return ExecutionTracer.getCurrentTestExecutionId();21 }22 public static List<RestCallResult> getTestResults() {23 return ExecutionTracer.getTestResults();24 }25 public static void addTestResults(List<RestCallResult> results) {26 ExecutionTracer.addTestResults(results);27 }28 public static List<RestCallResult> getRestCallResults() {29 return ExecutionTracer.getRestCallResults();30 }31 public static List<RestCallResult> getRestCallResults(String

Full Screen

Full Screen

getCurrentAdditionalInfo

Using AI Code Generation

copy

Full Screen

1 String additionalInfo = ExecutionTracer.getCurrentAdditionalInfo();2 ExecutionTracer.addAdditionalInfo(additionalInfo);3 ExecutionTracer.addAdditionalInfo(additionalInfo);4 ExecutionTracer.addAdditionalInfo(additionalInfo);5 ExecutionTracer.addAdditionalInfo(additionalInfo);6 ExecutionTracer.addAdditionalInfo(additionalInfo);7 ExecutionTracer.addAdditionalInfo(additionalInfo);8 ExecutionTracer.addAdditionalInfo(additionalInfo);9 ExecutionTracer.addAdditionalInfo(additionalInfo);10 ExecutionTracer.addAdditionalInfo(additionalInfo);11 ExecutionTracer.addAdditionalInfo(additionalInfo);12 ExecutionTracer.addAdditionalInfo(additionalInfo);

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