OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [or1ksim/] [testsuite/] [lib/] [or1ksim.exp] - Diff between revs 95 and 104

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 95 Rev 104
# Or1ksim expect test functiosn for use with DejaGNU under automake
# Or1ksim expect test functiosn for use with DejaGNU under automake
# Copyright (C) 2010 Embecosm Limited
# Copyright (C) 2010 Embecosm Limited
# Contributor Jeremy Bennett 
# Contributor Jeremy Bennett 
# This file is part of OpenRISC 1000 Architectural Simulator.
# This file is part of OpenRISC 1000 Architectural Simulator.
# This program is free software; you can redistribute it and/or modify it
# 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
# 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)
# Software Foundation; either version 3 of the License, or (at your option)
# any later version.
# any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
# more details.
# more details.
# You should have received a copy of the GNU General Public License along
# You should have received a copy of the GNU General Public License along
# with this program.  If not, see .  */
# with this program.  If not, see .  */
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# This code is commented throughout for use with Doxygen.
# This code is commented throughout for use with Doxygen.
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
#! Run a program on Or1ksim with the supplied config_file
#! Run a program on Or1ksim with the supplied config_file
#
#
#! @param[in] testname    The name of the test
#! @param[in] testname    The name of the test
#! @param[in] match_list  A list of expected responses
#! @param[in] match_list  A list of expected responses
#! @param[in] config_file The or1ksim config file to use
#! @param[in] config_file The or1ksim config file to use
# !@param[in] progname    The program image to use on Or1ksim
# !@param[in] progname    The program image to use on Or1ksim
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
proc run_or1ksim { testname match_list config_file progname } {
proc run_or1ksim { testname match_list config_file progname } {
    global verbose
    global verbose
    global srcdir
    global srcdir
    global objdir
    global objdir
    # Construct the filename
    # Construct the filename
    if {0 == [string length $config_file]} {
    if {0 == [string length $config_file]} {
        set config_full_file "$srcdir/or1ksim.tests/default.cfg";
        set config_full_file "$srcdir/or1ksim.tests/default.cfg";
    } else {
    } else {
        set config_full_file "$srcdir/or1ksim.tests/$config_file";
        set config_full_file "$srcdir/or1ksim.tests/$config_file";
    }
    }
    set prog_full_name "$objdir/test-code-or1k/$progname"
    set prog_full_name "$objdir/test-code-or1k/$progname"
    set command_line "$objdir/../sim -f $config_full_file $prog_full_name"
    set command_line "$objdir/../sim -f $config_full_file $prog_full_name"
    if { $verbose > 1 } {
    if { $verbose > 1 } {
        send_user "starting $command_line\n"
        send_user "starting $command_line\n"
    }
    }
    # Run the program.
    # Run the program.
    eval "spawn $command_line"
    eval "spawn $command_line"
    # Try each matchstr in turn, counting the lines for error reporting
    # Try each matchstr in turn, counting the lines for error reporting
    set match_line 0;
    set match_line 0;
 
 
 
    # The tests for Or1ksim are generally monolithic, with each line of output
 
    # matched representing a pass. This is different to the tests for the
 
    # library, which are each small and individual.
    foreach matchstr $match_list {
    foreach matchstr $match_list {
        set match_line [expr {$match_line + 1}];
        set match_line [expr {$match_line + 1}];
 
 
#       send_user "matching |$matchstr|\n";
        # Each matchstring corresponds to a pass, unless its first character
 
        # is '!', indicating a string which must match (without its '!'), but
 
        # does not count towards the pass rate.
 
        set first_ch [string index $matchstr 0]
 
 
        expect {
        if { $first_ch == "!" } {
 
            # A line to ignore
 
            set matchlen [string length $matchstr]
 
            set last_index [expr {$matchlen - 1}]
 
            set matchstr [string range $matchstr 1 $last_index]
 
 
            $matchstr {
            if { $verbose > 2 } {
                # String to match. Silently accept. Do first, so we can match
                send_user "ignorning |$matchstr|\n";
                # specific warnings or errors if desired
            }
            }
            }
 
 
            -re "Warning" {
        if { $verbose > 2 } {
                fail "$testname: warning: $expect_out(buffer)";
            send_user "matching |$matchstr|\n";
 
        }
 
 
 
        # The matching is slightly tricky. In general we want to find warnings
 
        # or errors. However expect will look at the entire buffer, so if we
 
        # have the match string *after* an error or warning message, then the
 
        # match will still work OK.
 
 
 
        # The trick is to do some post-processing of the matched buffer to see
 
        # if there was a preceding Warning or ERROR message.
 
 
 
        expect {
 
            -ex $matchstr {
 
                set matchlen [string length $matchstr]
 
                set buflen [string length $expect_out(buffer)]
 
                set lastch [expr {$buflen - $matchlen}]
 
                set prefix [string range $expect_out(buffer) 0 $lastch]
 
 
 
                if { [string match *ERROR* $prefix] } {
 
                    # We skipped an error
 
                    fail "$testname: ERROR seeking match line $match_line";
                return
                return
 
                } elseif { [string match *Warning* $prefix] } {
 
                    # We skipped a warning
 
                    fail "$testname: Warning seeking match line $match_line";
 
                    return;
 
                } elseif { $first_ch != "!" } {
 
                    # If we match we have a pass, unless we were asked to
 
                    # ignore.
 
                    pass "$testname: $matchstr"
 
                }
 
                # Everything else skip silently
            }
            }
 
 
            -re "ERROR" {
            ERROR {
                fail "$testname: error: $expect_out(buffer)";
                # An error other than the one we seek
 
                fail "$testname: ERROR seeking match line $match_line";
                return
                return
            }
            }
 
 
 
            Warning {
 
                # Any warning
 
                fail "$testname: Warning seeking match line $match_line";
 
                return;
 
            }
 
 
            eof {
            eof {
                fail "$testname: hit EOF seeking match line $match_line";
                fail "$testname: hit EOF seeking match line $match_line";
                return
                return
            }
            }
            timeout {
            timeout {
 
                perror "Timeout";
                unresolved "$testname: timeout";
                unresolved "$testname: timeout";
                return
                return
            }
            }
        }
        }
    }
    }
 
 
    # If we get here we've passed
    # If we get here we've passed the whole test. No need to report anything
    pass $testname;
    # else.
 
 
}
}
# Timeout 3 seconds is plenty as default
# Timeout 3 seconds is plenty as default
set timeout 3
set timeout 3
 
 

powered by: WebSVN 2.1.0

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