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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [or1ksim/] [testsuite/] [lib/] [libsim.exp] - Blame information for rev 143

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 93 jeremybenn
# Or1ksim library expect test functions for use with DejaGNU under automake
2
 
3
# Copyright (C) 2010 Embecosm Limited
4
 
5
# Contributor Jeremy Bennett 
6
 
7
# This file is part of OpenRISC 1000 Architectural Simulator.
8
 
9
# This program is free software; you can redistribute it and/or modify it
10
# under the terms of the GNU General Public License as published by the Free
11
# Software Foundation; either version 3 of the License, or (at your option)
12
# any later version.
13
 
14
# This program is distributed in the hope that it will be useful, but WITHOUT
15
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
17
# more details.
18
 
19
# You should have received a copy of the GNU General Public License along
20
# with this program.  If not, see .  */
21
 
22
# -----------------------------------------------------------------------------
23
# This code is commented throughout for use with Doxygen.
24
# -----------------------------------------------------------------------------
25
 
26
 
27
# -----------------------------------------------------------------------------
28
#! Run a libor1ksim program with the supplied config_file and target program.
29
#
30
#! @param[in] testname    The name of the test
31
#! @param[in] match_list  A list of expected responses
32
#! @param[in] libprog     The libor1ksim program
33
#! @param[in] config      The or1ksim config file to use
34
#! @param[in] or1kprog    The program image to use on libprog
35
#! @param[in] args        Any other arguments
36
# -----------------------------------------------------------------------------
37
proc run_libsim { testname match_list libprog config or1kprog args } {
38
    global verbose
39 95 jeremybenn
    global srcdir
40
    global objdir
41 93 jeremybenn
 
42
    # Construct the config filename or use the default
43
    if {0 == [string length $config]} {
44
        set config "default.cfg";
45
    }
46
 
47 95 jeremybenn
    set libprog_name  "$objdir/test-code/$libprog"
48
    set config_name   "$srcdir/libsim.tests/$config";
49
    set or1kprog_name "$objdir/test-code-or1k/$or1kprog"
50 93 jeremybenn
 
51
    set command_line "$libprog_name $config_name $or1kprog_name $args"
52
 
53
    if { $verbose > 1 } {
54
        send_user "starting $command_line\n"
55
    }
56
 
57
    # Run the program.
58
    eval "spawn $command_line"
59
 
60
    # Try each matchstr in turn, counting the lines for error reporting
61
    set match_line 0;
62
 
63
    foreach matchstr $match_list {
64
 
65
        set match_line [expr {$match_line + 1}];
66
 
67
        if { $verbose > 2 } {
68
            send_user "matching |$matchstr|\n";
69
        }
70
 
71 99 jeremybenn
        # The matching is slightly tricky. In general we want to find warnings
72
        # or errors. However expect will look at the entire buffer, so if we
73
        # have the match string *after* an error or warning message, then the
74
        # match will still work OK.
75
 
76
        # The trick is to do some post-processing of the matched buffer to see
77
        # if there was a preceding Warning or ERROR message.
78
 
79 93 jeremybenn
        expect {
80
            $matchstr {
81 99 jeremybenn
                set matchlen [string length $matchstr]
82
                set buflen [string length $expect_out(buffer)]
83
                set lastch [expr {$buflen - $matchlen}]
84
                set prefix [string range $expect_out(buffer) 0 $lastch]
85 93 jeremybenn
 
86 99 jeremybenn
                if { [string match *ERROR* $prefix] } {
87
                    # We skipped an error
88
                    fail "$testname: ERROR seeking match line $match_line";
89
                    return
90
                } elseif { [string match *Warning* $prefix] } {
91
                    # We skipped a warning
92
                    fail "$testname: Warning seeking match line $match_line";
93
                    return;
94
                }
95
 
96
                # Otherwise silently match
97 93 jeremybenn
            }
98 99 jeremybenn
 
99
            ERROR {
100
                # An error other than the one we seek
101
                fail "$testname: ERROR seeking match line $match_line";
102 93 jeremybenn
                return
103
            }
104 99 jeremybenn
 
105
            Warning {
106
                # Any warning
107
                fail "$testname: Warning seeking match line $match_line";
108
                return;
109
            }
110
 
111 93 jeremybenn
            eof {
112
                fail "$testname: hit EOF seeking match line $match_line";
113
                return
114
            }
115
 
116
            timeout {
117
                perror "Timeout";
118 95 jeremybenn
                unresolved "$testname: timeout";
119 93 jeremybenn
                return
120
            }
121
        }
122
    }
123
 
124
    # If we get here we've passed
125
    pass $testname;
126
 
127
}
128
 
129
# Timeout 3 seconds is plenty as default
130
set timeout 3

powered by: WebSVN 2.1.0

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