3 package PerlACE
::ProcessVX
;
9 $PerlACE::ProcessVX
::ExeSubDir
= './';
10 $PerlACE::ProcessVX
::DoVxInit
= (defined $ENV{'ACE_RUN_VX_NO_INITIAL_REBOOT'}) ?
0 : 1;
11 $PerlACE::ProcessVX
::VxDefGw
= 1;
12 $PerlACE::ProcessVX
::RebootTime
= (defined $ENV{'ACE_RUN_VX_REBOOT_TIME'}) ?
$ENV{'ACE_RUN_VX_REBOOT_TIME'} : 90;
13 $PerlACE::ProcessVX
::ExeExt
= ($PerlACE::VxWorks_RTP_Test
) ?
'.vxe' : '.out';
14 $PerlACE::ProcessVX
::RebootCmd
= $ENV{'ACE_RUN_VX_REBOOT_CMD'};
16 # Wait for the process to exit or kill after a time period
23 my $status = $self->TimedWait ($timeout);
26 print STDERR
"ERROR: $self->{EXECUTABLE} timedout\n";
28 # Don't need to Wait since we are on Win32
30 $PerlACE::ProcessVX
::DoVxInit
= 1; # force reboot on next run
39 # Do a Spawn and immediately WaitKill
46 if ($self->Spawn () == -1) {
50 return $self->WaitKill ($timeout);
54 ###############################################################################
58 sub Normalize_Executable_Name
61 my $executable = shift;
63 my $basename = basename
($executable);
64 my $dirname = dirname
($executable). '/';
66 $executable = $dirname.$PerlACE::ProcessVX
::ExeSubDir
.$basename.$PerlACE::ProcessVX
::ExeExt
;
68 ## Installed executables do not conform to the ExeSubDir
69 if (! -e
$executable && -e
$dirname.$basename.$PerlACE::ProcessVX
::ExeExt
) {
70 $executable = $dirname.$basename.$PerlACE::ProcessVX
::ExeExt
;
82 $self->{EXECUTABLE
} = shift;
85 my $executable = $self->{EXECUTABLE
};
87 if ($self->{IGNOREEXESUBDIR
} == 0) {
88 $executable = $self->Normalize_Executable_Name ($executable);
91 $executable = $executable.$PerlACE::ProcessVX
::ExeExt
;
102 $self->{ARGUMENTS
} = shift;
105 return $self->{ARGUMENTS
};
112 my $commandline = $self->Executable ();
114 if (defined $self->{ARGUMENTS
}) {
115 $commandline .= ' '.$self->{ARGUMENTS
};
126 $self->{IGNOREEXESUBDIR
} = shift;
129 return $self->{IGNOREEXESUBDIR
};
137 $self->{IGNOREHOSTROOT
} = shift;
140 return $self->{IGNOREHOSTROOT
};
148 ## Keep increasing the loops per second until the amount of time
149 ## exceeds the number of clocks per second. The original code
150 ## did not multiply $ticks by 8 but, for faster machines, it doesn't
151 ## seem to return false values. The multiplication is done to minimize
152 ## the amount of time it takes to determine the correct factor.
153 while(($lps <<= 1)) {
154 my($ticks) = clock
();
155 for(my $i = $lps; $i >= 0; $i--) {
157 $ticks = clock
() - $ticks;
158 if ($ticks * 8 >= CLOCKS_PER_SEC
) {
159 $factor = 500000 / (($lps / $ticks) * CLOCKS_PER_SEC
);
167 sub iboot_cycle_power
172 # mode 0 is reboot, mode 1 is just shutdown
177 $iboot_passwd ) = ($ENV{'ACE_RUN_VX_IBOOT'},
178 $ENV{'ACE_RUN_VX_IBOOT_OUTLET'},
179 $ENV{'ACE_RUN_VX_IBOOT_USER'},
180 $ENV{'ACE_RUN_VX_IBOOT_PASSWORD'});
182 my $v = $ENV{'ACE_TEST_VERBOSE'};
185 print "Using iBoot: $iboot_host\n";
186 if (defined $iboot_outlet) {
187 print "Using iBoot Outlet #: $iboot_outlet\n";
191 # There are three cases to handle here:
192 # 1. using a single-outlet iBoot
193 # 2. using a multi-outlet iBootBar with custom firmware
194 # 3. using a multi-outlet iBootBar with standard firmware
196 # In cases 1 & 2, we use the iPAL protocol; in case 3 we
197 # use a telnet connection and the command-line syntax.
199 # We determine that it's case #3 by the concurrent presence
200 # of an outlet number, an iboot username, and an iboot password
201 # in the environment.
203 if (defined($iboot_outlet) && defined($iboot_user) && defined($iboot_passwd)) {
205 # This case doesn't support shutdown
206 return if $mode == 1;
208 my $t = new Net
::Telnet
();
210 $t->prompt('/iBootBar \> /');
211 my $savedmode = $t->errmode();
212 $t->errmode("return");
218 my $r = $t->open($iboot_host);
225 print "Couldn't open connection; sleeping then retrying\n" if ($v);
230 print "Unable to open $iboot_host.\n" if ($v);
234 $t->errmode($savedmode);
236 # Simple login b/c Net::Telnet::login hardcodes the prompts
237 $t->waitfor('/User Name:\s*$/i');
238 $t->print($iboot_user);
239 $t->waitfor('/password:\s*/i');
240 $t->print($iboot_passwd);
242 $t->waitfor($t->prompt);
244 print "successfully logged in to $iboot_host\n" if ($v);
246 my $output = $t->cmd("set outlet $iboot_outlet cycle");
248 print "successfully cycled power on outlet $iboot_outlet\n" if ($v);
253 # Perform cases 1 & 2
256 if (!defined($iboot_passwd)) {
257 $iboot_passwd = "PASS";
260 my $ipal_command_series;
261 if (defined $iboot_outlet) {
262 $ipal_command_series = ($mode == 0 ?
['E', 'D'] : ['E']);
264 $ipal_command_series = ($mode == 0 ?
['f', 'n'] : ['f']);
267 foreach my $ipal_cmd (@
$ipal_command_series) {
271 $iboot = IO
::Socket
::INET
->new ("$iboot_host");
273 # if ACE_RUN_VX_IBOOT_OUTLET is defined, we're using
274 # the iBootBar, and we're using the iPAL Protocol
275 # to communicate with the iBootBar
276 if (defined $iboot_outlet) {
277 $iboot->send ("\e".$iboot_passwd."\e".$iboot_outlet.$ipal_cmd);
280 $iboot->send ("\e".$iboot_passwd."\e$ipal_cmd\r");
282 $iboot->recv ($text,128);
283 print "iBoot is currently: $text (iteration $retries)\n" if ($v);
285 if (defined $iboot_outlet) {
286 $text = substr $text, $iboot_outlet - 1, 1;
287 if ($text eq "0" || $text eq "1") {
292 print "iBoot is $text; sleeping then retrying\n" if ($v);
297 if ($text eq "OFF" || $text eq "ON") {
302 print "iBoot is $text; sleeping then retrying\n" if ($v);
308 print "Unable to execute 'reboot' command, going to try another $retries times!\n";
312 print "Unable to reboot using $iboot_host.\n" if ($v);
327 my $target_login = $ENV{'ACE_RUN_VX_LOGIN'};
328 my $target_password = $ENV{'ACE_RUN_VX_PASSWORD'};
331 ## initialize VxWorks kernel (reboot!) if needed
332 if ($PerlACE::ProcessVX
::DoVxInit
|| $ENV{'ACE_RUN_VX_TGT_REBOOT'}) {
333 if (defined $ENV{'ACE_RUN_VX_REBOOT_TOOL'}) {
334 if (defined $ENV{'ACE_TEST_VERBOSE'}) {
335 print "Calling: $ENV{'ACE_RUN_VX_REBOOT_TOOL'}\n";
337 system ($ENV{'ACE_RUN_VX_REBOOT_TOOL'});
340 if (defined $ENV{'ACE_RUN_VX_IBOOT'}) {
341 $self->iboot_cycle_power(0);
344 if (defined $ENV{'ACE_TEST_VERBOSE'}) {
345 print "Executing 'reboot' command over Telnet to ".$ENV{'ACE_RUN_VX_TGTHOST'}.".\n";
347 $t = new Net
::Telnet
(Timeout
=> 10,
349 Errmode
=> 'return');
350 $t->open($ENV{'ACE_RUN_VX_TGTHOST'});
351 if (defined $target_login) {
352 $t->waitfor('/VxWorks login: $/');
353 $t->print("$target_login");
355 if (defined $target_password) {
356 $t->waitfor('/Password: $/');
357 $t->print("$target_password");
360 $ok = $t->waitfor('/-> $/');
362 $t->print($PerlACE::ProcessVX
::RebootCmd
);
366 print "ERROR: FAILED to execute 'reboot' command!\n";
371 $PerlACE::ProcessVX
::VxDefGw
= 1;
372 $PerlACE::ProcessVX
::DoVxInit
= 0;
373 sleep($PerlACE::ProcessVX
::RebootTime
);
377 # Helper for spawning with list of kernel modules in a .vxtest file
378 sub handle_vxtest_file
381 my $vxtestfile = shift;
383 my $unld_ref = shift;
384 my $fh = new FileHandle
;
385 if (open ($fh, $vxtestfile)) {
391 push @
$vx_ref, "ld < lib$line1" . ".so";
392 unshift @
$unld_ref, "unld \"lib$line1" . ".so\"";
401 # Load a file that is used as startup script. This script has to be
402 # located on the host system
403 sub handle_startup_script
407 my $fh = new FileHandle
;
408 if (open ($fh, $script)) {
412 push @
$cmds, "$line1";
421 ### Check for -ExeSubDir commands, store the last one
424 for(my $i = 0; $i <= $#ARGV; ++$i) {
425 if ($ARGV[$i] eq '-ExeSubDir') {
426 if (defined $ARGV[$i + 1]) {
427 $PerlACE::ProcessVX
::ExeSubDir
= $ARGV[++$i].'/';
430 print STDERR
"You must pass a directory with ExeSubDir\n";
435 push @new_argv, $ARGV[$i];
440 $PerlACE::ProcessVX
::WAIT_DELAY_FACTOR
= $ENV{'ACE_RUNTEST_DELAY'};
442 if (defined $ENV{'ACE_TEST_WINCE'}) {
443 if ($OSNAME eq "MSWin32") {
444 require PerlACE
::ProcessWinCE
;
446 require PerlACE
::ProcessWinCE_Unix
;
449 if ($OSNAME eq "MSWin32") {
450 require PerlACE
::ProcessVX_Win32
;
453 require PerlACE
::ProcessVX_Unix
;
461 my $procmask = shift;
463 ## NOT IMPLEMENTED YET