Skip to content

Commit 92ee318

Browse files
authored
Merge pull request github#13643 from jketema/inline-5
Rework the remaining inline expectation tests to use the parameterized module
2 parents a4c0063 + 8cee4f3 commit 92ee318

File tree

25 files changed

+160
-175
lines changed

25 files changed

+160
-175
lines changed

python/ql/test/experimental/dataflow/TestUtil/FlowTest.qll

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ signature module FlowTestSig {
99
predicate relevantFlow(DataFlow::Node fromNode, DataFlow::Node toNode);
1010
}
1111

12-
private module FlowTest<FlowTestSig Impl> implements TestSig {
12+
module MakeTestSig<FlowTestSig Impl> implements TestSig {
1313
string getARelevantTag() { result = Impl::flowTag() }
1414

1515
predicate hasActualResult(Location location, string element, string tag, string value) {
@@ -37,11 +37,3 @@ private module FlowTest<FlowTestSig Impl> implements TestSig {
3737
)
3838
}
3939
}
40-
41-
module MakeFlowTest<FlowTestSig Impl> {
42-
import MakeTest<FlowTest<Impl>>
43-
}
44-
45-
module MakeFlowTest2<FlowTestSig Impl1, FlowTestSig Impl2> {
46-
import MakeTest<MergeTests<FlowTest<Impl1>, FlowTest<Impl2>>>
47-
}

python/ql/test/experimental/dataflow/TestUtil/LocalFlowStepTest.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ module LocalFlowStepTest implements FlowTestSig {
1010
}
1111
}
1212

13-
import MakeFlowTest<LocalFlowStepTest>
13+
import MakeTest<MakeTestSig<LocalFlowStepTest>>

python/ql/test/experimental/dataflow/TestUtil/MaximalFlowTest.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module MaximalFlowTest implements FlowTestSig {
1212
}
1313
}
1414

15-
import MakeFlowTest<MaximalFlowTest>
15+
import MakeTest<MakeTestSig<MaximalFlowTest>>
1616

