@@ -95,12 +95,12 @@ class Summarization(val sourceFile: File?, val invokeDescriptions: List<InvokeDe
95
95
when (summaryGenerationType) {
96
96
SummariesGenerationType .FULL -> {
97
97
executionClusters + = generateSummariesForTestsWithNonEmptyPathsProducedBySymbolicExecutor(testSet)
98
- executionClusters + = generateSummariesForTestsProducedByFuzzer (testSet)
98
+ executionClusters + = generateFuzzerBasedSummariesForTests (testSet)
99
99
executionClusters + = generateSummariesForTestsWithEmptyPathsProducedBySymbolicExecutor(testSet)
100
100
}
101
101
SummariesGenerationType .LIGHT -> {
102
- executionClusters + = generateSummariesForTestsProducedBySymbolicExecutorWithoutSources (testSet)
103
- executionClusters + = generateSummariesForTestsProducedByFuzzer (testSet)
102
+ executionClusters + = generateFuzzerBasedSummariesForTests (testSet, MethodDescriptionSource . SYMBOLIC )
103
+ executionClusters + = generateFuzzerBasedSummariesForTests (testSet)
104
104
}
105
105
SummariesGenerationType .NONE -> error(" We must not fill summaries if SummariesGenerationType is NONE" )
106
106
}
@@ -228,83 +228,56 @@ class Summarization(val sourceFile: File?, val invokeDescriptions: List<InvokeDe
228
228
return clustersToReturn.toList()
229
229
}
230
230
231
- private fun generateSummariesForTestsProducedBySymbolicExecutorWithoutSources (
232
- testSet : UtMethodTestSet
233
- ) : List <UtExecutionCluster > {
234
- val clustersToReturn: MutableList <UtExecutionCluster > = mutableListOf ()
235
-
236
- val testSetWithFuzzedExecutions = prepareTestSetForByteCodeAnalysis(testSet)
237
- val executions = testSetWithFuzzedExecutions.executions as List <UtSymbolicExecution >
238
-
239
- if (executions.isNotEmpty()) {
240
- executions.forEach { utExecution ->
241
-
242
- val nameSuggester = sequenceOf(ModelBasedNameSuggester (), MethodBasedNameSuggester ())
243
- val testMethodName = try {
244
- nameSuggester.flatMap {
245
- val executableId = testSet.method
246
- val description = FuzzedMethodDescription (executableId).apply {
247
- compilableName = if (! executableId.isConstructor) executableId.name else null
248
- }
249
- it.suggest(
250
- description,
251
- utExecution.stateBefore.parameters.map { value -> FuzzedValue (value) },
252
- utExecution.result
253
- )
254
- }.firstOrNull()
255
- } catch (t: Throwable ) {
256
- logger.error(t) { " Cannot create suggested test name for $utExecution " }
257
- null
258
- }
259
- utExecution.testMethodName = testMethodName?.testName
260
- utExecution.displayName = testMethodName?.displayName
261
- utExecution.summary = testMethodName?.javaDoc
262
- }
263
-
264
- val clusteredExecutions = groupFuzzedExecutions(testSetWithFuzzedExecutions)
265
- clusteredExecutions.forEach {
266
- clustersToReturn.add(
267
- UtExecutionCluster (
268
- UtClusterInfo (it.header),
269
- it.executions
270
- )
271
- )
272
- }
273
- }
274
-
275
- return clustersToReturn.toList()
276
- }
277
-
278
- private fun generateSummariesForTestsProducedByFuzzer (
279
- testSet : UtMethodTestSet
231
+ private fun generateFuzzerBasedSummariesForTests (
232
+ testSet : UtMethodTestSet ,
233
+ descriptionSource : MethodDescriptionSource = MethodDescriptionSource .FUZZER
280
234
): List <UtExecutionCluster > {
281
235
val clustersToReturn: MutableList <UtExecutionCluster > = mutableListOf ()
282
- val testSetWithFuzzedExecutions = prepareTestSetWithFuzzedExecutions(testSet)
283
- val executionsProducedByFuzzer = testSetWithFuzzedExecutions.executions as List <UtFuzzedExecution >
284
-
285
- if (executionsProducedByFuzzer.isNotEmpty()) {
286
- executionsProducedByFuzzer.forEach { utExecution ->
236
+ val methodTestSet = when (descriptionSource) {
237
+ MethodDescriptionSource .FUZZER -> prepareTestSetWithFuzzedExecutions(testSet)
238
+ MethodDescriptionSource .SYMBOLIC -> prepareTestSetForByteCodeAnalysis(testSet)
239
+ }
287
240
288
- val nameSuggester = sequenceOf(ModelBasedNameSuggester (), MethodBasedNameSuggester ())
241
+ if (methodTestSet.executions.isNotEmpty()) {
242
+ methodTestSet.executions.forEach { utExecution ->
243
+ val nameSuggester = sequenceOf(ModelBasedNameSuggester (), MethodBasedNameSuggester (descriptionSource))
289
244
val testMethodName = try {
290
245
nameSuggester.flatMap {
291
- it.suggest(
292
- utExecution.fuzzedMethodDescription as FuzzedMethodDescription ,
293
- utExecution.fuzzingValues as List <FuzzedValue >,
294
- utExecution.result
295
- )
246
+ when (descriptionSource) {
247
+ MethodDescriptionSource .FUZZER -> {
248
+ with (utExecution as UtFuzzedExecution ) {
249
+ it.suggest(
250
+ utExecution.fuzzedMethodDescription as FuzzedMethodDescription ,
251
+ utExecution.fuzzingValues as List <FuzzedValue >,
252
+ utExecution.result
253
+ )
254
+ }
255
+ }
256
+
257
+ MethodDescriptionSource .SYMBOLIC -> {
258
+ val executableId = testSet.method
259
+ val description = FuzzedMethodDescription (executableId).apply {
260
+ compilableName = if (! executableId.isConstructor) executableId.name else null
261
+ }
262
+ it.suggest(
263
+ description,
264
+ utExecution.stateBefore.parameters.map { value -> FuzzedValue (value) },
265
+ utExecution.result
266
+ )
267
+ }
268
+ }
296
269
}.firstOrNull()
297
270
} catch (t: Throwable ) {
298
271
logger.error(t) { " Cannot create suggested test name for $utExecution " } // TODO: add better explanation or default behaviour
299
272
null
300
273
}
274
+
301
275
utExecution.testMethodName = testMethodName?.testName
302
276
utExecution.displayName = testMethodName?.displayName
303
277
utExecution.summary = testMethodName?.javaDoc
304
278
}
305
279
306
- val clusteredExecutions = groupFuzzedExecutions(testSetWithFuzzedExecutions)
307
-
280
+ val clusteredExecutions = groupFuzzedExecutions(methodTestSet)
308
281
clusteredExecutions.forEach {
309
282
clustersToReturn.add(
310
283
UtExecutionCluster (
@@ -445,4 +418,13 @@ private fun invokeDescriptions(testSet: UtMethodTestSet, searchDirectory: Path):
445
418
}
446
419
}
447
420
448
- data class InvokeDescription (val sootMethod : SootMethod , val ast : MethodDeclaration )
421
+ data class InvokeDescription (val sootMethod : SootMethod , val ast : MethodDeclaration )
422
+
423
+ /* *
424
+ * Sometimes, we need to use fuzzer for preparing summaries even for [UtSymbolicExecution]s.
425
+ * See [Summarization.generateFuzzerBasedSummariesForTests].
426
+ */
427
+ enum class MethodDescriptionSource {
428
+ FUZZER ,
429
+ SYMBOLIC ,
430
+ }
0 commit comments