3 package PerlACE
::ProcessVX
;
12 eval { require Net
::Telnet
; };
14 ###############################################################################
16 # This is what GetExitCode will return if the process is still running.
17 my $STILL_ACTIVE = 259;
19 ###############################################################################
21 ### Constructor and Destructor
26 my $class = ref ($proto) || $proto;
30 $self->{IGNOREEXESUBDIR
} = 1;
31 $self->{IGNOREHOSTROOT
} = 0;
32 $self->{PROCESS
} = undef;
33 $self->{EXECUTABLE
} = shift;
34 $self->{ARGUMENTS
} = shift;
35 if (!defined $PerlACE::ProcessVX
::WAIT_DELAY_FACTOR
) {
36 $PerlACE::ProcessVX
::WAIT_DELAY_FACTOR
= 3;
38 if (!defined $PerlACE::ProcessVX
::RebootCmd
) {
39 $PerlACE::ProcessVX
::RebootCmd
= "reboot";
41 bless ($self, $class);
49 if ($self->{RUNNING
} == 1) {
50 print STDERR
"ERROR: <", $self->{EXECUTABLE
},
51 "> still running upon object destruction\n";
55 if (!defined $ENV{'ACE_TEST_VERBOSE'}) {
59 if (defined $ENV{'ACE_RUN_VX_IBOOT'} && !defined $ENV{'ACE_RUN_VX_NO_SHUTDOWN'}) {
60 # Shutdown the target to save power
61 $self->iboot_cycle_power(1);
65 ###############################################################################
67 ### Spawning processes
70 # Spawn the process and continue.
76 if ($self->{RUNNING
} == 1) {
77 print STDERR
"ERROR: Cannot Spawn: <", $self->Executable (),
78 "> already running\n";
82 if (!defined $self->{EXECUTABLE
}) {
83 print STDERR
"ERROR: Cannot Spawn: No executable specified\n";
87 if ($self->{IGNOREEXESUBDIR
} == 0) {
88 if (!-f
$self->Executable ()) {
89 print STDERR
"ERROR: Cannot Spawn: <", $self->Executable (),
99 # Reboot the target if necessery
102 my $program = $self->Executable ();
103 my $cwdrel = dirname
($program);
104 my $prjroot = defined $ENV{'ACE_RUN_VX_PRJ_ROOT'} ?
$ENV{'ACE_RUN_VX_PRJ_ROOT'} : $ENV{'ACE_ROOT'};
105 if (length ($cwdrel) > 0) {
106 $cwdrel = File
::Spec
->abs2rel( cwd
(), $prjroot );
109 $cwdrel = File
::Spec
->abs2rel( $cwdrel, $prjroot );
111 $cwdrel =~ s/\\/\//g
;
112 $program = basename
($program, $PerlACE::ProcessVX
::ExeExt
);
115 my $oh = new FileHandle
();
116 if (!open($oh, ">run_vx.pl")) {
117 print STDERR
"ERROR: Unable to write to run_vx.pl\n";
125 my $exesubdir = defined $ENV{'ACE_RUN_VX_EXE_SUBDIR'} ?
$ENV{'ACE_RUN_VX_EXE_SUBDIR'} : "";
127 if (defined $ENV{'ACE_RUN_VX_STARTUP_SCRIPT'}) {
128 if (defined $ENV{'ACE_RUN_VX_STARTUP_SCRIPT_ROOT'}) {
129 @cmds[$cmdnr++] = 'cd "' . $ENV{'ACE_RUN_VX_STARTUP_SCRIPT_ROOT'} . '"';
131 @cmds[$cmdnr++] = '< ' . $ENV{'ACE_RUN_VX_STARTUP_SCRIPT'};
134 if (defined $ENV{'ACE_RUN_VX_STARTUP_COMMAND'}) {
135 @cmds[$cmdnr++] = $ENV{'ACE_RUN_VX_STARTUP_COMMAND'};
138 if ($PerlACE::VxWorks_RTP_Test
) {
139 @cmds[$cmdnr++] = 'cmd';
140 if ( defined $ENV{'ACE_RUN_VX_TGTSVR_DEFGW'} && $PerlACE::ProcessVX
::VxDefGw
) {
141 @cmds[$cmdnr++] = "C mRouteAdd(\"0.0.0.0\", \"" . $ENV{'ACE_RUN_VX_TGTSVR_DEFGW'} . "\", 0,0,0)";
142 $PerlACE::ProcessVX
::VxDefGw
= 0;
145 if (defined $ENV{'ACE_RUN_VX_TGT_STARTUP_SCRIPT'}) {
147 if (handle_startup_script
($ENV{'ACE_RUN_VX_TGT_STARTUP_SCRIPT'}, \
@start_commands)) {
148 push @cmds, @start_commands;
149 $cmdnr += scalar @start_commands;
153 @cmds[$cmdnr++] = 'cd "' . $ENV{'ACE_RUN_VX_TGTSVR_ROOT'} . "/" . $cwdrel . '"';
154 @cmds[$cmdnr++] = 'C putenv("TMPDIR=' . $ENV{'ACE_RUN_VX_TGTSVR_ROOT'} . "/" . $cwdrel . '")';
156 if (defined $ENV{'ACE_RUN_ACE_DEBUG'}) {
157 @cmds[$cmdnr++] = 'C putenv("ACE_DEBUG=' . $ENV{'ACE_RUN_ACE_DEBUG'} . '")';
160 if (defined $ENV{'ACE_RUN_TAO_ORB_DEBUG'}) {
161 @cmds[$cmdnr++] = 'C putenv("TAO_ORB_DEBUG=' . $ENV{'ACE_RUN_TAO_ORB_DEBUG'} . '")';
164 if (defined $ENV{'ACE_RUN_ACE_LD_SEARCH_PATH'}) {
165 @cmds[$cmdnr++] = 'C putenv("ACE_LD_SEARCH_PATH=' . $ENV{'ACE_RUN_ACE_LD_SEARCH_PATH'} . '")';
167 if (defined $self->{TARGET
}) {
168 my $x_env_ref = $self->{TARGET
}->{EXTRA_ENV
};
169 while ( my ($env_key, $env_value) = each(%$x_env_ref) ) {
170 if (defined $ENV{'ACE_TEST_VERBOSE'}) {
171 print "INFO: adding target environment $env_key=$env_value\n";
173 @cmds[$cmdnr++] = 'C putenv("' . $env_key. '=' . $env_value . '")';
177 if (defined $ENV{'ACE_RUN_VX_CHECK_RESOURCES'}) {
178 @cmds[$cmdnr++] = 'C memShow()';
181 $cmdline = $program . $PerlACE::ProcessVX
::ExeExt
. ' ' . $self->{ARGUMENTS
};
182 @cmds[$cmdnr++] = $cmdline;
183 $prompt = '\[vxWorks \*\]\# $';
185 if ($PerlACE::VxWorks_Test
) {
186 if ( defined $ENV{'ACE_RUN_VX_TGTSVR_DEFGW'} && $PerlACE::ProcessVX
::VxDefGw
) {
187 @cmds[$cmdnr++] = "mRouteAdd(\"0.0.0.0\", \"" . $ENV{'ACE_RUN_VX_TGTSVR_DEFGW'} . "\", 0,0,0)";
188 $PerlACE::ProcessVX
::VxDefGw
= 0;
191 if (defined $ENV{'ACE_RUN_VX_TGT_STARTUP_SCRIPT'}) {
193 if (handle_startup_script
($ENV{'ACE_RUN_VX_TGT_STARTUP_SCRIPT'}, \
@start_commands)) {
194 push @cmds, @start_commands;
195 $cmdnr += scalar @start_commands;
200 my(@unload_commands);
201 if (!$PerlACE::Static
&& !$PerlACE::VxWorks_RTP_Test
) {
202 my $vxtest_file = $program . '.vxtest';
203 if (handle_vxtest_file
($self, $vxtest_file, \
@load_commands, \
@unload_commands)) {
204 @cmds[$cmdnr++] = "cd \"$ENV{'ACE_RUN_VX_TGTSVR_ROOT'}/lib\"";
205 push @cmds, @load_commands;
206 $cmdnr += scalar @load_commands;
208 print STDERR
"ERROR: Cannot find <", $vxtest_file, ">\n";
213 @cmds[$cmdnr++] = 'cd "' . $ENV{'ACE_RUN_VX_TGTSVR_ROOT'} . "/" . $cwdrel . "/" . $exesubdir . '"';
214 @cmds[$cmdnr++] = 'putenv("TMPDIR=' . $ENV{'ACE_RUN_VX_TGTSVR_ROOT'} . "/" . $cwdrel . '")';
216 if (defined $ENV{'ACE_RUN_VX_CHECK_RESOURCES'}) {
217 @cmds[$cmdnr++] = 'memShow()';
220 if (defined $ENV{'ACE_RUN_ACE_DEBUG'}) {
221 @cmds[$cmdnr++] = 'putenv("ACE_DEBUG=' . $ENV{'ACE_RUN_ACE_DEBUG'} . '")';
224 if (defined $ENV{'ACE_RUN_TAO_ORB_DEBUG'}) {
225 @cmds[$cmdnr++] = 'putenv("TAO_ORB_DEBUG=' . $ENV{'ACE_RUN_TAO_ORB_DEBUG'} . '")';
228 if (defined $ENV{'ACE_RUN_ACE_LD_SEARCH_PATH'}) {
229 @cmds[$cmdnr++] = 'putenv("ACE_LD_SEARCH_PATH=' . $ENV{'ACE_RUN_ACE_LD_SEARCH_PATH'} . '")';
231 if (defined $self->{TARGET
}) {
232 my $x_env_ref = $self->{TARGET
}->{EXTRA_ENV
};
233 while ( my ($env_key, $env_value) = each(%$x_env_ref) ) {
234 if (defined $ENV{'ACE_TEST_VERBOSE'}) {
235 print "INFO: adding target environment $env_key=$env_value\n";
237 @cmds[$cmdnr++] = 'putenv("' . $env_key. '=' . $env_value . '")';
241 @cmds[$cmdnr++] = 'ld <'. $program . $PerlACE::ProcessVX
::ExeExt
;
242 if (defined $self->{ARGUMENTS
}) {
243 ($arguments = $self->{ARGUMENTS
})=~ s/\"/\\\"/g;
244 ($arguments = $self->{ARGUMENTS
})=~ s/\'/\\\'/g;
245 $arguments = ",\"" . $arguments . "\"";
247 if (defined $ENV{'ACE_RUN_VX_TGTSRV_WORKINGDIR'}) {
248 @cmds[$cmdnr++] = 'cd "' . $ENV{'ACE_RUN_VX_TGTSRV_WORKINGDIR'} . '"';
250 @cmds[$cmdnr++] = 'cd "' . $ENV{'ACE_RUN_VX_TGTSVR_ROOT'} . "/" . $cwdrel . '"';
252 @cmds[$cmdnr++] = 'ace_vx_rc = vx_execae(ace_main' . $arguments . ')';
253 @cmds[$cmdnr++] = 'unld "'. $program . $PerlACE::ProcessVX
::ExeExt
. '"';
254 push @cmds, @unload_commands;
255 $cmdnr += scalar @unload_commands;
259 print $oh "require Net::Telnet;\n";
260 print $oh "my \@cmds;\n";
261 print $oh "my \$prompt = '$prompt';\n";
264 print $oh "\@cmds[$i] = '" . @cmds[$i++] . "';\n";
266 print $oh "my \$cmdnr = $cmdnr;\n\n";
268 print $oh <<'__END__';
271 my $telnet_port = $ENV{'ACE_RUN_VX_TGT_TELNET_PORT'};
272 my $telnet_host = $ENV{'ACE_RUN_VX_TGT_TELNET_HOST'};
273 if (!defined $telnet_host) {
274 $telnet_host = $ENV{'ACE_RUN_VX_TGTHOST'};
276 if (!defined $telnet_port) {
279 my $t = new Net
::Telnet
(Timeout
=> 600, Errmode
=> 'return', Host
=> $telnet_host, Port
=> $telnet_port);
281 die "ERROR: Telnet failed to <" . $telnet_host . ":". $telnet_port . ">";
284 die "ERROR: Telnet open to <" . $telnet_host . ":". $telnet_port . "> " . $t->errmsg;
288 if (defined $ENV{'ACE_RUN_VX_TERMSERV_DEV'}) {
289 print $oh <<'__END__';
291 $t->prompt('/' . $ENV{'ACE_RUN_VX_IBOOT_USER'} . '>$/');
292 $t->login($ENV{'ACE_RUN_VX_IBOOT_USER'}, $ENV{'ACE_RUN_VX_IBOOT_PASSWORD'});
293 $t->print('direct ' . $ENV{'ACE_RUN_VX_TERMSERV_DEV'});
294 $t->waitfor('/Entering Direct mode/');
300 print $oh <<'__END__';
301 my $target_login = $ENV{'ACE_RUN_VX_LOGIN'};
302 my $target_password = $ENV{'ACE_RUN_VX_PASSWORD'};
304 if (defined $target_login) {
305 $t->waitfor('/VxWorks login: $/');
306 $t->print("$target_login");
309 if (defined $target_password) {
310 $t->waitfor('/Password: $/');
311 $t->print("$target_password");
314 # wait for the prompt
316 my $prompt1 = '-> $';
321 if ($buf =~ /$prompt1/) {
325 if ($buf !~ /$prompt1/) {
326 die "ERROR: Didn't got prompt but got <$buf>";
331 if (defined $ENV{'ACE_TEST_VERBOSE'}) {
332 print @cmds[$i]."\n";
334 if ($t->print (@cmds[$i++])) {
340 if ($buf =~ /$prompt/) {
355 Win32
::Process
::Create
($self->{PROCESS
},
362 Win32
::Process
::GetExitCode
($self->{PROCESS
}, $status);
364 if ($status != $STILL_ACTIVE) {
365 print STDERR
"ERROR: Spawn failed for <", "$^X run_vx.pl", ">\n";
369 $self->{RUNNING
} = 1;
373 # Wait for a process to exit with a timeout
378 my($timeout) = shift;
379 return $self->Wait($timeout);
383 # Terminate the process and wait for it to finish
385 sub TerminateWaitKill
($)
390 if ($self->{RUNNING
}) {
391 print STDERR
"INFO: $self->{EXECUTABLE} being killed.\n";
392 Win32
::Process
::Kill
($self->{PROCESS
}, 0);
393 $PerlACE::ProcessVX
::DoVxInit
= 1; # force reboot on next run
396 return $self->WaitKill ($timeout);
399 # Wait until a process exits.
400 # return -1 if the process is still alive.
405 if (!defined $timeout || $timeout < 0) {
408 $timeout = $timeout * 1000 * $PerlACE::ProcessVX
::WAIT_DELAY_FACTOR
;
413 if ($self->{RUNNING
}) {
414 $result = Win32
::Process
::Wait
($self->{PROCESS
}, $timeout);
419 Win32
::Process
::GetExitCode
($self->{PROCESS
}, $result);
420 $self->{RUNNING
} = 0;
422 $PerlACE::ProcessVX
::DoVxInit
= 1; # force reboot on next run
435 if ($self->{RUNNING
}) {
436 Win32
::Process
::Kill
($self->{PROCESS
}, -1);
439 $self->{RUNNING
} = 0;