1
2#
3# Returns the filename of the vmips binary we are supposed
4# to be using.
5#
6proc vmips_tool_exec_name {} {
7    global objdir
8    if [info exists objdir] {
9        set vmips "$objdir/../vmips"
10        if ![file exists $vmips] {
11            perror "Can't find vmips in $vmips"
12        } else {
13            return $vmips
14        }
15    } else {
16        perror "objdir is not set"
17        return ""
18    }
19}
20
21proc vmips_endian_option {} {
22    if {[vmips_target_endian] == "little"} {
23        return "nobigendian"
24    } else {
25        return "bigendian"
26    }
27}
28
29#
30# Start vmips with the specified COMMANDLINE.
31# Disables the reading of system-wide and user-specific config files.
32# The user is expected to have set a global timeout.
33# Returns zero if the test case completed within the timeout, or
34# negative if it did not.
35# As a side effect, sets global variable COMP_OUTPUT
36# to the output from running vmips.
37#
38proc vmips_start {commandline} {
39    global comp_output spawn_id objdir
40    set vmips [vmips_tool_exec_name]
41    # Do not read config files - use defaults only.
42    set commandline "-n -F $objdir/../vmipsrc -o [vmips_endian_option] $commandline"
43    verbose "*** RUNNING $vmips $commandline"
44    #
45    # This is a mess because exec throws an error if the command fails,
46    # and we want to get stdout _and_ stderr from the command. Exec
47    # unfortunately isn't smart enough to handle this, so we have to
48    # spawn a shell.
49    #
50    # This was the old way to do it:
51    # set comp_output [exec -- sh -c "$vmips $commandline 2>&1 || true"]
52    #
53    # But, alas, this did not account for things that vmips prints to
54    # /dev/tty, which we'd dearly like to have included in the parseable
55    # output.
56    #
57    set timed_out 0
58    eval { spawn -noecho sh -c "$vmips $commandline 2>&1 || true" }
59    set comp_output ""
60    expect {
61        -re ".+" { set comp_output "$comp_output$expect_out(0,string)";
62                   exp_continue }
63        timeout { verbose "testcase timed out"; set timed_out -1 }
64        eof
65    }
66    regsub -all "\r\n" $comp_output "\n" munged_output
67    set comp_output "$munged_output"
68    catch { close -i $spawn_id }
69    wait
70    return $timed_out
71}
72
73#
74# Stop vmips.
75# Does nothing for now, because vmips stops more or less automatically
76# for all our test cases.
77#
78proc vmips_exit {} {
79}
80
81#
82# Load a testcase into vmips.
83# Does nothing for now, because vmips loads test cases from the command
84# line. One could conceive of a (hairy) framework where we actually use
85# xmboot to load a test case into a running vmips...
86#
87proc vmips_load {} {
88}
89
90#
91# Prints out the vmips version.
92#
93proc vmips_version {} {
94    set vmips [vmips_tool_exec_name]
95    set version_output [exec $vmips --version | head -1]
96    regsub -- "vmips (.*)$" $version_output {"\1"} version
97    clone_output "vmips version $version\n"
98}
99
100