OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.2.2/] [gcc/] [testsuite/] [lib/] [gcc-dg.exp] - Blame information for rev 318

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 149 jeremybenn
#   Copyright (C) 1997, 1999, 2000, 2003, 2004, 2005, 2006, 2007
2
#   Free Software Foundation, Inc.
3
 
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 3 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with GCC; see the file COPYING3.  If not see
16
# .
17
 
18
load_lib dg.exp
19
load_lib file-format.exp
20
load_lib target-supports.exp
21
load_lib target-supports-dg.exp
22
load_lib scanasm.exp
23
load_lib scanrtl.exp
24
load_lib scantree.exp
25
load_lib scanipa.exp
26
load_lib prune.exp
27
load_lib libgloss.exp
28
load_lib target-libpath.exp
29
 
30
# We set LC_ALL and LANG to C so that we get the same error messages as expected.
31
setenv LC_ALL C
32
setenv LANG C
33
 
34
if ![info exists TORTURE_OPTIONS] {
35
    # It is theoretically beneficial to group all of the O2/O3 options together,
36
    # as in many cases the compiler will generate identical executables for
37
    # all of them--and the c-torture testsuite will skip testing identical
38
    # executables multiple times.
39
    # Also note that -finline-functions is explicitly included in one of the
40
    # items below, even though -O3 is also specified, because some ports may
41
    # choose to disable inlining functions by default, even when optimizing.
42
    set TORTURE_OPTIONS [list \
43
        { -O0 } \
44
        { -O1 } \
45
        { -O2 } \
46
        { -O3 -fomit-frame-pointer } \
47
        { -O3 -fomit-frame-pointer -funroll-loops } \
48
        { -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions } \
49
        { -O3 -g } \
50
        { -Os } ]
51
}
52
 
53
global GCC_UNDER_TEST
54
if ![info exists GCC_UNDER_TEST] {
55
    set GCC_UNDER_TEST "[find_gcc]"
56
}
57
 
58
global orig_environment_saved
59
 
60
# This file may be sourced, so don't override environment settings
61
# that have been previously setup.
62
if { $orig_environment_saved == 0 } {
63
    append ld_library_path [gcc-set-multilib-library-path $GCC_UNDER_TEST]
64
    set_ld_library_path_env_vars
65
}
66
 
67
# Split TORTURE_OPTIONS into two choices: one for testcases with loops and
68
# one for testcases without loops.
69
 
70
set torture_with_loops $TORTURE_OPTIONS
71
set torture_without_loops ""
72
foreach option $TORTURE_OPTIONS {
73
    if ![string match "*loop*" $option] {
74
        lappend torture_without_loops $option
75
    }
76
}
77
 
78
# Define gcc callbacks for dg.exp.
79
 
