Skip to content

Commit acfaaed

Browse files
authored
Merge branch 'main' into ideaseeker/timeout_tests_in_sarif
2 parents c86278e + 6b838cd commit acfaaed

File tree

7 files changed

+83
-10
lines changed

7 files changed

+83
-10
lines changed

docs/OverallArchitecture.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,17 @@ TODO (Nikita Stroganov)
129129
TODO (Nikita Stroganov)
130130

131131
### Contest estimator
132+
Contest estimator runs UnitTestBot on the provided projects and returns the generation statistics such as instruction coverage.
132133

133-
TODO (Rustam Sadykov)
134+
Contest estimator is placed in the [utbot-junit-contest][contest estimator 1] module and has two entry points:
135+
- [ContestEstimator.kt][contest estimator 2] is the main entry point. It runs UnitTestBot on the specified projects, calculates statistics for the target classes and projects, and outputs them to a console.
136+
- [StatisticsMonitoring.kt][contest estimator 3] is an additional entry point, which does the same as the previous one but can be configured from a file and dumps the resulting statistics to a file.
137+
It is used to [monitor and chart][contest estimator 4] statistics nightly.
134138

139+
[contest estimator 1]: ../utbot-junit-contest
140+
[contest estimator 2]: ../utbot-junit-contest/src/main/kotlin/org/utbot/contest/ContestEstimator.kt
141+
[contest estimator 3]: ../utbot-junit-contest/src/main/kotlin/org/utbot/monitoring/StatisticsMonitoring.kt
142+
[contest estimator 4]: NightStatisticsMonitoring.md
135143

136144
# Components
137145

