[gcc r15-1633] testsuite: use check-jsonschema for validating .sarif files [PR109360]

David Malcolm dmalcolm@gcc.gnu.org
Wed Jun 26 00:29:33 GMT 2024


https://gcc.gnu.org/g:17967907102099806dc80c71ee7665ffb22ffa23

commit r15-1633-g17967907102099806dc80c71ee7665ffb22ffa23
Author: David Malcolm <dmalcolm@redhat.com>
Date:   Tue Jun 25 20:26:21 2024 -0400

    testsuite: use check-jsonschema for validating .sarif files [PR109360]
    
    As reported here:
      https://gcc.gnu.org/pipermail/gcc-patches/2024-June/655434.html
    the schema validation I added for generated .sarif files in
    r15-1541-ga84fe222029ff2 used the "jsonschema" command line tool, which
    has been deprecated by more recent versions of the Python 3 "jsonschema"
    module.
    
    This patch updates the validation to use the more recent
    "check-jsonschema" command line tool, from the Python 3 "check-jsonschema"
    module, fixing the testsuite FAILs due to the deprecation message.
    
    As an added bonus, the output on validation failures is *much* nicer, e.g.
    if I undo r15-1540-g9f4fdc3acebcf6, the error messages begin like this:
    verify-sarif-file: res: Schema validation errors were encountered.
      diagnostic-format-sarif-file-bad-utf8-pr109098-1.c.sarif::$.runs[0].results[0].locations[0].physicalLocation.region.startColumn: 0 is less than the minimum of 1
      diagnostic-format-sarif-file-bad-utf8-pr109098-1.c.sarif::$.runs[0].results[0].relatedLocations[0].physicalLocation.region.startColumn: 0 is less than the minimum of 1
      diagnostic-format-sarif-file-bad-utf8-pr109098-1.c.sarif::$.runs[0].results[0].relatedLocations[1].physicalLocation.region.startColumn: 0 is less than the minimum of 1
      diagnostic-format-sarif-file-bad-utf8-pr109098-1.c.sarif::$.runs[0].results[0].relatedLocations[2].physicalLocation.region.startColumn: 0 is less than the minimum of 1
    child process exited abnormally
    FAIL: c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-1.c  -Wc++-compat   (test .sarif output against SARIF schema)
    
    Tested with Python 3.8 with check_jsonschema 0.28.6
    
    gcc/ChangeLog:
            PR testsuite/109360
            * doc/install.texi (Python3 modules): Update SARIF validation
            requirement to use check-jsonschema rather than jsonschema.
    
    gcc/testsuite/ChangeLog:
            PR testsuite/109360
            * lib/scansarif.exp (verify-sarif-file): Use check-jsonschema
            rather than jsonschema, updating the invocation accordingly.
            * lib/target-supports.exp (check_effective_target_jsonschema): Convert
            to...
            (check_effective_target_check_jsonschema): ...this.
    
    Signed-off-by: David Malcolm <dmalcolm@redhat.com>

Diff:
---
 gcc/doc/install.texi                  | 7 ++++---
 gcc/testsuite/lib/scansarif.exp       | 8 ++++----
 gcc/testsuite/lib/target-supports.exp | 6 +++---
 3 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index 0c769165146..b5456992583 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -461,9 +461,10 @@ is shown below:
 @code{gcov}, @code{gzip}, @code{json}, @code{os} and @code{pytest}.
 
 @item SARIF testsuite
-Tests of SARIF output will use the @code{jsonschema} program from the
-@code{jsonschema} module (if available) to validate generated .sarif files.
-If this tool is not found, the validation parts of those tests are skipped.
+Tests of SARIF output will use the @code{check-jsonschema} program from
+the @code{check-jsonschema} module (if available) to validate generated
+.sarif files.  If this tool is not found, the validation parts of those
+tests are skipped.
 
 @item c++ cxx api generation
 @code{csv}, @code{os}, @code{sys} and @code{time}.
diff --git a/gcc/testsuite/lib/scansarif.exp b/gcc/testsuite/lib/scansarif.exp
index 3eb38b8102e..cc0890ef5d8 100644
--- a/gcc/testsuite/lib/scansarif.exp
+++ b/gcc/testsuite/lib/scansarif.exp
@@ -57,7 +57,7 @@ proc scan-sarif-file-not { args } {
 # Assuming python3 is available, use verify-sarif-file.py to check
 # that the .sarif file is UTF-8 encoded and is parseable as JSON.
 #
-# Assuming "jsonschema" is available, use it to verify that the .sarif
+# Assuming "check-jsonschema" is available, use it to verify that the .sarif
 # file complies with the SARIF schema.
 
 proc verify-sarif-file { args } {
@@ -86,8 +86,8 @@ proc verify-sarif-file { args } {
     # Verify that the file complies with the SARIF schema.
 
     # Check that jsonschema is installed.
-    if { ![check_effective_target_jsonschema] } {
-	unsupported "$testcase verify-sarif-file: jsonschema is missing"
+    if { ![check_effective_target_check_jsonschema] } {
+	unsupported "$testcase verify-sarif-file: check-jsonschema is missing"
 	return	
     }
 
@@ -95,7 +95,7 @@ proc verify-sarif-file { args } {
     verbose "schema_file: $schema_file" 2
 
     set what "$testcase (test .sarif output against SARIF schema)"
-    if [catch {exec jsonschema --instance $output_file $schema_file} res ] {
+    if [catch {exec check-jsonschema --schemafile $schema_file $output_file} res ] {
 	verbose "verify-sarif-file: res: $res" 2
 	fail "$what"
 	return
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index 47ef8f41fb7..b7df6150bcb 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -13594,10 +13594,10 @@ proc check_effective_target_heap_trampoline {} {
     return 0
 }
 
-# Return 1 if jsonschema is available.
+# Return 1 if check-jsonschema is available.
 
-proc check_effective_target_jsonschema { } {
-    set result [remote_exec host "jsonschema --version"]
+proc check_effective_target_check_jsonschema { } {
+    set result [remote_exec host "check-jsonschema --version"]
     set status [lindex $result 0]
     if { $status == 0 } then {
         return 1;


More information about the Gcc-cvs mailing list