1717
/**
1818
* A configuration to find all "maximal" flows.

python/ql/test/experimental/dataflow/TestUtil/NormalDataflowTest.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module DataFlowTest implements FlowTestSig {
1111
}
1212
}
1313

14-
import MakeFlowTest<DataFlowTest>
14+
import MakeTest<MakeTestSig<DataFlowTest>>
1515

1616
query predicate missingAnnotationOnSink(Location location, string error, string element) {
1717
error = "ERROR, you should add `# $ MISSING: flow` annotation" and

python/ql/test/experimental/dataflow/TestUtil/NormalTaintTrackingTest.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module DataFlowTest implements FlowTestSig {
1111
}
1212
}
1313

14-
import MakeFlowTest<DataFlowTest>
14+
import MakeTest<MakeTestSig<DataFlowTest>>
1515

1616
query predicate missingAnnotationOnSink(Location location, string error, string element) {
1717
error = "ERROR, you should add `# $ MISSING: flow` annotation" and

python/ql/test/experimental/dataflow/TestUtil/RoutingTest.qll

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,25 @@ private import semmle.python.dataflow.new.internal.DataFlowPrivate as DataFlowPr
1010
* the functions tested sink their arguments sequentially, that is
1111
* `SINK1(arg1)`, etc.
1212
*/
13-
abstract class RoutingTest extends InlineExpectationsTest {
14-
bindingset[this]
15-
RoutingTest() { any() }
13+
signature module RoutingTestSig {
14+
class Argument;
1615

17-
abstract string flowTag();
16+
string flowTag(Argument arg);
1817

19-
abstract predicate relevantFlow(DataFlow::Node fromNode, DataFlow::Node toNode);
18+
predicate relevantFlow(DataFlow::Node fromNode, DataFlow::Node toNode, Argument arg);
19+
}
2020

21-
override string getARelevantTag() { result in ["func", this.flowTag()] }
21+
module MakeTestSig<RoutingTestSig Impl> implements TestSig {
22+
string getARelevantTag() { result in ["func", Impl::flowTag(_)] }
2223

23-
override predicate hasActualResult(Location location, string element, string tag, string value) {
24-
exists(DataFlow::Node fromNode, DataFlow::Node toNode | this.relevantFlow(fromNode, toNode) |
24+
predicate hasActualResult(Location location, string element, string tag, string value) {
25+
exists(DataFlow::Node fromNode, DataFlow::Node toNode, Impl::Argument arg |
26+
Impl::relevantFlow(fromNode, toNode, arg)
27+
|
2528
location = fromNode.getLocation() and
2629
element = fromNode.toString() and
2730
(
28-
tag = this.flowTag() and
31+
tag = Impl::flowTag(arg) and
2932
if "\"" + tag + "\"" = fromValue(fromNode) then value = "" else value = fromValue(fromNode)
3033
or
3134
// only have result for `func` tag if the function where `arg<n>` is used, is
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
failures
2+
testFailures
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
failures
2+
testFailures
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
failures
2+
testFailures

python/ql/test/experimental/dataflow/coverage/argumentRoutingTest.ql

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,22 @@ import semmle.python.dataflow.new.DataFlow
33
private import semmle.python.dataflow.new.internal.DataFlowPrivate as DataFlowPrivate
44
import experimental.dataflow.TestUtil.RoutingTest
55

6-
class Argument1RoutingTest extends RoutingTest {
7-
Argument1RoutingTest() { this = "Argument1RoutingTest" }
8-
9-
override string flowTag() { result = "arg1" }
10-
11-
override predicate relevantFlow(DataFlow::Node source, DataFlow::Node sink) {
12-
exists(Argument1ExtraRoutingConfig cfg | cfg.hasFlow(source, sink))
13-
or
14-
exists(ArgumentRoutingConfig cfg |
15-
cfg.hasFlow(source, sink) and
16-
cfg.isArgSource(source, 1) and
17-
cfg.isGoodSink(sink, 1)
18-
)
6+
module Argument1RoutingTest implements RoutingTestSig {
7+
class Argument = Unit;
8+
9+
string flowTag(Argument arg) { result = "arg1" and exists(arg) }
10+
11+
predicate relevantFlow(DataFlow::Node source, DataFlow::Node sink, Argument arg) {
12+
(
13+
exists(Argument1ExtraRoutingConfig cfg | cfg.hasFlow(source, sink))
14+
or
15+
exists(ArgumentRoutingConfig cfg |
16+
cfg.hasFlow(source, sink) and
17+
cfg.isArgSource(source, 1) and
18+
cfg.isGoodSink(sink, 1)
19+
)
20+
) and
21+
exists(arg)
1922
}
2023
}
2124

@@ -87,59 +90,54 @@ class Argument1ExtraRoutingConfig extends DataFlow::Configuration {
8790
override predicate isBarrierIn(DataFlow::Node node) { this.isSource(node) }
8891
}
8992

90-
class RestArgumentRoutingTest extends RoutingTest {
91-
ArgNumber argNumber;
93+
module RestArgumentRoutingTest implements RoutingTestSig {
94+
class Argument = ArgNumber;
9295

93-
RestArgumentRoutingTest() {
94-
argNumber > 1 and
95-
this = "Argument" + argNumber + "RoutingTest"
96-
}
97-
98-
override string flowTag() { result = "arg" + argNumber }
96+
string flowTag(Argument arg) { result = "arg" + arg }
9997

100-
override predicate relevantFlow(DataFlow::Node source, DataFlow::Node sink) {
98+
predicate relevantFlow(DataFlow::Node source, DataFlow::Node sink, Argument arg) {
10199
exists(ArgumentRoutingConfig cfg |
102100
cfg.hasFlow(source, sink) and
103-
cfg.isArgSource(source, argNumber) and
104-
cfg.isGoodSink(sink, argNumber)
105-
)
101+
cfg.isArgSource(source, arg) and
102+
cfg.isGoodSink(sink, arg)
103+
) and
104+
arg > 1
106105
}
107106
}
108107

109108
/** Bad flow from `arg<n>` to `SINK<N>_F` */
110-
class BadArgumentRoutingTestSinkF extends RoutingTest {
111-
ArgNumber argNumber;
109+
module BadArgumentRoutingTestSinkF implements RoutingTestSig {
110+
class Argument = ArgNumber;
112111

113-
BadArgumentRoutingTestSinkF() { this = "BadArgumentRoutingTestSinkF" + argNumber }
112+
string flowTag(Argument arg) { result = "bad" + arg }
114113

115-
override string flowTag() { result = "bad" + argNumber }
116-
117-
override predicate relevantFlow(DataFlow::Node source, DataFlow::Node sink) {
114+
predicate relevantFlow(DataFlow::Node source, DataFlow::Node sink, Argument arg) {
118115
exists(ArgumentRoutingConfig cfg |
119116
cfg.hasFlow(source, sink) and
120-
cfg.isArgSource(source, argNumber) and
121-
cfg.isBadSink(sink, argNumber)
117+
cfg.isArgSource(source, arg) and
118+
cfg.isBadSink(sink, arg)
122119
)
123120
}
124121
}
125122

126123
/** Bad flow from `arg<n>` to `SINK<M>` or `SINK<M>_F`, where `n != m`. */
127-
class BadArgumentRoutingTestWrongSink extends RoutingTest {
128-
ArgNumber argNumber;
129-
130-
BadArgumentRoutingTestWrongSink() { this = "BadArgumentRoutingTestWrongSink" + argNumber }
124+
module BadArgumentRoutingTestWrongSink implements RoutingTestSig {
125+
class Argument = ArgNumber;
131126

132-
override string flowTag() { result = "bad" + argNumber }
127+
string flowTag(Argument arg) { result = "bad" + arg }
133128

134-
override predicate relevantFlow(DataFlow::Node source, DataFlow::Node sink) {
129+
predicate relevantFlow(DataFlow::Node source, DataFlow::Node sink, Argument arg) {
135130
exists(ArgumentRoutingConfig cfg |
136131
cfg.hasFlow(source, sink) and
137-
cfg.isArgSource(source, any(ArgNumber i | not i = argNumber)) and
132+
cfg.isArgSource(source, any(ArgNumber i | not i = arg)) and
138133
(
139-
cfg.isGoodSink(sink, argNumber)
134+
cfg.isGoodSink(sink, arg)
140135
or
141-
cfg.isBadSink(sink, argNumber)
136+
cfg.isBadSink(sink, arg)
142137
)
143138
)
144139
}
145140
}
141+
142+
import MakeTest<MergeTests4<MakeTestSig<Argument1RoutingTest>, MakeTestSig<RestArgumentRoutingTest>,
143+
MakeTestSig<BadArgumentRoutingTestSinkF>, MakeTestSig<BadArgumentRoutingTestWrongSink>>>

0 commit comments

Comments
 (0)