]>
Commit | Line | Data |
---|---|---|
83ffe9cd | 1 | # Copyright (C) 2015-2023 Free Software Foundation, Inc. |
90bc4878 NC |
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 this program; if not, write to the Free Software | |
15 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
16 | ||
17 | # GCC testsuite that uses the `dg.exp' driver. | |
18 | ||
19 | # Exit immediately if this isn't the right target. | |
20 | if { ![istarget msp430-*-*] } then { | |
e37e2bb1 JL |
21 | return |
22 | } | |
23 | ||
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" } { "" } ]] | |
28 | } | |
29 | ||
30 | proc check_effective_target_msp430_430x_selected { } { | |
31 | return [check-flags [list "" { *-*-* } \ | |
32 | { "-mcpu=msp430x" "-mcpu=msp430xv2" } { "" } ]] | |
33 | } | |
34 | ||
35 | proc check_effective_target_msp430_mlarge_selected { } { | |
36 | return [check-flags [list "" { *-*-* } { "-mlarge" } { "" } ]] | |
37 | } | |
38 | ||
8682b1a5 JL |
39 | proc check_effective_target_msp430_region_not_lower { } { |
40 | return [check-flags [list "" { *-*-* } { "-mdata-region=none" "-mdata-region=upper" "-mdata-region=either" } { "" } ]] | |
41 | } | |
42 | ||
43 | proc check_effective_target_msp430_region_lower { } { | |
44 | return [check-flags [list "" { *-*-* } { "*" } { "-mdata-region=none" "-mdata-region=upper" "-mdata-region=either" } ]] | |
45 | } | |
46 | ||
e37e2bb1 JL |
47 | proc check_effective_target_msp430_hwmul_not_none { } { |
48 | return [check-flags [list "" { *-*-* } \ | |
49 | { "-mhwmult=16bit" "-mhwmult=32bit" "-mhwmult=f5series" } { "" } ]] | |
50 | } | |
51 | ||
52 | proc check_effective_target_msp430_hwmul_not_16bit { } { | |
53 | return [check-flags [list "" { *-*-* } \ | |
54 | { "-mhwmult=f5series" "-mhwmult=32bit" } { "" } ]] | |
55 | } | |
56 | ||
57 | proc check_effective_target_msp430_hwmul_not_32bit { } { | |
58 | return [check-flags [list "" { *-*-* } \ | |
59 | { "-mhwmult=16bit" "-mhwmult=f5series" } { "" } ]] | |
60 | } | |
61 | ||
62 | proc check_effective_target_msp430_hwmul_not_f5 { } { | |
63 | return [check-flags [list "" { *-*-* } \ | |
64 | { "-mhwmult=16bit" "-mhwmult=32bit" } { "" } ]] | |
65 | } | |
66 | ||
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 } { | |
71 | global board_info | |
72 | # If the mcu name is not recognized, run the test as normal without | |
73 | # additional options. | |
74 | if { ![regexp {[a-z0-9]+430[a-z0-9_]+(?=\.c)} $test_file mcu_name] } { | |
75 | return { "" } | |
76 | } | |
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] } { | |
85 | return { "" } | |
86 | } | |
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} | |
92 | } | |
93 | ||
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 | |
98 | global runtests | |
99 | global MSP430_DEFAULT_CFLAGS | |
100 | foreach { test_file } $tests { | |
101 | if { ![runtest_file_p $runtests $test_file] } { | |
102 | continue | |
103 | } | |
d7eabfd4 JL |
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 | |
109 | continue | |
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" | |
114 | continue | |
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=\"\"" | |
121 | continue | |
122 | } | |
e37e2bb1 | 123 | foreach { mcu_flags } [msp430_get_opts $test_file] { |
d5c94995 JL |
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 | |
132 | # not be used. | |
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" | |
136 | } else { | |
d7eabfd4 | 137 | dg-runtest $test_file "$mcu_flags -DTESTING_HARD_DATA" "$MSP430_DEFAULT_CFLAGS" |
d5c94995 | 138 | } |
d7eabfd4 JL |
139 | } |
140 | } | |
141 | } | |
142 | ||
143 | ||
e8aa9f55 JL |
144 | # Return $TOOLCHAIN_ROOT/$target_alias/include/devices/ |
145 | # target_alias is expected to be either msp430-elf or msp430-elfbare. | |
d7eabfd4 | 146 | proc get_installed_device_data_path { } { |
e8aa9f55 | 147 | global target_alias |
d7eabfd4 JL |
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 | |
151 | # result. | |
152 | return [file normalize \ | |
e8aa9f55 | 153 | "$compiler/../../$target_alias/include/devices/devices.csv"] |
d7eabfd4 JL |
154 | } |
155 | ||
156 | # If the devices.csv is installed in | |
e8aa9f55 | 157 | # $TOOLCHAIN_ROOT/$target_alias/include/devices/, rename it so it doesn't |
d7eabfd4 JL |
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" | |
e37e2bb1 | 163 | } |
90bc4878 NC |
164 | } |
165 | ||
d7eabfd4 JL |
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 | |
171 | } | |
172 | } | |
173 | ||
174 | proc msp430_test_installed_device_data { name default_cflags } { | |
175 | global subdir | |
176 | global env | |
177 | ||
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 | |
186 | ||
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" | |
191 | } else { | |
192 | set shorter_name "$subdir/[file tail $name]" | |
193 | verbose -log "$shorter_name not supported, $devices_path doesn't exist." | |
194 | unsupported $shorter_name | |
195 | } | |
196 | msp430_hide_installed_devices_data | |
197 | } | |
198 | ||
199 | proc msp430_install_device_data { testsuite_dir } { | |
200 | set devices_path [get_installed_device_data_path] | |
201 | if { [file exists $devices_path] } { | |
202 | return | |
203 | } | |
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 | |
207 | } | |
208 | ||
90bc4878 NC |
209 | # Load support procs. |
210 | load_lib gcc-dg.exp | |
211 | ||
2aece9c1 JL |
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. | |
90bc4878 | 215 | global DEFAULT_CFLAGS |
2aece9c1 JL |
216 | if [info exists DEFAULT_CFLAGS] then { |
217 | set MSP430_DEFAULT_CFLAGS \ | |
218 | [ string map { "-pedantic-errors" "" } $DEFAULT_CFLAGS ] | |
219 | } else { | |
220 | set MSP430_DEFAULT_CFLAGS "" | |
90bc4878 NC |
221 | } |
222 | ||
223 | # Initialize `dg'. | |
224 | dg-init | |
225 | ||
d7eabfd4 JL |
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 | |
230 | ||
90bc4878 NC |
231 | # Main loop. |
232 | dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cCS\]]] \ | |
2aece9c1 | 233 | "" $MSP430_DEFAULT_CFLAGS |
90bc4878 | 234 | |
e37e2bb1 JL |
235 | msp430_device_permutations_runtest [lsort [glob -nocomplain $srcdir/$subdir/devices/*.\[cCS\]]] |
236 | ||
d7eabfd4 JL |
237 | msp430_restore_installed_devices_data |
238 | ||
90bc4878 NC |
239 | # All done. |
240 | dg-finish |