Skip to content

Commit 3ddb68c

Browse files
committed
Add stats
1 parent 9bee480 commit 3ddb68c

3 files changed

Lines changed: 29 additions & 0 deletions

File tree

core/src/main/kotlin/org/evomaster/core/search/service/Statistics.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ class Statistics : SearchListener {
9797
private var sqlZ3UnknownCount = 0
9898
private var sqlZ3ErrorCount = 0
9999
private var sqlZ3ParseFailureCount = 0
100+
private var sqlZ3PartialTranslationCount = 0
100101
private var sqlZ3TimeMs = 0L
101102
private var sqlZ3SmtlibGenTimeMs = 0L
102103
private val sqlZ3SmtlibSizeBytes = IncrementalAverage()
@@ -276,6 +277,15 @@ class Statistics : SearchListener {
276277
sqlZ3ParseFailureCount++
277278
}
278279

280+
/**
281+
* A query whose WHERE/JOIN condition could not be fully translated to SMT-LIB (the untranslatable
282+
* part was dropped). Counted independently of the SAT/UNSAT outcome, since the weakened formula is
283+
* usually still SAT: the generated data may not satisfy the original query.
284+
*/
285+
fun reportSqlZ3PartialTranslation() {
286+
sqlZ3PartialTranslationCount++
287+
}
288+
279289
fun reportSqlZ3SmtlibGenTime(ms: Long, sizeBytes: Int) {
280290
sqlZ3SmtlibGenTimeMs += ms
281291
sqlZ3SmtlibSizeBytes.addValue(sizeBytes)
@@ -484,6 +494,7 @@ class Statistics : SearchListener {
484494
add(Pair("sqlZ3Unknown", "$sqlZ3UnknownCount"))
485495
add(Pair("sqlZ3Errors", "$sqlZ3ErrorCount"))
486496
add(Pair("sqlZ3ParseFailures", "$sqlZ3ParseFailureCount"))
497+
add(Pair("sqlZ3PartialTranslations", "$sqlZ3PartialTranslationCount"))
487498
add(Pair("sqlZ3TotalMs", "$sqlZ3TimeMs"))
488499
add(Pair("sqlZ3SmtlibGenTotalMs", "$sqlZ3SmtlibGenTimeMs"))
489500
add(Pair("sqlZ3AvgSmtlibSizeBytes", "%.1f".format(sqlZ3SmtlibSizeBytes.mean)))

core/src/main/kotlin/org/evomaster/core/solver/SMTLibZ3DbConstraintSolver.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,13 @@ class SMTLibZ3DbConstraintSolver() : DbConstraintSolver {
187187
val smtlibGenMs = System.currentTimeMillis() - smtlibGenStart
188188
stats?.reportSqlZ3SmtlibGenTime(smtlibGenMs, smtlibBytes)
189189

190+
// If a WHERE/JOIN condition could not be translated, it was dropped from the SMT problem, so the
191+
// generated data may not satisfy the original query. Record it: this failure mode is otherwise
192+
// invisible in the stats (Z3 typically still returns SAT on the weakened formula).
193+
if (generator.skippedQueryConstraints > 0) {
194+
stats?.reportSqlZ3PartialTranslation()
195+
}
196+
190197
val fileName = storeToTmpFile(smtLib)
191198

192199
val z3Start = System.currentTimeMillis()

core/src/main/kotlin/org/evomaster/core/solver/SmtLibGenerator.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ class SmtLibGenerator(private val schema: DbInfoDto, private val numberOfRows: I
3232

3333
private var parser = JSqlConditionParser()
3434

35+
/**
36+
* Number of query constraints (WHERE conditions, JOIN ON conditions) that could not be translated
37+
* to SMT-LIB and were skipped during [generateSMT]. When greater than 0, the generated formula is
38+
* weaker than the original query, so Z3 may return SAT with rows that do not satisfy the dropped
39+
* predicate. Exposed so the caller can record it in the solver statistics.
40+
*/
41+
var skippedQueryConstraints = 0
42+
private set
43+
3544
private val smtTables: List<SmtTable> = schema.tables.map { SmtTable(it) }
3645
private val smtTableByOriginalName: Map<String, SmtTable> = smtTables.associateBy { it.originalName }
3746

@@ -420,6 +429,7 @@ class SmtLibGenerator(private val schema: DbInfoDto, private val numberOfRows: I
420429
smt.addNode(constraint)
421430
}
422431
} catch (e: RuntimeException) {
432+
skippedQueryConstraints++
423433
LoggingUtil.getInfoLogger().warn("Could not translate WHERE clause to SMT-LIB, skipping: ${where}. Reason: ${e.message}")
424434
}
425435
}
@@ -457,6 +467,7 @@ class SmtLibGenerator(private val schema: DbInfoDto, private val numberOfRows: I
457467
smt.addNode(constraint)
458468
}
459469
} catch (e: RuntimeException) {
470+
skippedQueryConstraints++
460471
LoggingUtil.getInfoLogger().warn("Could not translate JOIN ON clause to SMT-LIB, skipping: ${onExpression}. Reason: ${e.message}")
461472
}
462473
}

0 commit comments

Comments
 (0)