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 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
|
#! /usr/bin/perl
#
# ProcessLVRT - how to run ACE+TAO tests on a LabVIEW RT target.
# Tests on LabVIEW RT are not executables - LabVIEW RT can't start plain
# executables; the tests are built/packaged as DLLs and loaded and executed
# from a DLL loaded at LabVIEW RT boot time. The DLL on the target listens
# on a TCP port (8888 by default) for connections from the host. Host requests
# actions using text commands to the target.
#
# NOTE: This module requires the Net-Telnet Perl module.
#
# We can FTP files to and from the LabVIEW target, but there's no NFS or
# SMB shares.
package PerlACE::ProcessLVRT;
our @ISA = "PerlACE::Process";
use strict;
use Cwd;
use English;
use File::Basename;
use Net::FTP;
use Net::Telnet;
use POSIX qw(:time_h);
$PerlACE::ProcessLVRT::ExeSubDir = './';
### Check for -ExeSubDir commands, store the last one
my @new_argv = ();
for(my $i = 0; $i <= $#ARGV; ++$i) {
if ($ARGV[$i] eq '-ExeSubDir') {
if (defined $ARGV[$i + 1]) {
$PerlACE::ProcessLVRT::ExeSubDir = $ARGV[++$i].'/';
}
else {
print STDERR "You must pass a directory with ExeSubDir\n";
exit(1);
}
}
else {
push @new_argv, $ARGV[$i];
}
}
@ARGV = @new_argv;
### Constructor and Destructor
sub new
{
my $proto = shift;
my $class = ref ($proto) || $proto;
my $self = {};
$self->{TARGET} = shift;
$self->{EXECUTABLE} = shift;
$self->{ARGUMENTS} = shift;
$self->{RUNNING} = 0;
$self->{IGNOREEXESUBDIR} = 1;
bless ($self, $class);
return $self;
}
sub DESTROY
{
my $self = shift;
if ($self->{RUNNING} == 1) {
print STDERR "ERROR: <", $self->{EXECUTABLE},
"> still running upon object destruction\n";
$self->Kill ();
}
if (defined $self->{TELNET}) {
$self->{TELNET}->close();
$self->{TELNET} = undef;
}
}
###############################################################################
# Adjust executable name for LabVIEW RT testing needs. These tests are DLLs.
sub Executable
{
my $self = shift;
if (@_ != 0) {
$self->{EXECUTABLE} = shift;
}
my $executable = $self->{EXECUTABLE};
my $basename = basename ($executable);
my $dirname = dirname ($executable). '/';
my $subdir = $PerlACE::ProcessLVRT::ExeSubDir;
if (defined $self->{TARGET}) {
$subdir = $self->{TARGET}->ExeSubDir();
}
$executable = $dirname.$subdir.$basename.".DLL";
$executable =~ s/\//\\/g; # / <- # color coding issue in devenv
return $executable;
}
sub Arguments
{
my $self = shift;
if (@_ != 0) {
$self->{ARGUMENTS} = shift;
}
return $self->{ARGUMENTS};
}
sub CommandLine ()
{
my $self = shift;
my $commandline = "run " . basename($self->Executable(), ".dll");
if (defined $self->{ARGUMENTS}) {
$commandline .= ' '.$self->{ARGUMENTS};
}
return $commandline;
}
###############################################################################
# Spawn the process and continue.
sub Spawn ()
{
my $self = shift;
if ($self->{RUNNING} == 1) {
print STDERR "ERROR: Cannot Spawn: <", $self->Executable (),
"> already running\n";
return -1;
}
if (!defined $self->{EXECUTABLE}) {
print STDERR "ERROR: Cannot Spawn: No executable specified\n";
return -1;
}
if ($self->{IGNOREEXESUBDIR} == 0) {
if (!-f $self->Executable ()) {
print STDERR "ERROR: Cannot Spawn: <", $self->Executable (),
"> not found\n";
return -1;
}
}
my $status = 0;
my $program = $self->Executable ();
my $cwdrel = dirname ($program);
my $target_ace_root = $self->{TARGET}->ACE_ROOT();
if (length ($cwdrel) > 0) {
$cwdrel = File::Spec->abs2rel(cwd(), $target_ace_root);
}
else {
$cwdrel = File::Spec->abs2rel($cwdrel, $target_ace_root);
}
$self->{TARGET}->{FTP}->cwd($self->{TARGET}->{FSROOT});
$self->{TARGET}->{FTP}->binary();
$self->{TARGET}->{FTP}->put($program);
my $targethost = $self->{TARGET}->{IPNAME};
my $targetport = $self->{TARGET}->{CTLPORT};
$self->{TELNET} = new Net::Telnet(Errmode => 'return');
if (!$self->{TELNET}->open(Host => $targethost, Port => $targetport)) {
print STDERR "ERROR: target $targethost:$targetport: ",
$self->{TELNET}->errmsg(), "\n";
$self->{TELNET} = undef;
$self->{TARGET}->NeedReboot;
$self->{TARGET}->{FTP}->delete($program);
return -1;
}
my $cmdline = $self->CommandLine();
if (defined $ENV{'ACE_TEST_VERBOSE'}) {
print "-> $cmdline\n";
}
$self->{TELNET}->print("$cmdline");
my $reply;
$reply = $self->{TELNET}->getline();
if (defined $ENV{'ACE_TEST_VERBOSE'}) {
print "<- $reply\n";
}
if ($reply eq "OK\n") {
$self->{RUNNING} = 1;
return 0;
}
print STDERR "ERROR: can't $cmdline: " . $reply . "\n";
$self->{TARGET}->{FTP}->delete($program);
# Not unless can't get the response. $self->{TARGET}->NeedReboot;
return -1;
}
# Wait for the process to exit or kill after a time period
sub WaitKill ($)
{
my $self = shift;
my $timeout = shift;
my $status = $self->TimedWait ($timeout);
$self->{RUNNING} = 0;
# If the test timed out, the target is probably toast. Don't bother
# trying to get the log file until after rebooting and resetting FTP.
if ($status == -1) {
print STDERR "ERROR: $self->{EXECUTABLE} timedout\n";
$self->Kill();
}
# Now get the log file from the test, and delete the test from
# the target. The FTP session should still be open.
my $program = $self->Executable ();
my $logname = basename($program,".dll") . ".log";
my $target_log_path = $self->{TARGET}->{FSROOT} . "\\log\\" . $logname;
$program = basename($program);
$self->{TARGET}->{FTP}->delete($program);
$self->{TARGET}->{FTP}->get($target_log_path,"log\\$logname");
$self->{TARGET}->{FTP}->delete($target_log_path);
return $status;
}
# Do a Spawn and immediately WaitKill
sub SpawnWaitKill ($)
{
my $self = shift;
my $timeout = shift;
my $status = $self->Spawn ();
if ($status == 0) {
$status = $self->WaitKill ($timeout);
}
return $status;
}
sub TerminateWaitKill ($)
{
my $self = shift;
my $timeout = shift;
if ($self->{RUNNING}) {
print STDERR "INFO: $self->{EXECUTABLE} being killed.\n";
$self->Kill();
}
return $self->WaitKill ($timeout);
}
sub Kill ()
{
my $self = shift;
if ($self->{RUNNING}) {
if (defined $ENV{'ACE_TEST_VERBOSE'}) {
print "-> kill\n";
}
$self->{TELNET}->print("kill");
# Just wait for any reply; don't care what it is.
my $reply = $self->{TELNET}->getline();
if (defined $ENV{'ACE_TEST_VERBOSE'}) {
print "<- $reply\n";
}
}
$self->{RUNNING} = 0;
# Trying to kill a LabVIEW RT thread and recover is probably futile. Just
# reboot and reset the FTP connection.
if (defined $self->{TELNET}) {
$self->{TELNET}->close();
$self->{TELNET} = undef;
}
$self->{TARGET}->RebootReset;
}
# Wait until a process exits.
# return -1 if the process is still alive.
sub Wait ($)
{
my $self = shift;
my $timeout = shift;
if (!defined $timeout || $timeout < 0) {
if (defined $ENV{'ACE_TEST_VERBOSE'}) {
print "-> wait\n";
}
$self->{TELNET}->print("wait");
my $reply = $self->{TELNET}->getline(Timeout => 300);
$self->{RUNNING} = 0;
if (defined $ENV{'ACE_TEST_VERBOSE'}) {
print "<- $reply\n";
}
return 0+ $reply;
} else {
return TimedWait($self, $timeout);
}
}
sub TimedWait ($)
{
my $self = shift;
my $timeout = shift;
my $reply;
if (!$self->{RUNNING}) {
return -1;
}
CHECK:
while ($timeout > 0) {
$self->{TELNET}->print ("status");
if (defined $ENV{'ACE_TEST_VERBOSE'}) {
print "-> status\n";
}
$reply = $self->{TELNET}->getline(Timeout => $timeout);
if (!defined $reply) {
last CHECK;
}
if (defined $ENV{'ACE_TEST_VERBOSE'}) {
print "<- $reply\n";
}
if ($reply =~ /^RUNNING/) {
sleep 2;
$timeout -= 2;
next CHECK;
}
# Have a status; return it.
$self->{RUNNING} = 0;
return 0+ $reply;
}
return -1;
}
###
sub kill_all
{
my $procmask = shift;
my $target = shift;
## NOT IMPLEMENTED YET
}
1;
|