Skip to content

Commit a2a419e

Browse files
committed
testsuite: Add scan-ltrans-assembler directives for LTO tests.
This patch adds new DejaGnu test directives to scan assembly output from LTRANS units during LTO compilation. These procedures enable testing of code generation in the LTRANS phase, which is essential for verifying that target-specific features are correctly preserved through the LTO pipeline. The new directives scan .ltrans*.s files produced during LTO compilation: - scan-ltrans-assembler: Checks if a pattern exists in any LTRANS assembly file for the current test - scan-ltrans-assembler-times: Verifies a pattern appears exactly N times across all LTRANS assembly files Signed-off-by: Luis Silva <luiss@synopsys.com>
1 parent 201f513 commit a2a419e

File tree

1 file changed

+120
-0
lines changed

1 file changed

+120
-0
lines changed

gcc/testsuite/lib/scanltrans.exp

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,123 @@ foreach ir { tree rtl } {
7878
}
7979
}]
8080
}
81+
82+
# Assembly scanning procedures for LTRANS output.
83+
# These scan the .ltrans*.s assembly files produced during LTO compilation.
84+
85+
# Look for a pattern in all .ltrans*.s files produced by the LTO compiler.
86+
# This combines results from all LTRANS units for the current test.
87+
proc scan-ltrans-assembler { args } {
88+
if { [llength $args] < 1 } {
89+
error "scan-ltrans-assembler: too few arguments"
90+
return
91+
}
92+
if { [llength $args] > 2 } {
93+
error "scan-ltrans-assembler: too many arguments"
94+
return
95+
}
96+
if { [llength $args] >= 2 } {
97+
switch [dg-process-target [lindex $args 1]] {
98+
"S" { }
99+
"N" { return }
100+
"F" { setup_xfail "*-*-*" }
101+
"P" { }
102+
}
103+
}
104+
105+
set testcase [testname-for-summary]
106+
set pattern [lindex $args 0]
107+
set pp_pattern [make_pattern_printable $pattern]
108+
109+
# Get the testcase name (for LTO tests, this is the executable name like
110+
# gcc-target-riscv-apex-arcv-apex-lto-test0-01.exe)
111+
set testname [lindex $testcase 0]
112+
113+
# Strip .exe extension if present
114+
set basename [file rootname $testname]
115+
116+
# Match only ltrans files for this specific test
117+
# Pattern: basename.ltrans*.s (e.g., test-01.ltrans0.ltrans.s)
118+
set output_files [dg_glob_remote "${basename}.ltrans*.s"]
119+
120+
if { $output_files == "" } {
121+
verbose -log "$testcase: no ${basename}.ltrans*.s files found"
122+
unresolved "$testcase scan-ltrans-assembler $pp_pattern"
123+
return
124+
}
125+
126+
set total_matches 0
127+
foreach file $output_files {
128+
set fd [open $file r]
129+
set text [read $fd]
130+
close $fd
131+
set matches [regexp -all -- $pattern $text]
132+
set total_matches [expr $total_matches + $matches]
133+
}
134+
135+
if { $total_matches > 0 } {
136+
pass "$testcase scan-ltrans-assembler $pp_pattern"
137+
} else {
138+
fail "$testcase scan-ltrans-assembler $pp_pattern"
139+
}
140+
}
141+
set_required_options_for scan-ltrans-assembler
142+
143+
# Check that a pattern appears exactly N times across all .ltrans.s files for this test.
144+
proc scan-ltrans-assembler-times { args } {
145+
if { [llength $args] < 2 } {
146+
error "scan-ltrans-assembler-times: too few arguments"
147+
return
148+
}
149+
if { [llength $args] > 3 } {
150+
error "scan-ltrans-assembler-times: too many arguments"
151+
return
152+
}
153+
if { [llength $args] >= 3 } {
154+
switch [dg-process-target [lindex $args 2]] {
155+
"S" { }
156+
"N" { return }
157+
"F" { setup_xfail "*-*-*" }
158+
"P" { }
159+
}
160+
}
161+
162+
set testcase [testname-for-summary]
163+
set pattern [lindex $args 0]
164+
set times [lindex $args 1]
165+
set pp_pattern [make_pattern_printable $pattern]
166+
167+
# Get the testcase name (for LTO tests, this is the executable name like
168+
# gcc-target-riscv-apex-arcv-apex-lto-test0-01.exe)
169+
set testname [lindex $testcase 0]
170+
171+
# Strip .exe extension if present
172+
set basename [file rootname $testname]
173+
174+
# Match only ltrans files for this specific test
175+
# Pattern: basename.ltrans*.s (e.g., test-01.ltrans0.ltrans.s)
176+
set output_files [dg_glob_remote "${basename}.ltrans*.s"]
177+
178+
if { $output_files == "" } {
179+
verbose -log "$testcase: no ${basename}.ltrans*.s files found"
180+
unresolved "$testcase scan-ltrans-assembler-times $pp_pattern $times"
181+
return
182+
}
183+
184+
set total_matches 0
185+
foreach file $output_files {
186+
set fd [open $file r]
187+
set text [read $fd]
188+
close $fd
189+
set matches [regexp -all -- $pattern $text]
190+
set total_matches [expr $total_matches + $matches]
191+
}
192+
193+
if { $total_matches == $times } {
194+
pass "$testcase scan-ltrans-assembler-times $pp_pattern $times"
195+
} else {
196+
verbose -log "$testcase: $pp_pattern found $total_matches times"
197+
fail "$testcase scan-ltrans-assembler-times $pp_pattern $times"
198+
}
199+
}
200+
set_required_options_for scan-ltrans-assembler-times

0 commit comments

Comments
 (0)