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->{TARGET
} = shift;
34 $self->{EXECUTABLE
} = shift;
35 $self->{ARGUMENTS
} = shift;
36 if (!defined $PerlACE::ProcessVX
::WAIT_DELAY_FACTOR
) {
37 $PerlACE::ProcessVX
::WAIT_DELAY_FACTOR
= 3;
39 if (!defined $PerlACE::ProcessVX
::RebootCmd
) {
40 $PerlACE::ProcessVX
::RebootCmd
= "reboot";
42 bless ($self, $class);
50 if ($self->{RUNNING
} == 1) {
51 print STDERR
"ERROR: <", $self->{EXECUTABLE
},
52 "> still running upon object destruction\n";
56 if (!defined $ENV{'ACE_TEST_VERBOSE'}) {
60 if (defined $ENV{'ACE_RUN_VX_IBOOT'} && !defined $ENV{'ACE_RUN_VX_NO_SHUTDOWN'}) {
61 # Shutdown the target to save power
62 $self->iboot_cycle_power(1);
66 ###############################################################################
68 ### Spawning processes
71 # Spawn the process and continue.
77 if ($self->{RUNNING
} == 1) {
78 print STDERR
"ERROR: Cannot Spawn: <", $self->Executable (),
79 "> already running\n";
83 if (!defined $self->{EXECUTABLE
}) {
84 print STDERR
"ERROR: Cannot Spawn: No executable specified\n";
88 if ($self->{IGNOREEXESUBDIR
} == 0) {
89 if (!-f
$self->Executable ()) {
90 print STDERR
"ERROR: Cannot Spawn: <", $self->Executable (),
100 # Reboot the target if necessery
103 my $program = $self->Executable ();
104 my $cwdrel = dirname
($program);
105 my $prjroot = defined $ENV{'ACE_RUN_VX_PRJ_ROOT'} ?
$ENV{'ACE_RUN_VX_PRJ_ROOT'} : $ENV{'ACE_ROOT'};
106 if (length ($cwdrel) > 0) {
107 $cwdrel = File
::Spec
->abs2rel( cwd
(), $prjroot );
110 $cwdrel = File
::Spec
->abs2rel( $cwdrel, $prjroot );
112 $cwdrel =~ s/\\/\//g
;
113 $program = basename
($program, $PerlACE::ProcessVX
::ExeExt
);
116 my $oh = new FileHandle
();
117 if (!open($oh, ">run_vx.pl")) {
118 print STDERR
"ERROR: Unable to write to run_vx.pl\n";
126 my $exesubdir = defined $ENV{'ACE_RUN_VX_EXE_SUBDIR'} ?
$ENV{'ACE_RUN_VX_EXE_SUBDIR'} : "";
128 if (defined $ENV{'ACE_RUN_VX_STARTUP_SCRIPT'}) {
129 if (defined $ENV{'ACE_RUN_VX_STARTUP_SCRIPT_ROOT'}) {
130 @cmds[$cmdnr++] = 'cd "' . $ENV{'ACE_RUN_VX_STARTUP_SCRIPT_ROOT'} . '"';
132 @cmds[$cmdnr++] = '< ' . $ENV{'ACE_RUN_VX_STARTUP_SCRIPT'};
135 if (defined $ENV{'ACE_RUN_VX_STARTUP_COMMAND'}) {
136 @cmds[$cmdnr++] = $ENV{'ACE_RUN_VX_STARTUP_COMMAND'};
139 @cmds[$cmdnr++] = 'cd ' . $ENV{'ACE_RUN_VX_TGTSVR_ROOT'} . "/" . $cwdrel . "/" . $exesubdir;
140 @cmds[$cmdnr++] = 'set TMPDIR=' . $ENV{'ACE_RUN_VX_TGTSVR_ROOT'} . "/" . $cwdrel;
142 if (defined $ENV{'ACE_RUN_ACE_DEBUG'}) {
143 @cmds[$cmdnr++] = 'set ACE_DEBUG=' . $ENV{'ACE_RUN_ACE_DEBUG'};
146 if (defined $ENV{'ACE_RUN_TAO_ORB_DEBUG'}) {
147 @cmds[$cmdnr++] = 'set TAO_ORB_DEBUG=' . $ENV{'ACE_RUN_TAO_ORB_DEBUG'};
150 if (defined $ENV{'ACE_RUN_ACE_LD_SEARCH_PATH'}) {
151 @cmds[$cmdnr++] = 'set ACE_LD_SEARCH_PATH=' . $ENV{'ACE_RUN_ACE_LD_SEARCH_PATH'};
155 my(@unload_commands);
156 my $vxtest_file = $program . '.vxtest';
157 if (handle_vxtest_file
($self, $vxtest_file, \
@load_commands, \
@unload_commands)) {
158 push @cmds, @load_commands;
159 $cmdnr += scalar @load_commands;
161 print STDERR
"ERROR: Cannot find <", $vxtest_file, ">\n";
164 if (defined $self->{ARGUMENTS
}) {
165 ($arguments = $self->{ARGUMENTS
})=~ s/\"/\\\"/g;
166 ($arguments = $self->{ARGUMENTS
})=~ s/\'/\\\'/g;
168 $cmdline = $program . ' ' . $arguments;
169 if (defined $ENV{'ACE_RUN_VX_TGTSRV_WORKINGDIR'}) {
170 @cmds[$cmdnr++] = 'cd ' . $ENV{'ACE_RUN_VX_TGTSRV_WORKINGDIR'};
172 @cmds[$cmdnr++] = 'cd ' . $ENV{'ACE_RUN_VX_TGTSVR_ROOT'} . "/" . $cwdrel;
174 @cmds[$cmdnr++] = $cmdline;
175 if (!defined $ENV{'ACE_TEST_VERBOSE'}) {
176 push @cmds, @unload_commands;
177 $cmdnr += scalar @unload_commands;
181 print $oh "require Net::Telnet;\n";
182 print $oh "my \@cmds;\n";
183 print $oh "my \$prompt = '$prompt';\n";
186 print $oh "\@cmds[$i] = '" . @cmds[$i++] . "';\n";
188 print $oh "my \$cmdnr = $cmdnr;\n\n";
190 print $oh <<'__END__';
192 my $telnet_port = $ENV{'ACE_RUN_VX_TGT_TELNET_PORT'};
193 my $telnet_host = $ENV{'ACE_RUN_VX_TGT_TELNET_HOST'};
194 if (!defined $telnet_host) {
195 $telnet_host = $ENV{'ACE_RUN_VX_TGTHOST'};
197 if (!defined $telnet_port) {
200 my $t = new Net
::Telnet
(Timeout
=> 600, Errmode
=> 'return', Host
=> $telnet_host, Port
=> $telnet_port);
202 die "ERROR: Telnet failed to <" . $telnet_host . ":". $telnet_port . ">";
212 if ($buf =~ /$prompt/) {
221 if (defined $ENV{'ACE_TEST_VERBOSE'}) {
222 print STDERR
@cmds[$i]."\n";
224 if ($t->print (@cmds[$i++])) {
230 if ($buf =~ /$prompt/) {
240 die "ERROR: No prompt appeared\n";
249 Win32
::Process
::Create
($self->{PROCESS
},
256 Win32
::Process
::GetExitCode
($self->{PROCESS
}, $status);
258 if ($status != $STILL_ACTIVE) {
259 print STDERR
"ERROR: Spawn failed for <", "$^X run_vx.pl", ">\n";
263 $self->{RUNNING
} = 1;
267 # Wait for a process to exit with a timeout
272 my($timeout) = shift;
273 return $self->Wait($timeout);
277 # Terminate the process and wait for it to finish
279 sub TerminateWaitKill
($)
284 if ($self->{RUNNING
}) {
285 print STDERR
"INFO: $self->{EXECUTABLE} being killed.\n";
286 Win32
::Process
::Kill
($self->{PROCESS
}, 0);
287 $PerlACE::ProcessVX
::DoVxInit
= 1; # force reboot on next run
290 return $self->WaitKill ($timeout);
293 # Wait until a process exits.
294 # return -1 if the process is still alive.
299 if (!defined $timeout || $timeout < 0) {
302 $timeout = $timeout * 1000 * $PerlACE::ProcessVX
::WAIT_DELAY_FACTOR
;
307 if ($self->{RUNNING
}) {
308 $result = Win32
::Process
::Wait
($self->{PROCESS
}, $timeout);
313 Win32
::Process
::GetExitCode
($self->{PROCESS
}, $result);
315 $PerlACE::ProcessVX
::DoVxInit
= 1; # force reboot on next run
328 if ($self->{RUNNING
}) {
329 Win32
::Process
::Kill
($self->{PROCESS
}, -1);
332 $self->{RUNNING
} = 0;
335 sub handle_vxtest_file
338 my $vxtestfile = shift;
340 my $unld_ref = shift;
341 my $fh = new FileHandle
;
343 if (defined $self->{TARGET
} && $self->{TARGET
}->SystemLibs()) {
344 my @tokens = split(/;/, $self->{TARGET
}->SystemLibs());
345 foreach my $token (@tokens) {
346 push @
$vx_ref, "copy \"" . $ENV{'ACE_RUN_VX_TGTSVR_ROOT'} . "/lib/" . $token . "\" .";
349 if (!$PerlACE::Static
) {
350 if (open ($fh, $vxtestfile)) {
356 push @
$vx_ref, "copy \"" . $ENV{'ACE_RUN_VX_TGTSVR_ROOT'} . "/lib/$line1" . "d.dll\" .";
357 unshift @
$unld_ref, "del $line1" . "d.dll";