aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs-sarif.py
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs-sarif.py')
-rw-r--r--gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs-sarif.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs-sarif.py b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs-sarif.py
new file mode 100644
index 0000000..4bb7535
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs-sarif.py
@@ -0,0 +1,55 @@
+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_result_graph(sarif):
+ runs = sarif['runs']
+ run = runs[0]
+ results = run['results']
+
+ assert len(results) == 1
+
+ result = results[0]
+ assert result['level'] == 'error'
+ assert result['message']['text'] == "this is a placeholder error, with graphs"
+
+ assert len(result['graphs']) == 2
+
+ assert result['graphs'][0]['description']['text'] == 'foo'
+
+ assert len(result['graphs'][0]['nodes']) == 2
+ assert result['graphs'][0]['nodes'][0]['id'] == 'a'
+ assert result['graphs'][0]['nodes'][1]['id'] == 'b'
+ assert result['graphs'][0]['nodes'][1]['properties']['/placeholder-prefix/color'] == 'red'
+ assert len(result['graphs'][0]['nodes'][1]['children']) == 1
+ assert result['graphs'][0]['nodes'][1]['children'][0]['id'] == 'c'
+ assert result['graphs'][0]['nodes'][1]['children'][0]['label']['text'] == 'I am a node label'
+
+ assert len(result['graphs'][0]['edges']) == 1
+ result['graphs'][0]['edges'][0]['id'] == 'my-edge'
+ assert result['graphs'][0]['edges'][0]['label']['text'] == 'I am an edge label'
+ assert result['graphs'][0]['edges'][0]['sourceNodeId'] == 'a'
+ assert result['graphs'][0]['edges'][0]['targetNodeId'] == 'c'
+
+ assert result['graphs'][1]['description']['text'] == 'bar'
+
+def test_run_graph(sarif):
+ runs = sarif['runs']
+ run = runs[0]
+
+ assert len(run['graphs']) == 1
+
+ assert run['graphs'][0]['description']['text'] == 'Optimization Passes'
+ assert run['graphs'][0]['nodes'][0]['id'] == 'all_lowering_passes'
+ assert run['graphs'][0]['edges'][0]['id'] == 'edge0'