home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-bin / lib / dejagnu / udi.exp < prev    next >
Encoding:
Text File  |  1996-10-12  |  5.2 KB  |  230 lines

  1. #   Copyright (C) 1988, 1990, 1991, 1992 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. # This program is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  10. # GNU General Public License for more details.
  11. # You should have received a copy of the GNU General Public License
  12. # along with this program; if not, write to the Free Software
  13. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  14.  
  15. # Please email any bugs, comments, and/or additions to this file to:
  16. # bug-dejagnu@prep.ai.mit.edu
  17.  
  18. # This file was written by Rob Savoye. (rob@cygnus.com)
  19.  
  20. # these just need to be initialized
  21. set shell_id       0
  22.  
  23. #
  24. # set target variables only if needed.
  25. #
  26. global  targetname
  27. global connectmode
  28. global env
  29.  
  30. if ![info exists targetname] then {
  31.     if [info exists env(TARGETNAME)] then {
  32.     set targetname $env(TARGETNAME)
  33.     } else {
  34.     puts stderr "ERROR: Need a target name for the udi target."
  35.     puts stderr "       Use the --name option\n"
  36.     exit 1
  37.     }
  38. }
  39.  
  40. # the default connect program to use
  41. if ![info exists connectmode] then {
  42.     set connectmode    "mondfe"
  43.     warning "Using default of $connectmode for target communication."
  44.     if {[which mondfe] == 0} then {
  45.     perror "\"mondfe\" does not exist. Check your path."
  46.     exit 1
  47.     }
  48. }
  49.  
  50.  
  51.  
  52. #
  53. # mondfe -- connect to udi using mondfe
  54. #
  55. proc mondfe { hostname } {
  56.     global verbose
  57.     global connectmode
  58.     global shell_prompt
  59.     global spawn_id
  60.     global shell_id
  61.     global spawn_id
  62.  
  63.     set retries 0
  64.     set result  -1
  65.     spawn mondfe -D -TIP $hostname
  66.     set shell_id $spawn_id
  67.  
  68.     expect {
  69.     "$shell_prompt"    { 
  70.         verbose "Got prompt"
  71.         set result 0
  72.     }
  73.     "*server bind*failed: Address already in use*" {
  74.         warning "Socket file already exists."
  75.         incr retries
  76.         if $retries<=2 then {
  77.         continue -expect
  78.         }
  79.     }
  80.     timeout            { 
  81.         warning "Timed out trying to connect."
  82.         set result -1
  83.         incr retries
  84.         if $retries<=2 then {
  85.         continue -expect
  86.         }
  87.     }
  88.     }
  89.  
  90.     if $result<0 then {
  91.     perror "Couldn't connect after $retries retries.\n"
  92.     return -1
  93.     } else {
  94.     return $spawn_id
  95.     }
  96. }
  97.  
  98. #
  99. # mondfe_download -- downloads using the y (yank) command in mondfe.
  100. #                 arg - is a full path name to the file to download
  101. #                 returns 1 if an error occured, 0 otherwise
  102. #
  103. proc mondfe_download { arg } {
  104.     global verbose
  105.     global shell_id
  106.     global decimal
  107.     global shell_prompt
  108.     global expect_out
  109.     global connectmode
  110.  
  111.     set result 1
  112.     if ![file exists $arg] then {
  113.     perror "$arg doesn't exist."
  114.     return 1
  115.     }
  116.  
  117.     verbose "Downloading $arg..."
  118.     send -i $shell_id "y $arg\n"
  119.     expect {
  120.     -i $shell_id "y $arg*loading $arg*" {
  121.         continue -expect
  122.     }
  123.     -i $shell_id "Loading*TEXT section from*\r" {
  124.         verbose "."
  125.         continue -expect
  126.     }
  127.     -i $shell_id "Loaded*TEXT section from*\n" {
  128.         verbose "\nLoaded TEXT section"
  129.         continue -expect
  130.     }
  131.     -i $shell_id "Loading*LIT section from*\r" {
  132.         verbose "."
  133.         continue -expect
  134.     }
  135.     -i $shell_id "Loaded*LIT section from*\n" {
  136.         verbose "\nLoaded LIT section"
  137.         continue -expect
  138.     }
  139.     -i $shell_id "Loading*DATA section from*\r" {
  140.         verbose "."
  141.         continue -expect
  142.     }
  143.     -i $shell_id "Loaded*DATA section from*\n" {
  144.         verbose "\nLoaded DATA section"
  145.         continue -expect
  146.     }
  147.     -i $shell_id -re "DFEWARNING: $decimal : EMMAGIC:  Bad COFF file magic number.*Command failed.*$shell_prompt$" {
  148.         warning "Bad COFF file magic number"
  149.         set result -1
  150.     }
  151.         -i $shell_id -re ".*Ignoring COMMENT section \($decimal bytes\).*$shell_prompt$" {
  152.             verbose "Ignoring COMMENT section"
  153.             verbose "Downloaded $arg successfully"
  154.             set result 0
  155.         }
  156.  
  157.     -i $shell_id -re ".*Cleared.*BSS section from.*$shell_prompt$" {
  158.         verbose "Cleared BSS section"
  159.         verbose "Downloaded $arg successfully"
  160.         set result 0
  161.     }
  162.     -i $shell_id timeout {
  163.         perror "Timed out trying to download $arg."
  164.         set result 1
  165.     }
  166.     }
  167.  
  168. # FIXME: the following kepts the download from working
  169. #    "Could not read COFF section" {
  170. #        perror "Couldn't read COFF section."
  171. #        set result 1
  172. #    }
  173.     set timeout 10
  174.     if [info exists expect_out(buffer)] then {
  175.     send_log $expect_out(buffer)
  176.     }
  177.     return $result
  178. }
  179.  
  180. #
  181. # exit_mondfe -- exit the remote shell
  182. #
  183. proc exit_mondfe {  } {
  184.     global verbose
  185.     global connectmode
  186.     global targetname
  187.     global shell_prompt
  188.     global shell_id
  189.  
  190.     send -i $shell_id "q\n"
  191.     expect { 
  192.     -i $shell_id "Goodbye." {
  193.         verbose "Exited mondfe $shell_id"
  194.     }
  195.     timeout {
  196.         warning "$connectmode didn't exit cleanly"
  197.     }
  198.     }
  199.  
  200.     catch "close -i $shell_id"
  201.     set shell_id 0
  202.     return 0
  203. }
  204.  
  205. #
  206. # exit_montip -- exit the remote shell
  207. #
  208. proc exit_montip { } {
  209.     global verbose
  210.     global connectmode
  211.     global targetname
  212.     global shell_prompt
  213.     global shell_id
  214.  
  215.     verbose "exiting mondtip $shell_id"
  216.  
  217.     catch "close -i $shell_id"
  218.     set shell_id 0
  219.     return 0
  220. }
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.