/bin/PerlDDS/Run_Test.pm

https://bitbucket.org/snaewe/dds · Perl · 197 lines · 152 code · 30 blank · 15 comment · 14 complexity · f692b91cb5f81e25bff5b75944310549 MD5 · raw file

  1. # $Id$
  2. # This module contains a few miscellaneous functions and some
  3. # startup ARGV processing that is used by all tests.
  4. use PerlACE::Run_Test;
  5. use PerlDDS::Process;
  6. use PerlDDS::ProcessFactory;
  7. use Cwd;
  8. package PerlDDS;
  9. sub orbsvcs {
  10. my $o = "$ENV{'TAO_ROOT'}/orbsvcs";
  11. my $n = -r "$o/Naming_Service/tao_cosnaming" || # using new names?
  12. -r "$o/Naming_Service/tao_cosnaming.exe" ||
  13. -r "$o/Naming_Service/Release/tao_cosnaming.exe";
  14. return (
  15. 'Naming_Service' => "$o/Naming_Service/" . ($n ? 'tao_cosnaming'
  16. : 'Naming_Service'),
  17. 'ImplRepo_Service' => "$o/ImplRepo_Service/" . ($n ? 'tao_imr_locator'
  18. : 'ImplRepo_Service'),
  19. 'ImR_Activator' => "$o/ImplRepo_Service/" . ($n ? 'tao_imr_activator'
  20. : 'ImR_Activator'),
  21. );
  22. }
  23. # load gcov helpers in case this is a coverage build
  24. my $config = new PerlACE::ConfigList;
  25. $PerlDDS::Coverage_Test = $config->check_config("Coverage");
  26. # used to prevent multiple special processes from running remotely
  27. $PerlDDS::Special_Process_Created = 0;
  28. $PerlDDS::Coverage_Count = 0;
  29. $PerlDDS::Coverage_MAX_COUNT = 6;
  30. $PerlDDS::Coverage_Overflow_Count = $PerlDDS::Coverage_MAX_COUNT;
  31. $PerlDDS::Coverage_Processes = [];
  32. # used for VxWorks
  33. $PerlDDS::vxworks_test_target = undef;
  34. $PerlDDS::added_lib_path = "";
  35. sub return_coverage_process {
  36. my $count = shift;
  37. if ($count >= $PerlDDS::Coverage_Count) {
  38. print STDERR "return_coverage_process called with $count, but only" .
  39. ($PerlDDS::Coverage_Count - 1) . " processes have been created.\n";
  40. return;
  41. }
  42. $PerlDDS::Coverage_Processes->[$count] = 0;
  43. }
  44. sub next_coverage_process {
  45. my $next;
  46. for ($next = 0; $next < $PerlDDS::Coverage_MAX_COUNT; ++$next) {
  47. if (!$PerlDDS::Coverage_Processes->[$next]) {
  48. $PerlDDS::Coverage_Processes->[$next] = 1;
  49. return $next;
  50. }
  51. }
  52. ++$PerlDDS::Coverage_Overflow_Count;
  53. $next = $PerlDDS::Coverage_MAX_COUNT - 1;
  54. print STDERR "ERROR: maximum coverage processes reached, " .
  55. "$PerlDDS::Coverage_Overflow_Count processes active.\n";
  56. return $next;
  57. }
  58. sub is_coverage_test()
  59. {
  60. return $PerlDDS::Coverage_Test;
  61. }
  62. sub is_special_process_created()
  63. {
  64. return $PerlDDS::Special_Process_Created;
  65. }
  66. sub special_process_created()
  67. {
  68. $PerlDDS::Special_Process_Created = 1;
  69. }
  70. sub get_test_target_config_name()
  71. {
  72. # could refactor out of PerlACE::create_target
  73. my $component = shift;
  74. my $envname = "DOC_TEST_\U$component";
  75. if (!exists $ENV{$envname}) {
  76. # no test target config name
  77. return undef;
  78. }
  79. my $config_name = $ENV{$envname};
  80. # There's a configuration name
  81. $config_name = uc $config_name;
  82. return $config_name;
  83. }
  84. sub get_test_target_os()
  85. {
  86. # could refactor out of PerlACE::create_target
  87. my $config_name = shift;
  88. $envname = $config_name.'_OS';
  89. if (!exists $ENV{$envname}) {
  90. print STDERR "$config_name requires an OS type in $envname\n";
  91. return undef;
  92. }
  93. my $config_os = $ENV{$envname};
  94. return $config_os;
  95. }
  96. sub create_test_target()
  97. {
  98. # could refactor out of PerlACE::create_target
  99. my $config_name = shift;
  100. my $config_os = shift;
  101. my $target = undef;
  102. SWITCH: {
  103. if ($config_os =~ m/local|remote/i) {
  104. $target = new PerlACE::TestTarget ($config_name);
  105. last SWITCH;
  106. }
  107. if ($config_os =~ m/LabVIEW_RT/i) {
  108. require PerlACE::TestTarget_LVRT;
  109. $target = new PerlACE::TestTarget_LVRT ($config_name);
  110. last SWITCH;
  111. }
  112. if ($config_os =~ /VxWorks/i) {
  113. require PerlACE::TestTarget_VxWorks;
  114. $target = new PerlACE::TestTarget_VxWorks ($config_name);
  115. last SWITCH;
  116. }
  117. if ($config_os =~ /WinCE/i) {
  118. require PerlACE::TestTarget_WinCE;
  119. $target = new PerlACE::TestTarget_WinCE ($config_name);
  120. last SWITCH;
  121. }
  122. if ($config_os =~ /ANDROID/i) {
  123. require PerlACE::TestTarget_Android;
  124. $target = new PerlACE::TestTarget_Android ($config_name, $component);
  125. last SWITCH;
  126. }
  127. print STDERR "$config_os is an unknown OS type!\n";
  128. }
  129. return $target;
  130. }
  131. sub swap_path {
  132. my $name = shift;
  133. my $new_value = shift;
  134. my $orig_value = shift;
  135. my $environment = $ENV{$name};
  136. $environment =~ s/$orig_value/$new_value/g;
  137. $ENV{$name} = $environment;
  138. }
  139. sub swap_lib_path {
  140. my($new_value) = shift;
  141. my($orig_value) = shift;
  142. # Set the library path supporting various platforms.
  143. swap_path('PATH', $new_value, $orig_value);
  144. swap_path('DYLD_LIBRARY_PATH', $new_value, $orig_value);
  145. swap_path('LD_LIBRARY_PATH', $new_value, $orig_value);
  146. swap_path('LIBPATH', $new_value, $orig_value);
  147. swap_path('SHLIB_PATH', $new_value, $orig_value);
  148. }
  149. sub add_lib_path {
  150. my($dir) = shift;
  151. # add the cwd to the directory if it is relative
  152. if (($dir =~ /^\.\//) || ($dir =~ /^\.\.\//)) {
  153. $dir = Cwd::getcwd() . "/$dir";
  154. }
  155. PerlACE::add_lib_path($dir);
  156. if (defined($PerlDDS::vxworks_test_target)) {
  157. $PerlDDS::vxworks_test_target->AddLibPath($dir);
  158. }
  159. elsif (PerlACE::is_vxworks_test()) {
  160. # store added lib path for late created TestTargets
  161. $PerlDDS::added_lib_path .= $dir . ':';
  162. }
  163. }
  164. # Add PWD to the load library path
  165. add_lib_path ('.');
  166. $sleeptime = 5;
  167. 1;