Skip to content

Commit 7ba4d71

Browse files
authored
Merge pull request #494 from markshannon/python-tests
QL tests for Python queries and libraries.
2 parents 6317546 + 05b69a1 commit 7ba4d71

File tree

1,140 files changed

+32676
-0
lines changed

Some content is hidden

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

1,140 files changed

+32676
-0
lines changed

python/ql/test/library-tests/ControlFlow/PointsToSupport/UseFromDefinition.expected

Whitespace-only changes.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @name UseFromDefinition
3+
* @description Insert description here...
4+
* @kind problem
5+
* @problem.severity warning
6+
*/
7+
8+
import python
9+
10+
/*Find any Definition, assigned value pairs that 'valueForDefinition' misses */
11+
12+
Expr assignedValue(Name n) {
13+
exists(Assign a | a.getATarget() = n and result = a.getValue())
14+
or
15+
exists(Alias a | a.getAsname() = n and result = a.getValue())
16+
}
17+
18+
from Name def, DefinitionNode d
19+
where d = def.getAFlowNode() and
20+
exists(assignedValue(def)) and
21+
not d.getValue().getNode() = assignedValue(def)
22+
23+
select def.toString(), assignedValue(def)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
| ControlFlowNode for Attribute | ControlFlowNode for Attribute | 8 |
2+
| ControlFlowNode for Attribute | ControlFlowNode for Attribute | 22 |
3+
| ControlFlowNode for Subscript | ControlFlowNode for Subscript | 9 |
4+
| ControlFlowNode for Subscript | ControlFlowNode for Subscript | 23 |
5+
| ControlFlowNode for v | ControlFlowNode for v | 28 |
6+
| ControlFlowNode for x | ControlFlowNode for x | 7 |
7+
| ControlFlowNode for x | ControlFlowNode for x | 21 |
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import python
2+
3+
int lineof(ControlFlowNode f) {
4+
result = f.getNode().getLocation().getStartLine()
5+
}
6+
7+
from ControlFlowNode defn, ControlFlowNode use
8+
where defn.getNode() = use.getNode()
9+
and defn.isStore() and use.isLoad()
10+
select defn.toString(), use.toString(), lineof(defn)
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
| 4 | test.py:4:5:4:9 | ControlFlowNode for func1 | store |
2+
| 7 | test.py:7:5:7:5 | ControlFlowNode for x | aug load |
3+
| 7 | test.py:7:5:7:5 | ControlFlowNode for x | aug store |
4+
| 7 | test.py:7:10:7:10 | ControlFlowNode for f | load |
5+
| 7 | test.py:7:12:7:12 | ControlFlowNode for y | load |
6+
| 7 | test.py:7:16:7:20 | ControlFlowNode for Tuple | load |
7+
| 8 | test.py:8:5:8:5 | ControlFlowNode for o | load |
8+
| 8 | test.py:8:5:8:9 | ControlFlowNode for Attribute | load |
9+
| 8 | test.py:8:5:8:14 | ControlFlowNode for Attribute | aug load |
10+
| 8 | test.py:8:5:8:14 | ControlFlowNode for Attribute | aug store |
11+
| 8 | test.py:8:19:8:19 | ControlFlowNode for f | load |
12+
| 8 | test.py:8:21:8:21 | ControlFlowNode for y | load |
13+
| 8 | test.py:8:25:8:29 | ControlFlowNode for Tuple | load |
14+
| 9 | test.py:9:5:9:5 | ControlFlowNode for s | load |
15+
| 9 | test.py:9:5:9:17 | ControlFlowNode for Subscript | aug load |
16+
| 9 | test.py:9:5:9:17 | ControlFlowNode for Subscript | aug store |
17+
| 9 | test.py:9:7:9:7 | ControlFlowNode for z | load |
18+
| 9 | test.py:9:7:9:16 | ControlFlowNode for Tuple | load |
19+
| 9 | test.py:9:22:9:22 | ControlFlowNode for f | load |
20+
| 9 | test.py:9:24:9:24 | ControlFlowNode for y | load |
21+
| 9 | test.py:9:28:9:32 | ControlFlowNode for Tuple | load |
22+
| 10 | test.py:10:12:10:12 | ControlFlowNode for x | load |
23+
| 13 | test.py:13:5:13:9 | ControlFlowNode for func2 | store |
24+
| 14 | test.py:14:5:14:5 | ControlFlowNode for s | store |
25+
| 14 | test.py:14:9:14:12 | ControlFlowNode for None | load |
26+
| 15 | test.py:15:5:15:5 | ControlFlowNode for o | store |
27+
| 15 | test.py:15:9:15:12 | ControlFlowNode for None | load |
28+
| 16 | test.py:16:5:16:5 | ControlFlowNode for x | store |
29+
| 16 | test.py:16:9:16:12 | ControlFlowNode for None | load |
30+
| 17 | test.py:17:5:17:5 | ControlFlowNode for y | store |
31+
| 17 | test.py:17:9:17:12 | ControlFlowNode for None | load |
32+
| 18 | test.py:18:5:18:5 | ControlFlowNode for z | store |
33+
| 18 | test.py:18:9:18:12 | ControlFlowNode for None | load |
34+
| 21 | test.py:21:5:21:5 | ControlFlowNode for x | aug load |
35+
| 21 | test.py:21:5:21:5 | ControlFlowNode for x | aug store |
36+
| 21 | test.py:21:10:21:10 | ControlFlowNode for f | load |
37+
| 21 | test.py:21:12:21:12 | ControlFlowNode for y | load |
38+
| 21 | test.py:21:16:21:20 | ControlFlowNode for Tuple | load |
39+
| 22 | test.py:22:5:22:5 | ControlFlowNode for o | load |
40+
| 22 | test.py:22:5:22:9 | ControlFlowNode for Attribute | load |
41+
| 22 | test.py:22:5:22:14 | ControlFlowNode for Attribute | aug load |
42+
| 22 | test.py:22:5:22:14 | ControlFlowNode for Attribute | aug store |
43+
| 22 | test.py:22:19:22:19 | ControlFlowNode for f | load |
44+
| 22 | test.py:22:21:22:21 | ControlFlowNode for y | load |
45+
| 22 | test.py:22:25:22:29 | ControlFlowNode for Tuple | load |
46+
| 23 | test.py:23:5:23:5 | ControlFlowNode for s | load |
47+
| 23 | test.py:23:5:23:17 | ControlFlowNode for Subscript | aug load |
48+
| 23 | test.py:23:5:23:17 | ControlFlowNode for Subscript | aug store |
49+
| 23 | test.py:23:7:23:7 | ControlFlowNode for z | load |
50+
| 23 | test.py:23:7:23:16 | ControlFlowNode for Tuple | load |
51+
| 23 | test.py:23:22:23:22 | ControlFlowNode for f | load |
52+
| 23 | test.py:23:24:23:24 | ControlFlowNode for y | load |
53+
| 23 | test.py:23:28:23:32 | ControlFlowNode for Tuple | load |
54+
| 24 | test.py:24:12:24:12 | ControlFlowNode for x | load |
55+
| 27 | test.py:27:5:27:8 | ControlFlowNode for comp | store |
56+
| 28 | test.py:28:5:28:5 | ControlFlowNode for v | aug load |
57+
| 28 | test.py:28:5:28:5 | ControlFlowNode for v | aug store |
58+
| 28 | test.py:28:10:28:10 | ControlFlowNode for a | load |
59+
| 28 | test.py:28:15:28:18 | ControlFlowNode for cond | load |
60+
| 28 | test.py:28:25:28:25 | ControlFlowNode for b | load |
61+
| 29 | test.py:29:12:29:12 | ControlFlowNode for v | load |
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
import python
3+
4+
string kind(ControlFlowNode f) {
5+
if f.isAugLoad() then
6+
result = "aug load"
7+
else (
8+
if f.isAugStore() then
9+
result = "aug store"
10+
else (
11+
if f.isLoad() then
12+
result = "load"
13+
else (
14+
f.isStore() and result = "store"
15+
)
16+
)
17+
)
18+
}
19+
20+
from ControlFlowNode cfg
21+
select cfg.getLocation().getStartLine(), cfg, kind(cfg)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
| ControlFlowNode for v | 28 |
2+
| ControlFlowNode for x | 7 |
3+
| ControlFlowNode for x | 21 |
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @name SSA
3+
* @description Insert description here...
4+
* @kind problem
5+
* @problem.severity warning
6+
*/
7+
8+
import python
9+
10+
11+
from ControlFlowNode defn, SsaVariable v, AugAssign a, BinaryExpr b
12+
where v.getDefinition() = defn and a.getOperation() = b and b.contains((Expr)defn.getNode())
13+
select defn.toString(), defn.getNode().getLocation().getStartLine()
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#Test flow control for augmented assignment statements:
2+
3+
#Parameters
4+
def func1(s, o, x, y, z):
5+
#Note that the right hand sides should be sufficiently complex
6+
#to make the parts of the statement sufficiently separated
7+
x += f(y, (1,2,3))
8+
o.val.item += f(y, (1,2,3))
9+
s[z, 10, 1:3] += f(y, (1,2,3))
10+
return x
11+
12+
#Local variables
13+
def func2():
14+
s = None
15+
o = None
16+
x = None
17+
y = None
18+
z = None
19+
#Note that the right hand sides should be sufficiently complex
20+
#to make the parts of the statement sufficiently separated
21+
x += f(y, (1,2,3))
22+
o.val.item += f(y, (1,2,3))
23+
s[z, 10, 1:3] += f(y, (1,2,3))
24+
return x
25+
26+
#Complex flow
27+
def comp(v, cond):
28+
v += a if cond else b
29+
return v
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
| 1 | ControlFlowNode for Compare | a | b | == |
2+
| 2 | ControlFlowNode for Compare | c | d | > |
3+
| 3 | ControlFlowNode for Compare | e | f | < |
4+
| 4 | ControlFlowNode for Compare | g | h | >= |
5+
| 5 | ControlFlowNode for Compare | i | j | <= |
6+
| 6 | ControlFlowNode for Compare | k | l | != |

0 commit comments

Comments
 (0)