utbot-framework/src/main/kotlin/org/utbot/framework/concrete/UtExecutionInstrumentation.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ object UtExecutionInstrumentation : Instrumentation<UtConcreteExecutionResult> {
169169
val executionResult = convertToExecutionResult(concreteResult, returnClassId)
170170

171171
val stateAfterParametersWithThis = constructParameters(params)
172-
val stateAfterStatics = constructStatics(statics.keys/* + traceHandler.computePutStatics()*/)
172+
val stateAfterStatics = constructStatics(stateBefore, statics)
173173
val (stateAfterThis, stateAfterParameters) = if (stateBefore.thisInstance == null) {
174174
null to stateAfterParametersWithThis
175175
} else {

utbot-framework/src/main/kotlin/org/utbot/framework/concrete/phases/ModelConstructionContext.kt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import org.utbot.common.withAccessibility
66
import org.utbot.framework.concrete.constructors.UtCompositeModelStrategy
77
import org.utbot.framework.concrete.constructors.UtModelConstructor
88
import org.utbot.framework.plugin.api.ClassId
9+
import org.utbot.framework.plugin.api.EnvironmentModels
910
import org.utbot.framework.plugin.api.FieldId
1011
import org.utbot.framework.plugin.api.TimeoutException
1112
import org.utbot.framework.plugin.api.UtConcreteValue
@@ -58,11 +59,20 @@ class ModelConstructionContext(
5859
constructor.construct(it.value, it.clazz.id)
5960
}
6061

61-
fun constructStatics(staticFields: Set<FieldId>): Map<FieldId, UtModel> =
62-
staticFields.associateWith { fieldId ->
62+
fun constructStatics(
63+
stateBefore: EnvironmentModels,
64+
staticFields: Map<FieldId, UtConcreteValue<*>>
65+
): Map<FieldId, UtModel> =
66+
staticFields.keys.associateWith { fieldId ->
6367
fieldId.jField.run {
6468
val computedValue = withAccessibility { get(null) }
65-
constructor.construct(computedValue, fieldId.type)
69+
val knownModel = stateBefore.statics[fieldId]
70+
val knownValue = staticFields[fieldId]?.value
71+
if (knownModel != null && knownValue != null && knownValue == computedValue) {
72+
knownModel
73+
} else {
74+
constructor.construct(computedValue, fieldId.type)
75+
}
6676
}
6777
}
6878

utbot-intellij-python/src/main/kotlin/org/utbot/intellij/plugin/language/python/PythonLanguageAssistant.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,18 @@ object PythonLanguageAssistant : LanguageAssistant() {
4444
}
4545

4646
private fun getPsiTargets(e: AnActionEvent): Targets? {
47-
val editor = e.getData(CommonDataKeys.EDITOR) ?: return null
47+
val editor = e.getData(CommonDataKeys.EDITOR)
4848
val file = e.getData(CommonDataKeys.PSI_FILE) as? PyFile ?: return null
49-
val element = findPsiElement(file, editor) ?: return null
5049

5150
if (file.module?.sdk?.sdkType !is PythonSdkType)
5251
return null
5352

53+
val element = if (editor != null) {
54+
findPsiElement(file, editor) ?: return null
55+
} else {
56+
e.getData(CommonDataKeys.PSI_ELEMENT) ?: return null
57+
}
58+
5459
val containingFunction = getContainingElement<PyFunction>(element)
5560
val containingClass = getContainingElement<PyClass>(element)
5661

@@ -67,7 +72,8 @@ object PythonLanguageAssistant : LanguageAssistant() {
6772
if (functions.isEmpty())
6873
return null
6974

70-
val focusedFunction = if (functions.any { it.name == containingFunction?.name }) containingFunction else null
75+
val focusedFunction =
76+
if (functions.any { it.name == containingFunction?.name }) containingFunction else null
7177
return Targets(functions.toSet(), containingClass, focusedFunction, file)
7278
}
7379

utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/actions/GenerateTestsAction.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ class GenerateTestsAction : AnAction() {
1010
}
1111

1212
override fun update(e: AnActionEvent) {
13-
LanguageAssistant.get(e)?.update(e)
13+
val languageAssistant = LanguageAssistant.get(e)
14+
if (languageAssistant == null) {
15+
e.presentation.isEnabled = false
16+
} else {
17+
languageAssistant.update(e)
18+
}
1419
}
1520
}

utbot-junit-contest/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Contest estimator
2+
3+
Contest estimator runs UnitTestBot on the provided projects and returns the generation statistics such as instruction coverage.
4+
5+
There are two entry points:
6+
- [ContestEstimator.kt][ep 1] is the main entry point. It runs UnitTestBot on the specified projects, calculates statistics for the target classes and projects, and outputs them to a console.
7+
- [StatisticsMonitoring.kt][ep 2] is an additional entry point, which does the same as the previous one but can be configured from a file and dumps the resulting statistics to a file.
8+
It is used to [monitor and chart][monitoring] statistics nightly.
9+
10+
11+
[ep 1]: src/main/kotlin/org/utbot/contest/ContestEstimator.kt
12+
[ep 2]: src/main/kotlin/org/utbot/monitoring/StatisticsMonitoring.kt
13+
[monitoring]: ../docs/NightStatisticsMonitoring.md
14+
15+
## Key functions
16+
17+
| Function name | File name | Description |
18+
|---------------|---------------------|----------------------------------------------------------------------------------------|
19+
| runGeneration | Contest.kt | Runs UnitTestBot and manages its work |
20+
| runEstimator | ContestEstimator.kt | Configures a project classpath, runs the main generation loop, and collects statistics |
21+
22+
23+
## Projects
24+
25+
The projects are provided to Contest estimator in advance.
26+
27+
### Structure
28+
All available projects are placed in the [resources][resources] folder, which contains:
29+
- [projects][projects] consisting of the folders with the project JAR files in them.
30+
- [classes][classes] consisting of the folders — each named after the project and containing the `list` file with the fully qualified class names.
31+
32+
### How to add a new project
33+
You should add both the JAR files to the `projects` folder and the file with a list of classes to the `classes` folder.
34+
35+
[resources]: src/main/resources
36+
[projects]: src/main/resources/projects
37+
[classes]: src/main/resources/classes
38+
39+
## Statistics
40+
Statistics are collected and memorized by the corresponding classes placed in [Statistics.kt][statistics].
41+
Then [monitoring][ep 2] dumps them using auxiliary classes that are defined in [MonitoringReport.kt][report] — they describe the format of output data.
42+
43+
[statistics]: src/main/kotlin/org/utbot/contest/Statistics.kt
44+
[report]: src/main/kotlin/org/utbot/monitoring/MonitoringReport.kt

utbot-rider/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ tasks {
3939

4040
patchPluginXml {
4141
sinceBuild.set("222")
42-
untilBuild.set("222.*")
42+
untilBuild.set("232.*")
4343
version.set(semVer)
4444
}
4545

0 commit comments

Comments
 (0)