Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8e51b2f

Browse files
committed
Python: refactor test for global flow
1 parent 71f364e commit 8e51b2f

6 files changed

Lines changed: 61 additions & 30 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import experimental.dataflow.DataFlow
2+
3+
/**
4+
* A configuration to find "all" flows.
5+
* To be used on small programs.
6+
*/
7+
class AllFlowsConfig extends DataFlow::Configuration {
8+
AllFlowsConfig() { this = "AllFlowsConfig" }
9+
10+
override predicate isSource(DataFlow::Node node) {
11+
node.asCfgNode() instanceof CallNode
12+
}
13+
14+
override predicate isSink(DataFlow::Node node) {
15+
not exists(DataFlow::Node succ |
16+
DataFlow::localFlowStep(node, succ)
17+
)
18+
}
19+
}
Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,9 @@
1-
import python
2-
import experimental.dataflow.DataFlow
3-
4-
class SimpleConfig extends DataFlow::Configuration {
5-
SimpleConfig() { this = "SimpleConfig" }
6-
7-
// TODO: make a test out of this
8-
override predicate isSource(DataFlow::Node node) {
9-
node.asEssaNode() instanceof EssaNodeDefinition
10-
}
11-
12-
// TODO: make a test out of this
13-
override predicate isSink(DataFlow::Node node) {
14-
not exists(EssaDefinition succ |
15-
node.asEssaNode().getDefinition() = pred(succ)
16-
)
17-
}
18-
19-
EssaDefinition pred(EssaDefinition n) {
20-
// result = value(n.(EssaNodeDefinition))
21-
// or
22-
result = n.(EssaNodeRefinement).getInput()
23-
or
24-
result = n.(EssaEdgeRefinement).getInput()
25-
or
26-
result = n.(PhiFunction).getShortCircuitInput()
27-
}
28-
}
1+
import allFlowsConfig
292

303
from
314
DataFlow::Node source,
325
DataFlow::Node sink
336
where
34-
exists(SimpleConfig cfg | cfg.hasFlow(source, sink))
7+
exists(AllFlowsConfig cfg | cfg.hasFlow(source, sink))
358
select
36-
source, sink
9+
source, sink
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
| test.py:0:0:0:0 | Entry node for Module test |
2+
| test.py:0:0:0:0 | Exit node for Module test |
3+
| test.py:0:0:0:0 | GSSA Variable __name__ |
4+
| test.py:0:0:0:0 | GSSA Variable __package__ |
5+
| test.py:0:0:0:0 | GSSA Variable c |
6+
| test.py:0:0:0:0 | SSA variable $ |
7+
| test.py:1:1:1:1 | ControlFlowNode for a |
8+
| test.py:2:1:2:1 | ControlFlowNode for b |
9+
| test.py:2:1:2:1 | GSSA Variable b |
10+
| test.py:4:1:4:9 | Entry node for Function f |
11+
| test.py:4:1:4:9 | Exit node for Function f |
12+
| test.py:4:5:4:5 | ControlFlowNode for f |
13+
| test.py:4:5:4:5 | GSSA Variable f |
14+
| test.py:4:7:4:7 | ControlFlowNode for x |
15+
| test.py:4:7:4:7 | SSA variable x |
16+
| test.py:5:3:5:3 | ControlFlowNode for y |
17+
| test.py:5:3:5:3 | SSA variable y |
18+
| test.py:5:7:5:7 | ControlFlowNode for x |
19+
| test.py:5:11:5:11 | ControlFlowNode for IntegerLiteral |
20+
| test.py:6:3:6:14 | ControlFlowNode for Return |
21+
| test.py:6:10:6:10 | ControlFlowNode for y |
22+
| test.py:6:10:6:14 | ControlFlowNode for BinaryExpr |
23+
| test.py:6:14:6:14 | ControlFlowNode for IntegerLiteral |
24+
| test.py:8:1:8:1 | ControlFlowNode for c |
25+
| test.py:8:1:8:1 | GSSA Variable c |
26+
| test.py:8:5:8:5 | ControlFlowNode for f |
27+
| test.py:8:5:8:8 | GSSA Variable a |
28+
| test.py:8:7:8:7 | ControlFlowNode for a |
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import allFlowsConfig
2+
3+
from DataFlow::Node sink
4+
where exists(AllFlowsConfig cfg | cfg.isSink(sink))
5+
select sink
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| test.py:8:5:8:8 | ControlFlowNode for f() |
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import allFlowsConfig
2+
3+
from DataFlow::Node source
4+
where exists(AllFlowsConfig cfg | cfg.isSource(source))
5+
select source

0 commit comments

Comments
 (0)