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

Subversion Repositories openrisc

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

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

Line No. Rev Author Line
1 82 jeremybenn
# Or1ksim expect test functiosn 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 program on Or1ksim with the supplied config_file
29
#
30
#! @param[in] testname    The name of the test
31
#! @param[in] match_list  A list of expected responses
32
#! @param[in] config_file The or1ksim config file to use
33
# !@param[in] progname    The program image to use on Or1ksim
34
# -----------------------------------------------------------------------------
35
proc run_or1ksim { testname match_list config_file progname } {
36
    global verbose
37 95 jeremybenn
    global srcdir
38
    global objdir
39 82 jeremybenn
 
40
    # Construct the filename
41
    if {0 == [string length $config_file]} {
42 95 jeremybenn
        set config_full_file "$srcdir/or1ksim.tests/default.cfg";
43 82 jeremybenn
    } else {
44 95 jeremybenn
        set config_full_file "$srcdir/or1ksim.tests/$config_file";
45 82 jeremybenn
    }
46
 
47 95 jeremybenn
    set prog_full_name "$objdir/test-code-or1k/$progname"
48
    set command_line "$objdir/../sim -f $config_full_file $prog_full_name"
49 82 jeremybenn
 
50
    if { $verbose > 1 } {
51
        send_user "starting $command_line\n"
52
    }
53
 
54
    # Run the program.
55
    eval "spawn $command_line"
56
 
57
    # Try each matchstr in turn, counting the lines for error reporting
58
    set match_line 0;
59
 
60 104 jeremybenn
    # The tests for Or1ksim are generally monolithic, with each line of output
61
    # matched representing a pass. This is different to the tests for the
62
    # library, which are each small and individual.
63 82 jeremybenn
    foreach matchstr $match_list {
64
 
65
        set match_line [expr {$match_line + 1}];
66
 
67 104 jeremybenn
        # Each matchstring corresponds to a pass, unless its first character
68
        # is '!', indicating a string which must match (without its '!'), but
69
        # does not count towards the pass rate.
70
        set first_ch [string index $matchstr 0]
71 82 jeremybenn
 
72 104 jeremybenn
        if { $first_ch == "!" } {
73
            # A line to ignore
74
            set matchlen [string length $matchstr]
75
            set last_index [expr {$matchlen - 1}]
76
            set matchstr [string range $matchstr 1 $last_index]
77 82 jeremybenn
 
78 104 jeremybenn
            if { $verbose > 2 } {
79
                send_user "ignorning |$matchstr|\n";
80 93 jeremybenn
            }
81 104 jeremybenn
        }
82 93 jeremybenn
 
83 104 jeremybenn
        if { $verbose > 2 } {
84
            send_user "matching |$matchstr|\n";
85
        }
86
 
87
        # The matching is slightly tricky. In general we want to find warnings
88
        # or errors. However expect will look at the entire buffer, so if we
89
        # have the match string *after* an error or warning message, then the
90
        # match will still work OK.
91
 
92
        # The trick is to do some post-processing of the matched buffer to see
93
        # if there was a preceding Warning or ERROR message.
94
 
95
        expect {
96
            -ex $matchstr {
97
                set matchlen [string length $matchstr]
98
                set buflen [string length $expect_out(buffer)]
99
                set lastch [expr {$buflen - $matchlen}]
100
                set prefix [string range $expect_out(buffer) 0 $lastch]
101
 
102
                if { [string match *ERROR* $prefix] } {
103
                    # We skipped an error
104
                    fail "$testname: ERROR seeking match line $match_line";
105
                    return
106
                } elseif { [string match *Warning* $prefix] } {
107
                    # We skipped a warning
108
                    fail "$testname: Warning seeking match line $match_line";
109
                    return;
110
                } elseif { $first_ch != "!" } {
111
                    # If we match we have a pass, unless we were asked to
112
                    # ignore.
113
                    pass "$testname: $matchstr"
114
                }
115
                # Everything else skip silently
116 82 jeremybenn
            }
117 104 jeremybenn
 
118
            ERROR {
119
                # An error other than the one we seek
120
                fail "$testname: ERROR seeking match line $match_line";
121 82 jeremybenn
                return
122
            }
123 104 jeremybenn
 
124
            Warning {
125
                # Any warning
126
                fail "$testname: Warning seeking match line $match_line";
127
                return;
128
            }
129
 
130 82 jeremybenn
            eof {
131
                fail "$testname: hit EOF seeking match line $match_line";
132
                return
133
            }
134
 
135
            timeout {
136 104 jeremybenn
                perror "Timeout";
137 95 jeremybenn
                unresolved "$testname: timeout";
138 82 jeremybenn
                return
139
            }
140
        }
141
    }
142
 
143 104 jeremybenn
    # If we get here we've passed the whole test. No need to report anything
144
    # else.
145 82 jeremybenn
}
146
 
147
# Timeout 3 seconds is plenty as default
148
set timeout 3

powered by: WebSVN 2.1.0

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