80
proc gcc-dg-test-1 { target_compile prog do_what extra_tool_flags } {
81
    # Set up the compiler flags, based on what we're going to do.
82
 
83
    set options [list]
84
 
85
    # Tests should be able to use "dg-do repo".  However, the dg test
86
    # driver checks the argument to dg-do against a list of acceptable
87
    # options, and "repo" is not among them.  Therefore, we resort to
88
    # this ugly approach.
89
    if [string match "*-frepo*" $extra_tool_flags] then {
90
        set do_what "repo"
91
    }
92
 
93
    switch $do_what {
94
        "preprocess" {
95
            set compile_type "preprocess"
96
            set output_file "[file rootname [file tail $prog]].i"
97
        }
98
        "compile" {
99
            set compile_type "assembly"
100
            set output_file "[file rootname [file tail $prog]].s"
101
        }
102
        "assemble" {
103
            set compile_type "object"
104
            set output_file "[file rootname [file tail $prog]].o"
105
        }
106
        "precompile" {
107
            set compile_type "precompiled_header"
108
            set output_file "[file tail $prog].gch"
109
        }
110
        "link" {
111
            set compile_type "executable"
112
            set output_file "[file rootname [file tail $prog]].exe"
113
            # The following line is needed for targets like the i960 where
114
            # the default output file is b.out.  Sigh.
115
        }
116
        "repo" {
117
            set compile_type "object"
118
            set output_file "[file rootname [file tail $prog]].o"
119
        }
120
        "run" {
121
            set compile_type "executable"
122
            # FIXME: "./" is to cope with "." not being in $PATH.
123
            # Should this be handled elsewhere?
124
            # YES.
125
            set output_file "./[file rootname [file tail $prog]].exe"
126
            # This is the only place where we care if an executable was
127
            # created or not.  If it was, dg.exp will try to run it.
128
            catch { remote_file build delete $output_file }
129
        }
130
        default {
131
            perror "$do_what: not a valid dg-do keyword"
132
            return ""
133
        }
134
    }
135
 
136
    if { $extra_tool_flags != "" } {
137
        lappend options "additional_flags=$extra_tool_flags"
138
    }
139
 
140
    set comp_output [$target_compile "$prog" "$output_file" "$compile_type" $options]
141
 
142
    # Look for an internal compiler error, which sometimes masks the fact
143
    # that we didn't get an expected error message.  An ICE always fails,
144
    # there's no way to XFAIL it.
145
    if [string match "*internal compiler error*" $comp_output] {
146
        upvar 2 name name
147
        fail "$name (internal compiler error)"
148
    }
149
 
150
    if { $do_what == "repo" } {
151
        set object_file "$output_file"
152
        set output_file "[file rootname [file tail $prog]].exe"
153
        set comp_output \
154
            [ concat $comp_output \
155
                  [$target_compile "$object_file" "$output_file" \
156
                       "executable" $options] ]
157
    }
158
 
159
    return [list $comp_output $output_file]
160
}
161
 
162
proc gcc-dg-test { prog do_what extra_tool_flags } {
163
    return [gcc-dg-test-1 gcc_target_compile $prog $do_what $extra_tool_flags]
164
}
165
 
166
proc gcc-dg-prune { system text } {
167
    global additional_prunes
168
 
169
    set text [prune_gcc_output $text]
170
 
171
    foreach p $additional_prunes {
172
        if { [string length $p] > 0 } {
173
            # Following regexp matches a complete line containing $p.
174
            regsub -all "(^|\n)\[^\n\]*$p\[^\n\]*" $text "" text
175
        }
176
    }
177
 
178
    # If we see "region xxx is full" then the testcase is too big for ram.
179
    # This is tricky to deal with in a large testsuite like c-torture so
180
    # deal with it here.  Just mark the testcase as unsupported.
181
    if [regexp "(^|\n)\[^\n\]*: region \[^\n\]* is full" $text] {
182
        # The format here is important.  See dg.exp.
183
        return "::unsupported::memory full"
184
    }
185
 
186
    return $text
187
}
188
 
189
# Replace ${tool}_load with a wrapper to provide for an expected nonzero
190
# exit status.  Multiple languages include this file so this handles them
191
# all, not just gcc.
192
if { [info procs ${tool}_load] != [list] \
193
      && [info procs saved_${tool}_load] == [list] } {
194
    rename ${tool}_load saved_${tool}_load
195
 
196
    proc ${tool}_load { program args } {
197
        global tool
198
        global shouldfail
199
        set result [eval [list saved_${tool}_load $program] $args]
200
        if { $shouldfail != 0 } {
201
            switch [lindex $result 0] {
202
                "pass" { set status "fail" }
203
                "fail" { set status "pass" }
204
            }
205
            set result [list $status [lindex $result 1]]
206
        }
207
        return $result
208
    }
209
}
210
 
211
# Utility routines.
212
 
213
#
214
# search_for -- looks for a string match in a file
215
#
216
proc search_for { file pattern } {
217
    set fd [open $file r]
218
    while { [gets $fd cur_line]>=0 } {
219
        if [string match "*$pattern*" $cur_line] then {
220
            close $fd
221
            return 1
222
        }
223
    }
224
    close $fd
225
    return 0
226
}
227
 
