dejagnu
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using telnet for remote testing


From: Ryan Smiderle
Subject: Re: Using telnet for remote testing
Date: Wed, 16 Jul 2003 14:46:30 -0400 (EDT)

Hi,

Here's the changes I made to get telnet execution working:

-----------------------------

telnet.exp (in proc telnet_open)

I commented this out:
   191:     # it doesn't always show up in the expect in buffer till the server 
times out.
   192:     if [info exists expect_out(buffer)] {
   193:         if [regexp "assword:|ogin:" $expect_out(buffer)] {
   194:             perror "telnet: need to supply a login and password."
   195:         }
   196:     }

This block was causing me issues.  I didn't really spend much time in it, but 
removing it worked for me.

----------------------

standard.exp (in proc standard_load)

added
    remote_exec $dest "chmod a+x $remotefile" $pargs $inp
before
  1026:         set status [remote_exec $dest $remotefile $pargs $inp];

FTP-ing a binary removes the execute permissions, so I add it again before 
executing

-------------------------

You'll need these setting defined.  (For ftp file transer, telnet execution)

set_board_info connect telnet
set_board_info file_transfer ftp
set_board_info ftp_username expect
set_board_info ftp_password expect
set_board_info telnet_username expect
set_board_info telnet_password expect
set_board_info shell_prompt "# "


--------------------------------------
telnet_exec:

proc telnet_exec {boardname cmd args} {
   global timeout
   global verbose
   set output "(no output)"

   verbose "Executing $boardname:$cmd $args"

    if { [llength $args] > 0 } {
         set pargs [lindex $args 0];
    } else {
         set pargs ""
    }

    if [board_info $boardname exists shell_prompt] {
       set shell_prompt [board_info $boardname shell_prompt]
    }
    if ![info exists shell_prompt] {    # if no prompt, then set it to 
something generic
          set shell_prompt ".*> "
    }

   #Start a new telnet session if one dosen't already exist
   if ![board_info $boardname exists fileid] {
      if {[telnet_open $boardname] == -1} {
         return [list -1 "telnet to $boardname failed for $cmd, couldn't begin 
telnet session"]
      }
   }

   set spawn_id [board_info $boardname fileid]
   set timeout 30

   #Hit enter to make sure you get a shell prompt
   send -- "\r"

   expect {
      -re "$shell_prompt.*$" { 
         verbose "Got a prompt"
      }
      default {
         telnet_close $boardname
         if {[telnet_open $boardname] != -1} {
            verbose "started new telnet session, spawn_id is [board_info 
$boardname fileid]"
            send -- "\r"
            exp_continue
         } else {
            return [list -1 "telnet to $boardname failed for $cmd, couldn't get 
a shell prompt"]
         }
         send -- "\r"
         exp_continue
      }
   }
   
   set timeout 10
   send "$cmd $pargs\r"

   expect {
      -re "$shell_prompt.*$" { 
      }
      timeout {
         if  [info exists expect_out(buffer)] {
            set execute_output_string $expect_out(buffer)
            }
         telnet_close $boardname
         return "fail timeout"
      }
   }
   
   #Remove unesesary strings from the output string
   #
   #If the file path contains any "+" signs, it will mess things up when $cmd
   #is used as a regsub pattern (2 lines down), so we replace all "+"s with "."
   regsub -all "\\+" $cmd "." cmd
   regsub -all $cmd "$expect_out(buffer)" {} output  
   regsub $shell_prompt $output {} output
   regsub -all "\[\r\n\]" $output {} output

   #Check the return status
   set timeout 30
   send -- "echo \$?\r"
   expect -re "$shell_prompt.*$"

   #Regsub the output to get the status number
   regsub -all {echo \$\?} $expect_out(buffer) {} status
   regsub $shell_prompt $status {} status
   regsub -all "\[\r\n \]" $status {} status

   #This probably isn't neccessary..
   if {[regexp {[0123456789]+} $status] != 1} {
      warning "status not a number, it is <$status>, setting it to 1"
      set status 1
   }

   if {$status == 0} {
      return [list "0" "$output"]
   } else {
      return [list "1" "$output"]
   }   
}





reply via email to

[Prev in Thread] Current Thread [Next in Thread]