| # 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 |