228
# Modified dg-runtest that can cycle through a list of optimization options
229
# as c-torture does.
230
proc gcc-dg-runtest { testcases default-extra-flags } {
231
    global runtests
232
 
233
    foreach test $testcases {
234
        # If we're only testing specific files and this isn't one of
235
        # them, skip it.
236
        if ![runtest_file_p $runtests $test] {
237
            continue
238
        }
239
 
240
        # Look for a loop within the source code - if we don't find one,
241
        # don't pass -funroll[-all]-loops.
242
        global torture_with_loops torture_without_loops
243
        if [expr [search_for $test "for*("]+[search_for $test "while*("]] {
244
            set option_list $torture_with_loops
245
        } else {
246
            set option_list $torture_without_loops
247
        }
248
 
249
        set nshort [file tail [file dirname $test]]/[file tail $test]
250
 
251
        foreach flags $option_list {
252
            verbose "Testing $nshort, $flags" 1
253
            dg-test $test $flags ${default-extra-flags}
254
        }
255
    }
256
}
257
 
258
proc gcc-dg-debug-runtest { target_compile trivial opt_opts testcases } {
259
    global srcdir subdir
260
 
261
    if ![info exists DEBUG_TORTURE_OPTIONS] {
262
        set DEBUG_TORTURE_OPTIONS ""
263
        foreach type {-gdwarf-2 -gstabs -gstabs+ -gxcoff -gxcoff+ -gcoff} {
264
            set comp_output [$target_compile \
265
                    "$srcdir/$subdir/$trivial" "trivial.S" assembly \
266
                    "additional_flags=$type"]
267
            if { ! [string match "*: target system does not support the * debug format*" \
268
                    $comp_output] } {
269
                foreach level {1 "" 3} {
270
                    lappend DEBUG_TORTURE_OPTIONS [list "${type}${level}"]
271
                    foreach opt $opt_opts {
272
                        lappend DEBUG_TORTURE_OPTIONS \
273
                                [list "${type}${level}" "$opt" ]
274
                    }
275
                }
276
            }
277
        }
278
    }
279
 
280
    verbose -log "Using options $DEBUG_TORTURE_OPTIONS"
281
 
282
    global runtests
283
 
284
    foreach test $testcases {
285
        # If we're only testing specific files and this isn't one of
286
        # them, skip it.
287
        if ![runtest_file_p $runtests $test] {
288
            continue
289
        }
290
 
291
        set nshort [file tail [file dirname $test]]/[file tail $test]
292
 
293
        foreach flags $DEBUG_TORTURE_OPTIONS {
294
            set doit 1
295
 
296
            # These tests check for information which may be deliberately
297
            # suppressed at -g1.
298
            if { ([string match {*/debug-[126].c} "$nshort"] \
299
                   || [string match {*/enum-1.c} "$nshort"] \
300
                   || [string match {*/enum-[12].C} "$nshort"]) \
301
                    && [string match "*1" [lindex "$flags" 0] ] } {
302
                set doit 0
303
            }
304
 
305
    # High optimization can remove the variable whose existence is tested.
306
    # Dwarf debugging with commentary (-dA) preserves the symbol name in the
307
    # assembler output, but stabs debugging does not.
308
    # http://gcc.gnu.org/ml/gcc-regression/2003-04/msg00095.html
309
            if { [string match {*/debug-[12].c} "$nshort"] \
310
                    && [string match "*O*" "$flags"] \
311
                    && ( [string match "*coff*" "$flags"] \
312
                         || [string match "*stabs*" "$flags"] ) } {
313
                set doit 0
314
            }
315
 
316
            if { $doit } {
317
                verbose -log "Testing $nshort, $flags" 1
318
                dg-test $test $flags ""
319
            }
320
        }
321
    }
322
}
323
 
