| 1 |
# We expect a warning with this textual form: |
| 2 |
# |
| 3 |
# | In file included from PATH/crash-test-ice-header-sarif-2.2.c:5: |
| 4 |
# | PATH/crash-test-ice-in-header-sarif-2.2.c: In function 'test_inject_ice': |
| 5 |
# | PATH/crash-test-ice-in-header.h:3:22: internal compiler error: I'm sorry Dave, I'm afraid I can't do that |
| 6 |
# | 3 | #define INJECT_ICE() inject_ice () |
| 7 |
# | | ^~~~~~~~~~~~~ |
| 8 |
# | PATH/crash-test-ice-in-header-sarif-2.2.c:9:3: note: in expansion of macro 'INJECT_ICE' |
| 9 |
# | 9 | INJECT_ICE (); /* { dg-ice "" } */ |
| 10 |
# | | ^~~~~~~~~~ |
| 11 |
|
| 12 |
from sarif import * |
| 13 |
|
| 14 |
import pytest |
| 15 |
|
| 16 |
@pytest.fixture(scope='function', autouse=True) |
| 17 |
def sarif(): |
| 18 |
return sarif_from_env() |
| 19 |
|
| 20 |
def test_basics(sarif): |
| 21 |
# We expect SARIF 2.2 |
| 22 |
schema = sarif['$schema'] |
| 23 |
assert schema == "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/refs/tags/2.2-prerelease-2024-08-08/sarif-2.2/schema/sarif-2-2.schema.json" |
| 24 |
|
| 25 |
version = sarif['version'] |
| 26 |
assert version == "2.2" |
| 27 |
|
| 28 |
def test_no_result(sarif): |
| 29 |
# We expect no results in the run |
| 30 |
runs = sarif['runs'] |
| 31 |
run = runs[0] |
| 32 |
results = run['results'] |
| 33 |
assert len(results) == 0 |
| 34 |
|
| 35 |
def test_notification(sarif): |
| 36 |
# We expect an execution notification for the ICE in the invocation |
| 37 |
runs = sarif['runs'] |
| 38 |
run = runs[0] |
| 39 |
|
| 40 |
invocations = run['invocations'] |
| 41 |
assert len(invocations) == 1 |
| 42 |
invocation = invocations[0] |
| 43 |
|
| 44 |
assert invocation['executionSuccessful'] == False |
| 45 |
|
| 46 |
notifications = invocation['toolExecutionNotifications'] |
| 47 |
assert len(notifications) == 1 |
| 48 |
|
| 49 |
notification = notifications[0] |
| 50 |
|
| 51 |
assert notification['message']['text'] == "I'm sorry Dave, I'm afraid I can't do that" |
| 52 |
assert notification['level'] == 'error' |
| 53 |
|
| 54 |
loc0 = notification['locations'][0] |
| 55 |
assert get_location_artifact_uri(loc0).endswith('crash-test-ice-in-header.h') |
| 56 |
assert 'inject_ice ();' in get_location_snippet_text(loc0) |
| 57 |
|
| 58 |
# We may have backtrace information |
| 59 |
if 'properties' in notification: |
| 60 |
backtrace = notification['properties']['gcc/backtrace'] |
| 61 |
assert 'frames' in backtrace |
| 62 |
# Ideally we should have a frame for pass_crash_test::execute(function*) |
| 63 |
# but we can't rely on this. |
| 64 |
|
| 65 |
# In SARIF 2.2 onwards we should be able to capture the include path |
| 66 |
# as a related location within the notification |
| 67 |
assert len(loc0['relationships']) == 1 |
| 68 |
assert loc0['relationships'][0]['kinds'] == ['isIncludedBy'] |
| 69 |
|
| 70 |
assert len(notification['relatedLocations']) == 1 |
| 71 |
rel_loc = notification['relatedLocations'][0] |
| 72 |
|
| 73 |
assert get_location_artifact_uri(rel_loc).endswith('crash-test-ice-in-header-sarif-2.2.c') |
| 74 |
assert '#include "crash-test-ice-in-header.h"' in get_location_snippet_text(rel_loc) |
| 75 |
assert len(rel_loc['relationships']) == 1 |
| 76 |
assert rel_loc['relationships'][0]['kinds'] == ['includes'] |