Skip to content

Commit 980372f

Browse files
mmvpmtamarinvs19
authored andcommitted
Support UtMock for fuzzer tests (#1517)
1 parent 609c3a9 commit 980372f

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.utbot.api.exception;
2+
3+
public class UtMockAssumptionViolatedException extends RuntimeException {
4+
@Override
5+
public String getMessage() {
6+
return "UtMock assumption violated";
7+
}
8+
}

utbot-api/src/main/java/org/utbot/api/mock/UtMock.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.utbot.api.mock;
22

3+
import org.utbot.api.exception.UtMockAssumptionViolatedException;
4+
35
public class UtMock {
46
public static <T> T makeSymbolic() {
57
return makeSymbolic(false);
@@ -14,14 +16,14 @@ public static <T> T makeSymbolic(boolean isNullable) {
1416
public static void assume(boolean predicate) {
1517
// to use compilers checks, i.e. for possible NPE
1618
if (!predicate) {
17-
throw new RuntimeException();
19+
throw new UtMockAssumptionViolatedException();
1820
}
1921
}
2022

2123
@SuppressWarnings("unused")
2224
public static void assumeOrExecuteConcretely(boolean predicate) {
2325
// In oppose to assume, we don't have predicate check here
24-
// to avoid RuntimeException during concrete execution
26+
// to avoid UtMockAssumptionViolatedException during concrete execution
2527
}
2628

2729
@SuppressWarnings("unused")

utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import mu.KotlinLogging
77
import org.utbot.analytics.EngineAnalyticsContext
88
import org.utbot.analytics.FeatureProcessor
99
import org.utbot.analytics.Predictors
10+
import org.utbot.api.exception.UtMockAssumptionViolatedException
1011
import org.utbot.common.bracket
1112
import org.utbot.common.debug
1213
import org.utbot.engine.MockStrategy.NO_MOCKS
@@ -366,6 +367,11 @@ class UtBotSymbolicEngine(
366367
// in case an exception occurred from the concrete execution
367368
concreteExecutionResult ?: return@runJavaFuzzing BaseFeedback(result = Trie.emptyNode(), control = Control.PASS)
368369

370+
if (concreteExecutionResult.result.exceptionOrNull() is UtMockAssumptionViolatedException) {
371+
logger.debug { "Generated test case by fuzzer violates the UtMock assumption" }
372+
return@runJavaFuzzing BaseFeedback(result = Trie.emptyNode(), control = Control.PASS)
373+
}
374+
369375
val coveredInstructions = concreteExecutionResult.coverage.coveredInstructions
370376
var trieNode: Trie.Node<Instruction>? = null
371377
if (coveredInstructions.isNotEmpty()) {
475 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)