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