OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gdb/] [gdb-6.8/] [gdb-6.8.openrisc-2.1/] [sim/] [testsuite/] [lib/] [sim-defs.exp] - Diff between revs 24 and 33

Only display areas with differences | Details | Blame | View Log

Rev 24 Rev 33
# Simulator dejagnu utilities.
# Simulator dejagnu utilities.
# Communicate simulator path from sim_init to sim_version.
# Communicate simulator path from sim_init to sim_version.
# For some reason [board_info target sim] doesn't work in sim_version.
# For some reason [board_info target sim] doesn't work in sim_version.
# [Presumubly because the target has been "popped" by then.  Odd though.]
# [Presumubly because the target has been "popped" by then.  Odd though.]
set sim_path "unknown-run"
set sim_path "unknown-run"
# Initialize the testrun.
# Initialize the testrun.
# Required by dejagnu.
# Required by dejagnu.
proc sim_init { args } {
proc sim_init { args } {
    global sim_path
    global sim_path
    set sim_path [board_info target sim]
    set sim_path [board_info target sim]
    # Need to return an empty string (copied from GAS).
    # Need to return an empty string (copied from GAS).
    return ""
    return ""
}
}
# Print the version of the simulator being tested.
# Print the version of the simulator being tested.
# Required by dejagnu.
# Required by dejagnu.
proc sim_version {} {
proc sim_version {} {
    global sim_path
    global sim_path
    set version 0.5
    set version 0.5
    clone_output "$sim_path $version\n"
    clone_output "$sim_path $version\n"
}
}
# Cover function to target_compile.
# Cover function to target_compile.
# Copied from gdb_compile.
# Copied from gdb_compile.
proc sim_compile { source dest type options } {
proc sim_compile { source dest type options } {
    set result [target_compile $source $dest $type $options]
    set result [target_compile $source $dest $type $options]
    regsub "\[\r\n\]*$" "$result" "" result
    regsub "\[\r\n\]*$" "$result" "" result
    regsub "^\[\r\n\]*" "$result" "" result
    regsub "^\[\r\n\]*" "$result" "" result
    if { $result != "" } {
    if { $result != "" } {
        clone_output "sim compile output: $result"
        clone_output "sim compile output: $result"
    }
    }
    return $result
    return $result
}
}
# Run a program on the simulator.
# Run a program on the simulator.
# Required by dejagnu (at least ${tool}_run used to be).
# Required by dejagnu (at least ${tool}_run used to be).
#
#
# SIM_OPTS are options for the simulator.
# SIM_OPTS are options for the simulator.
# PROG_OPTS are options passed to the simulated program.
# PROG_OPTS are options passed to the simulated program.
# At present REDIR must be "" or "> foo".
# At present REDIR must be "" or "> foo".
# OPTIONS is a list of options internal to this routine.
# OPTIONS is a list of options internal to this routine.
# This is modelled after target_compile.  We want to be able to add new
# This is modelled after target_compile.  We want to be able to add new
# options without having to update all our users.
# options without having to update all our users.
# Currently:
# Currently:
#       env(foo)=val    - set environment variable foo to val for this run
#       env(foo)=val    - set environment variable foo to val for this run
#       timeout=val     - set the timeout to val for this run
#       timeout=val     - set the timeout to val for this run
#
#
# The result is a list of two elements.
# The result is a list of two elements.
# The first is one of pass/fail/etc.
# The first is one of pass/fail/etc.
# The second is the program's output.
# The second is the program's output.
#
#
# This is different than the sim_load routine provided by
# This is different than the sim_load routine provided by
# dejagnu/config/sim.exp.  It's not clear how to pass arguments to the
# dejagnu/config/sim.exp.  It's not clear how to pass arguments to the
# simulator (not the simulated program, the simulator) with sim_load.
# simulator (not the simulated program, the simulator) with sim_load.
proc sim_run { prog sim_opts prog_opts redir options } {
proc sim_run { prog sim_opts prog_opts redir options } {
    global SIMFLAGS
    global SIMFLAGS
    # Set the default value of the timeout.
    # Set the default value of the timeout.
    # FIXME: The timeout value we actually want is a function of
    # FIXME: The timeout value we actually want is a function of
    # host, target, and testcase.
    # host, target, and testcase.
    set testcase_timeout [board_info target sim_time_limit]
    set testcase_timeout [board_info target sim_time_limit]
    if { "$testcase_timeout" == "" } {
    if { "$testcase_timeout" == "" } {
        set testcase_timeout [board_info host testcase_timeout]
        set testcase_timeout [board_info host testcase_timeout]
    }
    }
    if { "$testcase_timeout" == "" } {
    if { "$testcase_timeout" == "" } {
        set testcase_timeout 240 ;# 240 same as in dejagnu/config/sim.exp.
        set testcase_timeout 240 ;# 240 same as in dejagnu/config/sim.exp.
    }
    }
    # Initial the environment we pass to the testcase.
    # Initial the environment we pass to the testcase.
    set testcase_env ""
    set testcase_env ""
    # Process OPTIONS ...
    # Process OPTIONS ...
    foreach o $options {
    foreach o $options {
        if [regexp {^env\((.*)\)=(.*)} $o full var val] {
        if [regexp {^env\((.*)\)=(.*)} $o full var val] {
            set testcase_env "$testcase_env $var=$val"
            set testcase_env "$testcase_env $var=$val"
        } elseif [regexp {^timeout=(.*)} $o full val] {
        } elseif [regexp {^timeout=(.*)} $o full val] {
            set testcase_timeout $val
            set testcase_timeout $val
        }
        }
    }
    }
    verbose "testcase timeout is set to $testcase_timeout" 1
    verbose "testcase timeout is set to $testcase_timeout" 1
    set sim [board_info target sim]
    set sim [board_info target sim]
    if [is_remote host] {
    if [is_remote host] {
        set prog [remote_download host $prog]
        set prog [remote_download host $prog]
        if { $prog == "" } {
        if { $prog == "" } {
            error "download failed"
            error "download failed"
            return -1
            return -1
        }
        }
    }
    }
    set board [target_info name]
    set board [target_info name]
    if [board_info $board exists sim,options] {
    if [board_info $board exists sim,options] {
        set always_opts [board_info $board sim,options]
        set always_opts [board_info $board sim,options]
    } else {
    } else {
        set always_opts ""
        set always_opts ""
    }
    }
    # FIXME: this works for UNIX only
    # FIXME: this works for UNIX only
    if { "$testcase_env" != "" } {
    if { "$testcase_env" != "" } {
        set sim "env $testcase_env $sim"
        set sim "env $testcase_env $sim"
    }
    }
    if { [board_info target sim,protocol] == "sid" } {
    if { [board_info target sim,protocol] == "sid" } {
        set cmd ""
        set cmd ""
        set sim_opts "$sim_opts -e \"set cpu-loader file [list ${prog}]\""
        set sim_opts "$sim_opts -e \"set cpu-loader file [list ${prog}]\""
    } else {
    } else {
        set cmd "$prog"
        set cmd "$prog"
    }
    }
    send_log "$sim $always_opts $SIMFLAGS $sim_opts $cmd $prog_opts\n"
    send_log "$sim $always_opts $SIMFLAGS $sim_opts $cmd $prog_opts\n"
    if { "$redir" == "" } {
    if { "$redir" == "" } {
        remote_spawn host "$sim $always_opts $SIMFLAGS $sim_opts $cmd $prog_opts"
        remote_spawn host "$sim $always_opts $SIMFLAGS $sim_opts $cmd $prog_opts"
    } else {
    } else {
        remote_spawn host "$sim $always_opts $SIMFLAGS $sim_opts $cmd $prog_opts $redir" writeonly
        remote_spawn host "$sim $always_opts $SIMFLAGS $sim_opts $cmd $prog_opts $redir" writeonly
    }
    }
    set result [remote_wait host $testcase_timeout]
    set result [remote_wait host $testcase_timeout]
    set return_code [lindex $result 0]
    set return_code [lindex $result 0]
    set output [lindex $result 1]
    set output [lindex $result 1]
    # Remove the \r part of "\r\n" so we don't break all the patterns
    # Remove the \r part of "\r\n" so we don't break all the patterns
    # we want to match.
    # we want to match.
    regsub -all -- "\r" $output "" output
    regsub -all -- "\r" $output "" output
    if [is_remote host] {
    if [is_remote host] {
        # clean up after ourselves.
        # clean up after ourselves.
        remote_file host delete $prog
        remote_file host delete $prog
    }
    }
    # ??? Not sure the test for pass/fail is right.
    # ??? Not sure the test for pass/fail is right.
    # We just care that the simulator ran correctly, not whether the simulated
    # We just care that the simulator ran correctly, not whether the simulated
    # program return 0 or non-zero from `main'.
    # program return 0 or non-zero from `main'.
    set status fail
    set status fail
    if { $return_code == 0 } {
    if { $return_code == 0 } {
        set status pass
        set status pass
    }
    }
    return [list $status $output]
    return [list $status $output]
}
}
# Run testcase NAME.
# Run testcase NAME.
# NAME is either a fully specified file name, or just the file name in which
# NAME is either a fully specified file name, or just the file name in which
# case $srcdir/$subdir will be prepended.
# case $srcdir/$subdir will be prepended.
# REQUESTED_MACHS is a list of machines to run the testcase on.  If NAME isn't
# REQUESTED_MACHS is a list of machines to run the testcase on.  If NAME isn't
# for the specified machine(s), it is ignored.
# for the specified machine(s), it is ignored.
# Typically REQUESTED_MACHS contains just one element, it is up to the caller
# Typically REQUESTED_MACHS contains just one element, it is up to the caller
# to iterate over the desired machine variants.
# to iterate over the desired machine variants.
#
#
# The file can contain options in the form "# option(mach list): value".
# The file can contain options in the form "# option(mach list): value".
# Possibilities:
# Possibilities:
# mach: [all | machine names]
# mach: [all | machine names]
# as[(mach-list)]: 
# as[(mach-list)]: 
# ld[(mach-list)]: 
# ld[(mach-list)]: 
# sim[(mach-list)]: 
# sim[(mach-list)]: 
# output: program output pattern to match with string-match
# output: program output pattern to match with string-match
# xerror: program is expected to return with a "failure" exit code
# xerror: program is expected to return with a "failure" exit code
# xfail:  
# xfail:  
# kfail:  
# kfail:  
# If `output' is not specified, the program must output "pass" if !xerror or
# If `output' is not specified, the program must output "pass" if !xerror or
# "fail" if xerror.
# "fail" if xerror.
# The parens in "optname()" are optional if the specification is for all machs.
# The parens in "optname()" are optional if the specification is for all machs.
# Multiple "output", "xfail" and "kfail" options concatenate.
# Multiple "output", "xfail" and "kfail" options concatenate.
# The xfail and kfail arguments are space-separated target triplets and PRIDs.
# The xfail and kfail arguments are space-separated target triplets and PRIDs.
# There must be a PRMS (bug report ID) specified for kfail, while it's
# There must be a PRMS (bug report ID) specified for kfail, while it's
# optional for xfail.
# optional for xfail.
proc run_sim_test { name requested_machs } {
proc run_sim_test { name requested_machs } {
    global subdir srcdir
    global subdir srcdir
    global SIMFLAGS
    global SIMFLAGS
    global opts
    global opts
    global cpu_option
    global cpu_option
    global global_as_options
    global global_as_options
    global global_ld_options
    global global_ld_options
    global global_sim_options
    global global_sim_options
    if [string match "*/*" $name] {
    if [string match "*/*" $name] {
        set file $name
        set file $name
        set name [file tail $name]
        set name [file tail $name]
    } else {
    } else {
        set file "$srcdir/$subdir/$name"
        set file "$srcdir/$subdir/$name"
    }
    }
    set opt_array [slurp_options "${file}"]
    set opt_array [slurp_options "${file}"]
    if { $opt_array == -1 } {
    if { $opt_array == -1 } {
        unresolved $subdir/$name
        unresolved $subdir/$name
        return
        return
    }
    }
    # Clear default options
    # Clear default options
    set opts(as) ""
    set opts(as) ""
    set opts(ld) ""
    set opts(ld) ""
    set opts(sim) ""
    set opts(sim) ""
    set opts(output) ""
    set opts(output) ""
    set opts(mach) ""
    set opts(mach) ""
    set opts(timeout) ""
    set opts(timeout) ""
    set opts(xerror) "no"
    set opts(xerror) "no"
    set opts(xfail) ""
    set opts(xfail) ""
    set opts(kfail) ""
    set opts(kfail) ""
    if ![info exists global_as_options] {
    if ![info exists global_as_options] {
        set global_as_options ""
        set global_as_options ""
    }
    }
    if ![info exists global_ld_options] {
    if ![info exists global_ld_options] {
        set global_ld_options ""
        set global_ld_options ""
    }
    }
    if ![info exists global_sim_options] {
    if ![info exists global_sim_options] {
        set global_sim_options ""
        set global_sim_options ""
    }
    }
    # Clear any machine specific options specified in a previous test case
    # Clear any machine specific options specified in a previous test case
    foreach m $requested_machs {
    foreach m $requested_machs {
        if [info exists opts(as,$m)] {
        if [info exists opts(as,$m)] {
            unset opts(as,$m)
            unset opts(as,$m)
        }
        }
        if [info exists opts(ld,$m)] {
        if [info exists opts(ld,$m)] {
            unset opts(ld,$m)
            unset opts(ld,$m)
        }
        }
        if [info exists opts(sim,$m)] {
        if [info exists opts(sim,$m)] {
            unset opts(sim,$m)
            unset opts(sim,$m)
        }
        }
    }
    }
    foreach i $opt_array {
    foreach i $opt_array {
        set opt_name [lindex $i 0]
        set opt_name [lindex $i 0]
        set opt_machs [lindex $i 1]
        set opt_machs [lindex $i 1]
        set opt_val [lindex $i 2]
        set opt_val [lindex $i 2]
        if ![info exists opts($opt_name)] {
        if ![info exists opts($opt_name)] {
            perror "unknown option $opt_name in file $file"
            perror "unknown option $opt_name in file $file"
            unresolved $subdir/$name
            unresolved $subdir/$name
            return
            return
        }
        }
        # Multiple "output" specifications concatenate, they don't override.
        # Multiple "output" specifications concatenate, they don't override.
        if { $opt_name == "output" } {
        if { $opt_name == "output" } {
            set opt_val "$opts(output)$opt_val"
            set opt_val "$opts(output)$opt_val"
        }
        }
        # Similar with "xfail" and "kfail", but arguments are space-separated.
        # Similar with "xfail" and "kfail", but arguments are space-separated.
        if { $opt_name == "xfail" || $opt_name == "kfail" } {
        if { $opt_name == "xfail" || $opt_name == "kfail" } {
            set opt_val "$opts($opt_name) $opt_val"
            set opt_val "$opts($opt_name) $opt_val"
        }
        }
        foreach m $opt_machs {
        foreach m $opt_machs {
            set opts($opt_name,$m) $opt_val
            set opts($opt_name,$m) $opt_val
        }
        }
        if { "$opt_machs" == "" } {
        if { "$opt_machs" == "" } {
            set opts($opt_name) $opt_val
            set opts($opt_name) $opt_val
        }
        }
    }
    }
    set testname $name
    set testname $name
    set sourcefile $file
    set sourcefile $file
    if { $opts(output) == "" } {
    if { $opts(output) == "" } {
        if { "$opts(xerror)" == "no" } {
        if { "$opts(xerror)" == "no" } {
            set opts(output) "pass\n"
            set opts(output) "pass\n"
        } else {
        } else {
            set opts(output) "fail\n"
            set opts(output) "fail\n"
        }
        }
    }
    }
    # Change \n sequences to newline chars.
    # Change \n sequences to newline chars.
    regsub -all "\\\\n" $opts(output) "\n" opts(output)
    regsub -all "\\\\n" $opts(output) "\n" opts(output)
    set testcase_machs $opts(mach)
    set testcase_machs $opts(mach)
    if { "$testcase_machs" == "all" } {
    if { "$testcase_machs" == "all" } {
        set testcase_machs $requested_machs
        set testcase_machs $requested_machs
    }
    }
    foreach mach $testcase_machs {
    foreach mach $testcase_machs {
        if { [lsearch $requested_machs $mach] < 0 } {
        if { [lsearch $requested_machs $mach] < 0 } {
            verbose -log "Skipping $mach version of $name, not requested."
            verbose -log "Skipping $mach version of $name, not requested."
            continue
            continue
        }
        }
        verbose -log "Testing $name on machine $mach."
        verbose -log "Testing $name on machine $mach."
        # Time to setup xfailures and kfailures.
        # Time to setup xfailures and kfailures.
        if { "$opts(xfail)" != "" } {
        if { "$opts(xfail)" != "" } {
            verbose -log "xfail: $opts(xfail)"
            verbose -log "xfail: $opts(xfail)"
            # Using eval to make $opts(xfail) appear as individual
            # Using eval to make $opts(xfail) appear as individual
            # arguments.
            # arguments.
            eval setup_xfail $opts(xfail)
            eval setup_xfail $opts(xfail)
        }
        }
        if { "$opts(kfail)" != "" } {
        if { "$opts(kfail)" != "" } {
            verbose -log "kfail: $opts(kfail)"
            verbose -log "kfail: $opts(kfail)"
            eval setup_kfail $opts(kfail)
            eval setup_kfail $opts(kfail)
        }
        }
        if ![info exists opts(as,$mach)] {
        if ![info exists opts(as,$mach)] {
            set opts(as,$mach) $opts(as)
            set opts(as,$mach) $opts(as)
        }
        }
        set as_options "$opts(as,$mach) -I$srcdir/$subdir"
        set as_options "$opts(as,$mach) -I$srcdir/$subdir"
        if [info exists cpu_option] {
        if [info exists cpu_option] {
            set as_options "$as_options $cpu_option=$mach"
            set as_options "$as_options $cpu_option=$mach"
        }
        }
        set comp_output [target_assemble $sourcefile ${name}.o "$as_options $global_as_options"]
        set comp_output [target_assemble $sourcefile ${name}.o "$as_options $global_as_options"]
        if ![string match "" $comp_output] {
        if ![string match "" $comp_output] {
            verbose -log "$comp_output" 3
            verbose -log "$comp_output" 3
            fail "$mach $testname (assembling)"
            fail "$mach $testname (assembling)"
            continue
            continue
        }
        }
        if ![info exists opts(ld,$mach)] {
        if ![info exists opts(ld,$mach)] {
            set opts(ld,$mach) $opts(ld)
            set opts(ld,$mach) $opts(ld)
        }
        }
        set comp_output [target_link ${name}.o ${name}.x "$opts(ld,$mach) $global_ld_options"]
        set comp_output [target_link ${name}.o ${name}.x "$opts(ld,$mach) $global_ld_options"]
        if ![string match "" $comp_output] {
        if ![string match "" $comp_output] {
            verbose -log "$comp_output" 3
            verbose -log "$comp_output" 3
            fail "$mach $testname (linking)"
            fail "$mach $testname (linking)"
            continue
            continue
        }
        }
        # If no machine specific options, default to the general version.
        # If no machine specific options, default to the general version.
        if ![info exists opts(sim,$mach)] {
        if ![info exists opts(sim,$mach)] {
            set opts(sim,$mach) $opts(sim)
            set opts(sim,$mach) $opts(sim)
        }
        }
        # Build the options argument.
        # Build the options argument.
        set options ""
        set options ""
        if { "$opts(timeout)" != "" } {
        if { "$opts(timeout)" != "" } {
            set options "$options timeout=$opts(timeout)"
            set options "$options timeout=$opts(timeout)"
        }
        }
        set result [sim_run ${name}.x "$opts(sim,$mach) $global_sim_options" "" "" "$options"]
        set result [sim_run ${name}.x "$opts(sim,$mach) $global_sim_options" "" "" "$options"]
        set status [lindex $result 0]
        set status [lindex $result 0]
        set output [lindex $result 1]
        set output [lindex $result 1]
        if { "$status" == "pass" } {
        if { "$status" == "pass" } {
            if { "$opts(xerror)" == "no" } {
            if { "$opts(xerror)" == "no" } {
                if [string match $opts(output) $output] {
                if [string match $opts(output) $output] {
                    pass "$mach $testname"
                    pass "$mach $testname"
                    file delete ${name}.o ${name}.x
                    file delete ${name}.o ${name}.x
                } else {
                } else {
                    verbose -log "output:  $output" 3
                    verbose -log "output:  $output" 3
                    verbose -log "pattern: $opts(output)" 3
                    verbose -log "pattern: $opts(output)" 3
                    fail "$mach $testname (execution)"
                    fail "$mach $testname (execution)"
                }
                }
            } else {
            } else {
                verbose -log "`pass' return code when expecting failure" 3
                verbose -log "`pass' return code when expecting failure" 3
                fail "$mach $testname (execution)"
                fail "$mach $testname (execution)"
            }
            }
        } elseif { "$status" == "fail" } {
        } elseif { "$status" == "fail" } {
            if { "$opts(xerror)" == "no" } {
            if { "$opts(xerror)" == "no" } {
                fail "$mach $testname (execution)"
                fail "$mach $testname (execution)"
            } else {
            } else {
                if [string match $opts(output) $output] {
                if [string match $opts(output) $output] {
                    pass "$mach $testname"
                    pass "$mach $testname"
                    file delete ${name}.o ${name}.x
                    file delete ${name}.o ${name}.x
                } else {
                } else {
                    verbose -log "output:  $output" 3
                    verbose -log "output:  $output" 3
                    verbose -log "pattern: $opts(output)" 3
                    verbose -log "pattern: $opts(output)" 3
                    fail "$mach $testname (execution)"
                    fail "$mach $testname (execution)"
                }
                }
            }
            }
        } else {
        } else {
            $status "$mach $testname"
            $status "$mach $testname"
        }
        }
    }
    }
}
}
# Subroutine of run_sim_test to process options in FILE.
# Subroutine of run_sim_test to process options in FILE.
proc slurp_options { file } {
proc slurp_options { file } {
    if [catch { set f [open $file r] } x] {
    if [catch { set f [open $file r] } x] {
        #perror "couldn't open `$file': $x"
        #perror "couldn't open `$file': $x"
        perror "$x"
        perror "$x"
        return -1
        return -1
    }
    }
    set opt_array {}
    set opt_array {}
    # whitespace expression
    # whitespace expression
    set ws  {[  ]*}
    set ws  {[  ]*}
    set nws {[^         ]*}
    set nws {[^         ]*}
    # whitespace is ignored anywhere except within the options list;
    # whitespace is ignored anywhere except within the options list;
    # option names are alphabetic only
    # option names are alphabetic only
    set pat "^#${ws}(\[a-zA-Z\]*)\\(?(\[^):\]*)\\)?$ws:${ws}(.*)$ws\$"
    set pat "^#${ws}(\[a-zA-Z\]*)\\(?(\[^):\]*)\\)?$ws:${ws}(.*)$ws\$"
    # Allow arbitrary lines until the first option is seen.
    # Allow arbitrary lines until the first option is seen.
    set seen_opt 0
    set seen_opt 0
    while { [gets $f line] != -1 } {
    while { [gets $f line] != -1 } {
        set line [string trim $line]
        set line [string trim $line]
        # Whitespace here is space-tab.
        # Whitespace here is space-tab.
        if [regexp $pat $line xxx opt_name opt_machs opt_val] {
        if [regexp $pat $line xxx opt_name opt_machs opt_val] {
            # match!
            # match!
            lappend opt_array [list $opt_name $opt_machs $opt_val]
            lappend opt_array [list $opt_name $opt_machs $opt_val]
            set seen_opt 1
            set seen_opt 1
        } else {
        } else {
            if { $seen_opt } {
            if { $seen_opt } {
                break
                break
            }
            }
        }
        }
    }
    }
    close $f
    close $f
    return $opt_array
    return $opt_array
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.