aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/plugin/crash-test-ice-in-header-sarif-2_1.py
blob: c7dee92618ac68c2c4bc7137fe23980cd59fbf10 (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
# We expect a warning with this textual form:
#
# | In file included from PATH/crash-test-ice-header-sarif-2.1.c:5:
# | PATH/crash-test-ice-in-header-sarif-2.1.c: In function 'test_inject_ice':
# | PATH/crash-test-ice-in-header.h:3:22: internal compiler error: I'm sorry Dave, I'm afraid I can't do that
# |     3 | #define INJECT_ICE() inject_ice ()
# |       |                      ^~~~~~~~~~~~~
# | PATH/crash-test-ice-in-header-sarif-2.1.c:9:3: note: in expansion of macro 'INJECT_ICE'
# |     9 |   INJECT_ICE (); /* { dg-ice "" } */
# |       |   ^~~~~~~~~~

from sarif import *

import pytest

@pytest.fixture(scope='function', autouse=True)
def sarif():
    return sarif_from_env()

def test_basics(sarif):
    # We expect SARIF 2.1
    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_no_result(sarif):
    # We expect no results in the run
    runs = sarif['runs']
    run = runs[0]
    results = run['results']
    assert len(results) == 0

def test_notification(sarif):
    # We expect an execution notification for the ICE in the invocation
    runs = sarif['runs']
    run = runs[0]

    invocations = run['invocations']
    assert len(invocations) == 1
    invocation = invocations[0]

    assert invocation['executionSuccessful'] == False

    notifications = invocation['toolExecutionNotifications']
    assert len(notifications) == 1

    notification = notifications[0]

    assert notification['message']['text'] == "I'm sorry Dave, I'm afraid I can't do that"
    assert notification['level'] == 'error'

    loc0 = notification['locations'][0]
    assert get_location_artifact_uri(loc0).endswith('crash-test-ice-in-header.h')
    assert 'inject_ice ();' in get_location_snippet_text(loc0)

    # We may have backtrace information
    if 'properties' in notification:
        backtrace = notification['properties']['gcc/backtrace']
        assert 'frames' in backtrace
        # Ideally we should have a frame for pass_crash_test::execute(function*)
        # but we can't rely on this.

    # In SARIF 2.1 and earlier we aren't able to capture the include path
    # as a related location within the notification
    assert 'relationships' not in loc0
    assert 'relatedLocations' not in notification