Skip to content

Commit b05d079

Browse files
committed
Add taint analysis unit tests
1 parent 3b6cdc5 commit b05d079

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1360
-62
lines changed

.github/workflows/framework-tests-matrix.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
},
77
{
88
"PART_NAME": "composite-part2",
9-
"TESTS_TO_RUN": "--tests \"org.utbot.engine.*\" --tests \"org.utbot.framework.*\" --tests \"org.utbot.sarif.*\""
9+
"TESTS_TO_RUN": "--tests \"org.utbot.engine.*\" --tests \"org.utbot.framework.*\" --tests \"org.utbot.sarif.*\" --tests \"org.utbot.examples.taint.*\""
1010
},
1111
{
1212
"PART_NAME": "composite-part3",
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.utbot.examples.taint
2+
3+
import org.junit.jupiter.api.Test
4+
import org.utbot.framework.plugin.api.TaintAnalysisError
5+
import org.utbot.taint.TaintConfigurationProviderResources
6+
import org.utbot.testcheckers.eq
7+
import org.utbot.testcheckers.ge
8+
import org.utbot.testing.UtValueTestCaseCheckerForTaint
9+
import org.utbot.testing.isException
10+
11+
internal class TaintBranchingTest : UtValueTestCaseCheckerForTaint(
12+
testClass = TaintBranching::class,
13+
taintConfigurationProvider = TaintConfigurationProviderResources("taint/TaintBranchingConfig.yaml")
14+
) {
15+
@Test
16+
fun testTaintBad() {
17+
checkWithException(
18+
TaintBranching::bad,
19+
ge(2), // success & taint error
20+
{ cond, r -> cond == r.isException<TaintAnalysisError>() }
21+
)
22+
}
23+
24+
@Test
25+
fun testTaintGood() {
26+
check(
27+
TaintBranching::good,
28+
eq(2), // success in both cases
29+
)
30+
}
31+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package org.utbot.examples.taint
2+
3+
import org.junit.jupiter.api.Test
4+
import org.utbot.framework.plugin.api.TaintAnalysisError
5+
import org.utbot.taint.TaintConfigurationProviderResources
6+
import org.utbot.testcheckers.eq
7+
import org.utbot.testcheckers.ge
8+
import org.utbot.testing.UtValueTestCaseCheckerForTaint
9+
import org.utbot.testing.isException
10+
11+
internal class TaintCleanerConditionsTest : UtValueTestCaseCheckerForTaint(
12+
testClass = TaintCleanerConditions::class,
13+
taintConfigurationProvider = TaintConfigurationProviderResources("taint/TaintCleanerConditionsConfig.yaml")
14+
) {
15+
@Test
16+
fun testTaintBadArg() {
17+
checkWithException(
18+
TaintCleanerConditions::badArg,
19+
ge(2), // success & taint error
20+
{ r -> r.isException<TaintAnalysisError>() },
21+
)
22+
}
23+
24+
@Test
25+
fun testTaintBadReturn() {
26+
checkWithException(
27+
TaintCleanerConditions::badReturn,
28+
ge(2), // success & taint error
29+
{ r -> r.isException<TaintAnalysisError>() },
30+
)
31+
}
32+
33+
@Test
34+
fun testTaintBadThis() {
35+
checkWithException(
36+
TaintCleanerConditions::badThis,
37+
ge(2), // success & taint error
38+
{ r -> r.isException<TaintAnalysisError>() },
39+
)
40+
}
41+
42+
@Test
43+
fun testTaintGoodArg() {
44+
check(
45+
TaintCleanerConditions::goodArg,
46+
eq(1), // only success
47+
)
48+
}
49+
50+
@Test
51+
fun testTaintGoodReturn() {
52+
check(
53+
TaintCleanerConditions::goodReturn,
54+
eq(1), // only success
55+
)
56+
}
57+
58+
@Test
59+
fun testTaintGoodThis() {
60+
check(
61+
TaintCleanerConditions::goodThis,
62+
eq(1), // only success
63+
)
64+
}
65+
}

utbot-framework-test/src/test/kotlin/org/utbot/examples/taint/SimpleTaintExampleTest.kt renamed to utbot-framework-test/src/test/kotlin/org/utbot/examples/taint/TaintCleanerSimpleTest.kt

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,21 @@
11
package org.utbot.examples.taint
22

33
import org.junit.jupiter.api.Test
4-
import org.utbot.framework.plugin.api.CodegenLanguage
54
import org.utbot.framework.plugin.api.TaintAnalysisError
65
import org.utbot.taint.TaintConfigurationProviderResources
76
import org.utbot.testcheckers.eq
87
import org.utbot.testcheckers.ge
9-
import org.utbot.testing.CodeGeneration
108
import org.utbot.testing.UtValueTestCaseCheckerForTaint
119
import org.utbot.testing.isException
1210

13-
internal class SimpleTaintExampleTest : UtValueTestCaseCheckerForTaint(
14-
testClass = SimpleTaintExample::class,
15-
testCodeGeneration = true,
16-
pipelines = listOf(
17-
TestLastStage(CodegenLanguage.JAVA),
18-
TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration)
19-
),
20-
taintConfigurationProvider = TaintConfigurationProviderResources("taint/SimpleExampleConfig.yaml")
11+
internal class TaintCleanerSimpleTest : UtValueTestCaseCheckerForTaint(
12+
testClass = TaintCleanerSimple::class,
13+
taintConfigurationProvider = TaintConfigurationProviderResources("taint/TaintCleanerSimpleConfig.yaml")
2114
) {
2215
@Test
2316
fun testTaintBad() {
2417
checkWithException(
25-
SimpleTaintExample::bad,
18+
TaintCleanerSimple::bad,
2619
ge(2), // success & taint error
2720
{ r -> r.isException<TaintAnalysisError>() },
2821
)
@@ -31,7 +24,7 @@ internal class SimpleTaintExampleTest : UtValueTestCaseCheckerForTaint(
3124
@Test
3225
fun testTaintGood() {
3326
check(
34-
SimpleTaintExample::good,
27+
TaintCleanerSimple::good,
3528
eq(1), // only success
3629
)
3730
}

utbot-framework-test/src/test/kotlin/org/utbot/examples/taint/LongTaintPathTest.kt renamed to utbot-framework-test/src/test/kotlin/org/utbot/examples/taint/TaintLongPathTest.kt

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,21 @@
11
package org.utbot.examples.taint
22

33
import org.junit.jupiter.api.Test
4-
import org.utbot.framework.plugin.api.CodegenLanguage
54
import org.utbot.framework.plugin.api.TaintAnalysisError
65
import org.utbot.taint.TaintConfigurationProviderResources
76
import org.utbot.testcheckers.eq
87
import org.utbot.testcheckers.ge
9-
import org.utbot.testing.CodeGeneration
108
import org.utbot.testing.UtValueTestCaseCheckerForTaint
119
import org.utbot.testing.isException
1210

13-
internal class LongTaintPathTest : UtValueTestCaseCheckerForTaint(
14-
testClass = LongTaintPath::class,
15-
testCodeGeneration = true,
16-
pipelines = listOf(
17-
TestLastStage(CodegenLanguage.JAVA),
18-
TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration)
19-
),
20-
taintConfigurationProvider = TaintConfigurationProviderResources("taint/LongTaintPathConfig.yaml")
11+
internal class TaintLongPathTest : UtValueTestCaseCheckerForTaint(
12+
testClass = TaintLongPath::class,
13+
taintConfigurationProvider = TaintConfigurationProviderResources("taint/TaintLongPathConfig.yaml")
2114
) {
2215
@Test
2316
fun testTaintBad() {
2417
checkWithException(
25-
LongTaintPath::bad,
18+
TaintLongPath::bad,
2619
ge(2), // success & taint error
2720
{ r -> r.isException<TaintAnalysisError>() }
2821
)
@@ -31,7 +24,7 @@ internal class LongTaintPathTest : UtValueTestCaseCheckerForTaint(
3124
@Test
3225
fun testTaintGood() {
3326
check(
34-
LongTaintPath::good,
27+
TaintLongPath::good,
3528
eq(1), // only success
3629
)
3730
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.utbot.examples.taint
2+
3+
import org.junit.jupiter.api.Test
4+
import org.utbot.framework.plugin.api.TaintAnalysisError
5+
import org.utbot.taint.TaintConfigurationProviderResources
6+
import org.utbot.testcheckers.eq
7+
import org.utbot.testcheckers.ge
8+
import org.utbot.testing.UtValueTestCaseCheckerForTaint
9+
import org.utbot.testing.isException
10+
11+
internal class TaintOtherClassTest : UtValueTestCaseCheckerForTaint(
12+
testClass = TaintOtherClass::class,
13+
taintConfigurationProvider = TaintConfigurationProviderResources("taint/TaintOtherClassConfig.yaml")
14+
) {
15+
@Test
16+
fun testTaintBad() {
17+
checkWithException(
18+
TaintOtherClass::bad,
19+
ge(2), // success & taint error
20+
{ r -> r.isException<TaintAnalysisError>() },
21+
)
22+
}
23+
24+
@Test
25+
fun testTaintGood() {
26+
check(
27+
TaintOtherClass::good,
28+
eq(1), // only success
29+
)
30+
}
31+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package org.utbot.examples.taint
2+
3+
import org.junit.jupiter.api.Test
4+
import org.utbot.framework.plugin.api.TaintAnalysisError
5+
import org.utbot.taint.TaintConfigurationProviderResources
6+
import org.utbot.testcheckers.eq
7+
import org.utbot.testcheckers.ge
8+
import org.utbot.testing.UtValueTestCaseCheckerForTaint
9+
import org.utbot.testing.isException
10+
11+
internal class TaintPassConditionsTest : UtValueTestCaseCheckerForTaint(
12+
testClass = TaintPassConditions::class,
13+
taintConfigurationProvider = TaintConfigurationProviderResources("taint/TaintPassConditionsConfig.yaml")
14+
) {
15+
@Test
16+
fun testTaintBadArg() {
17+
checkWithException(
18+
TaintPassConditions::badArg,
19+
ge(2), // success & taint error
20+
{ r -> r.isException<TaintAnalysisError>() },
21+
)
22+
}
23+
24+
@Test
25+
fun testTaintBadReturn() {
26+
checkWithException(
27+
TaintPassConditions::badReturn,
28+
ge(2), // success & taint error
29+
{ r -> r.isException<TaintAnalysisError>() },
30+
)
31+
}
32+
33+
@Test
34+
fun testTaintBadThis() {
35+
checkWithException(
36+
TaintPassConditions::badThis,
37+
ge(2), // success & taint error
38+
{ r -> r.isException<TaintAnalysisError>() },
39+
)
40+
}
41+
42+
@Test
43+
fun testTaintGoodArg() {
44+
check(
45+
TaintPassConditions::goodArg,
46+
eq(1), // only success
47+
)
48+
}
49+
50+
@Test
51+
fun testTaintGoodReturn() {
52+
check(
53+
TaintPassConditions::goodReturn,
54+
eq(1), // only success
55+
)
56+
}
57+
58+
@Test
59+
fun testTaintGoodThis() {
60+
check(
61+
TaintPassConditions::goodThis,
62+
eq(1), // only success
63+
)
64+
}
65+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package org.utbot.examples.taint
2+
3+
import org.junit.jupiter.api.Test
4+
import org.utbot.framework.plugin.api.TaintAnalysisError
5+
import org.utbot.taint.TaintConfigurationProviderResources
6+
import org.utbot.testcheckers.eq
7+
import org.utbot.testcheckers.ge
8+
import org.utbot.testing.UtValueTestCaseCheckerForTaint
9+
import org.utbot.testing.isException
10+
11+
internal class TaintPassSimpleTest : UtValueTestCaseCheckerForTaint(
12+
testClass = TaintPassSimple::class,
13+
taintConfigurationProvider = TaintConfigurationProviderResources("taint/TaintPassSimpleConfig.yaml")
14+
) {
15+
@Test
16+
fun testTaintBad() {
17+
checkWithException(
18+
TaintPassSimple::bad,
19+
ge(2), // success & taint error
20+
{ r -> r.isException<TaintAnalysisError>() },
21+
)
22+
}
23+
24+
@Test
25+
fun testTaintBadDoublePass() {
26+
checkWithException(
27+
TaintPassSimple::badDoublePass,
28+
ge(2), // success & taint error
29+
{ r -> r.isException<TaintAnalysisError>() },
30+
)
31+
}
32+
33+
@Test
34+
fun testTaintGood() {
35+
check(
36+
TaintPassSimple::good,
37+
eq(1), // only success
38+
)
39+
}
40+
}

0 commit comments

Comments
 (0)