Skip to content

Commit 5ad2a4c

Browse files
Merge branch 'main' into Vassiliy-Kudryashov/68-ide-fatal-error-during-tests-generation
2 parents 7d28093 + 2a2173a commit 5ad2a4c

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

HowToUseLoggers.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ The file is usually in the resource folder.
1818

1919
The easiest way is:
2020

21-
- Go in the code that you are going to debug. Let’s assume it is a method in com.home.utbot.framework.plugin.api.UtBotTestCaseGenerator.
21+
- Go in the code that you are going to debug. Let’s assume it is a method in org.utbot.framework.plugin.api.UtBotTestCaseGenerator.
2222
- Find out if there is a KotlinLogging object that is used to create a **logger**
2323
- If such a logger exists, use the fully qualified class name as the logger name in the next steps
2424
<br/>
@@ -28,7 +28,7 @@ The easiest way is:
2828
Open log4j2.xml and add the logger in the loggers section like this
2929

3030
```
31-
<Logger name=" com.home.utbot.framework.plugin.api.UtBotTestCaseGenerator " level="info">
31+
<Logger name=" org.utbot.framework.plugin.api.UtBotTestCaseGenerator " level="info">
3232
<AppenderRef ref="Console"/>
3333
</Logger>
3434
```
@@ -78,6 +78,6 @@ Having this logger, you can use it in code with different log levels in parallel
7878
3. Find the closest log4j2.xml file (usually it is located in the resources file), enable the logger with a desirable log level
7979

8080

81-
`<Logger name="com.huawei.utbot.engine.UtBotSymbolicEngine.timeout" level="debug"/>`
81+
`<Logger name="org.utbot.engine.UtBotSymbolicEngine.timeout" level="debug"/>`
8282

8383

utbot-framework/src/main/kotlin/org/utbot/fuzzer/FuzzerFunctions.kt

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@ import soot.CharType
1717
import soot.DoubleType
1818
import soot.FloatType
1919
import soot.IntType
20+
import soot.Local
2021
import soot.LongType
2122
import soot.ShortType
2223
import soot.Unit
2324
import soot.Value
2425
import soot.ValueBox
2526
import soot.jimple.Constant
27+
import soot.jimple.IntConstant
2628
import soot.jimple.InvokeExpr
2729
import soot.jimple.NullConstant
30+
import soot.jimple.internal.AbstractSwitchStmt
2831
import soot.jimple.internal.ImmediateBox
2932
import soot.jimple.internal.JAssignStmt
3033
import soot.jimple.internal.JCastExpr
@@ -33,8 +36,10 @@ import soot.jimple.internal.JGeExpr
3336
import soot.jimple.internal.JGtExpr
3437
import soot.jimple.internal.JIfStmt
3538
import soot.jimple.internal.JLeExpr
39+
import soot.jimple.internal.JLookupSwitchStmt
3640
import soot.jimple.internal.JLtExpr
3741
import soot.jimple.internal.JNeExpr
42+
import soot.jimple.internal.JTableSwitchStmt
3843
import soot.jimple.internal.JVirtualInvokeExpr
3944
import soot.toolkits.graph.ExceptionalUnitGraph
4045

@@ -45,17 +50,18 @@ private val logger = KotlinLogging.logger {}
4550
*/
4651
fun collectConstantsForFuzzer(graph: ExceptionalUnitGraph): Set<FuzzedConcreteValue> {
4752
return graph.body.units.reversed().asSequence()
48-
.filter { it is JIfStmt || it is JAssignStmt }
53+
.filter { it is JIfStmt || it is JAssignStmt || it is AbstractSwitchStmt}
4954
.flatMap { unit ->
5055
unit.useBoxes.map { unit to it.value }
5156
}
5257
.filter { (_, value) ->
53-
value is Constant || value is JCastExpr || value is InvokeExpr
58+
value is Constant || value is Local || value is JCastExpr || value is InvokeExpr
5459
}
5560
.flatMap { (unit, value) ->
5661
sequenceOf(
5762
ConstantsFromIfStatement,
5863
ConstantsFromCast,
64+
ConstantsFromSwitchCase,
5965
BoundValuesForDoubleChecks,
6066
StringConstant,
6167
).flatMap { finder ->
@@ -158,6 +164,24 @@ private object ConstantsFromCast: ConstantsFinder {
158164

159165
}
160166

167+
private object ConstantsFromSwitchCase: ConstantsFinder {
168+
override fun find(graph: ExceptionalUnitGraph, unit: Unit, value: Value): List<FuzzedConcreteValue> {
169+
if (unit !is JTableSwitchStmt && unit !is JLookupSwitchStmt) return emptyList()
170+
val result = mutableListOf<FuzzedConcreteValue>()
171+
if (unit is JTableSwitchStmt) {
172+
for (i in unit.lowIndex..unit.highIndex) {
173+
result.add(FuzzedConcreteValue(intClassId, i, FuzzedOp.EQ))
174+
}
175+
}
176+
if (unit is JLookupSwitchStmt) {
177+
unit.lookupValues.asSequence().filterIsInstance<IntConstant>().forEach {
178+
result.add(FuzzedConcreteValue(intClassId, it.value, FuzzedOp.EQ))
179+
}
180+
}
181+
return result
182+
}
183+
}
184+
161185
private object BoundValuesForDoubleChecks: ConstantsFinder {
162186
override fun find(graph: ExceptionalUnitGraph, unit: Unit, value: Value): List<FuzzedConcreteValue> {
163187
if (value !is InvokeExpr) return emptyList()

0 commit comments

Comments
 (0)