summaryrefslogtreecommitdiff
path: root/gcc/testsuite/lib/options.exp
blob: b8503078c0f634f70d295e95e68354a1517adbc6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# Copyright (C) 2009-2019 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GCC; see the file COPYING3.  If not see
# <http://www.gnu.org/licenses/>.

# We set LC_ALL and LANG to C so that we get the same error messages as expected.
setenv LC_ALL C
setenv LANG C

# Many hosts now default to a non-ASCII C locale, however, so
# they can set a charset encoding here if they need.
if { [ishost "*-*-cygwin*"] } {
  setenv LC_ALL C.ASCII
  setenv LANG C.ASCII
}

# Run the LANGUAGE compiler with GCC_OPTIONS and inspect the compiler
# output excluding EXCLUDE lines to make sure that they match the
# newline-separated patterns in COMPILER_PATTERNS but not the patterns in
# COMPILER_NON_PATTERNS.  In case of failure, xfail if XFAIL is nonempty.

proc check_for_options_with_filter { language gcc_options exclude \
					 compiler_patterns \
					 compiler_non_patterns \
					 expected_failure } {
    set filename test-[pid]
    set fd [open $filename.c w]
    puts $fd "int main (void) { return 0; }"
    close $fd
    remote_download host $filename.c

    set test "compiler driver $gcc_options option(s):"
    set gcc_options "\{additional_flags=$gcc_options\}"

    switch "$language" {
	"c" { set compiler cc1 }
	default { error "unknown language" }
    }
    set gcc_output [gcc_target_compile $filename.c $filename.x executable $gcc_options]
    remote_file build delete $filename.c $filename.x $filename.gcno

    if { $exclude != "" } {
	set lines [split $gcc_output "\n"]
	set gcc_output ""
	foreach line $lines {
	    if {[regexp -line -- "$exclude" $line]} {
		continue
	    }
	    if { $gcc_output == "" } {
		set gcc_output "$line"
	    } else {
		set gcc_output "$gcc_output\n$line"
	    }
	}	
   }
    
    # Verify that COMPILER_PATTERRNS appear in gcc output.
    foreach pattern [split $compiler_patterns "\n"] {
	if {$pattern != ""} {
	    if {[regexp -line -- "$pattern" $gcc_output]} {
		pass "$test $pattern"
	    } else {
		if {$expected_failure != ""} {
		    xfail "$test \"$pattern\" present in output"
		} else {
		    fail "$test \"$pattern\" present in output"
		}
	    }
	}
    }

    # Verify that COMPILER_NON_PATTERRNS do not appear in gcc output.
    foreach pattern [split $compiler_non_patterns "\n"] {
	if {$pattern != ""} {
	    if {![regexp -line -- "$pattern" $gcc_output result]} {
		pass "$test $pattern"
	    } else {
		if {$expected_failure != ""} {
		    xfail "$test \"$pattern\" absent from output"
		} else {
		    # Print the unexpected line that caused the failure
		    # to make it easier to find in the multiline output.
		    fail "$test \"$pattern\" absent from output: \"$result\""
		}
	    }
	}
    }
}

# As check_for_options_with_filter, but without the EXCLUDE parameter.

proc check_for_options { language gcc_options compiler_patterns \
			     compiler_non_patterns expected_failure } {
    check_for_options_with_filter $language $gcc_options "" $compiler_patterns \
	$compiler_non_patterns $expected_failure
}