Skip to content

Commit 795b138

Browse files
committed
Python: Add self-validating CFG tests
These tests consist of various Python constructions (hopefully a somewhat comprehensive set) with specific timestamp annotations scattered throughout. When the tests are run using the Python 3 interpreter, these annotations are checked and compared to the "current timestamp" to see that they are in agreement. This is what makes the tests "self-validating". There are a few different kinds of annotations: the basic `t[4]` style (meaning this is executed at timestamp 4), the `t[dead(4)]` variant (meaning this _would_ happen at timestamp 4, but it is in a dead branch), and `t[never]` (meaning this is never executed at all). In addition to this, there is a query, MissingAnnotations, which checks whether we have applied these annotations maximally. Many expression nodes are not actually annotatable, so there is a sizeable list of excluded nodes for that query.
1 parent 1ba9601 commit 795b138

23 files changed

Lines changed: 2500 additions & 0 deletions

python/ql/test/library-tests/ControlFlow/evaluation-order/MissingAnnotations.expected

Whitespace-only changes.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Finds expressions in test functions that lack a timer annotation
3+
* and are not part of the timer mechanism or otherwise excluded.
4+
* An empty result means every annotatable expression is covered.
5+
*/
6+
7+
import python
8+
import TimerUtils
9+
10+
from TestFunction f, Expr e
11+
where
12+
e.getScope().getEnclosingScope*() = f and
13+
not isTimerMechanism(e, f) and
14+
not isUnannotatable(e)
15+
select e, "Missing annotation in $@", f, f.getName()
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Implementation of the evaluation-order CFG signature using the existing
3+
* Python control flow graph.
4+
*/
5+
6+
private import python as Py
7+
import TimerUtils
8+
9+
/** Existing Python CFG implementation of the evaluation-order signature. */
10+
module OldCfg implements EvalOrderCfgSig {
11+
class CfgNode = Py::ControlFlowNode;
12+
13+
class BasicBlock = Py::BasicBlock;
14+
15+
CfgNode scopeGetEntryNode(Py::Scope s) { result = s.getEntryNode() }
16+
}

0 commit comments

Comments
 (0)