3 # TestTarget_LVRT - how to manage the test environment on a LabVIEW RT target.
5 # We can FTP files to and from the LabVIEW target, but there's no NFS or
7 # Most information about the target itself is specified via environment
8 # variables. Environment variables with settings are named using the target's
9 # config name with a specific suffix. The current environment variables are:
10 # <config-name>_IPNAME - the host name/IP of the target.
11 # <config-name>_CTLPORT- the TCP port number to connect to for the test
12 # controller. If this is not set, port 8888 is used.
13 # <config-name>_FSROOT - the root of the filesystem on the target where
14 # ACE files will be created from (cwd, if you will).
15 # If this is not set, "\ni-rt" is used as the root.
17 # Each of these settings are stored in a member variable of the same name in
18 # each object. The process objects can access them using, e.g.,
19 # $self->{TARGET}->{IPNAME}.
21 # This class also makes an FTP object available to process objects that are
22 # created. FTP is set up before creating a process object and can be used to
23 # transfer files to and from the LVRT target.
25 package PerlACE
::TestTarget_LVRT
;
26 our @ISA = "PerlACE::TestTarget";
28 ### Constructor and Destructor
33 my $config_name = shift;
34 my $class = ref ($proto) || $proto;
36 bless ($self, $class);
37 $self->GetConfigSettings($config_name);
39 my $env_name = $config_name.'_IPNAME';
40 if (exists $ENV{$env_name}) {
41 $targethost = $ENV{$env_name};
44 print STDERR
"You must define target hostname/IP with $env_name\n";
49 $env_name = $config_name.'_CTLPORT';
50 if (exists $ENV{$env_name}) {
51 $self->{CTLPORT
} = $ENV{$env_name};
54 print STDERR
"Warning: no $env_name variable; falling back to ",
56 $self->{CTLPORT
} = 8888;
59 $env_name = $config_name.'_FSROOT';
60 my $fsroot = '\\ni-rt\\system';
61 if (exists $ENV{$env_name}) {
62 $fsroot = $ENV{$env_name};
65 print STDERR
"Warning: no $env_name variable; falling back ",
68 $self->{FSROOT
} = $fsroot;
70 $self->{REBOOT_CMD
} = $ENV{'ACE_REBOOT_LVRT_CMD'};
71 if (!defined $self->{REBOOT_CMD
}) {
72 $self->{REBOOT_CMD
} = 'I_Need_A_Reboot_Command';
74 $self->{REBOOT_TIME
} = $ENV{'ACE_LVRT_REBOOT_TIME'};
75 if (!defined $self->{REBOOT_TIME
}) {
76 $self->{REBOOT_TIME
} = 200;
79 $self->{REBOOT_TIME
} = $ENV{'ACE_RUN_LVRT_REBOOT_TIME'};
80 if (!defined $self->{REBOOT_TIME
}) {
81 $self->{REBOOT_TIME
} = 200;
83 $self->{REBOOT_NEEDED
} = undef;
85 $self->{FTP
} = new Net
::FTP
($targethost);
86 $self->{IPNAME
} = $targethost;
87 if (!defined $self->{FTP
}) {
88 print STDERR
"Error opening FTP to $targethost: $@\n";
89 $self->{REBOOT_NEEDED
} = 1;
93 $self->{FTP
}->login("","");
102 # Reboot if needed; set up clean for the next test.
103 if (defined $self->{REBOOT_NEEDED
} && $self->{REBOOT_CMD
}) {
107 # See if there's a log; should be able to retrieve it from rebooted target.
108 if (defined $ENV{'ACE_TEST_VERBOSE'}) {
109 print STDERR
"LVRT target checking for remaining log...\n";
111 $self->GetStderrLog();
112 if (defined $self->{FTP
}) {
114 $self->{FTP
} = undef;
118 ##################################################################
124 my $newfile = $self->{FSROOT
} . '\\' . $file;
125 print STDERR
"LVRT LocalFile for $file is $newfile\n";
132 $self->{FTP
}->login("","");
133 foreach my $file (@_) {
134 my $newfile = $self->LocalFile($file);
135 $self->{FTP
}->delete($newfile);
141 # Use FTP to retrieve the file from the target; should still be open.
142 # If only one name is given, use it for both local and remote (after
143 # properly LocalFile-ing it). If both names are given, assume the caller
144 # knows what he wants and don't adjust the paths.
146 my $remote_file = shift;
147 my $local_file = shift;
148 if (!defined $local_file) {
149 $local_file = $remote_file;
150 $remote_file = $self->LocalFile($local_file);
152 $self->{FTP
}->ascii();
153 if ($self->{FTP
}->get($remote_file, $local_file)) {
159 sub WaitForFileTimed
($)
164 my $newfile = $self->LocalFile($file);
165 my $targetport = $self->{CTLPORT
};
166 my $target = new Net
::Telnet
(Errmode
=> 'return');
167 if (!$target->open(Host
=> $self->{IPNAME
}, Port
=> $targetport)) {
168 print STDERR
"ERROR: target $self->{IPNAME}:$targetport: ",
169 $target->errmsg(), "\n";
172 my $cmdline = "waitforfile $newfile $timeout";
173 if (defined $ENV{'ACE_TEST_VERBOSE'}) {
174 print "-> $cmdline\n";
176 $target->print("$cmdline");
178 # Add a small comms delay factor to the timeout
179 $timeout = $timeout + 2;
180 $reply = $target->getline(Timeout
=> $timeout);
181 if (defined $ENV{'ACE_TEST_VERBOSE'}) {
185 if ($reply eq "OK\n") {
191 sub CreateProcess
($)
194 my $process = new PerlACE
::ProcessLVRT
($self, @_);
201 # Tell the target to snapshot the stderr log; if there is one, copy
202 # it up here and put it out to our stderr.
203 my $targetport = $self->{CTLPORT
};
204 my $target = new Net
::Telnet
(Errmode
=> 'return');
205 if (!$target->open(Host
=> $self->{IPNAME
}, Port
=> $targetport)) {
206 print STDERR
"ERROR: target $self->{IPNAME}:$targetport: ",
207 $target->errmsg(), "\n";
210 my $cmdline = "snaplog";
211 if (defined $ENV{'ACE_TEST_VERBOSE'}) {
212 print "-> $cmdline\n";
214 $target->print("$cmdline");
216 $reply = $target->getline();
217 if (defined $ENV{'ACE_TEST_VERBOSE'}) {
221 if ($reply eq "NONE\n") {
225 if (undef $self->{FTP
}) {
226 $self->{FTP
} = new Net
::FTP
($self->{IPNAME
});
227 if (!defined $self->{FTP
}) {
231 $self->{FTP
}->login("","");
233 $self->{FTP
}->ascii();
234 if ($self->{FTP
}->get($reply, "stderr.txt")) {
235 $self->{FTP
}->delete($reply);
236 open(LOG
, "stderr.txt");
246 # Copy a file to the target. Adjust for different types (DLL, EXE, TEXT)
247 # and debug/non (for DLLs). Additionally, a file can be removed when this
248 # object is deleted, or left in place.
254 # Need a reboot when this target is destroyed.
258 $self->{REBOOT_NEEDED
} = 1;
265 $self->{REBOOT_NEEDED
} = undef;
266 print STDERR
"Attempting to reboot target...\n";
267 if (defined $self->{FTP
}) {
269 $self->{FTP
} = undef;
271 system ($self->{REBOOT_CMD
});
272 sleep ($self->{REBOOT_TIME
});
275 # Reboot now then try to restore the FTP connection.
280 my $targethost = $self->{IPNAME
};
281 $self->{FTP
} = new Net
::FTP
($targethost);
282 if (!defined $self->{FTP
}) {
283 print STDERR
"Error reestablishing FTP to $targethost: $@\n";
286 $self->{FTP
}->login("","");
293 my $procmask = shift;
294 PerlACE
::ProcessLVRT
::kill_all
($procmask, $self);