aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/lib
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/testsuite/lib')
-rw-r--r--gcc/testsuite/lib/scanasm.exp22
-rw-r--r--gcc/testsuite/lib/scansarif.exp13
2 files changed, 32 insertions, 3 deletions
diff --git a/gcc/testsuite/lib/scanasm.exp b/gcc/testsuite/lib/scanasm.exp
index 4b018ab..fb53544 100644
--- a/gcc/testsuite/lib/scanasm.exp
+++ b/gcc/testsuite/lib/scanasm.exp
@@ -24,19 +24,33 @@ proc make_pattern_printable { pattern } {
return [string map {\t \\t \n \\n \r \\r \\ \\\\} $pattern]
}
+# Append to ARGS to make it suitable for use by dg-scan to indicate
+# that encoding ENC should be used when reading from the file.
+
+proc append_encoding_arg { args enc } {
+ if { [llength $args] < 2 } {
+ # Add target selector.
+ lappend args { target "*-*-*" }
+ }
+ # Add encoding ENC.
+ lappend args $enc
+ return $args
+}
+
# Scan the OUTPUT_FILE for a pattern. If it is present and POSITIVE
# is non-zero, or it is not present and POSITIVE is zero, the test
# passes. The ORIG_ARGS is the list of arguments provided by dg-final
# to scan-assembler. The first element in ORIG_ARGS is the regular
# expression to look for in the file. The second element, if present,
-# is a DejaGNU target selector.
+# is a DejaGNU target selector. The third element, if present, is the
+# encoding to use when reading from the file.
proc dg-scan { name positive testcase output_file orig_args } {
if { [llength $orig_args] < 1 } {
error "$name: too few arguments"
return
}
- if { [llength $orig_args] > 2 } {
+ if { [llength $orig_args] > 3 } {
error "$name: too many arguments"
return
}
@@ -59,6 +73,10 @@ proc dg-scan { name positive testcase output_file orig_args } {
return
}
set fd [open $output_file r]
+ if { [llength $orig_args] >= 3 } {
+ set file_encoding [lindex $orig_args 2]
+ fconfigure $fd -encoding $file_encoding
+ }
set text [read $fd]
close $fd
diff --git a/gcc/testsuite/lib/scansarif.exp b/gcc/testsuite/lib/scansarif.exp
index d06390b..05524aa 100644
--- a/gcc/testsuite/lib/scansarif.exp
+++ b/gcc/testsuite/lib/scansarif.exp
@@ -17,7 +17,10 @@
# Various utilities for scanning SARIF output, used by gcc-dg.exp and
# g++-dg.exp.
#
-# This is largely borrowed from scanasm.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.
@@ -27,6 +30,10 @@ proc scan-sarif-file { args } {
# 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
}
@@ -38,5 +45,9 @@ proc scan-sarif-file-not { args } {
# 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
}