3 # This module contains a few miscellaneous functions and some
4 # startup ARGV processing that is used by all tests.
7 use PerlACE
::ConfigList
;
13 $PerlACE::ACE_ROOT
= $ENV{ACE_ROOT
};
14 if(exists $ENV{TAO_ROOT
}) {
15 $PerlACE::TAO_ROOT
= $ENV{TAO_ROOT
};
17 $PerlACE::TAO_ROOT
= "$PerlACE::ACE_ROOT/TAO";
20 my $config = new PerlACE
::ConfigList
;
21 $PerlACE::TestConfig
= $config;
23 # load VxWorks Process helpers in case this is a VxWorks target build
24 $PerlACE::Static
= $config->check_config("STATIC");
25 $PerlACE::VxWorks_Test
= $config->check_config("VxWorks");
26 $PerlACE::VxWorks_RTP_Test
= $config->check_config("VxWorks_RTP");
27 if ($PerlACE::VxWorks_Test
or $PerlACE::VxWorks_RTP_Test
) {
28 require PerlACE
::ProcessVX
;
31 # Load LabVIEW RT Process helpers in case this is a LabVIEW RT target build.
32 $PerlACE::LabVIEW_RT_Test
= $config->check_config("LabVIEW_RT");
33 if ($PerlACE::LabVIEW_RT_Test
) {
34 require PerlACE
::ProcessLVRT
;
37 $PerlACE::WinCE_Test
= $config->check_config("WINCE");
38 if ($PerlACE::WinCE_Test
) {
39 if ($OSNAME eq "MSWin32") {
40 require PerlACE
::ProcessWinCE
;
42 require PerlACE
::ProcessWinCE_Unix
;
46 $PerlACE::Android_Test
= $config->check_config("ANDROID");
47 if ($PerlACE::Android_Test
) {
48 require PerlACE
::ProcessAndroid
;
51 # Figure out the svc.conf extension
52 $svcconf_ext = $ENV{'ACE_RUNTEST_SVCCONF_EXT'};
53 if (!defined $svcconf_ext) {
54 $svcconf_ext = ".conf";
57 # Default timeout. NSCORBA needs more time for process start up.
58 $wait_interval_for_process_creation = (($PerlACE::VxWorks_Test
or $PerlACE::VxWorks_RTP_Test
) ?
60 : 15);
60 $wait_interval_for_process_creation *= 3;
62 elsif ($^O
eq 'nto') {
63 ## QNX can be slow to start processes
64 $wait_interval_for_process_creation += 5;
67 $wait_interval_for_process_shutdown = (($PerlACE::VxWorks_Test
or $PerlACE::VxWorks_RTP_Test
) ?
30 : 10);
75 if (File
::Spec
->file_name_is_absolute( $file )) {
78 my $newfile = getcwd
() . '/' . $file;
80 if ($^O
eq "MSWin32") {
81 $newfile =~ s/\//\\/g
;
83 elsif ($^O
eq 'cygwin') {
84 chop($newfile = `/usr/bin/cygpath -w $newfile`);
85 $newfile =~ s/\\/\\\\/g;
95 $path = File
::Spec
->rel2abs ($path);
96 $path = File
::Spec
->abs2rel ($path, $cur_root);
97 return $new_root."/".$path;
103 return rebase_path
($file, $ENV{'ACE_ROOT'}, $ENV{'HOST_ROOT'});
106 # Returns a random port within the range of 10002 - 32767
108 return (int(rand($$)) % 22766) + 10002;
111 # Returns a unique id, uid for unix, last digit of IP for NT
114 if ($^O
eq "MSWin32") {
117 open (IPNUM
, "ipconfig|") || die "Can't run ipconfig: $!\n";
121 $uid = (split (/: (\d+)\.(\d+)\.(\d+)\.(\d+)/))[4];
134 # Waits until a file exists
138 select(undef, undef, undef, 0.1) while (!(-e
$file && -s
$file));
141 sub waitforfile_timed
145 $maxtime *= (($PerlACE::VxWorks_Test
|| $PerlACE::VxWorks_RTP_Test
) ?
146 $PerlACE::ProcessVX
::WAIT_DELAY_FACTOR
:
147 $PerlACE::Process
::WAIT_DELAY_FACTOR
);
148 # Multiply with 10 because we wait a tenth of a second each time
151 while ($maxtime-- != 0) {
152 if (-e
$file && -s
$file) {
155 select(undef, undef, undef, 0.1);
160 sub check_n_cleanup_files
163 my @flist = glob ($file);
166 my $nfile = scalar(@flist);
169 for (; $cntr < $nfile; $cntr++) {
170 print STDERR
"File <$flist[$cntr]> exists but should be cleaned up\n";
176 sub generate_test_file
185 my $data = "abcdefghijklmnopqrstuvwxyz";
186 $data = $data.uc($data)."0123456789";
188 open( INPUT
, "> $file" ) || die( "can't create input file: $file" );
189 for($i=62; $i < $size ; $i += 62 ) {
194 print INPUT
substr($data, 0, $size-$i);
201 sub is_labview_rt_test
()
203 return ($PerlACE::LabVIEW_RT_Test
);
206 sub is_vxworks_test
()
208 return ($PerlACE::VxWorks_Test
|| $PerlACE::VxWorks_RTP_Test
);
211 sub is_vxworks_rtp_test
()
213 return ($PerlACE::VxWorks_RTP_Test
);
217 my $pathlist = shift;
219 if ((!defined $pathlist) || $pathlist =~ /^\s*$/) {
222 return $pathlist . ($^O
eq 'MSWin32' ?
';' : ':') . $path;
229 $ENV{$name} = concat_path
($ENV{$name}, $value);
235 # Set the library path supporting various platforms.
236 foreach my $env ('PATH', 'DYLD_LIBRARY_PATH', 'LD_LIBRARY_PATH',
238 add_path
($env, $value);
239 if (grep(($_ eq 'ARCH'), @PerlACE::ConfigList
::Configs
)) {
240 add_path
($env, $value . '/' . $PerlACE::Process
::ExeSubDir
);
244 if (defined $ENV{'HOST_ROOT'}) {
245 add_path
('PATH', VX_HostFile
($value));
246 add_path
('LD_LIBRARY_PATH', VX_HostFile
($value));
247 add_path
('LIBPATH', VX_HostFile
($value));
248 add_path
('SHLIB_PATH', VX_HostFile
($value));
252 sub check_privilege_group
256 # waits until it finds a matching regular expression in a file
257 # escape metacharacters in the text to wait for
258 sub waitforfileoutput
261 my $waittext = shift;
263 if (-e
$file && -s
$file) {
265 while (my $line = <DATA
>) {
266 if ($line =~ /($waittext)/) {
276 sub waitforfileoutput_timed
279 my $waittext = shift;
282 $maxtime *= (($PerlACE::VxWorks_Test
|| $PerlACE::VxWorks_RTP_Test
) ?
283 $PerlACE::ProcessVX
::WAIT_DELAY_FACTOR
:
284 $PerlACE::Process
::WAIT_DELAY_FACTOR
);
285 # Multiply with 10 because we wait a tenth of a second each time
288 while ($maxtime-- != 0) {
289 if (-e
$file && -s
$file) {
291 while (my $line = <DATA
>) {
292 if ($line =~ /($waittext)/) {
299 select(undef, undef, undef, 0.1);
307 if (grep(($_ eq 'ARCH'), @PerlACE::ConfigList
::Configs
)) {
308 return $dir . $PerlACE::Process
::ExeSubDir
;
313 # Add PWD to the load library path