From 264dcc17cc4d2252d58bda347dfd78c1b78517da Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Thu, 11 Nov 2021 00:36:52 -0500 Subject: [PATCH] sim: testsuite: unify basic C compiler checks Both bfin & cris ports test the C compiler to see if it works, but in their own way. Unify the checks in the common code so we can leverage them in more ports in the future, and collapse the bfin & cris code. --- sim/testsuite/bfin/allinsn.exp | 34 ++++----------------------- sim/testsuite/cris/c/c.exp | 16 +++++-------- sim/testsuite/lib/compilercheck.c | 5 ++++ sim/testsuite/lib/sim-defs.exp | 38 +++++++++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 40 deletions(-) create mode 100644 sim/testsuite/lib/compilercheck.c diff --git a/sim/testsuite/bfin/allinsn.exp b/sim/testsuite/bfin/allinsn.exp index d5269dabd20..a9dc08457b2 100644 --- a/sim/testsuite/bfin/allinsn.exp +++ b/sim/testsuite/bfin/allinsn.exp @@ -1,42 +1,16 @@ # Analog Devices Blackfin simulator testsuite +# Set a default CPU to satisfy bfin-elf-gcc requirements. BF537 should work +# with all standard Blackfin toolchains. +set CC_FOR_TARGET "[find_gcc] -mcpu=bf537" sim_init +unset CC_FOR_TARGET if [istarget bfin-*-elf] { # all machines set all_machs "bfin" - global objdir - - # See if we have a preprocessor available. - if { [target_compile $srcdir/$subdir/usp.S $objdir/compilercheck.x "preprocess" \ - [list "incdir=$srcdir/$subdir"]] == "" } { - set has_cpp 1 - } { - verbose -log "Can't execute preprocessor" - set has_cpp 0 - } - - # See if we have a compiler available. - if { [target_compile $srcdir/$subdir/argc.c $objdir/compilercheck.x "executable" \ - [list "incdir=$srcdir/$subdir" "additional_flags=-msim"]] == "" } { - set has_cc 1 - } { - verbose -log "Can't execute C compiler" - set has_cc 0 - } - foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.\[csS\]]] { - # If we don't have a compiler available, skip tests :(. - if { $has_cpp == 0 && [string match "*.S" $src] } { - untested $src - continue - } - if { $has_cc == 0 && [string match "*.c" $src] } { - untested $src - continue - } - # If we're only testing specific files and this isn't one of them, # skip it. if ![runtest_file_p $runtests $src] { diff --git a/sim/testsuite/cris/c/c.exp b/sim/testsuite/cris/c/c.exp index 08a085dd6fc..dfafa003bf5 100644 --- a/sim/testsuite/cris/c/c.exp +++ b/sim/testsuite/cris/c/c.exp @@ -33,11 +33,8 @@ if [istarget cris*-*-elf] { } # Using target_compile, since it is less noisy, -global objdir -if { [target_compile $srcdir/$subdir/hello.c $objdir/compilercheck.x \ - "executable" "" ] == "" } { - set has_cc 1 - +global global_cc_works +if { $global_cc_works == 1 } { # Now check if we can link a program dynamically, and where # libc.so is located. If it is, we provide a sym link to the # directory (which must end in /lib) in [pwd], so /lib/ld.so.1 is @@ -45,8 +42,9 @@ if { [target_compile $srcdir/$subdir/hello.c $objdir/compilercheck.x \ # replacing the board ldflags like below as we don't care about # detrimental effects on the executable from the specs and # -static in the board ldflags, we just add -Bdynamic. + global objdir if [regexp "(.*/lib)/libc.so" \ - [target_compile $srcdir/$subdir/hello.c $objdir/compilercheck.x \ + [target_compile $srcdir/lib/compilercheck.c $objdir/compilercheck.x \ "executable" \ "ldflags=-print-file-name=libc.so -Wl,-Bdynamic"] \ xxx libcsodir] { @@ -54,9 +52,7 @@ if { [target_compile $srcdir/$subdir/hello.c $objdir/compilercheck.x \ verbose -log "Creating link to $libcsodir in [pwd]" file link lib $libcsodir } -} { - verbose -log "Can't execute C compiler" - set has_cc 0 + file delete $objdir/compilercheck.x } # Like istarget, except take a list of targets as a string. @@ -92,7 +88,7 @@ foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.c]] { } # Note absence of CC in results, but don't make a big fuss over it. - if { $has_cc == 0 } { + if { $global_cc_works == 0 } { untested $testname continue } diff --git a/sim/testsuite/lib/compilercheck.c b/sim/testsuite/lib/compilercheck.c new file mode 100644 index 00000000000..63a95770547 --- /dev/null +++ b/sim/testsuite/lib/compilercheck.c @@ -0,0 +1,5 @@ +/* Used by the test harness to verify working compiler & preprocessor. */ +int main() +{ + return 0; +} diff --git a/sim/testsuite/lib/sim-defs.exp b/sim/testsuite/lib/sim-defs.exp index 46a8b3f21d8..f399d2f3da1 100644 --- a/sim/testsuite/lib/sim-defs.exp +++ b/sim/testsuite/lib/sim-defs.exp @@ -33,11 +33,35 @@ proc sim_init { args } { # all simulators. unset_currtarget_info ldscript + sim_init_toolchain + # Need to return an empty string. This tells dejagnu to *not* re-run us # with the exact test that we're about to run. return "" } +# Initialize the toolchain settings for this port. +# Needs to be called once per-port. + +proc sim_init_toolchain {} { + global objdir + global srcdir + global global_cpp_works + global global_cc_works + + # See if we have a preprocessor available. + set result [target_compile $srcdir/lib/compilercheck.c \ + $objdir/compilercheck.x "preprocess" ""] + set global_cpp_works [string equal "" "$result"] + + # See if we have a compiler available. + set result [target_compile $srcdir/lib/compilercheck.c \ + $objdir/compilercheck.x "executable" ""] + set global_cc_works [string equal "" "$result"] + + file delete $objdir/compilercheck.x +} + # Print the version of the simulator being tested. # Required by dejagnu. @@ -185,6 +209,8 @@ proc run_sim_test { name requested_machs } { global cpu_option global cpu_option_sep global SIMFLAGS_FOR_TARGET + global global_cpp_works + global global_cc_works if ![file exists $sim_path] { unsupported "$name: missing simulator $sim_path" @@ -327,11 +353,23 @@ proc run_sim_test { name requested_machs } { } if [string match "*.c" $sourcefile] { + # If we don't have a compiler available, skip tests :(. + if { $global_cc_works == 0 } { + untested $subdir/$name + return + } + set comp_output [target_compile $sourcefile $objdir/${name}.x "executable" \ [list "incdir=$srcdir/$subdir" "additional_flags=$c_as_options $c_ld_options $opts(cc,$mach)"]] set method "compiling/linking" } else { if [string match "*.S" $sourcefile] { + # If we don't have a preprocessor available, skip tests :(. + if { $global_cpp_works == 0 } { + untested $subdir/$name + return + } + set comp_output [target_compile $sourcefile $objdir/${name}.o "object" \ [list "incdir=$srcdir/$subdir" "additional_flags=$c_as_options"]] set method "compiling" -- 2.30.2