Skip to content

Commit f759f20

Browse files
committed
Fix summarization display name
1 parent aa239b8 commit f759f20

File tree

5 files changed

+89
-25
lines changed

5 files changed

+89
-25
lines changed

utbot-fuzzers/src/main/kotlin/org/utbot/fuzzing/JavaLanguage.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ suspend fun runJavaFuzzing(
6262
).apply {
6363
compilableName = if (!methodUnderTest.isConstructor) methodUnderTest.name else null
6464
className = classUnderTest.simpleName
65+
canonicalName = classUnderTest.canonicalName
66+
isNested = classUnderTest.isNested
6567
packageName = classUnderTest.packageName
6668
parameterNameMap = { index ->
6769
when {

utbot-fuzzers/src/main/kotlin/org/utbot/fuzzing/providers/Primitives.kt

Lines changed: 68 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ import org.utbot.framework.plugin.api.ClassId
44
import org.utbot.framework.plugin.api.UtPrimitiveModel
55
import org.utbot.framework.plugin.api.util.*
66
import org.utbot.fuzzer.FuzzedContext
7+
import org.utbot.fuzzer.FuzzedContext.Comparison.*
78
import org.utbot.fuzzer.FuzzedType
89
import org.utbot.fuzzer.FuzzedValue
910
import org.utbot.fuzzer.providers.ConstantsModelProvider.fuzzed
10-
import org.utbot.fuzzing.FuzzedDescription
11-
import org.utbot.fuzzing.Seed
12-
import org.utbot.fuzzing.ValueProvider
11+
import org.utbot.fuzzing.*
1312
import org.utbot.fuzzing.seeds.*
1413
import java.util.regex.Pattern
1514
import java.util.regex.PatternSyntaxException
@@ -24,27 +23,70 @@ abstract class PrimitiveValueProvider(
2423

2524
protected suspend fun <T : KnownValue> SequenceScope<Seed<FuzzedType, FuzzedValue>>.yieldKnown(
2625
value: T,
27-
description: String = value.toString(),
2826
toValue: T.() -> Any
2927
) {
3028
yield(Seed.Known(value) { known ->
3129
UtPrimitiveModel(toValue(known)).fuzzed {
3230
summary = buildString {
33-
append("%var% = ")
31+
append("%var% = ${known.valueToString()}")
3432
if (known.mutatedFrom != null) {
35-
append("mutated from ")
33+
append(" (mutated from ${known.mutatedFrom?.valueToString()})")
3634
}
37-
append(description)
3835
}
3936
}
4037
})
4138
}
39+
40+
private fun <T : KnownValue> T.valueToString(): String {
41+
when (this) {
42+
is BitVectorValue -> {
43+
for (defaultBound in Signed.values()) {
44+
if (defaultBound.test(this)) {
45+
return defaultBound.name.lowercase()
46+
}
47+
}
48+
return when (size) {
49+
8 -> toByte().toString()
50+
16 -> toShort().toString()
51+
32 -> toInt().toString()
52+
64 -> toLong().toString()
53+
else -> toString(10)
54+
}
55+
}
56+
is IEEE754Value -> {
57+
for (defaultBound in DefaultFloatBound.values()) {
58+
if (defaultBound.test(this)) {
59+
return defaultBound.name.lowercase().replace("_", " ")
60+
}
61+
}
62+
return when {
63+
is32Float() -> toFloat().toString()
64+
is64Float() -> toDouble().toString()
65+
else -> toString()
66+
}
67+
}
68+
is StringValue -> {
69+
return "'${value.substringToLength(10, "...")}'"
70+
}
71+
is RegexValue -> {
72+
return "'${value.substringToLength(10, "...")}' from $pattern"
73+
}
74+
else -> return toString()
75+
}
76+
}
77+
78+
private fun String.substringToLength(size: Int, postfix: String): String {
79+
return when {
80+
length <= size -> this
81+
else -> substring(0, size) + postfix
82+
}
83+
}
4284
}
4385

4486
object BooleanValueProvider : PrimitiveValueProvider(booleanClassId, booleanWrapperClassId) {
4587
override fun generate(description: FuzzedDescription, type: FuzzedType) = sequence {
46-
yieldKnown(Bool.TRUE(), description = "true") { toBoolean() }
47-
yieldKnown(Bool.FALSE(), description = "false") { toBoolean() }
88+
yieldKnown(Bool.TRUE()) { toBoolean() }
89+
yieldKnown(Bool.FALSE()) { toBoolean() }
4890
}
4991
}
5092

@@ -80,6 +122,15 @@ object IntegerValueProvider : PrimitiveValueProvider(
80122

81123
private fun ClassId.cast(value: BitVectorValue): Any = tryCast(value)!!
82124

125+
private val randomStubWithNoUsage = Random(0)
126+
private val configurationStubWithNoUsage = Configuration()
127+
128+
private fun BitVectorValue.change(func: BitVectorValue.() -> Unit): BitVectorValue {
129+
return Mutation<KnownValue> { _, _, _ ->
130+
BitVectorValue(this).apply { func() }
131+
}.mutate(this, randomStubWithNoUsage, configurationStubWithNoUsage) as BitVectorValue
132+
}
133+
83134
override fun generate(
84135
description: FuzzedDescription,
85136
type: FuzzedType
@@ -90,14 +141,14 @@ object IntegerValueProvider : PrimitiveValueProvider(
90141
val values = listOfNotNull(
91142
value,
92143
when (c) {
93-
FuzzedContext.Comparison.EQ, FuzzedContext.Comparison.NE, FuzzedContext.Comparison.LE, FuzzedContext.Comparison.GT -> BitVectorValue(value).apply { inc() }
94-
FuzzedContext.Comparison.LT, FuzzedContext.Comparison.GE -> BitVectorValue(value).apply { dec() }
144+
EQ, NE, LE, GT -> value.change { inc() }
145+
LT, GE -> value.change { dec() }
95146
else -> null
96147
}
97148
)
98149
values.forEach {
99150
if (type.classId.tryCast(it) != null) {
100-
yieldKnown(it, description = "$it") {
151+
yieldKnown(it) {
101152
type.classId.cast(this)
102153
}
103154
}
@@ -109,7 +160,7 @@ object IntegerValueProvider : PrimitiveValueProvider(
109160
val s = type.classId.typeSize
110161
val value = bound(s)
111162
if (type.classId.tryCast(value) != null) {
112-
yieldKnown(value, description = bound.name.lowercase().replace("_", " ")) {
163+
yieldKnown(value) {
113164
type.classId.cast(this)
114165
}
115166
}
@@ -143,12 +194,12 @@ object FloatValueProvider : PrimitiveValueProvider(
143194
) = sequence {
144195
description.constants.forEach { (t, v, _) ->
145196
if (t in acceptableTypes) {
146-
yieldKnown(IEEE754Value.fromValue(v), description = "$v") { type.classId.cast(this) }
197+
yieldKnown(IEEE754Value.fromValue(v)) { type.classId.cast(this) }
147198
}
148199
}
149200
DefaultFloatBound.values().forEach { bound ->
150201
val (m, e) = type.classId.typeSize
151-
yieldKnown(bound(m ,e), description = bound.name.lowercase().replace("_", " ")) {
202+
yieldKnown(bound(m ,e)) {
152203
type.classId.cast(this)
153204
}
154205
}
@@ -165,7 +216,7 @@ object StringValueProvider : PrimitiveValueProvider(stringClassId) {
165216
val values = constants
166217
.mapNotNull { it.value as? String } +
167218
sequenceOf("", "abc", "\n\t\r")
168-
values.forEach { yieldKnown(StringValue(it), description = "predefined string") { value } }
219+
values.forEach { yieldKnown(StringValue(it)) { value } }
169220
constants
170221
.filter { it.fuzzedContext.isPatterMatchingContext() }
171222
.map { it.value as String }
@@ -178,7 +229,7 @@ object StringValueProvider : PrimitiveValueProvider(stringClassId) {
178229
false
179230
}
180231
}.forEach {
181-
yieldKnown(RegexValue(it, Random(0)), description = "regex($it)") { value }
232+
yieldKnown(RegexValue(it, Random(0))) { value }
182233
}
183234
}
184235

utbot-fuzzing/src/main/kotlin/org/utbot/fuzzing/seeds/BitVectorValue.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ enum class Signed : Bound {
232232
;
233233

234234
operator fun invoke(size: Int) = BitVectorValue(size, this)
235+
236+
fun test(value: BitVectorValue) = (0..value.size).all { value[it] == initializer(it, value.size) }
235237
}
236238

237239
enum class Unsigned : Bound {

utbot-fuzzing/src/main/kotlin/org/utbot/fuzzing/seeds/IEEE754Value.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ class IEEE754Value : KnownValue {
112112
return result * if (isPositive) 1.0 else -1.0
113113
}
114114

115+
fun is32Float(): Boolean {
116+
return vector.size == 32 && mantissaSize == 23 && exponentSize == 8
117+
}
118+
119+
fun is64Float(): Boolean {
120+
return vector.size == 64 && mantissaSize == 52 && exponentSize == 11
121+
}
122+
115123
override fun toString() = buildString {
116124
for (i in 0 until vector.size) {
117125
if (i == 1 || i == 1 + exponentSize) append(" ")

utbot-fuzzing/src/main/kotlin/org/utbot/fuzzing/utils/Functions.kt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,12 @@ internal fun <T> List<T>.transformIfNotEmpty(transform: List<T>.() -> List<T>):
8585
return if (isNotEmpty()) transform() else this
8686
}
8787

88-
fun main() {
89-
val endian = Endian.BE
90-
println(255.toUByte().toBinaryString(endian))
91-
println(2.toBinaryString(endian))
92-
println(BitVectorValue.fromInt(2).toBinaryString(endian))
93-
print(8.75f.toBinaryString(endian))
94-
print(8.75.toBinaryString(endian))
95-
}
88+
// todo move to tests
89+
//fun main() {
90+
// val endian = Endian.BE
91+
// println(255.toUByte().toBinaryString(endian))
92+
// println(2.toBinaryString(endian))
93+
// println(BitVectorValue.fromInt(2).toBinaryString(endian))
94+
// print(8.75f.toBinaryString(endian))
95+
// print(8.75.toBinaryString(endian))
96+
//}

0 commit comments

Comments
 (0)