aboutsummaryrefslogtreecommitdiff
path: root/config/udi.exp
blob: ff3705a29b01b7ec77269e1419484675eba6f55d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free Software
# Foundation, Inc.
#
# This file is part of DejaGnu.
#
# DejaGnu 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 Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# DejaGnu is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with DejaGnu; if not, write to the Free Software Foundation,

# When using the simulator (-n iss) and running nice'd, things can naturally
# take a little longer, so increase the timeout.

#
# udi_load -- load the program and execute it
#
# See default.exp for explanation of arguments and results.
#

proc udi_load { dest prog args } {
    set shell_prompt [board_info $dest shell_prompt]
    set output ""

    if ![file exists $prog] then {
	perror "$prog does not exist."
	verbose -log "$prog does not exist." 3
	return [list "untested" ""]
    }

    # Load the program.
    if ![board_info $dest exists fileid] then {
	remote_open $dest
	if ![board_info $dest exists fileid] then {
	    verbose -log "$prog not executed, couldn't connect to $dest." 3
	    return "untested"
	}
    }

    if { [remote_ld $dest $prog] == "" } {
	verbose -log "$prog not executed, load failed." 3
	return [list "unresolved" ""]
    }

    # Execute it.
    set result -1
    set output ""
    set noappend 0

    verbose "Executing $prog." 2
    remote_send $dest "g\n"
    # FIXME: The value 300 below should be a parameter.
    remote_expect $dest 300 {
	-re "(.*)Process exited with 0x0\[^\r\n\]*\[\r\n\]" {
	    append output $expect_out(1,string)
            verbose "$prog executed successfully" 2
	    set noappend 1
	    set result 0
	    exp_continue
	}
	-re "(.*)Halt instruction encountered" {
	    append output $expect_out(1,string)
            verbose "$prog got a HALT instruction" 2
	    set result 1
	    set noappend 1
	    exp_continue
	}
	-re "(^|\[\r\n\])$shell_prompt" {
	    if { $result == -1 } {
		exp_continue
	    }
	}
	-re "(^|\[\r\n\]+)g\[\r\n\]+" {
	    exp_continue
	}
	-re "\[\r\n\]+" {
	    if { ! $noappend } {
		append output $expect_out(buffer)
		if { [string length $output] < 512000 } {
		    exp_continue
		} else {
		    set result 1
		}
	    } else {
		exp_continue
	    }
	}
	timeout {
	    warning "$prog timed out."
	}
    }

    # See what happened.
    switch -- $result {
	0 {
	    set status [check_for_board_status output]
	    if { $status < 0 } {
		blammo
	    }
	    if { $status > 0 } {
		set result "fail"
	    } else {
		set result "pass"
	    }
	}
	1 - -1 {
	    warning "Resetting $dest."
	    remote_send $dest "r\n"
	    remote_expect $dest 5 {
		-re "r.*$shell_prompt.*" {
		    verbose "Target reset." 2
		}
		timeout {
		    # Get nastier.  We want to leave the system in a state
		    # ready to run the next testcase.
		    remote_send $dest "q\n"
		    remote_close $dest
		    set udi_shell_id [remote_open $dest]
		    if { $udi_shell_id < 0 } {
			perror "Couldn't reset $dest."
		    }
		}
	    }
	    if { $result == 1 } {
		set result "fail"
	    } else {
		set result "unresolved"
	    }
	}
	default {
	    set result "unresolved"
	}
    }
    return [list $result $output]
}

#
# udi_exit -- shutdown the connection (or simulator)
#

proc udi_exit {} {
    remote_close target
}

set_board_info protocol "udi"
set_board_info connect "mondfe"
set_board_info shell_prompt "mondfe>"