Skip to content

Support UtMock for fuzzer tests #1517

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.utbot.api.exception;

public class UtMockAssumptionViolatedException extends RuntimeException {
@Override
public String getMessage() {
return "UtMock assumption violated";
}
}
6 changes: 4 additions & 2 deletions utbot-api/src/main/java/org/utbot/api/mock/UtMock.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.utbot.api.mock;

import org.utbot.api.exception.UtMockAssumptionViolatedException;

public class UtMock {
public static <T> T makeSymbolic() {
return makeSymbolic(false);
Expand All @@ -14,14 +16,14 @@ public static <T> T makeSymbolic(boolean isNullable) {
public static void assume(boolean predicate) {
// to use compilers checks, i.e. for possible NPE
if (!predicate) {
throw new RuntimeException();
throw new UtMockAssumptionViolatedException();
}
}

@SuppressWarnings("unused")
public static void assumeOrExecuteConcretely(boolean predicate) {
// In oppose to assume, we don't have predicate check here
// to avoid RuntimeException during concrete execution
// to avoid UtMockAssumptionViolatedException during concrete execution
}

@SuppressWarnings("unused")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import mu.KotlinLogging
import org.utbot.analytics.EngineAnalyticsContext
import org.utbot.analytics.FeatureProcessor
import org.utbot.analytics.Predictors
import org.utbot.api.exception.UtMockAssumptionViolatedException
import org.utbot.common.bracket
import org.utbot.common.debug
import org.utbot.engine.MockStrategy.NO_MOCKS
Expand Down Expand Up @@ -366,6 +367,11 @@ class UtBotSymbolicEngine(
// in case an exception occurred from the concrete execution
concreteExecutionResult ?: return@runJavaFuzzing BaseFeedback(result = Trie.emptyNode(), control = Control.PASS)

if (concreteExecutionResult.result.exceptionOrNull() is UtMockAssumptionViolatedException) {
logger.debug { "Generated test case by fuzzer violates the UtMock assumption" }
return@runJavaFuzzing BaseFeedback(result = Trie.emptyNode(), control = Control.PASS)
}

val coveredInstructions = concreteExecutionResult.coverage.coveredInstructions
var trieNode: Trie.Node<Instruction>? = null
if (coveredInstructions.isNotEmpty()) {
Expand Down
Binary file modified utbot-sample/src/main/resources/utbot-api.jar
Binary file not shown.