blob: 43d40cea372bc2bcac8a8f524a329a3b92d99457 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
# We expect a warning with this textual form:
#
# . warning: deadlock due to inconsistent lock acquisition order
# . 17 | acquire_lock_a (); /* { dg-warning "deadlock due to inconsistent lock acquisition order" } */
# . | ^~~~~~~~~~~~~~~~~
# . Thread: 'Thread 1'
# . 'foo': event 1
# . |
# . | 9 | {
# . | | ^
# . | | |
# . | | (1) entering 'foo'
# . |
# . +--> 'foo': event 2
# . |
# . | 10 | acquire_lock_a ();
# . | | ^~~~~~~~~~~~~~~~~
# . | | |
# . | | (2) lock a is now held by thread 1
# . |
# .
# . Thread: 'Thread 2'
# . 'bar': event 3
# . |
# . | 15 | {
# . | | ^
# . | | |
# . | | (3) entering 'bar'
# . |
# . +--> 'bar': event 4
# . |
# . | 16 | acquire_lock_b ();
# . | | ^~~~~~~~~~~~~~~~~
# . | | |
# . | | (4) lock b is now held by thread 2
# . |
from sarif import *
import pytest
@pytest.fixture(scope='function', autouse=True)
def sarif():
return sarif_from_env()
def test_basics(sarif):
schema = sarif['$schema']
assert schema == "https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/schemas/sarif-schema-2.1.0.json"
version = sarif['version']
assert version == "2.1.0"
def test_execution_successful(sarif):
runs = sarif['runs']
run = runs[0]
invocations = run['invocations']
assert len(invocations) == 1
invocation = invocations[0]
# We expect a mere 'warning' to allow executionSuccessful be true
assert invocation['executionSuccessful'] == True
def test_result(sarif):
runs = sarif['runs']
run = runs[0]
results = run['results']
assert len(results) == 1
result = results[0]
assert result['level'] == 'warning'
assert result['message']['text'] == "deadlock due to inconsistent lock acquisition order"
code_flows = result['codeFlows']
assert len(code_flows) == 1
code_flow = code_flows[0]
thread_flows = code_flow['threadFlows']
assert len(thread_flows) == 2
tf0 = thread_flows[0]
assert tf0['id'] == 'Thread 1'
tf1 = thread_flows[1]
assert tf1['id'] == 'Thread 2'
assert len(tf0['locations']) == 3
assert tf0['locations'][0]['executionOrder'] == 1
assert tf0['locations'][0]['location']['message']['text'] \
== "entering 'foo'"
assert tf0['locations'][1]['executionOrder'] == 2
assert tf0['locations'][1]['location']['message']['text'] \
== "lock a is now held by thread 1"
assert tf0['locations'][2]['executionOrder'] == 5
assert tf0['locations'][2]['location']['message']['text'] \
== "deadlocked due to waiting for lock b in thread 1 (acquired by thread 2 at (4))..."
assert len(tf1['locations']) == 3
assert tf1['locations'][0]['executionOrder'] == 3
assert tf1['locations'][0]['location']['message']['text'] \
== "entering 'bar'"
assert tf1['locations'][1]['executionOrder'] == 4
assert tf1['locations'][1]['location']['message']['text'] \
== "lock b is now held by thread 2"
assert tf1['locations'][2]['executionOrder'] == 6
assert tf1['locations'][2]['location']['message']['text'] \
== "...whilst waiting for lock a in thread 2 (acquired by thread 1 at (2))"
|