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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [dejagnu/] [testsuite/] [lib/] [libsup.exp] - Blame information for rev 1767

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

Line No. Rev Author Line
1 578 markom
# Copyright (C) 92, 93, 94, 95, 1996 Free Software Foundation, Inc.
2
 
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16
 
17
# Please email any bugs, comments, and/or additions to this file to:
18
# bug-dejagnu@prep.ai.mit.edu
19
 
20
# This file was written by Rob Savoye. (rob@cygnus.com)
21
 
22
#
23
# Setup an environment so we can execute library procs without DejaGnu
24
#
25
 
26
#
27
# Create a default environment and start expect.
28
#
29
proc make_defaults_file { defs } {
30
    global srcdir
31
    global objdir
32
    global subdir
33
    global build_triplet
34
    global host_triplet
35
    global target_triplet
36
    global target_os
37
    global target_cpu
38
 
39
    # We need to setup default values and a few default procs so we
40
    # can execute library code without DejaGnu
41
    set fd [open $defs w]
42
    puts ${fd} "set tool foobar"
43
    puts ${fd} "set srcdir ${srcdir}"
44
    puts ${fd} "set objdir ${objdir}"
45
    puts ${fd} "set subdir ${subdir}"
46
    puts ${fd} "set build_triplet ${build_triplet}"
47
    puts ${fd} "set host_triplet ${host_triplet}"
48
    puts ${fd} "set target_triplet ${target_triplet}"
49
    puts ${fd} "set target_os ${target_os}"
50
    puts ${fd} "set target_cpu ${target_cpu}"
51
    puts ${fd} "set tool foobar"
52
    puts ${fd} "set testcnt 0"
53
    puts ${fd} "set warncnt 0"
54
    puts ${fd} "set errcnt 0"
55
    puts ${fd} "set passcnt 0"
56
    puts ${fd} "set xpasscnt 0"
57
    puts ${fd} "set failcnt 0"
58
    puts ${fd} "set xfailcnt 0"
59
    puts ${fd} "set prms_id 0"
60
    puts ${fd} "set bug_id 0"
61
    puts ${fd} "set exit_status 0"
62
    puts ${fd} "set untestedcnt 0"
63
    puts ${fd} "set unresolvedcnt 0"
64
    puts ${fd} "set unsupportedcnt 0"
65
    puts ${fd} "set xfail_flag 0"
66
    puts ${fd} "set xfail_prms 0"
67
    puts ${fd} "set mail_logs 0"
68
    puts ${fd} "set multipass_name 0"
69
    catch "close $fd"
70
}
71
 
72
proc start_expect { } {
73
    global spawn_id
74
    global base_dir
75
 
76
    # We need to setup default values and a few default procs so we
77
    # can execute library code without DejaGnu
78
    set defaults_file setval.tmp
79
    make_defaults_file $defaults_file
80
    set fd [open ${defaults_file} w]
81
 
82
    # look for expect
83
    if ![info exists EXPECT] {
84
        set EXPECT [findfile $base_dir/../../expect/expect "$base_dir/../../expect/expect" expect]
85
        verbose "EXPECT defaulting to $EXPECT" 2
86
    }
87
 
88
#    catch close
89
#    catch wait
90
 
91
    # Start expect runing
92
    spawn "$EXPECT"
93
    expect {
94
        -re "expect.*> " {
95
            verbose "Started the child expect shell" 2
96
        }
97
        timeout {
98
            perror "Timed out starting the child expect shell."
99
            return -1
100
        }
101
    }
102
 
103
    # Load the defaults file
104
    exp_send "source ${defaults_file}\n"
105
    expect {
106
        "expect*> " {
107
            verbose "Loaded testing defaults file." 2
108
            return 1
109
        }
110
        timeout {
111
            perror "Couldn't load the testing defaults file."
112
            return -1
113
        }
114
    }
115
}
116
 
117
#
118
# Stop the runing expect process
119
#
120
proc stop_expect { }  {
121
    global spawn_id
122
 
123
    # make expect exit
124
    exp_send "exit\n"
125
    catch "close -i $spawn_id"
126
    catch "wait -i $spawn_id"
127
}
128
 
129
#
130
# Load the library to test
131
#
132
proc load_test_lib { lib } {
133
    global spawn_id
134
    exp_send "source ${lib}\n"
135
    expect {
136
        "expect*> " {
137
            verbose "Testing ${lib}" 2
138
        }
139
        timeout {
140
            perror "Couldn't load the libraries to test"
141
            return -1
142
        }
143
    }
144
}
145
 
146
#
147
# test a library proc that emits patterns
148
#
149
proc exp_test { cmd pattern msg } {
150
    global spawn_id
151
 
152
    exp_send "puts ACK ; $cmd ; puts NAK\r\n"
153
    expect {
154
        "puts ACK*puts NAK" {
155
            verbose "Got command echo" 3
156
        }
157
        timeout {
158
            warning "Never got command echo"
159
        }
160
    }
161
 
162
    expect {
163
        "ACK" {
164
            exp_continue
165
        }
166
        -re "\r\n1\r\n" {
167
            warning "$msg, 1 was returned"
168
            exp_continue
169
        }
170
        -re "\r\n0\r\n" {
171
            warning "$msg, 0 was returned"
172
            exp_continue
173
        }
174
        "$pattern" {
175
            pass "$msg"
176
        }
177
        timeout {
178
            fail "$msg"
179
        }
180
    }
181
}
182
 
183
# test a config proc that only returns a code
184
# ex... config_test "isbuild $build_triplet" "pass" "fail" "isbuild, native"
185
# args are:  command, true condition, false condition, message to print
186
proc config_test { cmd true false msg } {
187
    global spawn_id
188
 
189
    set timeout 20
190
    exp_send "puts ACK ; puts \[$cmd\] ; puts NAK\r\n"
191
    expect {
192
        "puts ACK*$cmd*puts NAK" {
193
            verbose "Got command echo" 3
194
        }
195
        timeout {
196
            warning "Never got command echo"
197
        }
198
    }
199
 
200
    expect {
201
        -re "Checking pattern*with*\[\r\n\]" {
202
            exp_continue
203
        }
204
        -re "\r\n1\r\n" {
205
            $true "$msg"
206
        }
207
        -re "\r\n0\r\n" {
208
            $false "$msg"
209
        }
210
        timeout {
211
            perror "$msg (timed out)"
212
        }
213
    }
214
}
215
 
216
 
217
 
218
 
219
 
220
 

powered by: WebSVN 2.1.0

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