1 # Copyright (C) 2015-2021 Free Software Foundation, Inc.
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.
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.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # GCC testsuite that uses the `dg.exp' driver.
19 # Exit immediately if this isn't the right target.
20 if { ![istarget msp430-*-*] } then {
24 # Below are msp430-specific effective target keywords, required for checking
25 # device related warnings/errors
26 proc check_effective_target_msp430_430_selected { } {
27 return [check-flags [list "" { *-*-* } { "-mcpu=msp430" } { "" } ]]
30 proc check_effective_target_msp430_430x_selected { } {
31 return [check-flags [list "" { *-*-* } \
32 { "-mcpu=msp430x" "-mcpu=msp430xv2" } { "" } ]]
35 proc check_effective_target_msp430_mlarge_selected { } {
36 return [check-flags [list "" { *-*-* } { "-mlarge" } { "" } ]]
39 proc check_effective_target_msp430_region_not_lower { } {
40 return [check-flags [list "" { *-*-* } { "-mdata-region=none" "-mdata-region=upper" "-mdata-region=either" } { "" } ]]
43 proc check_effective_target_msp430_region_lower { } {
44 return [check-flags [list "" { *-*-* } { "*" } { "-mdata-region=none" "-mdata-region=upper" "-mdata-region=either" } ]]
47 proc check_effective_target_msp430_hwmul_not_none { } {
48 return [check-flags [list "" { *-*-* } \
49 { "-mhwmult=16bit" "-mhwmult=32bit" "-mhwmult=f5series" } { "" } ]]
52 proc check_effective_target_msp430_hwmul_not_16bit { } {
53 return [check-flags [list "" { *-*-* } \
54 { "-mhwmult=f5series" "-mhwmult=32bit" } { "" } ]]
57 proc check_effective_target_msp430_hwmul_not_32bit { } {
58 return [check-flags [list "" { *-*-* } \
59 { "-mhwmult=16bit" "-mhwmult=f5series" } { "" } ]]
62 proc check_effective_target_msp430_hwmul_not_f5 { } {
63 return [check-flags [list "" { *-*-* } \
64 { "-mhwmult=16bit" "-mhwmult=32bit" } { "" } ]]
67 # Return a list of msp430-specific options we can run the test with.
68 # The mcu name is extracted from the file name, not from the -mmcu option
69 # specified in the test file.
70 proc msp430_get_opts { test_file } {
72 # If the mcu name is not recognized, run the test as normal without
74 if { ![regexp {[a-z0-9]+430[a-z0-9_]+(?=\.c)} $test_file mcu_name] } {
77 # If the testsuite has been invoked with specific MSP430 options, don't run
78 # in this torture style.
79 set multi_flags [board_info [target_info name] multilib_flags]
80 if { [string match "*mlarge*" $multi_flags]
81 || [string match "*msmall*" $multi_flags]
82 || [string match "*mcpu*" $multi_flags]
83 || [string match "*mmcu*" $multi_flags]
84 || [string match "*mhwmult*" $multi_flags] } {
87 # Test all device related options. The compiler will warn about
88 # incompatibilities, so ensure dg-warning or dg-error directives are set up
89 # in the test sources.
90 return {"" -mhwmult=none -mhwmult=16bit -mhwmult=32bit -mhwmult=f5series \
91 -mcpu=msp430 -mcpu=msp430x -mcpu=msp430xv2 -mlarge}
94 # Run each test file in 'tests' with every possible value for -mcpu and
95 # -mhwmult, and with -mlarge.
96 proc msp430_device_permutations_runtest { tests } {
97 # The specific tests being run
99 global MSP430_DEFAULT_CFLAGS
100 foreach { test_file } $tests {
101 if { ![runtest_file_p $runtests $test_file] } {
104 # The device name passed to -mmcu in the csv-using-* tests do not exist
105 # in the hard-coded data, to ensure the test fails if the method can't
106 # find the device data.
107 if { [file tail $test_file] eq "csv-using-installed.c" } {
108 msp430_test_installed_device_data $test_file $MSP430_DEFAULT_CFLAGS
110 } elseif { [file tail $test_file] eq "csv-using-option.c" } {
111 dg-runtest $test_file \
112 "-mdevices-csv-loc=[file dirname $test_file]/devices.csv" \
113 "$MSP430_DEFAULT_CFLAGS"
115 } elseif { [file tail $test_file] eq "csv-using-env-var.c" } {
116 setenv MSP430_GCC_INCLUDE_DIR [file dirname $test_file]
117 verbose -log "MSP430_GCC_INCLUDE_DIR=[file dirname $test_file]"
118 dg-runtest $test_file "" "$MSP430_DEFAULT_CFLAGS"
119 setenv MSP430_GCC_INCLUDE_DIR ""
120 verbose -log "MSP430_GCC_INCLUDE_DIR=\"\""
123 foreach { mcu_flags } [msp430_get_opts $test_file] {
124 if { [string match "csv-*" [file tail $test_file]] } {
125 # Specify the path to devices.csv for devices/csv-* tests with -I.
126 # Note that the csv-* tests do not have dg-options directives,
127 # they only have dg-additional-options to pass -mmcu. This is
128 # so we can set the path to devices.csv as a "default" flag
129 # with -I, and the path won't show up in the test results
130 # summary. If there were dg-options directives, then these
131 # default flags passed as the 3rd argument to dg-runtest would
133 dg-runtest $test_file "$mcu_flags" "-I[file dirname $test_file] $MSP430_DEFAULT_CFLAGS"
134 } elseif { [string match "bad-devices*" [file tail $test_file]] } {
135 dg-runtest $test_file "$mcu_flags" "-mdevices-csv-loc=[file dirname $test_file]/[file tail $test_file]sv $MSP430_DEFAULT_CFLAGS"
137 dg-runtest $test_file "$mcu_flags -DTESTING_HARD_DATA" "$MSP430_DEFAULT_CFLAGS"
144 # Return $TOOLCHAIN_ROOT/$target_alias/include/devices/
145 # target_alias is expected to be either msp430-elf or msp430-elfbare.
146 proc get_installed_device_data_path { } {
148 set compiler [lindex [regexp -all -inline {\S+} \
149 [board_info [target_info name] compiler]] 0]
150 # $compiler is actually a file, but normalize will still get us the desired
152 return [file normalize \
153 "$compiler/../../$target_alias/include/devices/devices.csv"]
156 # If the devices.csv is installed in
157 # $TOOLCHAIN_ROOT/$target_alias/include/devices/, rename it so it doesn't
158 # interfere with the hard-coded device data tests.
159 proc msp430_hide_installed_devices_data { } {
160 set devices_path [get_installed_device_data_path]
161 if { [file exists $devices_path] } {
162 file rename $devices_path "$devices_path.bak"
166 # Restore devices.csv if renamed by msp430_hide_installed_devices_data.
167 proc msp430_restore_installed_devices_data { } {
168 set devices_path [get_installed_device_data_path]
169 if { [file exists "$devices_path.bak"] } {
170 file rename "$devices_path.bak" $devices_path
174 proc msp430_test_installed_device_data { name default_cflags } {
178 # The initial value for GCC_EXEC_PREFIX set by target-libpath.exp is not
179 # correct for cross-compilers so fix it here. GCC fixes the value itself,
180 # but not after spec functions are executed, which can cause a warning
181 # about missing devices.csv to be emitted.
182 set compiler [lindex [regexp -all -inline {\S+} \
183 [board_info [target_info name] compiler]] 0]
184 set real_exec_prefix "[file normalize "$compiler/../../lib/gcc"]/"
185 setenv GCC_EXEC_PREFIX $real_exec_prefix
187 msp430_restore_installed_devices_data
188 set devices_path [get_installed_device_data_path]
189 if { [file exists $devices_path] } {
190 dg-runtest $name "" "$default_cflags"
192 set shorter_name "$subdir/[file tail $name]"
193 verbose -log "$shorter_name not supported, $devices_path doesn't exist."
194 unsupported $shorter_name
196 msp430_hide_installed_devices_data
199 proc msp430_install_device_data { testsuite_dir } {
200 set devices_path [get_installed_device_data_path]
201 if { [file exists $devices_path] } {
204 set installed_path [file dirname $devices_path]
205 file mkdir $installed_path
206 file copy $testsuite_dir/msp430-devices.h $testsuite_dir/devices.csv $installed_path
209 # Load support procs.
212 # The '-pedantic-errors' option in the global variable DEFAULT_CFLAGS that is
213 # set by other drivers causes an error when the __int20 type is used, so remove
214 # this option from DEFAULT_CFLAGS for the msp430 tests.
215 global DEFAULT_CFLAGS
216 if [info exists DEFAULT_CFLAGS] then {
217 set MSP430_DEFAULT_CFLAGS \
218 [ string map { "-pedantic-errors" "" } $DEFAULT_CFLAGS ]
220 set MSP430_DEFAULT_CFLAGS ""
226 # Install then hide the devices data now, in case it is already installed. We
227 # don't want it to interfere with tests until we need it to.
228 msp430_install_device_data $srcdir/$subdir/devices
229 msp430_hide_installed_devices_data
232 dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cCS\]]] \
233 "" $MSP430_DEFAULT_CFLAGS
235 msp430_device_permutations_runtest [lsort [glob -nocomplain $srcdir/$subdir/devices/*.\[cCS\]]]
237 msp430_restore_installed_devices_data