aboutsummaryrefslogtreecommitdiff
path: root/dejagnu/chromeos.exp.in
blob: 02fc3af2de4d04fad02a53828414a3d054a40adf (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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#
# Initialize the board. The function is executed before any test.
#
proc __boardname___init { board } {
  set hostname [board_info $board hostname]
  set timeout [board_info $board timeout]
  set ssh_options [board_info $board ssh,options]
  set runtimes [board_info $board runtimes]
  set tmpdir [board_info $board tmpdir]
  verbose -log "Opening persistent connection ..." 1
  eval "exec ssh -N -f $ssh_options root@$hostname &"
  local_exec "ssh -n $ssh_options root@$hostname sh -c 'mkdir -p $tmpdir'" \
    {} {}  $timeout
}

#
# Remove test run by-products. The function is executed at DejaGNU exit.
#
proc __boardname___exit {} {
  set board "__boardname__"
  set hostname [board_info $board hostname]
  set ssh_options [board_info $board ssh,options]
  set tmpdir [board_info $board tmpdir]
  verbose -log "Closing persistent connection ..." 1
  local_exec "ssh $ssh_options -O exit root@$hostname" {} {} 10
  verbose -log "Cleaning up - executing on board 'rm -fr $tmpdir' ..." 1
  local_exec "ssh -n $ssh_options root@$hostname sh -c 'rm -fr $tmpdir'" \
    {} {} 10
}

#
# Upload a file to the board. Uses scp over persistent SSH connection.
#
proc __boardname___download { board file args } {
  set hostname [board_info $board hostname]
  set tmpdir [board_info $board tmpdir]
  set timeout [board_info $board timeout]
  set ssh_options [board_info $board ssh,options]
  set destfile [lindex [file split $file] end]
  verbose -log "scp -q $ssh_options $file root@$hostname:$tmpdir/"
  set result [local_exec "scp -q $ssh_options $file root@$hostname:$tmpdir/" \
                {} {} $timeout]
  if { [lindex $result 0] != 0 } {
    verbose -log "failed to upload \'$file\' to \'$tmpdir/$destfile\'"
  } else {
    verbose -log "uploaded \"$file\' to remote board@\'$tmpdir/$destfile\'"
    return "$tmpdir/$destfile"
  }
}

#
# Download a file to the host machine. Uses scp over persistent SSH connection.
#
proc __boardname___upload { board file args } {
  set hostname [board_info $board hostname]
  set tmpdir [board_info $board tmpdir]
  set timeout [board_info $board timeout]
  set ssh_options [board_info $board ssh,options]
  set filen [file tail $file]
  verbose -log "scp -q $ssh_options \"root@$hostname:$tmpdir/$filen\" ."
  set result [local_exec \
                "scp -q $ssh_options \"root@$hostname:$tmpdir/$filen\" ." \
                {} {} $timeout]
  if { [lindex $result 0] != 0 } {
    verbose -log \
      "failed to transfer \"root@$hostname:$tmpdir/$filen\" to \".\""
  } else {
    verbose -log "transferred \"root@$hostname:$tmpdir/$filen\" to \".\""
    # In case of success, always return the original file.
    return "$file"
  }
}

#
# Cache program output within different invoking of __boardname___exec.
# For example, the following command sequence will be executed
#   > cd /tmp/dejagnu_xxxx/ && ./xxx.x0
#   <output1 here>
#   return [0, <output1>]   (a)
#   > rm /tmp/dejagnu_xxxx/xxxx.x0
#   <output2 here>
#   return [0, <output2>]   (b)
# We need <output1>, not <output2>. What we do here is to keep <output1> in
# $program_output and in (b) we return [0, <output1>].
#
set program_output ""

#
# Execute a test on remote machine. Log into the target machine using
# persistent SSH connection and run a command in modified environment.
#
proc __boardname___exec { board program args } {
  global program_output
  if { [llength $args] > 0 } {
    set pargs [lindex $args 0]
  } else {
    set pargs ""
  }

  if { [llength $args] > 1 } {
    set inp "[lindex $args 1]"
  } else {
    set inp ""
  }

  if { [llength $args] > 2 } {
    set outp "[lindex $args 2]"
  } else {
    set outp ""
  }

  if { [llength $args] > 3 } {
    set timeout "[lindex $args 3]"
  } else {
    set timeout [board_info $board timeout]
  }

  set hostname [board_info $board hostname]
  set tmpdir [board_info $board tmpdir]
  set other_file ""

  # Check if a file to be executed was copied from host machine.  If so, we
  # need to run it in copied runtimes.
  set is_program "0"
  if { [string match "$tmpdir/*" $program] } {
    set path [file dirname $program]
    # "$program" would usually be like "/x/y/z.out", set command to be "z.out".
    set command [file tail $program]
    set rootname [file rootname $command]
    # TODO(shenhan): using rsync to copy all test case relatd stuff to host
    # machine in case ".o" files are different from the exe files.
    set other_file [file join $path "${rootname}.*"]
    # Change directory to "/x/y", then execute "./z.out" - we want the working
    # directory to be "/x/y". Setting GCOV_PREFIX_STRIP and GCOV_PREFIX is to
    # force generating ".gcda" file under "/x/y" instead of some host path.
    set program "cd $path && GCOV_PREFIX_STRIP=999 GCOV_PREFIX=$tmpdir/ \
                 [file join "." $command]"
    set is_program "1"
  }
  verbose -log "Exec: $program"
  set ssh_options [board_info $board ssh,options]
  set retv [local_exec \
              "ssh -n $ssh_options root@$hostname sh -c '$program $pargs'" \
              $inp $outp $timeout]
  set status [lindex $retv 0]
  if { $is_program == "1" } {
    set program_output [lindex $retv 1]
  }

  # Before returning the execution status, we try to transfer the ".gcda"
  # (and/or other files that have the same base name as the program) file to
  # host, though for every program that runs, there is no corresponding "other"
  # file. We have no idea when such an other file will be generated for the
  # program, so every time, we assume there is an "other" file and try to do the
  # transfer.
  if { $status == 0 && $other_file != "" } {
    set upv [${board}_upload $board $other_file ""]
    if { $upv == "" } {
      verbose -log "Safely ignored - \"$other_file\" does not exist."
    }
  }

  return [list $status $program_output]
}

load_generic_config "unix"
load_base_board_description "linux-libremote"

set_board_info hostname "__board_hostname__"
set_board_info tmpdir "__tmp_dir__"

set_board_info isremote 1
set_board_info timeout 60
set_board_info ssh,options "-i __tmp_testing_rsa__ -o ControlMaster=auto \
-o ControlPath=__tmp_dir__/%r@%h:%p -o StrictHostKeyChecking=no "