324
# Prune any messages matching ARGS[1] (a regexp) from test output.
325
proc dg-prune-output { args } {
326
    global additional_prunes
327
 
328
    if { [llength $args] != 2 } {
329
        error "[lindex $args 1]: need one argument"
330
        return
331
    }
332
 
333
    lappend additional_prunes [lindex $args 1]
334
}
335
 
336
# Remove files matching the pattern from the build machine.
337
proc remove-build-file { pat } {
338
    verbose "remove-build-file `$pat'" 2
339
    set file_list "[glob -nocomplain $pat]"
340
    verbose "remove-build-file `$file_list'" 2
341
    foreach output_file $file_list {
342
        remote_file build delete $output_file
343
    }
344
}
345
 
346
# Remove compiler-generated coverage files for the current test.
347
proc cleanup-coverage-files { } {
348
    # This assumes that we are two frames down from dg-test or some other proc
349
    # that stores the filename of the testcase in a local variable "name".
350
    # A cleaner solution would require a new DejaGnu release.
351
    upvar 2 name testcase
352
    remove-build-file "[file rootname [file tail $testcase]].gc??"
353
 
354
    # Clean up coverage files for additional source files.
355
    if [info exists additional_sources] {
356
        foreach srcfile $additional_sources {
357
            remove-build-file "[file rootname [file tail $srcfile]].gc??"
358
        }
359
    }
360
}
361
 
362
# Remove compiler-generated files from -repo for the current test.
363
proc cleanup-repo-files { } {
364
    # This assumes that we are two frames down from dg-test or some other proc
365
    # that stores the filename of the testcase in a local variable "name".
366
    # A cleaner solution would require a new DejaGnu release.
367
    upvar 2 name testcase
368
    remove-build-file "[file rootname [file tail $testcase]].o"
369
    remove-build-file "[file rootname [file tail $testcase]].rpo"
370
 
371
    # Clean up files for additional source files.
372
    if [info exists additional_sources] {
373
        foreach srcfile $additional_sources {
374
            remove-build-file "[file rootname [file tail $srcfile]].o"
375
            remove-build-file "[file rootname [file tail $srcfile]].rpo"
376
        }
377
    }
378
}
379
 
380
# Remove compiler-generated RTL dump files for the current test.
381
#
382
# SUFFIX is the filename suffix pattern.
383
proc cleanup-rtl-dump { suffix } {
384
  cleanup-dump "\[0-9\]\[0-9\]\[0-9\]r.$suffix"
385
}
386
 
387
# Remove a specific tree dump file for the current test.
388
#
389
# SUFFIX is the tree dump file suffix pattern.
390
proc cleanup-tree-dump { suffix } {
391
  cleanup-dump "\[0-9\]\[0-9\]\[0-9\]t.$suffix"
392
}
393
 
394
# Remove a specific ipa dump file for the current test.
395
#
396
# SUFFIX is the ipa dump file suffix pattern.
397
proc cleanup-ipa-dump { suffix } {
398
  cleanup-dump "\[0-9\]\[0-9\]\[0-9\]i.$suffix"
399
}
400
 
401
# Remove all dump files with the provided suffix.
402
proc cleanup-dump { suffix } {
403
    # This assumes that we are three frames down from dg-test or some other
404
    # proc that stores the filename of the testcase in a local variable
405
    # "name".  A cleaner solution would require a new DejaGnu release.
406
    upvar 3 name testcase
407
    # The name might include a list of options; extract the file name.
408
    set src [file tail [lindex $testcase 0]]
409
    remove-build-file "[file tail $src].$suffix"
410
 
411
    # Clean up dump files for additional source files.
412
    if [info exists additional_sources] {
413
        foreach srcfile $additional_sources {
414
            remove-build-file "[file tail $srcfile].$suffix"
415
        }
416
    }
417
}
418
 
