Home | History | Annotate | Line # | Download | only in rv-n-cris
      1  1.1.1.2  christos # Copyright (C) 2006-2024 Free Software Foundation, Inc.
      2      1.1  christos #
      3      1.1  christos # This program is free software; you can redistribute it and/or modify
      4      1.1  christos # it under the terms of the GNU General Public License as published by
      5      1.1  christos # the Free Software Foundation; either version 3 of the License, or
      6      1.1  christos # (at your option) any later version.
      7      1.1  christos #
      8      1.1  christos # This program is distributed in the hope that it will be useful,
      9      1.1  christos # but WITHOUT ANY WARRANTY; without even the implied warranty of
     10      1.1  christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     11      1.1  christos # GNU General Public License for more details.
     12      1.1  christos #
     13      1.1  christos # You should have received a copy of the GNU General Public License
     14      1.1  christos # along with this program.  If not, see <http://www.gnu.org/licenses/>.
     15      1.1  christos 
     16      1.1  christos # Miscellaneous CRIS simulator testcases in assembly code, testing
     17      1.1  christos # dv-rv.c and dv-cris.c functions.
     18      1.1  christos 
     19      1.1  christos sim_init
     20      1.1  christos 
     21      1.1  christos # Check whether dv-rv and dv-cris are present.
     22      1.1  christos 
     23      1.1  christos proc sim_has_rv_and_cris {} {
     24      1.1  christos     global srcdir
     25      1.1  christos     global subdir
     26      1.1  christos     global objdir
     27      1.1  christos     global sim_path
     28      1.1  christos     global SIMFLAGS_FOR_TARGET
     29      1.1  christos 
     30      1.1  christos     if ![file exists $sim_path] {
     31      1.1  christos 	return 0
     32      1.1  christos     }
     33      1.1  christos 
     34      1.1  christos     # We need to assemble and link a trivial program and pass that, in
     35      1.1  christos     # order to test successful exit.
     36      1.1  christos 
     37      1.1  christos     # A bit of duplication here for the assembling and linking part;
     38      1.1  christos     # what we want to do it to run the simulator without affecting the
     39      1.1  christos     # PASS/FAIL counters, and we can use e.g. run_sim_test for that.
     40      1.1  christos 
     41      1.1  christos     if ![info exists SIMFLAGS_FOR_TARGET] {
     42      1.1  christos 	set SIMFLAGS_FOR_TARGET ""
     43      1.1  christos     }
     44      1.1  christos 
     45      1.1  christos     set comp_output [target_assemble $srcdir/$subdir/quit.s $objdir/quit.o \
     46      1.1  christos 			 "-I$srcdir/$subdir"]
     47      1.1  christos 
     48      1.1  christos     if ![string match "" $comp_output] {
     49      1.1  christos 	verbose -log "$comp_output" 3
     50      1.1  christos 	fail "rv sim test setup (assembling)"
     51      1.1  christos 	return 0
     52      1.1  christos     }
     53      1.1  christos 
     54      1.1  christos     set comp_output [target_link $objdir/quit.o $objdir/quit.x ""]
     55      1.1  christos 
     56      1.1  christos     if ![string match "" $comp_output] {
     57      1.1  christos 	verbose -log "$comp_output" 3
     58      1.1  christos 	fail "rv sim test setup (linking)"
     59      1.1  christos 	return 0
     60      1.1  christos     }
     61      1.1  christos 
     62      1.1  christos     set result \
     63      1.1  christos 	[sim_run $objdir/quit.x \
     64      1.1  christos 	     "$SIMFLAGS_FOR_TARGET --hw-device rv --hw-device cris --hw-info" \
     65      1.1  christos 	     "" "" ""]
     66      1.1  christos     set return_code [lindex $result 0]
     67      1.1  christos     set output [lindex $result 1]
     68      1.1  christos 
     69      1.1  christos     if { $return_code == 0 } {
     70      1.1  christos 	return 1
     71      1.1  christos     }
     72      1.1  christos 
     73      1.1  christos     return 0
     74      1.1  christos }
     75      1.1  christos 
     76      1.1  christos # Similar to slurp_options, but lines are fixed format "^#r ..." (not
     77      1.1  christos # "^#{ws}*r:{ws}+" to avoid intruding on slurp_options syntax).  Only
     78      1.1  christos # trailing whitespace of the "..." is trimmed.  Beware that lines
     79      1.1  christos # including parameters may not contain ":".
     80      1.1  christos 
     81      1.1  christos proc slurp_rv { file } {
     82      1.1  christos     global subdir srcdir
     83      1.1  christos     if [catch { set f [open $file r] } x] {
     84      1.1  christos 	#perror "couldn't open `$file': $x"
     85      1.1  christos 	perror "$x"
     86      1.1  christos 	return -1
     87      1.1  christos     }
     88      1.1  christos     set rv_array {}
     89      1.1  christos     # whitespace expression
     90      1.1  christos     set ws  {[ 	]*}
     91      1.1  christos     # whitespace is ignored at the end of a line.
     92      1.1  christos     set pat "^#r (.*)$ws\$"
     93      1.1  christos     # Allow arbitrary lines until the first option is seen.
     94      1.1  christos     set seen_opt 0
     95      1.1  christos     while { [gets $f line] != -1 } {
     96      1.1  christos 	set line [string trim $line]
     97      1.1  christos 	# Whitespace here is space-tab.
     98      1.1  christos 	if [regexp $pat $line xxx cmd] {
     99      1.1  christos 	    # match!
    100      1.1  christos 	    set cmd [string map [list \
    101      1.1  christos 		{$pwd} [pwd] \
    102      1.1  christos 		{$srcdir} "$srcdir" \
    103      1.1  christos 		{$subdir} "$subdir" \
    104      1.1  christos 	    ] "$cmd"]
    105      1.1  christos 	    lappend rv_array $cmd
    106      1.1  christos 	    set seen_opt 1
    107      1.1  christos 	} else {
    108      1.1  christos 	    if { $seen_opt } {
    109      1.1  christos 		break
    110      1.1  christos 	    }
    111      1.1  christos 	}
    112      1.1  christos     }
    113      1.1  christos     close $f
    114      1.1  christos     return $rv_array
    115      1.1  christos }
    116      1.1  christos 
    117      1.1  christos # The main test loop.
    118      1.1  christos 
    119      1.1  christos if [istarget *] {
    120      1.1  christos     global ASFLAGS_FOR_TARGET
    121      1.1  christos     global LDFLAGS_FOR_TARGET
    122      1.1  christos     global SIMFLAGS_FOR_TARGET
    123      1.1  christos     set has_rv_and_cris [sim_has_rv_and_cris]
    124      1.1  christos 
    125      1.1  christos     global builddir
    126      1.1  christos     set rvdummy "$builddir/cris/rvdummy"
    127      1.1  christos 
    128      1.1  christos     # All machines we test and the corresponding assembler option.
    129      1.1  christos     # We'll only ever test v10 and higher here.
    130      1.1  christos 
    131      1.1  christos     set combos {{"crisv10" "--march=v10 --no-mul-bug-abort"}
    132      1.1  christos                 {"crisv32" "--march=v32"}}
    133      1.1  christos 
    134      1.1  christos     # We need to pass different assembler flags for each machine.
    135      1.1  christos     # Specifying it here rather than adding a specifier to each and every
    136      1.1  christos     # test-file is preferrable.
    137      1.1  christos 
    138      1.1  christos     foreach combo $combos {
    139      1.1  christos 	set mach [lindex $combo 0]
    140      1.1  christos 	set ASFLAGS_FOR_TARGET "[lindex $combo 1]"
    141      1.1  christos 
    142      1.1  christos 	# The .ms suffix is for "miscellaneous .s".
    143      1.1  christos 	foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.ms]] {
    144      1.1  christos 
    145      1.1  christos 	    # If we're only testing specific files and this isn't one of them,
    146      1.1  christos 	    # skip it.
    147      1.1  christos 	    if ![runtest_file_p $runtests $src] {
    148      1.1  christos 		continue
    149      1.1  christos 	    }
    150      1.1  christos 
    151      1.1  christos 	    # Whoever runs the test should be alerted that not all
    152      1.1  christos 	    # testcases have been checked; that's why we do the loop
    153      1.1  christos 	    # and don't just return at the top.
    154      1.1  christos 	    if !$has_rv_and_cris {
    155      1.1  christos 		untested $src
    156      1.1  christos 		continue
    157      1.1  christos 	    }
    158      1.1  christos 
    159      1.1  christos 	    # Unfortunately this seems like the only way to pass
    160      1.1  christos 	    # additional sim, ld etc. options to run_sim_test.
    161      1.1  christos 	    set SIMFLAGS_FOR_TARGET "--hw-file $srcdir/$subdir/std.dev"
    162      1.1  christos 	    set LDFLAGS_FOR_TARGET "--section-start=.text=0"
    163      1.1  christos 
    164      1.1  christos 	    # We parse options an extra time besides in run_sim_test,
    165      1.1  christos 	    # to determine if our defaults should be overridden.
    166      1.1  christos 
    167      1.1  christos 	    set opt_array [slurp_options $src]
    168      1.1  christos 	    foreach i $opt_array {
    169      1.1  christos 		set opt_name [lindex $i 0]
    170      1.1  christos 		set opt_machs [lindex $i 1]
    171      1.1  christos 		set opt_val [lindex $i 2]
    172      1.1  christos 
    173      1.1  christos 		# Allow concatenating to the default options by
    174      1.1  christos 		# specifying a mach.
    175      1.1  christos 		if { $opt_name == "sim" && $opt_machs == "" } {
    176      1.1  christos 		    set SIMFLAGS_FOR_TARGET ""
    177      1.1  christos 		}
    178      1.1  christos 	    }
    179      1.1  christos 
    180      1.1  christos 	    set rvdummy_id -1
    181      1.1  christos 	    set hostcmds [slurp_rv $src]
    182      1.1  christos 
    183      1.1  christos 	    if { $hostcmds != "" } {
    184      1.1  christos 		# I guess we could ask to have rvdummy executed on a
    185      1.1  christos 		# remote host, but it looks like too much trouble for
    186      1.1  christos 		# a feature rarely used.
    187      1.1  christos 		if [is_remote host] {
    188      1.1  christos 		    untested $src
    189      1.1  christos 		    continue
    190      1.1  christos 		}
    191      1.1  christos 
    192      1.1  christos 		set src_components [file split $src]
    193      1.1  christos 		set rvfile "[lindex $src_components \
    194      1.1  christos 			    [expr [llength $src_components] - 1]].r"
    195      1.1  christos 
    196      1.1  christos 		if [catch { set f [open $rvfile w] } x] {
    197      1.1  christos 		    error "$x"
    198      1.1  christos 		} {
    199      1.1  christos 		    set contents [join $hostcmds "\n"]
    200      1.1  christos 		    verbose "rv: $contents" 2
    201      1.1  christos 		    puts $f $contents
    202      1.1  christos 		    close $f
    203      1.1  christos 		}
    204      1.1  christos 
    205      1.1  christos 		spawn -noecho $rvdummy "$rvfile"
    206      1.1  christos 		if { $spawn_id < 0 } {
    207      1.1  christos 		    error "Couldn't spawn $rvdummy"
    208      1.1  christos 		    continue
    209      1.1  christos 		}
    210      1.1  christos 		set rvdummy_id $spawn_id
    211      1.1  christos 	    }
    212      1.1  christos 
    213      1.1  christos 	    run_sim_test $src $mach
    214      1.1  christos 
    215      1.1  christos 	    # Stop the rvdummy, if it's still running.  We need to
    216      1.1  christos 	    # wait on it anyway to avoid it turning into a zombie.
    217      1.1  christos 	    if { $rvdummy_id != -1 } {
    218      1.1  christos 		close -i $rvdummy_id
    219      1.1  christos 		wait -i $rvdummy_id
    220      1.1  christos 
    221      1.1  christos 		# Gleaned from framework.exp, this seems an indicator
    222      1.1  christos 		# to whether the test had expected outcome.  If so, we
    223      1.1  christos 		# want to remove the rv-file.
    224      1.1  christos 		if { $exit_status == 0 } {
    225      1.1  christos 		    file delete $rvfile
    226      1.1  christos 		}
    227      1.1  christos 	    }
    228      1.1  christos 	}
    229      1.1  christos     }
    230      1.1  christos }
    231