]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/lib/scansarif.exp
Update copyright years.
[thirdparty/gcc.git] / gcc / testsuite / lib / scansarif.exp
1 # Copyright (C) 2000-2024 Free Software Foundation, Inc.
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with GCC; see the file COPYING3. If not see
15 # <http://www.gnu.org/licenses/>.
16
17 # Various utilities for scanning SARIF output, used by gcc-dg.exp and
18 # g++-dg.exp.
19 #
20 # This is largely borrowed from scanasm.exp, but tweaked to force Tcl
21 # to treat the file as UTF-8: section 3.1 of SARIF 2.1.0
22 # ("File Format" > "General") specifies: "A SARIF log file SHALL be
23 # encoded in UTF-8 [RFC3629])".
24
25 # Look for a pattern in the .sarif file produced by the compiler. See
26 # dg-scan for details.
27
28 proc scan-sarif-file { args } {
29 set testcase [testname-for-summary]
30 # The name might include a list of options; extract the file name.
31 set filename [lindex $testcase 0]
32 set output_file "[file tail $filename].sarif"
33
34 # Treat the file as UTF-8 encoded when reading it.
35 set args [append_encoding_arg $args "utf-8"]
36
37 dg-scan "scan-sarif-file" 1 $testcase $output_file $args
38 }
39
40 # Check that a pattern is not present in the .sarif file. See dg-scan
41 # for details.
42
43 proc scan-sarif-file-not { args } {
44 set testcase [testname-for-summary]
45 # The name might include a list of options; extract the file name.
46 set filename [lindex $testcase 0]
47 set output_file "[file tail $filename].sarif"
48
49 # Treat the file as UTF-8 encoded when reading it.
50 set args [append_encoding_arg $args "utf-8"]
51
52 dg-scan "scan-sarif-file-not" 0 $testcase $output_file $args
53 }
54
55 # Perform validity checks on the .sarif file produced by the compiler.
56 #
57 # Assuming python3 is available, use verify-sarif-file.py to check
58 # that the .sarif file is UTF-8 encoded and is parseable as JSON.
59
60 proc verify-sarif-file { args } {
61 global srcdir subdir
62
63 set testcase [testname-for-summary]
64 set filename [lindex $testcase 0]
65 set output_file "[file tail $filename].sarif"
66
67 if { ![check_effective_target_recent_python3] } {
68 unsupported "$testcase verify-sarif-file: python3 is missing"
69 return
70 }
71
72 # Verify that the file is correctly encoded and is parseable as JSON.
73 set script_name $srcdir/lib/verify-sarif-file.py
74 set what "$testcase (test .sarif output for UTF-8-encoded parseable JSON)"
75 if [catch {exec python3 $script_name $output_file} res ] {
76 verbose "verify-sarif-file: res: $res" 2
77 fail "$what"
78 return
79 } else {
80 pass "$what"
81 }
82 }