blob: 83e76c31de7df0bb711c88f62f03ac16869b3a43 (
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
|
# Copyright (C) 2000-2023 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GCC; see the file COPYING3. If not see
# <http://www.gnu.org/licenses/>.
# Various utilities for scanning SARIF output, used by gcc-dg.exp and
# g++-dg.exp.
#
# This is largely borrowed from scanasm.exp, but tweaked to force Tcl
# to treat the file as UTF-8: section 3.1 of SARIF 2.1.0
# ("File Format" > "General") specifies: "A SARIF log file SHALL be
# encoded in UTF-8 [RFC3629])".
# Look for a pattern in the .sarif file produced by the compiler. See
# dg-scan for details.
proc scan-sarif-file { args } {
set testcase [testname-for-summary]
# The name might include a list of options; extract the file name.
set filename [lindex $testcase 0]
set output_file "[file tail $filename].sarif"
# Treat the file as UTF-8 encoded when reading it.
set args [append_encoding_arg $args "utf-8"]
dg-scan "scan-sarif-file" 1 $testcase $output_file $args
}
# Check that a pattern is not present in the .sarif file. See dg-scan
# for details.
proc scan-sarif-file-not { args } {
set testcase [testname-for-summary]
# The name might include a list of options; extract the file name.
set filename [lindex $testcase 0]
set output_file "[file tail $filename].sarif"
# Treat the file as UTF-8 encoded when reading it.
set args [append_encoding_arg $args "utf-8"]
dg-scan "scan-sarif-file-not" 0 $testcase $output_file $args
}
# Perform validity checks on the .sarif file produced by the compiler.
#
# Assuming python3 is available, use verify-sarif-file.py to check
# that the .sarif file is UTF-8 encoded and is parseable as JSON.
proc verify-sarif-file { args } {
global srcdir subdir
set testcase [testname-for-summary]
set filename [lindex $testcase 0]
set output_file "[file tail $filename].sarif"
if { ![check_effective_target_recent_python3] } {
unsupported "$testcase verify-sarif-file: python3 is missing"
return
}
# Verify that the file is correctly encoded and is parseable as JSON.
set script_name $srcdir/lib/verify-sarif-file.py
set what "$testcase (test .sarif output for UTF-8-encoded parseable JSON)"
if [catch {exec python3 $script_name $output_file} res ] {
verbose "verify-sarif-file: res: $res" 2
fail "$what"
return
} else {
pass "$what"
}
}
|