OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [gnu-src/] [boards/] [or32-linux-sim.exp] - Diff between revs 555 and 565

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 555 Rev 565
Line 28... Line 28...
# Custom proc to close a telnet session
# Custom proc to close a telnet session
 
 
# @param[in] connhost  The connected host being closed.
# @param[in] connhost  The connected host being closed.
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
proc telnet_close {connhost} {
proc telnet_close {connhost} {
 
    global board_info
 
 
    verbose "telnet_close: connhost $connhost" 3
    verbose "telnet_close: connhost $connhost" 3
 
 
    # Use the standard close proc from remote.exp
    # Close the session
    standard_close $connhost
    set spawn_id [board_info $connhost fileid]
 
    catch close -i $spawn_id
 
    catch wait -i $spawn_id
 
 
 
    # Check we really succeeded in closing
 
    if [board_info $connhost exists fileid] {
 
        verbose "telnet_close: deleting remaining fileid"
 
        unset board_info(${connhost},fileid)
 
    }
}
}
 
 
 
 
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# Custom proc to check if we have had too many failures
# Custom proc to check if we have had too many failures
Line 86... Line 95...
# @param[in] args       Arguments to the command
# @param[in] args       Arguments to the command
 
 
# @return  A list of the return code (-1 on failure) and any error message.
# @return  A list of the return code (-1 on failure) and any error message.
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
proc telnet_exec {hostname cmd args} {
proc telnet_exec {hostname cmd args} {
    global timeout
 
    global board_info
    global board_info
    global verbose
    global verbose
    global spawn_id
 
 
 
    # Get the connected host name, if it exists. This code matches
    # Get the connected host name, if it exists. This code matches
    # telnet_open.
    # telnet_open.
    verbose "telnet_exec: original hostname is $hostname"
    verbose "telnet_exec: original hostname is $hostname"
 
 
Line 137... Line 144...
 
 
    # Start a new telnet session if one doesn't already exist. If sucessful
    # Start a new telnet session if one doesn't already exist. If sucessful
    # the fileid field associated with $connhost will be set to the spawn_id
    # the fileid field associated with $connhost will be set to the spawn_id
    # of the new telnet process.
    # of the new telnet process.
    if ![board_info $connhost exists fileid] {
    if ![board_info $connhost exists fileid] {
 
        verbose "telnet_exec: opening new telnet connection"
        if {[telnet_open $connhost] == -1} {
        if {[telnet_open $connhost] == -1} {
            return [list -1 "telnet to $hostname failed for $cmd, couldn't begin telnet session"]
            return [list -1 "telnet to $hostname failed for $cmd, couldn't begin telnet session"]
        }
        }
    }
    }
 
 
    # Save the timeout. It's a global, which we shall mess about with, and
    # The spawn_id we'll use throughout
    # restore on exit.
 
    set timeout_orig timeout
 
 
 
    # Make the telnet session the current process. Short timeout for this.
 
    set spawn_id [board_info $connhost fileid]
    set spawn_id [board_info $connhost fileid]
 
    verbose "telnet_exec: spawn_id is now $spawn_id"
 
 
 
    # Use a relatively short timeout for most operations. Only the command
 
    # itself uses a long timeout.
    set timeout 30
    set timeout 30
 
 
    #Hit enter to make sure you get a shell prompt
    #Hit enter to make sure you get a shell prompt
    send "\r"
    send -i $spawn_id "\r"
 
 
    expect {
    expect {
        # A prompt indicates the current session is alive
        # A prompt indicates the current session is alive
        -re "$shell_prompt" {
        -i $spawn_id -re "$shell_prompt" {
            verbose "telnet_exec: got prompt at start"
            verbose "telnet_exec: got prompt at start"
        }
        }
        default {
        -i $spawn_id default {
            # Timeout or EOF. Die if we have had too many failures
            # Timeout or EOF. Die if we have had too many failures
            telnet_failure_check $connhost "no prompt at telnet start"
            telnet_failure_check $connhost "no prompt at telnet start"
 
 
            # Try closing the connection and reopening.
            # Try closing the connection and reopening.
            telnet_close $connhost
            telnet_close $connhost
            if {[telnet_open $connhost] != -1} {
            if {[telnet_open $connhost] != -1} {
                set spawn_id [board_info $connhost fileid]
                set spawn_id [board_info $connhost fileid]
                verbose "telnet_exec: new telnet session, spawn_id: $spawn_id"
                verbose "telnet_exec: new telnet session, spawn_id: $spawn_id"
                send "\r"
                send -i $spawn_id "\r"
                exp_continue
                exp_continue
            } else {
            } else {
                set timeout timeout_orig
 
                return [list -1 "telnet to $hostname failed for $cmd, couldn't get a shell prompt"]
                return [list -1 "telnet to $hostname failed for $cmd, couldn't get a shell prompt"]
            }
            }
        }
        }
    }
    }
 
 
    # Send the command. We can't cope with any input, so only the first
    # Send the command. We can't cope with any input, so only the first
    # argument (group) is sent.
    # argument (group) is sent.
    send "$cmd $pargs\r"
    send -i $spawn_id -- "$cmd $pargs\r"
 
 
    # We really should get the command echoed back immediately. This is a good
    # We really should get the command echoed back immediately. This is a good
    # way of slurping up unexpected prompts. We first swap out any characters
    # way of slurping up unexpected prompts. We first swap out any characters
    # from the command and args that might cause us grief.
    # from the command and args that might cause us grief.
    regsub -all "\\+" "$cmd $pargs" "." cmdpargs
    regsub -all "\\+" "$cmd $pargs" "." cmdpargs
    verbose "telnet_exec: command match string is \"$cmdpargs\""
    verbose "telnet_exec: command match string is \"$cmdpargs\""
 
 
    expect {
    expect {
        -re "$cmdpargs" {
        -i $spawn_id -re "$cmdpargs" {
            verbose "telnet_exec: got command echoed back"
            verbose "telnet_exec: got command echoed back"
        }
        }
        default {
        -i $spawn_id default {
            verbose "telnet_exec: command not echoed: command expect_out(buffer): \"$expect_out(buffer)\""
            verbose "telnet_exec: command not echoed: command expect_out(buffer): \"$expect_out(buffer)\""
        }
        }
    }
    }
 
 
    # Set the telnet command custom timeout to wait for the command to
    # Set the telnet command custom timeout to wait for the command to
Line 207... Line 214...
        set timeout 300
        set timeout 300
        verbose "telnet_exec: command timeout set to default value $timeout"
        verbose "telnet_exec: command timeout set to default value $timeout"
    }
    }
 
 
    expect {
    expect {
        -re "$shell_prompt" {
        -i $spawn_id -re "$shell_prompt" {
            verbose "telnet_exec: got prompt after command"
            verbose "telnet_exec: got prompt after command"
        }
        }
        default {
        -i $spawn_id default {
            # Give up on timeout or EOF
            # Give up on timeout or EOF
            telnet_close $connhost
            telnet_close $connhost
            set timeout timeout_orig
 
            return [list -1 "telnet to $hostname for $cmd $pargs failed (timeout)"]
            return [list -1 "telnet to $hostname for $cmd $pargs failed (timeout)"]
        }
        }
    }
    }
 
 
    # Remove unnecessary strings from the output string
    # Remove unnecessary strings from the output string
