Skip to content

Commit 0a6417a

Browse files
authored
Remove old fuzzer dependencies from JavaScript module (#1900)
* Remove all `org.utbot.fuzzer` deps * Change getter naming for id generator * Remove JsFuzzedValue
1 parent 9367b5e commit 0a6417a

File tree

13 files changed

+132
-119
lines changed

13 files changed

+132
-119
lines changed

utbot-js/src/main/kotlin/api/JsTestGenerator.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import codegen.JsCodeGenerator
44
import com.google.javascript.rhino.Node
55
import framework.api.js.JsClassId
66
import framework.api.js.JsMethodId
7+
import framework.api.js.JsUtFuzzedExecution
78
import framework.api.js.util.isJsBasic
89
import framework.api.js.util.jsErrorClassId
910
import framework.api.js.util.jsUndefinedClassId
@@ -26,9 +27,8 @@ import org.utbot.framework.plugin.api.UtExecution
2627
import org.utbot.framework.plugin.api.UtExecutionResult
2728
import org.utbot.framework.plugin.api.UtExecutionSuccess
2829
import org.utbot.framework.plugin.api.UtExplicitlyThrownException
30+
import org.utbot.framework.plugin.api.UtModel
2931
import org.utbot.framework.plugin.api.UtTimeoutException
30-
import org.utbot.fuzzer.FuzzedValue
31-
import org.utbot.fuzzer.UtFuzzedExecution
3232
import org.utbot.fuzzing.Control
3333
import org.utbot.fuzzing.utils.Trie
3434
import parser.JsClassAstVisitor
@@ -187,7 +187,7 @@ class JsTestGenerator(
187187
private fun getUtModelResult(
188188
execId: JsMethodId,
189189
resultData: ResultData,
190-
fuzzedValues: List<FuzzedValue>
190+
fuzzedValues: List<UtModel>
191191
): UtExecutionResult {
192192
if (resultData.isError && resultData.rawString == "Timeout") return UtTimeoutException(
193193
TimeoutException(" Timeout in generating test for ${
@@ -197,7 +197,7 @@ class JsTestGenerator(
197197
prefix = "${execId.name}(",
198198
separator = ", ",
199199
postfix = ")"
200-
) { (_, value) -> value.model.toString() }
200+
) { (_, value) -> value.toString() }
201201
}")
202202
)
203203
val (returnValue, valueClassId) = resultData.toJsAny(
@@ -221,11 +221,11 @@ class JsTestGenerator(
221221
val jsDescription = JsMethodDescription(
222222
name = funcNode.getAbstractFunctionName(),
223223
parameters = execId.parameters,
224-
execId.classId,
224+
classId = execId.classId,
225225
concreteValues = fuzzerVisitor.fuzzedConcreteValues,
226226
tracer = Trie(JsStatement::number)
227227
)
228-
val collectedValues = mutableListOf<List<FuzzedValue>>()
228+
val collectedValues = mutableListOf<List<UtModel>>()
229229
// .location field gets us "jsFile:A:B", then we get A and B as ints
230230
val funcLocation = funcNode.firstChild!!.location.substringAfter("jsFile:")
231231
.split(":").map { it.toInt() }
@@ -265,13 +265,13 @@ class JsTestGenerator(
265265
return@runFuzzing JsFeedback(Control.PASS)
266266
} else if (!currentlyCoveredStmts.containsAll(covData.additionalCoverage)) {
267267
val (thisObject, modelList) = if (!funcNode.parent!!.isClassMembers) {
268-
null to params.map { it.model }
269-
} else params[0].model to params.drop(1).map { it.model }
268+
null to params
269+
} else params[0] to params.drop(1)
270270
val initEnv =
271271
EnvironmentModels(thisObject, modelList, mapOf())
272272
emit(
273273
JsValidExecution(
274-
UtFuzzedExecution(
274+
JsUtFuzzedExecution(
275275
stateBefore = initEnv,
276276
stateAfter = initEnv,
277277
result = result,

utbot-js/src/main/kotlin/api/JsUtModelConstructor.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,15 @@ import framework.api.js.JsPrimitiveModel
77
import framework.api.js.JsUndefinedModel
88
import framework.api.js.util.jsErrorClassId
99
import framework.api.js.util.jsUndefinedClassId
10+
import fuzzer.JsIdProvider
1011
import org.utbot.framework.plugin.api.ClassId
1112
import org.utbot.framework.plugin.api.UtAssembleModel
1213
import org.utbot.framework.plugin.api.UtExecutableCallModel
1314
import org.utbot.framework.plugin.api.UtModel
14-
import org.utbot.fuzzer.ReferencePreservingIntIdGenerator
1515
import org.utbot.instrumentation.instrumentation.execution.constructors.UtModelConstructorInterface
1616

1717
class JsUtModelConstructor : UtModelConstructorInterface {
1818

19-
private val idGenerator = ReferencePreservingIntIdGenerator()
20-
2119
// TODO SEVERE: Requires substantial expansion to other types
2220
@Suppress("NAME_SHADOWING")
2321
override fun construct(value: Any?, classId: ClassId): UtModel {
@@ -52,7 +50,7 @@ class JsUtModelConstructor : UtModelConstructorInterface {
5250
val values = (value as Map<String, Any>).values.map {
5351
construct(it, JsEmptyClassId())
5452
}
55-
val id = idGenerator.createId()
53+
val id = JsIdProvider.createId()
5654
val instantiationCall = UtExecutableCallModel(null, constructor, values)
5755
return UtAssembleModel(
5856
id = id,

utbot-js/src/main/kotlin/framework/api/js/JsApi.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,7 @@ class JsConstructorId(
9393
get() = 0
9494
}
9595

96-
class JsMultipleClassId(private val jsJoinedName: String) : JsClassId(jsJoinedName) {
97-
98-
val types: Sequence<JsClassId>
99-
get() = jsJoinedName.split('|').map { JsClassId(it) }.asSequence()
100-
}
96+
class JsMultipleClassId(jsJoinedName: String) : JsClassId(jsJoinedName)
10197

10298
open class JsUtModel(
10399
override val classId: JsClassId
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package framework.api.js
2+
3+
import org.utbot.framework.plugin.api.EnvironmentModels
4+
import org.utbot.framework.plugin.api.UtExecution
5+
import org.utbot.framework.plugin.api.UtExecutionResult
6+
7+
class JsUtFuzzedExecution(
8+
stateBefore: EnvironmentModels,
9+
stateAfter: EnvironmentModels,
10+
result: UtExecutionResult
11+
) : UtExecution(stateBefore, stateAfter, result, null, null, null, null)
Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
package fuzzer
22

33
import framework.api.js.JsClassId
4+
import framework.api.js.JsUtFuzzedExecution
45
import framework.api.js.util.isClass
6+
import org.utbot.framework.plugin.api.ClassId
7+
import org.utbot.framework.plugin.api.UtModel
58
import org.utbot.framework.plugin.api.UtTimeoutException
6-
import org.utbot.fuzzer.FuzzedConcreteValue
7-
import org.utbot.fuzzer.FuzzedValue
8-
import org.utbot.fuzzer.UtFuzzedExecution
99
import org.utbot.fuzzing.Control
1010
import org.utbot.fuzzing.Description
1111
import org.utbot.fuzzing.Feedback
1212
import org.utbot.fuzzing.utils.Trie
13+
import java.util.concurrent.atomic.AtomicInteger
1314

1415
sealed interface JsFuzzingExecutionFeedback
15-
class JsValidExecution(val utFuzzedExecution: UtFuzzedExecution) : JsFuzzingExecutionFeedback
16+
class JsValidExecution(val utFuzzedExecution: JsUtFuzzedExecution) : JsFuzzingExecutionFeedback
1617

1718
class JsTimeoutExecution(val utTimeout: UtTimeoutException) : JsFuzzingExecutionFeedback
1819

1920
class JsMethodDescription(
2021
val name: String,
2122
parameters: List<JsClassId>,
22-
val concreteValues: Collection<FuzzedConcreteValue>,
23+
val concreteValues: Collection<JsFuzzedConcreteValue>,
2324
val thisInstance: JsClassId? = null,
2425
val tracer: Trie<JsStatement, *>
2526
) : Description<JsClassId>(parameters) {
@@ -28,7 +29,7 @@ class JsMethodDescription(
2829
name: String,
2930
parameters: List<JsClassId>,
3031
classId: JsClassId,
31-
concreteValues: Collection<FuzzedConcreteValue>,
32+
concreteValues: Collection<JsFuzzedConcreteValue>,
3233
tracer: Trie<JsStatement, *>
3334
) : this(
3435
name,
@@ -39,21 +40,43 @@ class JsMethodDescription(
3940
)
4041
}
4142

42-
class JsFeedback(
43+
data class JsFeedback(
4344
override val control: Control = Control.CONTINUE,
4445
val result: Trie.Node<JsStatement> = Trie.emptyNode()
45-
) : Feedback<JsClassId, FuzzedValue> {
46+
) : Feedback<JsClassId, UtModel>
4647

47-
override fun equals(other: Any?): Boolean {
48-
val castOther = other as? JsFeedback
49-
return control == castOther?.control
50-
}
48+
data class JsStatement(
49+
val number: Int
50+
)
51+
52+
data class JsFuzzedConcreteValue(
53+
val classId: ClassId,
54+
val value: Any,
55+
val fuzzedContext: JsFuzzedContext = JsFuzzedContext.Unknown,
56+
)
5157

52-
override fun hashCode(): Int {
53-
return control.hashCode()
58+
enum class JsFuzzedContext {
59+
EQ,
60+
NE,
61+
GT,
62+
GE,
63+
LT,
64+
LE,
65+
Unknown;
66+
67+
fun reverse(): JsFuzzedContext = when (this) {
68+
EQ -> NE
69+
NE -> EQ
70+
GT -> LE
71+
LT -> GE
72+
LE -> GT
73+
GE -> LT
74+
Unknown -> Unknown
5475
}
5576
}
5677

57-
data class JsStatement(
58-
val number: Int
59-
)
78+
object JsIdProvider {
79+
private var id = AtomicInteger(0)
80+
81+
fun createId() = id.incrementAndGet()
82+
}

utbot-js/src/main/kotlin/fuzzer/JsFuzzing.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import fuzzer.providers.BoolValueProvider
55
import fuzzer.providers.NumberValueProvider
66
import fuzzer.providers.ObjectValueProvider
77
import fuzzer.providers.StringValueProvider
8-
import org.utbot.fuzzer.FuzzedValue
8+
import org.utbot.framework.plugin.api.UtModel
99
import org.utbot.fuzzing.Fuzzing
1010
import org.utbot.fuzzing.Seed
1111
import org.utbot.fuzzing.fuzz
@@ -18,10 +18,10 @@ fun defaultValueProviders() = listOf(
1818
)
1919

2020
class JsFuzzing(
21-
val exec: suspend (JsMethodDescription, List<FuzzedValue>) -> JsFeedback
22-
) : Fuzzing<JsClassId, FuzzedValue, JsMethodDescription, JsFeedback> {
21+
val exec: suspend (JsMethodDescription, List<UtModel>) -> JsFeedback
22+
) : Fuzzing<JsClassId, UtModel, JsMethodDescription, JsFeedback> {
2323

24-
override fun generate(description: JsMethodDescription, type: JsClassId): Sequence<Seed<JsClassId, FuzzedValue>> {
24+
override fun generate(description: JsMethodDescription, type: JsClassId): Sequence<Seed<JsClassId, UtModel>> {
2525
return defaultValueProviders().asSequence().flatMap { provider ->
2626
if (provider.accept(type)) {
2727
provider.generate(description, type)
@@ -31,12 +31,12 @@ class JsFuzzing(
3131
}
3232
}
3333

34-
override suspend fun handle(description: JsMethodDescription, values: List<FuzzedValue>): JsFeedback {
34+
override suspend fun handle(description: JsMethodDescription, values: List<UtModel>): JsFeedback {
3535
return exec(description, values)
3636
}
3737
}
3838

3939
suspend fun runFuzzing(
4040
description: JsMethodDescription,
41-
exec: suspend (JsMethodDescription, List<FuzzedValue>) -> JsFeedback
41+
exec: suspend (JsMethodDescription, List<UtModel>) -> JsFeedback
4242
) = JsFuzzing(exec).fuzz(description)
Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,28 @@
11
package fuzzer.providers
22

3+
34
import framework.api.js.JsClassId
45
import framework.api.js.JsPrimitiveModel
56
import framework.api.js.util.isJsBasic
67
import fuzzer.JsMethodDescription
7-
import org.utbot.fuzzer.FuzzedValue
8-
import org.utbot.fuzzer.providers.PrimitivesModelProvider.fuzzed
8+
import org.utbot.framework.plugin.api.UtModel
99
import org.utbot.fuzzing.Seed
1010
import org.utbot.fuzzing.ValueProvider
1111
import org.utbot.fuzzing.seeds.Bool
1212

13-
object BoolValueProvider : ValueProvider<JsClassId, FuzzedValue, JsMethodDescription> {
13+
object BoolValueProvider : ValueProvider<JsClassId, UtModel, JsMethodDescription> {
1414

1515
override fun accept(type: JsClassId): Boolean {
1616
return type.isJsBasic
1717
}
1818

19-
override fun generate(description: JsMethodDescription, type: JsClassId): Sequence<Seed<JsClassId, FuzzedValue>> =
19+
override fun generate(description: JsMethodDescription, type: JsClassId): Sequence<Seed<JsClassId, UtModel>> =
2020
sequence {
2121
yield(Seed.Known(Bool.TRUE()) {
22-
JsPrimitiveModel(true).fuzzed {
23-
summary = "%var% = true"
24-
}
22+
JsPrimitiveModel(true)
2523
})
2624
yield(Seed.Known(Bool.FALSE()) {
27-
JsPrimitiveModel(false).fuzzed {
28-
summary = "%var% = false"
29-
}
25+
JsPrimitiveModel(false)
3026
})
3127
}
3228
}

utbot-js/src/main/kotlin/fuzzer/providers/NumberValueProvider.kt

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,25 @@ package fuzzer.providers
33
import framework.api.js.JsClassId
44
import framework.api.js.JsPrimitiveModel
55
import framework.api.js.util.isJsBasic
6+
import fuzzer.JsFuzzedContext.EQ
7+
import fuzzer.JsFuzzedContext.GE
8+
import fuzzer.JsFuzzedContext.GT
9+
import fuzzer.JsFuzzedContext.LE
10+
import fuzzer.JsFuzzedContext.LT
611
import fuzzer.JsMethodDescription
7-
import org.utbot.fuzzer.FuzzedContext.Comparison.EQ
8-
import org.utbot.fuzzer.FuzzedContext.Comparison.GE
9-
import org.utbot.fuzzer.FuzzedContext.Comparison.GT
10-
import org.utbot.fuzzer.FuzzedContext.Comparison.LE
11-
import org.utbot.fuzzer.FuzzedContext.Comparison.LT
12-
import org.utbot.fuzzer.FuzzedValue
13-
import org.utbot.fuzzer.providers.PrimitivesModelProvider.fuzzed
12+
import org.utbot.framework.plugin.api.UtModel
1413
import org.utbot.fuzzing.Seed
1514
import org.utbot.fuzzing.ValueProvider
1615
import org.utbot.fuzzing.seeds.DefaultFloatBound
1716
import org.utbot.fuzzing.seeds.IEEE754Value
1817

19-
object NumberValueProvider : ValueProvider<JsClassId, FuzzedValue, JsMethodDescription> {
18+
object NumberValueProvider : ValueProvider<JsClassId, UtModel, JsMethodDescription> {
2019

2120
override fun accept(type: JsClassId): Boolean {
2221
return type.isJsBasic
2322
}
2423

25-
override fun generate(description: JsMethodDescription, type: JsClassId): Sequence<Seed<JsClassId, FuzzedValue>> =
24+
override fun generate(description: JsMethodDescription, type: JsClassId): Sequence<Seed<JsClassId, UtModel>> =
2625
sequence {
2726
description.concreteValues.forEach { (_, v, c) ->
2827
if (v is Double) {
@@ -33,18 +32,14 @@ object NumberValueProvider : ValueProvider<JsClassId, FuzzedValue, JsMethodDescr
3332
}
3433

3534
yield(Seed.Known(IEEE754Value.fromValue(v)) { known ->
36-
JsPrimitiveModel(known.toDouble() + balance).fuzzed {
37-
summary = "%var% = ${known.toDouble() + balance}"
38-
}
35+
JsPrimitiveModel(known.toDouble() + balance)
3936
})
4037
}
4138
}
4239
DefaultFloatBound.values().forEach { bound ->
4340
// All numbers in JavaScript are like Double in Java/Kotlin
4441
yield(Seed.Known(bound(52, 11)) { known ->
45-
JsPrimitiveModel(known.toDouble()).fuzzed {
46-
summary = "%var% = ${known.toDouble()}"
47-
}
42+
JsPrimitiveModel(known.toDouble())
4843
})
4944
}
5045
}

0 commit comments

Comments
 (0)