# Or1ksim library expect test functions for use with DejaGNU under automake
|
# Or1ksim library expect test functions 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 libor1ksim program with the supplied config_file and target program.
|
#! Run a libor1ksim program with the supplied config_file and target program.
|
#
|
#
|
#! @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] libprog The libor1ksim program
|
#! @param[in] libprog The libor1ksim program
|
#! @param[in] config The or1ksim config file to use
|
#! @param[in] config The or1ksim config file to use
|
#! @param[in] or1kprog The program image to use on libprog
|
#! @param[in] or1kprog The program image to use on libprog
|
#! @param[in] args Any other arguments
|
#! @param[in] args Any other arguments
|
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
proc run_libsim { testname match_list libprog config or1kprog args } {
|
proc run_libsim { testname match_list libprog config or1kprog args } {
|
global verbose
|
global verbose
|
global srcdir
|
global srcdir
|
global objdir
|
global objdir
|
|
|
# Construct the config filename or use the default
|
# Construct the config filename or use the default
|
if {0 == [string length $config]} {
|
if {0 == [string length $config]} {
|
set config "default.cfg";
|
set config "default.cfg";
|
}
|
}
|
|
|
set libprog_name "$objdir/test-code/$libprog"
|
set libprog_name "$objdir/test-code/$libprog"
|
set config_name "$srcdir/libsim.tests/$config";
|
set config_name "$srcdir/libsim.tests/$config";
|
set or1kprog_name "$objdir/test-code-or1k/$or1kprog"
|
set or1kprog_name "$objdir/test-code-or1k/$or1kprog"
|
|
|
set command_line "$libprog_name $config_name $or1kprog_name $args"
|
set command_line "$libprog_name $config_name $or1kprog_name $args"
|
|
|
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;
|
|
|
foreach matchstr $match_list {
|
foreach matchstr $match_list {
|
|
|
set match_line [expr {$match_line + 1}];
|
set match_line [expr {$match_line + 1}];
|
|
|
if { $verbose > 2 } {
|
if { $verbose > 2 } {
|
send_user "matching |$matchstr|\n";
|
send_user "matching |$matchstr|\n";
|
}
|
}
|
|
|
# The matching is slightly tricky. In general we want to find warnings
|
# 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
|
# 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
|
# have the match string *after* an error or warning message, then the
|
# match will still work OK.
|
# match will still work OK.
|
|
|
# The trick is to do some post-processing of the matched buffer to see
|
# The trick is to do some post-processing of the matched buffer to see
|
# if there was a preceding Warning or ERROR message.
|
# if there was a preceding Warning or ERROR message.
|
|
|
expect {
|
expect {
|
$matchstr {
|
$matchstr {
|
set matchlen [string length $matchstr]
|
set matchlen [string length $matchstr]
|
set buflen [string length $expect_out(buffer)]
|
set buflen [string length $expect_out(buffer)]
|
set lastch [expr {$buflen - $matchlen}]
|
set lastch [expr {$buflen - $matchlen}]
|
set prefix [string range $expect_out(buffer) 0 $lastch]
|
set prefix [string range $expect_out(buffer) 0 $lastch]
|
|
|
if { [string match *ERROR* $prefix] } {
|
if { [string match *ERROR* $prefix] } {
|
# We skipped an error
|
# We skipped an error
|
fail "$testname: ERROR seeking match line $match_line";
|
fail "$testname: ERROR seeking match line $match_line";
|
return
|
return
|
} elseif { [string match *Warning* $prefix] } {
|
} elseif { [string match *Warning* $prefix] } {
|
# We skipped a warning
|
# We skipped a warning
|
fail "$testname: Warning seeking match line $match_line";
|
fail "$testname: Warning seeking match line $match_line";
|
return;
|
return;
|
}
|
}
|
|
|
# Otherwise silently match
|
# Otherwise silently match
|
}
|
}
|
|
|
ERROR {
|
ERROR {
|
# An error other than the one we seek
|
# An error other than the one we seek
|
fail "$testname: ERROR seeking match line $match_line";
|
fail "$testname: ERROR seeking match line $match_line";
|
return
|
return
|
}
|
}
|
|
|
Warning {
|
Warning {
|
# Any warning
|
# Any warning
|
fail "$testname: Warning seeking match line $match_line";
|
fail "$testname: Warning seeking match line $match_line";
|
return;
|
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";
|
perror "Timeout";
|
unresolved "$testname: timeout";
|
unresolved "$testname: timeout";
|
|
close
|
return
|
return
|
}
|
}
|
}
|
}
|
}
|
}
|
|
|
# If we get here we've passed
|
# If we get here we've passed
|
pass $testname;
|
pass $testname;
|
|
|
}
|
}
|
|
|
# Timeout 3 seconds is plenty as default
|
# Timeout 3 seconds is plenty as default
|
set timeout 3
|
set timeout 3
|
|
|