summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.target/msp430/msp430.exp
blob: 8c97f63256329c4bf99d70f01657ce28ed32541e (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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# Copyright (C) 2015-2021 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 this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  

# GCC testsuite that uses the `dg.exp' driver.

# Exit immediately if this isn't the right target.
if { ![istarget msp430-*-*] } then {
    return
}

# Below are msp430-specific effective target keywords, required for checking
# device related warnings/errors
proc check_effective_target_msp430_430_selected { } {
    return [check-flags [list "" { *-*-* } { "-mcpu=msp430" } { "" } ]]
}

proc check_effective_target_msp430_430x_selected { } {
    return [check-flags [list "" { *-*-* } \
    { "-mcpu=msp430x" "-mcpu=msp430xv2" } { "" } ]]
}

proc check_effective_target_msp430_mlarge_selected { } {
    return [check-flags [list "" { *-*-* } { "-mlarge" } { "" } ]]
}

proc check_effective_target_msp430_region_not_lower { } {
    return [check-flags [list "" { *-*-* } { "-mdata-region=none" "-mdata-region=upper" "-mdata-region=either" } { "" } ]]
}

proc check_effective_target_msp430_region_lower { } {
    return [check-flags [list "" { *-*-* } { "*" } { "-mdata-region=none" "-mdata-region=upper" "-mdata-region=either" } ]]
}

proc check_effective_target_msp430_hwmul_not_none { } {
    return [check-flags [list "" { *-*-* } \
    { "-mhwmult=16bit" "-mhwmult=32bit" "-mhwmult=f5series" } { "" } ]]
}

proc check_effective_target_msp430_hwmul_not_16bit { } {
    return [check-flags [list "" { *-*-* } \
    { "-mhwmult=f5series" "-mhwmult=32bit" } { "" } ]]
}

proc check_effective_target_msp430_hwmul_not_32bit { } {
    return [check-flags [list "" { *-*-* } \
    { "-mhwmult=16bit" "-mhwmult=f5series" } { "" } ]]
}

proc check_effective_target_msp430_hwmul_not_f5 { } {
    return [check-flags [list "" { *-*-* } \
    { "-mhwmult=16bit" "-mhwmult=32bit" } { "" } ]]
}

# Return a list of msp430-specific options we can run the test with.
# The mcu name is extracted from the file name, not from the -mmcu option
# specified in the test file.
proc msp430_get_opts { test_file } {
    global board_info
    # If the mcu name is not recognized, run the test as normal without
    # additional options.
    if { ![regexp {[a-z0-9]+430[a-z0-9_]+(?=\.c)} $test_file mcu_name] } {
	return { "" }
    }
    # If the testsuite has been invoked with specific MSP430 options, don't run
    # in this torture style.
    set multi_flags [board_info [target_info name] multilib_flags]
    if { [string match "*mlarge*" $multi_flags]
	|| [string match "*msmall*" $multi_flags]
	|| [string match "*mcpu*" $multi_flags]
	|| [string match "*mmcu*" $multi_flags]
	|| [string match "*mhwmult*" $multi_flags] } {
	return { "" }
    }
    # Test all device related options. The compiler will warn about
    # incompatibilities, so ensure dg-warning or dg-error directives are set up
    # in the test sources.
    return {"" -mhwmult=none -mhwmult=16bit -mhwmult=32bit -mhwmult=f5series \
        -mcpu=msp430 -mcpu=msp430x -mcpu=msp430xv2 -mlarge}
}

# Run each test file in 'tests' with every possible value for -mcpu and
# -mhwmult, and with -mlarge.
proc msp430_device_permutations_runtest { tests } {
    # The specific tests being run
    global runtests
    global MSP430_DEFAULT_CFLAGS
    foreach { test_file } $tests {
	if { ![runtest_file_p $runtests $test_file] } {
	    continue
	}
	# The device name passed to -mmcu in the csv-using-* tests do not exist
	# in the hard-coded data, to ensure the test fails if the method can't
	# find the device data.
	if { [file tail $test_file] eq "csv-using-installed.c" } {
	    msp430_test_installed_device_data $test_file $MSP430_DEFAULT_CFLAGS
	    continue
	} elseif { [file tail $test_file] eq "csv-using-option.c" } {
	    dg-runtest $test_file \
		"-mdevices-csv-loc=[file dirname $test_file]/devices.csv" \
		"$MSP430_DEFAULT_CFLAGS"
	    continue
	} elseif { [file tail $test_file] eq "csv-using-env-var.c" } {
	    setenv MSP430_GCC_INCLUDE_DIR [file dirname $test_file]
	    verbose -log "MSP430_GCC_INCLUDE_DIR=[file dirname $test_file]"
	    dg-runtest $test_file "" "$MSP430_DEFAULT_CFLAGS"
	    setenv MSP430_GCC_INCLUDE_DIR ""
	    verbose -log "MSP430_GCC_INCLUDE_DIR=\"\""
	    continue
	}
	foreach { mcu_flags } [msp430_get_opts $test_file] {
	    if { [string match "csv-*" [file tail $test_file]] } {
		# Specify the path to devices.csv for devices/csv-* tests with -I.
		# Note that the csv-* tests do not have dg-options directives,
		# they only have dg-additional-options to pass -mmcu.  This is
		# so we can set the path to devices.csv as a "default" flag
		# with -I, and the path won't show up in the test results
		# summary.  If there were dg-options directives, then these
		# default flags passed as the 3rd argument to dg-runtest would
		# not be used.
		dg-runtest $test_file "$mcu_flags" "-I[file dirname $test_file] $MSP430_DEFAULT_CFLAGS"
	    } elseif { [string match "bad-devices*" [file tail $test_file]] } {
		dg-runtest $test_file "$mcu_flags" "-mdevices-csv-loc=[file dirname $test_file]/[file tail $test_file]sv $MSP430_DEFAULT_CFLAGS"
	    } else {
		dg-runtest $test_file "$mcu_flags -DTESTING_HARD_DATA" "$MSP430_DEFAULT_CFLAGS"
	    }
        }
    }
}


# Return $TOOLCHAIN_ROOT/$target_alias/include/devices/
# target_alias is expected to be either msp430-elf or msp430-elfbare.
proc get_installed_device_data_path { } {
    global target_alias
    set compiler [lindex [regexp -all -inline {\S+} \
	[board_info [target_info name] compiler]] 0]
    # $compiler is actually a file, but normalize will still get us the desired
    # result.
    return [file normalize \
	"$compiler/../../$target_alias/include/devices/devices.csv"]
}

# If the devices.csv is installed in
# $TOOLCHAIN_ROOT/$target_alias/include/devices/, rename it so it doesn't
# interfere with the hard-coded device data tests.
proc msp430_hide_installed_devices_data { } {
    set devices_path [get_installed_device_data_path]
    if { [file exists $devices_path] } {
	file rename $devices_path "$devices_path.bak"
    }
}

# Restore devices.csv if renamed by msp430_hide_installed_devices_data.
proc msp430_restore_installed_devices_data { } {
    set devices_path [get_installed_device_data_path]
    if { [file exists "$devices_path.bak"] } {
	file rename "$devices_path.bak" $devices_path 
    }
}

proc msp430_test_installed_device_data { name default_cflags } {
    global subdir
    global env

    # The initial value for GCC_EXEC_PREFIX set by target-libpath.exp is not
    # correct for cross-compilers so fix it here. GCC fixes the value itself,
    # but not after spec functions are executed, which can cause a warning
    # about missing devices.csv to be emitted.
    set compiler [lindex [regexp -all -inline {\S+} \
	[board_info [target_info name] compiler]] 0]
    set real_exec_prefix "[file normalize "$compiler/../../lib/gcc"]/"
    setenv GCC_EXEC_PREFIX $real_exec_prefix

    msp430_restore_installed_devices_data 
    set devices_path [get_installed_device_data_path]
    if { [file exists $devices_path] } {
	dg-runtest $name "" "$default_cflags"
    } else {
	set shorter_name "$subdir/[file tail $name]"
	verbose -log "$shorter_name not supported, $devices_path doesn't exist."
	unsupported $shorter_name
    }
    msp430_hide_installed_devices_data 
}

proc msp430_install_device_data { testsuite_dir } {
    set devices_path [get_installed_device_data_path]
    if { [file exists $devices_path] } {
        return
    }
    set installed_path [file dirname $devices_path]
    file mkdir $installed_path
    file copy $testsuite_dir/msp430-devices.h $testsuite_dir/devices.csv $installed_path
}

# Load support procs.
load_lib gcc-dg.exp

# The '-pedantic-errors' option in the global variable DEFAULT_CFLAGS that is
# set by other drivers causes an error when the __int20 type is used, so remove
# this option from DEFAULT_CFLAGS for the msp430 tests.
global DEFAULT_CFLAGS
if [info exists DEFAULT_CFLAGS] then {
    set MSP430_DEFAULT_CFLAGS \
      [ string map { "-pedantic-errors" "" } $DEFAULT_CFLAGS ]
} else {
   set MSP430_DEFAULT_CFLAGS ""
}

# Initialize `dg'.
dg-init

# Install then hide the devices data now, in case it is already installed. We
# don't want it to interfere with tests until we need it to.
msp430_install_device_data $srcdir/$subdir/devices
msp430_hide_installed_devices_data

# Main loop.
dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cCS\]]] \
	"" $MSP430_DEFAULT_CFLAGS

msp430_device_permutations_runtest [lsort [glob -nocomplain $srcdir/$subdir/devices/*.\[cCS\]]]

msp430_restore_installed_devices_data 

# All done.
dg-finish