1 # We expect a warning with this textual form:
3 # . warning: deadlock due to inconsistent lock acquisition order
4 # . 17 | acquire_lock_a (); /* { dg-warning "deadlock due to inconsistent lock acquisition order" } */
5 # . | ^~~~~~~~~~~~~~~~~
12 # . | | (1) entering 'foo'
14 # . +--> 'foo': event 2
16 # . | 10 | acquire_lock_a ();
17 # . | | ^~~~~~~~~~~~~~~~~
19 # . | | (2) lock a is now held by thread 1
22 # . Thread: 'Thread 2'
28 # . | | (3) entering 'bar'
30 # . +--> 'bar': event 4
32 # . | 16 | acquire_lock_b ();
33 # . | | ^~~~~~~~~~~~~~~~~
35 # . | | (4) lock b is now held by thread 2
42 @pytest.fixture(scope
='function', autouse
=True)
44 return sarif_from_env()
46 def test_basics(sarif
):
47 schema
= sarif
['$schema']
48 assert schema
== "https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/schemas/sarif-schema-2.1.0.json"
50 version
= sarif
['version']
51 assert version
== "2.1.0"
53 def test_execution_successful(sarif
):
57 invocations
= run
['invocations']
58 assert len(invocations
) == 1
59 invocation
= invocations
[0]
61 # We expect a mere 'warning' to allow executionSuccessful be true
62 assert invocation
['executionSuccessful'] == True
64 def test_result(sarif
):
67 results
= run
['results']
69 assert len(results
) == 1
72 assert result
['level'] == 'warning'
73 assert result
['message']['text'] == "deadlock due to inconsistent lock acquisition order"
75 code_flows
= result
['codeFlows']
76 assert len(code_flows
) == 1
78 code_flow
= code_flows
[0]
80 thread_flows
= code_flow
['threadFlows']
81 assert len(thread_flows
) == 2
84 assert tf0
['id'] == 'Thread 1'
87 assert tf1
['id'] == 'Thread 2'
89 assert len(tf0
['locations']) == 3
90 assert tf0
['locations'][0]['executionOrder'] == 1
91 assert tf0
['locations'][0]['location']['message']['text'] \
93 assert tf0
['locations'][1]['executionOrder'] == 2
94 assert tf0
['locations'][1]['location']['message']['text'] \
95 == "lock a is now held by thread 1"
96 assert tf0
['locations'][2]['executionOrder'] == 5
97 assert tf0
['locations'][2]['location']['message']['text'] \
98 == "deadlocked due to waiting for lock b in thread 1 (acquired by thread 2 at (4))..."
100 assert len(tf1
['locations']) == 3
101 assert tf1
['locations'][0]['executionOrder'] == 3
102 assert tf1
['locations'][0]['location']['message']['text'] \
104 assert tf1
['locations'][1]['executionOrder'] == 4
105 assert tf1
['locations'][1]['location']['message']['text'] \
106 == "lock b is now held by thread 2"
107 assert tf1
['locations'][2]['executionOrder'] == 6
108 assert tf1
['locations'][2]['location']['message']['text'] \
109 == "...whilst waiting for lock a in thread 2 (acquired by thread 1 at (2))"