Python: refactor test for global flow

This commit is contained in:
Rasmus Lerchedahl Petersen
2020-06-17 16:43:11 +02:00
parent 71f364eef3
commit 8e51b2fed8
6 changed files with 61 additions and 30 deletions

View File

@@ -0,0 +1,19 @@
import experimental.dataflow.DataFlow
/**
* A configuration to find "all" flows.
* To be used on small programs.
*/
class AllFlowsConfig extends DataFlow::Configuration {
AllFlowsConfig() { this = "AllFlowsConfig" }
override predicate isSource(DataFlow::Node node) {
node.asCfgNode() instanceof CallNode
}
override predicate isSink(DataFlow::Node node) {
not exists(DataFlow::Node succ |
DataFlow::localFlowStep(node, succ)
)
}
}

View File

@@ -1,36 +1,9 @@
import python
import experimental.dataflow.DataFlow
class SimpleConfig extends DataFlow::Configuration {
SimpleConfig() { this = "SimpleConfig" }
// TODO: make a test out of this
override predicate isSource(DataFlow::Node node) {
node.asEssaNode() instanceof EssaNodeDefinition
}
// TODO: make a test out of this
override predicate isSink(DataFlow::Node node) {
not exists(EssaDefinition succ |
node.asEssaNode().getDefinition() = pred(succ)
)
}
EssaDefinition pred(EssaDefinition n) {
// result = value(n.(EssaNodeDefinition))
// or
result = n.(EssaNodeRefinement).getInput()
or
result = n.(EssaEdgeRefinement).getInput()
or
result = n.(PhiFunction).getShortCircuitInput()
}
}
import allFlowsConfig
from
DataFlow::Node source,
DataFlow::Node sink
where
exists(SimpleConfig cfg | cfg.hasFlow(source, sink))
exists(AllFlowsConfig cfg | cfg.hasFlow(source, sink))
select
source, sink
source, sink

View File

@@ -0,0 +1,28 @@
| test.py:0:0:0:0 | Entry node for Module test |
| test.py:0:0:0:0 | Exit node for Module test |
| test.py:0:0:0:0 | GSSA Variable __name__ |
| test.py:0:0:0:0 | GSSA Variable __package__ |
| test.py:0:0:0:0 | GSSA Variable c |
| test.py:0:0:0:0 | SSA variable $ |
| test.py:1:1:1:1 | ControlFlowNode for a |
| test.py:2:1:2:1 | ControlFlowNode for b |
| test.py:2:1:2:1 | GSSA Variable b |
| test.py:4:1:4:9 | Entry node for Function f |
| test.py:4:1:4:9 | Exit node for Function f |
| test.py:4:5:4:5 | ControlFlowNode for f |
| test.py:4:5:4:5 | GSSA Variable f |
| test.py:4:7:4:7 | ControlFlowNode for x |
| test.py:4:7:4:7 | SSA variable x |
| test.py:5:3:5:3 | ControlFlowNode for y |
| test.py:5:3:5:3 | SSA variable y |
| test.py:5:7:5:7 | ControlFlowNode for x |
| test.py:5:11:5:11 | ControlFlowNode for IntegerLiteral |
| test.py:6:3:6:14 | ControlFlowNode for Return |
| test.py:6:10:6:10 | ControlFlowNode for y |
| test.py:6:10:6:14 | ControlFlowNode for BinaryExpr |
| test.py:6:14:6:14 | ControlFlowNode for IntegerLiteral |
| test.py:8:1:8:1 | ControlFlowNode for c |
| test.py:8:1:8:1 | GSSA Variable c |
| test.py:8:5:8:5 | ControlFlowNode for f |
| test.py:8:5:8:8 | GSSA Variable a |
| test.py:8:7:8:7 | ControlFlowNode for a |

View File

@@ -0,0 +1,5 @@
import allFlowsConfig
from DataFlow::Node sink
where exists(AllFlowsConfig cfg | cfg.isSink(sink))
select sink

View File

@@ -0,0 +1 @@
| test.py:8:5:8:8 | ControlFlowNode for f() |

View File

@@ -0,0 +1,5 @@
import allFlowsConfig
from DataFlow::Node source
where exists(AllFlowsConfig cfg | cfg.isSource(source))
select source