419
# Remove files kept by --save-temps for the current test.
420
#
421
# Currently this is only .i files, but more can be added if there are
422
# tests generating them.
423
proc cleanup-saved-temps { } {
424
    global additional_sources
425
 
426
    # This assumes that we are two frames down from dg-test or some other proc
427
    # that stores the filename of the testcase in a local variable "name".
428
    # A cleaner solution would require a new DejaGnu release.
429
    upvar 2 name testcase
430
    remove-build-file "[file rootname [file tail $testcase]].ii"
431
    remove-build-file "[file rootname [file tail $testcase]].i"
432
 
433
    # Clean up saved temp files for additional source files.
434
    if [info exists additional_sources] {
435
        foreach srcfile $additional_sources {
436
            remove-build-file "[file rootname [file tail $srcfile]].ii"
437
            remove-build-file "[file rootname [file tail $srcfile]].i"
438
        }
439
    }
440
}
441
 
442
# Remove files for specified Fortran modules.
443
proc cleanup-modules { modlist } {
444
    foreach modname $modlist {
445
        remove-build-file [string tolower $modname].mod
446
    }
447
}
448
 
449
# Verify that the compiler output file exists, invoked via dg-final.
450
proc output-exists { args } {
451
    # Process an optional target or xfail list.
452
    if { [llength $args] >= 1 } {
453
        switch [dg-process-target [lindex $args 0]] {
454
            "S" { }
455
            "N" { return }
456
            "F" { setup_xfail "*-*-*" }
457
            "P" { }
458
        }
459
    }
460
 
461
    # Access variables from gcc-dg-test-1.
462
    upvar 2 name testcase
463
    upvar 2 output_file output_file
464
 
465
    if [file exists $output_file] {
466
        pass "$testcase output-exists $output_file"
467
    } else {
468
        fail "$testcase output-exists $output_file"
469
    }
470
}
471
 
472
# Verify that the compiler output file does not exist, invoked via dg-final.
473
proc output-exists-not { args } {
474
    # Process an optional target or xfail list.
475
    if { [llength $args] >= 1 } {
476
        switch [dg-process-target [lindex $args 0]] {
477
            "S" { }
478
            "N" { return }
479
            "F" { setup_xfail "*-*-*" }
480
            "P" { }
481
        }
482
    }
483
 
484
    # Access variables from gcc-dg-test-1.
485
    upvar 2 name testcase
486
    upvar 2 output_file output_file
487
 
488
    if [file exists $output_file] {
489
        fail "$testcase output-exists-not $output_file"
490
    } else {
491
        pass "$testcase output-exists-not $output_file"
492
    }
493
}
494
 
495
# We need to make sure that additional_* are cleared out after every
496
# test.  It is not enough to clear them out *before* the next test run
497
# because gcc-target-compile gets run directly from some .exp files
498
# (outside of any test).  (Those uses should eventually be eliminated.)
499
 
500
# Because the DG framework doesn't provide a hook that is run at the
501
# end of a test, we must replace dg-test with a wrapper.
502
 
503
if { [info procs saved-dg-test] == [list] } {
504
    rename dg-test saved-dg-test
505
 
506
    proc dg-test { args } {
507
        global additional_files
508
        global additional_sources
509
        global additional_prunes
510
        global errorInfo
511
        global compiler_conditional_xfail_data
512
        global shouldfail
513
 
514
        if { [ catch { eval saved-dg-test $args } errmsg ] } {
515
            set saved_info $errorInfo
516
            set additional_files ""
517
            set additional_sources ""
518
            set additional_prunes ""
519
            set shouldfail 0
520
            if [info exists compiler_conditional_xfail_data] {
521
                unset compiler_conditional_xfail_data
522
            }
523
            error $errmsg $saved_info
524
        }
525
        set additional_files ""
526
        set additional_sources ""
527
        set additional_prunes ""
528
        set shouldfail 0
529
        if [info exists compiler_conditional_xfail_data] {
530
            unset compiler_conditional_xfail_data
531
        }
532
    }
533
}
534
 
535
set additional_prunes ""

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.