Line 235... Line 241...
    verbose "telnet_exec: command output $output"
    verbose "telnet_exec: command output $output"
 
 
    # Check the return status. Use a short timeout for this and following
    # Check the return status. Use a short timeout for this and following
    # commands.
    # commands.
    set timeout 30
    set timeout 30
    send "echo \$?\r"
    send -i $spawn_id "echo \$?\r"
 
 
    # Once again, look for the "echo" reflected back as a way of slurping up
    # Once again, look for the "echo" reflected back as a way of slurping up
    # unexpected prompts. We don't worry about timeout here - we'll sort that
    # unexpected prompts. We don't worry about timeout here - we'll sort that
    # out later.
    # out later.
    expect {
    expect {
        -re "echo \\$\\?" {
        -i $spawn_id -re "echo \\$\\?" {
            verbose "telnet_exec: got \"echo\" echoed back"
            verbose "telnet_exec: got \"echo\" echoed back"
        }
        }
        default {
        -i $spawn_id default {
            verbose "telnet_exec: echo not echoed: command expect_out(buffer): \"$expect_out(buffer)\""
            verbose "telnet_exec: echo not echoed: command expect_out(buffer): \"$expect_out(buffer)\""
        }
        }
    }
    }
 
 
    # Look for the shell prompt. Don't worry about timeout for now. It only
    # Look for the shell prompt. Don't worry about timeout for now. It only
    # really matters if we don't get a valid status, which we'll discover
    # really matters if we don't get a valid status, which we'll discover
    # below.
    # below.
    expect {
    expect {
        -re "$shell_prompt" {
        -i $spawn_id -re "$shell_prompt" {
            verbose "telnet_exec: got status shell prompt"
            verbose "telnet_exec: got status shell prompt"
        }
        }
        default {
        -i $spawn_id default {
            verbose "telnet_exec: no status shell prompt: command expect_out(buffer): \"$expect_out(buffer)\""
            verbose "telnet_exec: no status shell prompt: command expect_out(buffer): \"$expect_out(buffer)\""
        }
        }
    }
    }
 
 
    # Regsub the output to get the status number
    # Regsub the output to get the status number
Line 278... Line 284...
 
 
        # Die if we have had too many failures like this.
        # Die if we have had too many failures like this.
        telnet_failure_check $connhost "bad status"
        telnet_failure_check $connhost "bad status"
    }
    }
 
 
    set timeout timeout_orig
 
    if {$status == 0} {
    if {$status == 0} {
        return [list "0" "$output"]
        return [list "0" "$output"]
    } else {
    } else {
        return [list "1" "$output"]
        return [list "1" "$output"]
    }
    }

powered by: WebSVN 2.1.0

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