Debian Codegraph @

gcc/testsuite/lib/gm2-torture.exp

raw
1 # Copyright (C) 2003-2025 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 # This file was written by Rob Savoye. ([email protected])
18 # and modified by Gaius Mulley ([email protected])
19 # for GNU Modula-2
20
21 load_lib file-format.exp
22 load_lib target-libpath.exp
23 load_lib timeout.exp
24
25 # The default option list can be overridden by
26 # TORTURE_OPTIONS="{ { list1 } ... { listN } }"
27
28 if ![info exists TORTURE_OPTIONS] {
29 # It is theoretically beneficial to group all of the O2/O3 options together,
30 # as in many cases the compiler will generate identical executables for
31 # all of them--and the c-torture testsuite will skip testing identical
32 # executables multiple times.
33 # Also note that -finline-functions is explicitly included in one of the
34 # items below, even though -O3 is also specified, because some ports may
35 # choose to disable inlining functions by default, even when optimizing.
36 set TORTURE_OPTIONS [list \
37 { -g } \
38 { -O } \
39 { -O -g } \
40 { -Os } \
41 { -O3 -fomit-frame-pointer } \
42 { -O3 -fomit-frame-pointer -finline-functions } ]
43 }
44
45
46 #
47 # very costly options follow
48 #
49 # set TORTURE_OPTIONS [list \
50 \# { -g } \
51 \# { -O } \
52 \# { -O -g } \
53 \# { -Os } \
54 \# { -Os -g } \
55 \# { -O0 } \
56 \# { -O0 -g } \
57 \# { -O1 } \
58 \# { -O1 -g } \
59 \# { -O2 } \
60 \# { -O2 -g } \
61 \# { -O3 } \
62 \# { -O3 -g } \
63 \# { -O3 -fomit-frame-pointer } \
64 \# { -O3 -fomit-frame-pointer -finline-functions } ]
65 #
66 #
67 #
68
69
70
71 #
72 # gm2-torture-compile -- runs the gm2-torture test
73 #
74 # SRC is the full pathname of the testcase.
75 # OPTION is the specific compiler flag we're testing (eg: -O2).
76 #
77 proc gm2-torture-compile { src option } {
78 global output;
79 global srcdir tmpdir;
80 global host_triplet;
81
82 set output "$tmpdir/[file tail [file rootname $src]].o"
83
84 regsub "^$srcdir/?" $src "" testcase
85 # If we couldn't rip $srcdir out of `src' then just do the best we can.
86 # The point is to reduce the unnecessary noise in the logs. Don't strip
87 # out too much because different testcases with the same name can confuse
88 # `test-tool'.
89 if [string match "/*" $testcase] {
90 set testcase "[file tail [file dirname $src]]/[file tail $src]"
91 }
92
93 # puts stderr "gm2-torture-compiler src = $src, option = $option\n"
94
95 # Run the compiler and analyze the results.
96 set options ""
97 lappend options "additional_flags=${option}"
98
99 set comp_output [gm2_target_compile "$src" "$output" object $options];
100 # puts stderr "*** gm2 torture compile: $comp_output ${options} "
101 gm2_check_compile $testcase "$option" $output $comp_output
102 remote_file build delete $output
103 verbose "$comp_output" 1
104 }
105
106
107 #
108 # gm2_check_compile_fail -- Reports and returns pass/fail for a compilation
109 #
110
111 proc gm2_check_compile_fail {testcase option objname gcc_output} {
112 global tool;
113 set fatal_signal "*nternal compiler error: program*got fatal signal"
114
115 if [string match "$fatal_signal 6" $gcc_output] then {
116 ${tool}_fail $testcase "Got Signal 6, $option"
117 return 0
118 }
119
120 if [string match "$fatal_signal 11" $gcc_output] then {
121 ${tool}_fail $testcase "Got Signal 11, $option"
122 return 0
123 }
124
125 # # We shouldn't get these because of -w, but just in case.
126 # if [string match "*cc:*warning:*" $gcc_output] then {
127 # warning "$testcase: (with warnings) $option"
128 # send_log "$gcc_output\n"
129 # unresolved "$testcase, $option"
130 # return 0
131 # }
132
133 set gcc_output [prune_warnings $gcc_output]
134
135 set unsupported_message [${tool}_check_unsupported_p $gcc_output]
136 if { $unsupported_message != "" } {
137 unsupported "$testcase: $unsupported_message"
138 return 0
139 }
140
141 # remove any leftover LF/CR to make sure any output is legit
142 regsub -all -- "\[\r\n\]*" $gcc_output "" gcc_output
143
144 # check for any internal error
145 if { [string match "*internal error*" $gcc_output] ||
146 [string match "*internal compiler error*" $gcc_output] } then {
147 puts stderr "ICE: "
148 ${tool}_fail $testcase $option
149 return 0
150 }
151
152 # If any message remains, we pass, as it will be the error message
153 if ![string match "" $gcc_output] then {
154 ${tool}_pass $testcase $option
155 return 1
156 }
157
158 # a clean compilation means this test has failed
159 ${tool}_fail $testcase $option
160 return 1
161 }
162
163 #
164 # gm2-torture-compile-fail -- runs the gm2-torture test
165 #
166 # SRC is the full pathname of the testcase.
167 # OPTION is the specific compiler flag we're testing (eg: -O2).
168 #
169 proc gm2-torture-compile-fail { src option } {
170 global output;
171 global srcdir tmpdir;
172 global host_triplet;
173
174 # puts stderr "gm2-torture-compile-fail: ${option}\n"
175 set output "$tmpdir/[file tail [file rootname $src]].o"
176
177 regsub "^$srcdir/?" $src "" testcase
178 # If we couldn't rip $srcdir out of `src' then just do the best we can.
179 # The point is to reduce the unnecessary noise in the logs. Don't strip
180 # out too much because different testcases with the same name can confuse
181 # `test-tool'.
182 if [string match "/*" $testcase] {
183 set testcase "[file tail [file dirname $src]]/[file tail $src]"
184 }
185
186 verbose "Testing expected failure $testcase, $option" 1
187
188 # Run the compiler and analyze the results.
189 set options ""
190 set additional_flags ""
191 lappend options "additional_flags=$option" # do not use -w for gm2
192 if { $additional_flags != "" } {
193 lappend options "additional_flags=$additional_flags"
194 }
195
196 set comp_output [gm2_target_compile "$src" "$output" object $options];
197 gm2_check_compile_fail $testcase $option $output $comp_output
198 remote_file build delete $output
199 verbose "$comp_output" 1
200 }
201
202 #
203 # gm2-torture-execute -- utility to compile and execute a testcase
204 #
205 # SOURCES is a list of full pathnames to the test source files.
206 # The first filename in this list forms the "testcase".
207 #
208 # If the testcase has an associated .x file, we source that to run the
209 # test instead. We use .x so that we don't lengthen the existing filename
210 # to more than 14 chars.
211 #
212 proc gm2-torture-execute { sources args success } {
213 global tmpdir tool srcdir output compiler_conditional_xfail_data;
214 global TORTURE_OPTIONS;
215 global gm2_link_libraries;
216 global gm2_link_objects;
217 global gm2_link_path;
218
219 # Use the first source filename given as the filename under test.
220 set src [lindex $sources 0];
221
222 if { [llength $args] > 0 } {
223 set additional_flags [lindex $args 0];
224 } else {
225 set additional_flags "";
226 }
227 # Check for alternate driver.
228 if [file exists [file rootname $src].x] {
229 verbose "Using alternate driver [file rootname [file tail $src]].x" 2
230 set done_p 0;
231 catch "set done_p \[source [file rootname $src].x\]"
232 if { $done_p } {
233 return
234 }
235 }
236
237 set executable $tmpdir/[file tail [file rootname $src].x];
238 set objectfile $tmpdir/[file tail [file rootname $src].o];
239
240 regsub "^$srcdir/?" $src "" testcase
241 # If we couldn't rip $srcdir out of `src' then just do the best we can.
242 # The point is to reduce the unnecessary noise in the logs. Don't strip
243 # out too much because different testcases with the same name can confuse
244 # `test-tool'.
245 if [string match "/*" $testcase] {
246 set testcase "[file tail [file dirname $src]]/[file tail $src]"
247 }
248
249 set option_list $TORTURE_OPTIONS;
250
251 set count 0;
252 set oldstatus "foo";
253 foreach option $option_list {
254 if { $count > 0 } {
255 set oldexec $execname;
256 }
257 set execname "${executable}${count}";
258 incr count;
259
260 # torture_{compile,execute}_xfail are set by the .x script
261 # (if present)
262 if [info exists torture_compile_xfail] {
263 setup_xfail $torture_compile_xfail
264 }
265
266 # torture_execute_before_{compile,execute} can be set by the .x script
267 # (if present)
268 if [info exists torture_eval_before_compile] {
269 set ignore_me [eval $torture_eval_before_compile]
270 }
271
272 remote_file build delete $execname;
273 verbose "Testing $testcase, $option" 1
274
275 set options ""
276 lappend options "additional_flags=$option"
277 lappend options "timeout=[timeout_value]"
278 if { $additional_flags != "" } {
279 lappend options "additional_flags=$additional_flags"
280 }
281 set comp_output [gm2_target_compile "$sources" "${objectfile}" object "$options"];
282
283 # puts stderr "torture gm2 case: $comp_output ${options} "
284
285 if ![gm2_check_compile "$testcase compilation" ${options} $objectfile $comp_output] {
286 unresolved "$testcase execution, ${options}"
287 send_log "compile failed not attempting link\n"
288 remote_file build delete $objectfile
289 continue
290 }
291
292 send_log "finished compile now attempting link\n"
293 # now link the test
294 set options ${option};
295
296 lappend options "timeout=[timeout_value]"
297 if { [llength ${args}] > 0 } {
298 lappend options "additional_flags=[lindex ${args} 0]"
299 }
300
301 lappend options " additional_flags=${gm2_link_path}"
302
303 if {$gm2_link_path != ""} {
304 lappend options " ldflags=$gm2_link_path"
305 }
306
307 if {$gm2_link_libraries != ""} {
308 lappend options " ldflags=$gm2_link_libraries"
309 }
310
311 # lappend options "ldflags=/home/gaius/GM2/graft-combine/build-devel-modula2-enabled/x86_64-pc-linux-gnu/libgm2/libm2pim/.libs/libm2pim.a"
312 # lappend options "ldflags=/home/gaius/GM2/graft-combine/build-devel-modula2-enabled/x86_64-pc-linux-gnu/libgm2/libm2iso/.libs/libm2iso.a"
313 # lappend options "ldflags=-lm2pim -lm2iso"
314 #
315 if {$gm2_link_objects != ""} {
316 lappend options " additional_flags=${gm2_link_objects}"
317 }
318 if {$gm2_link_path != ""} {
319 lappend options " additional_flags=${gm2_link_path}"
320 }
321
322 # lappend options " additional_flags=${gm2_link_objects}"
323 # lappend options " additional_flags=${gm2_link_path}"
324 # lappend options " additional_flags=${gm2_link_libraries}"
325 set options [concat "{additional_flags=$gm2_link_path} " $options]
326 set options [concat "{additional_flags=-fno-libs=-} " $options]
327 set options [concat "{additional_flags=$gm2_link_objects} " $options]
328 # set options [concat "{additional_flags=$gm2_link_libraries} " $options]
329
330 send_log "gm2_link_path = $gm2_link_path\n"
331 send_log "attempting link\n"
332 set comp_output [gm2_target_compile "${sources}" "${execname}" executable ${options}];
333 # puts "Link libraries are: ${gm2_link_libraries}"
334 # puts "Link path is : ${gm2_link_path}"
335
336 if ![gm2_check_compile "${testcase} compilation" ${option} ${execname} ${comp_output}] {
337 send_log "unsuccessful link\n"
338 unresolved "${testcase} execution, ${option} (link failed)"
339 verbose "tried to link ${testcase} ${sources} ${execname} executable ${options}" 1
340 verbose "Link libraries are: ${gm2_link_libraries}" 1
341 verbose "Link path is : ${gm2_link_path}" 1
342 verbose "$comp_output" 1
343 lappend options "additional_flags=-fsources"
344 lappend options "additional_flags=-v"
345 verbose "****** s t a r t *********" 1
346 set comp_output [gm2_target_compile "$sources" "${objectfile}" object ${options}];
347 verbose "$comp_output" 1
348 set comp_output [gm2_target_compile "${sources}" "${execname}" executable ${options}];
349 verbose "$comp_output" 1
350 verbose "****** e n d *********" 1
351 remote_file build delete $execname
352 remote_file build delete $objectfile
353 continue
354 }
355
356 send_log "successful link\n"
357 # See if this source file uses "long long" types, if it does, and
358 # no_long_long is set, skip execution of the test.
359 if [target_info exists no_long_long] then {
360 if [expr [search_for $src "long long"]] then {
361 unsupported "$testcase execution, $option"
362 continue
363 }
364 }
365
366 if [info exists torture_execute_xfail] {
367 setup_xfail $torture_execute_xfail
368 }
369
370 if [info exists torture_eval_before_execute] {
371 set ignore_me [eval $torture_eval_before_execute]
372 }
373
374 # Sometimes we end up creating identical executables for two
375 # consecutive sets of different of compiler options.
376 #
377 # In such cases we know the result of this test will be identical
378 # to the result of the last test.
379 #
380 # So in cases where the time to load and run/simulate the test
381 # is relatively high, compare the two binaries and avoid rerunning
382 # tests if the executables are identical.
383 #
384 # Do not do this for native testing since the cost to load/execute
385 # the test is fairly small and the comparison step actually slows
386 # the entire process down because it usually does not "hit".
387 set skip 0;
388 if { ![isnative] && [info exists oldexec] } {
389 if { [remote_file build cmp $oldexec $execname] == 0 } {
390 set skip 1;
391 }
392 }
393 if { $skip == 0 } {
394 set result [gm2_load "$execname" "" ""]
395 set status [lindex $result 0];
396 set output [lindex $result 1];
397 if { $success == "fail" } {
398 # invert the result
399 if { $status == "pass" } {
400 set status "fail"
401 } else {
402 set status "pass"
403 }
404 }
405 send_log "executed $execname with result $status"
406 }
407 if { $oldstatus == "pass" } {
408 remote_file build delete $oldexec;
409 }
410 $status "$testcase execution, $option"
411 set oldstatus $status;
412 }
413 if [info exists status] {
414 if { $status == "pass" } {
415 remote_file build delete $execname;
416 remote_file build delete $objectfile;
417 }
418 }
419 }
420
421 #
422 # search_for -- looks for a string match in a file
423 #
424 proc search_for { file pattern } {
425 set fd [open $file r]
426 while { [gets $fd cur_line]>=0 } {
427 if [string match "*$pattern*" $cur_line] then {
428 close $fd
429 return 1
430 }
431 }
432 close $fd
433 return 0
434 }
435
436 #
437 # gm2-torture -- the gm2-torture testcase source file processor
438 #
439 # This runs compilation only tests (no execute tests).
440 # SRC is the full pathname of the testcase, or just a file name in which case
441 # we prepend $srcdir/$subdir.
442 #
443 # If the testcase has an associated .x file, we source that to run the
444 # test instead. We use .x so that we don't lengthen the existing filename
445 # to more than 14 chars.
446 #
447 proc gm2-torture { args } {
448 global srcdir subdir compiler_conditional_xfail_data TORTURE_OPTIONS;
449
450 set src [lindex $args 0];
451 if { [llength $args] > 1 } {
452 set options [lindex $args 1];
453 } else {
454 set options ""
455 }
456
457 # Prepend $srdir/$subdir if missing.
458 if ![string match "*/*" $src] {
459 set src "$srcdir/$subdir/$src"
460 }
461
462 # Check for alternate driver.
463 if [file exists [file rootname $src].x] {
464 verbose "Using alternate driver [file rootname [file tail $src]].x" 2
465 set done_p 0
466 catch "set done_p \[source [file rootname $src].x\]"
467 if { $done_p } {
468 return
469 }
470 }
471
472 set option_list $TORTURE_OPTIONS
473
474 # loop through all the options
475 foreach option $option_list {
476 # torture_compile_xfail is set by the .x script (if present)
477 if [info exists torture_compile_xfail] {
478 setup_xfail $torture_compile_xfail
479 }
480
481 # torture_execute_before_compile is set by the .x script (if present)
482 if [info exists torture_eval_before_compile] {
483 set ignore_me [eval $torture_eval_before_compile]
484 }
485
486 gm2-torture-compile $src "$option $options"
487 }
488 }
489
490 #
491 # gm2-torture -- the gm2-torture testcase source file processor
492 #
493 # This runs compilation only tests (no execute tests).
494 # SRC is the full pathname of the testcase, or just a file name in which case
495 # we prepend $srcdir/$subdir.
496 #
497 # If the testcase has an associated .x file, we source that to run the
498 # test instead. We use .x so that we don't lengthen the existing filename
499 # to more than 14 chars.
500 #
501 proc gm2-torture-fail { args } {
502 global srcdir subdir compiler_conditional_xfail_data TORTURE_OPTIONS;
503
504 set src [lindex $args 0];
505 if { [llength $args] > 1 } {
506 set options [lindex $args 1];
507 } else {
508 set options ""
509 }
510
511 # Prepend $srdir/$subdir if missing.
512 if ![string match "*/*" $src] {
513 set src "$srcdir/$subdir/$src"
514 }
515
516 # Check for alternate driver.
517 if [file exists [file rootname $src].x] {
518 verbose "Using alternate driver [file rootname [file tail $src]].x" 2
519 set done_p 0
520 catch "set done_p \[source [file rootname $src].x\]"
521 if { $done_p } {
522 return
523 }
524 }
525
526 set option_list $TORTURE_OPTIONS
527
528 # loop through all the options
529 foreach option $option_list {
530 # torture_compile_xfail is set by the .x script (if present)
531 if [info exists torture_compile_xfail] {
532 setup_xfail $torture_compile_xfail
533 }
534
535 # torture_execute_before_compile is set by the .x script (if present)
536 if [info exists torture_eval_before_compile] {
537 set ignore_me [eval $torture_eval_before_compile]
538 }
539
540 gm2-torture-compile-fail $src "$option $options"
541 }
542 }