PageRenderTime 53ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/external/webkit/Source/JavaScriptCore/tests/mozilla/runtests.pl

https://gitlab.com/brian0218/rk3188_r-box_android4.2.2_sdk
Perl | 495 lines | 361 code | 57 blank | 77 comment | 52 complexity | 126c8cff2e7f3496898db454d2cf88c5 MD5 | raw file
  1. #!/tools/ns/bin/perl5
  2. #
  3. # simple script that executes JavaScript tests. you have to build the
  4. # stand-alone, js shell executable (which is not the same as the dll that gets
  5. # built for mozilla). see the readme at
  6. # http://lxr.mozilla.org/mozilla/source/js/src/README.html for instructions on
  7. # how to build the jsshell.
  8. #
  9. # this is just a quick-n-dirty script. for full reporting, you need to run
  10. # the test driver, which requires java and is currently not available on
  11. # mozilla.org.
  12. #
  13. # this test looks for an executable JavaScript shell in
  14. # %MOZ_SRC/mozilla/js/src/[platform]-[platform-version]-OPT.OBJ/js,
  15. # which is the default build location when you build using the instructions
  16. # at http://lxr.mozilla.org/mozilla/source/js/src/README.html
  17. #
  18. #
  19. # christine@netscape.com
  20. #
  21. &parse_args;
  22. &setup_env;
  23. &main_test_loop;
  24. &cleanup_env;
  25. #
  26. # given a main directory, assume that there is a file called 'shell.js'
  27. # in it. then, open all the subdirectories, and look for js files.
  28. # for each test.js that is found, execute the shell, and pass shell.js
  29. # and the test.js as file arguments. redirect all process output to a
  30. # file.
  31. #
  32. sub main_test_loop {
  33. foreach $suite ( &get_subdirs( $test_dir )) {
  34. foreach $subdir (&get_subdirs( $suite, $test_dir )) {
  35. @jsfiles = &get_js_files($subdir);
  36. execute_js_tests(@jsfiles);
  37. }
  38. }
  39. }
  40. #
  41. # given a directory, return an array of all subdirectories
  42. #
  43. sub get_subdirs{
  44. local ($dir, $path) = @_;
  45. local @subdirs;
  46. local $dir_path = $path . $dir;
  47. chdir $dir_path;
  48. opendir ( DIR, ${dir_path} );
  49. local @testdir_contents = readdir( DIR );
  50. closedir( DIR );
  51. foreach (@testdir_contents) {
  52. if ( (-d $_) && ($_ !~ 'CVS') && ( $_ ne '.') && ($_ ne '..')) {
  53. @subdirs[$#subdirs+1] = $_;
  54. }
  55. }
  56. chdir $path;
  57. return @subdirs;
  58. }
  59. #
  60. # given a directory, return an array of all the js files that are in it.
  61. #
  62. sub get_js_files {
  63. ( $test_subdir ) = @_;
  64. local @js_file_array;
  65. $current_test_dir = $test_dir ."/". $suite . "/" .$test_subdir;
  66. chdir $current_test_dir;
  67. opendir ( TEST_SUBDIR, ${current_test_dir} );
  68. @subdir_files = readdir( TEST_SUBDIR );
  69. closedir( TOP_LEVEL_BUILD_DIR );
  70. foreach ( @subdir_files ) {
  71. if ( $_ =~ /\.js$/ ) {
  72. $js_file_array[$#js_file_array+1] = $_;
  73. }
  74. }
  75. return @js_file_array;
  76. }
  77. #
  78. # given an array of test.js files, execute the shell command and pass
  79. # the shell.js and test.js files as file arguments. redirect process
  80. # output to a file. if $js_verbose is set (not recommended), write all
  81. # testcase output to the output file. if $js_quiet is set, only write
  82. # failed test case information to the output file. the default setting
  83. # is to write a line for each test file, and whether each file passed
  84. # or failed.
  85. #
  86. sub execute_js_tests {
  87. (@js_file_array) = @_;
  88. $js_printed_suitename = 0;
  89. if ( !$js_quiet ) {
  90. &js_print_suitename;
  91. }
  92. foreach $js_test (@js_file_array) {
  93. $js_printed_filename = 0;
  94. $js_test_bugnumber = 0;
  95. $runtime_error = "";
  96. local $passed = -1;
  97. # create the test command
  98. $test_command =
  99. $shell_command .
  100. " -f $test_dir/$suite/shell.js " .
  101. " -f $test_dir/$suite/$subdir/$js_test";
  102. if ( !$js_quiet ) {
  103. &js_print_filename;
  104. } else {
  105. print '.';
  106. }
  107. $test_path = $test_dir ."/" . $suite ."/". $test_subdir ."/". $js_test;
  108. if ( !-e $test_path ) {
  109. &js_print( " FAILED! file not found\n",
  110. "<font color=#990000>", "</font><br>\n");
  111. } else {
  112. open( RUNNING_TEST, "$test_command" . ' 2>&1 |');
  113. # this is where we want the tests to provide a lot more information
  114. # that this script must parse so that we can
  115. while( <RUNNING_TEST> ){
  116. if ( $js_verbose && !$js_quiet ) {
  117. &js_print ($_ ."\n", "", "<br>\n");
  118. }
  119. if ( $_ =~ /BUGNUMBER/ ) {
  120. $js_test_bugnumber = $_;
  121. }
  122. if ( $_ =~ /PASSED/ && $passed == -1 ) {
  123. $passed = 1;
  124. }
  125. if ( $_ =~ /FAILED/ && $_ =~ /expected/) {
  126. &js_print_suitename;
  127. &js_print_filename;
  128. &js_print_bugnumber;
  129. local @msg = split ( "FAILED", $_ );
  130. &js_print ( $passed ? "\n" : "" );
  131. &js_print( " " . $msg[0], "&nbsp;&nbsp;<tt>" );
  132. &js_print( "FAILED", "<font color=#990000>", "</font>");
  133. &js_print( $msg[1], "", "</tt><br>\n" );
  134. $passed = 0;
  135. }
  136. if ( $_ =~ /$js_test/ ) {
  137. $runtime_error .= $_;
  138. }
  139. }
  140. close( RUNNING_TEST );
  141. #
  142. # figure out whether the test passed or failed. print out an
  143. # appropriate level of output based on the value of $js_quiet
  144. #
  145. if ( $js_test =~ /-n\.js$/ ) {
  146. if ( $runtime_error ) {
  147. if ( !$js_quiet ) {
  148. &js_print( " PASSED!\n ",
  149. "<font color=#009900>&nbsp;&nbsp",
  150. "</font><br>" );
  151. if ( $js_errors ) {
  152. &js_print( $runtime_error, "<pre>", "</pre>");
  153. }
  154. }
  155. } else {
  156. &js_print_suitename;
  157. &js_print_filename;
  158. &js_print_bugnumber;
  159. &js_print( " FAILED! ", "&nbsp;&nbsp;<font color=#990000>",
  160. "</font>");
  161. &js_print( " Should have resulted in an error\n",
  162. "","<br>" );
  163. }
  164. } else {
  165. if ( $passed == 1 && !$js_quiet) {
  166. &js_print( " PASSED!\n " , "&nbsp;&nbsp;<font color=#009900>",
  167. "</font><br>" );
  168. } else {
  169. if ($passed == -1) {
  170. &js_print_suitename;
  171. &js_print_filename;
  172. &js_print_bugnumber;
  173. &js_print( " FAILED!\n " , "&nbsp;&nbsp;<font color=#990000>",
  174. "</font><br>" );
  175. &js_print( " Missing 'PASSED' in output\n", "","<br>" );
  176. &js_print( $log, "output:<br><pre>", "</pre>" );
  177. }
  178. }
  179. }
  180. }
  181. }
  182. }
  183. #
  184. # figure out what os we're on, the default name of the object directory
  185. #
  186. sub setup_env {
  187. # MOZ_SRC must be set, so we can figure out where the
  188. # JavaScript executable is
  189. $moz_src = $ENV{"MOZ_SRC"}
  190. || die( "You need to set your MOZ_SRC environment variable.\n" );
  191. $src_dir = $moz_src . '/mozilla/js/src/';
  192. # JS_TEST_DIR must be set so we can figure out where the tests are.
  193. $test_dir = $ENV{"JS_TEST_DIR"};
  194. # if it's not set, look for it relative to $moz_src
  195. if ( !$test_dir ) {
  196. $test_dir = $moz_src . '/mozilla/js/tests/';
  197. }
  198. # make sure that the test dir exists
  199. if ( ! -e $test_dir ) {
  200. die "The JavaScript Test Library could not be found at $test_dir.\n" .
  201. "Check the tests out from /mozilla/js/tests or\n" .
  202. "Set the value of your JS_TEST_DIR environment variable\n " .
  203. "to the location of the test library.\n";
  204. }
  205. # make sure that the test dir ends with a trailing slash
  206. $test_dir .= '/';
  207. chdir $src_dir;
  208. # figure out which platform we're on, and figure out where the object
  209. # directory is
  210. $machine_os = `uname -s`;
  211. if ( $machine_os =~ /WIN/ ) {
  212. $machine_os = 'WIN';
  213. $object_dir = ($js_debug) ? 'Debug' : 'Release';
  214. $js_exe = 'jsshell.exe';
  215. } else {
  216. chop $machine_os;
  217. $js_exe = 'js';
  218. # figure out what the object directory is. on all platforms,
  219. # it's the directory that ends in OBJ. if $js_debug is set,
  220. # look the directory that ends with or DBG.OBJ; otherwise
  221. # look for the directory that ends with OPT.OBJ
  222. opendir ( SRC_DIR_FILES, $src_dir );
  223. @src_dir_files = readdir( SRC_DIR_FILES );
  224. closedir ( SRC_DIR_FILES );
  225. $object_pattern = $js_debug ? 'DBG.OBJ' : 'OPT.OBJ';
  226. foreach (@src_dir_files) {
  227. if ( $_ =~ /$object_pattern/ && $_ =~ $machine_os) {
  228. $object_dir = $_;
  229. }
  230. }
  231. }
  232. if ( ! $object_dir ) {
  233. die( "Couldn't find an object directory in $src_dir.\n" );
  234. }
  235. # figure out what the name of the javascript executable should be, and
  236. # make sure it's there. if it's not there, give a helpful message so
  237. # the user can figure out what they need to do next.
  238. if ( ! $js_exe_full_path ) {
  239. $shell_command = $src_dir . $object_dir .'/'. $js_exe;
  240. } else {
  241. $shell_command = $js_exe_full_path;
  242. }
  243. if ( !-e $shell_command ) {
  244. die ("Could not find JavaScript shell executable $shell_command.\n" .
  245. "Check the value of your MOZ_SRC environment variable.\n" .
  246. "Currently, MOZ_SRC is set to $ENV{\"MOZ_SRC\"}\n".
  247. "See the readme at http://lxr.mozilla.org/mozilla/src/js/src/ " .
  248. "for instructions on building the JavaScript shell.\n" );
  249. }
  250. # set the output file name. let's base its name on the date and platform,
  251. # and give it a sequence number.
  252. if ( $get_output ) {
  253. $js_output = &get_output;
  254. }
  255. if ($js_output) {
  256. print( "Writing results to $js_output\n" );
  257. chdir $test_dir;
  258. open( JS_OUTPUT, "> ${js_output}" ) ||
  259. die "Can't open log file $js_output\n";
  260. close JS_OUTPUT;
  261. }
  262. # get the start time
  263. $start_time = time;
  264. # print out some nice stuff
  265. $start_date = &get_date;
  266. &js_print( "JavaScript tests started: " . $start_date, "<p><tt>", "</tt></p>" );
  267. &js_print ("Executing all the tests under $test_dir\n against " .
  268. "$shell_command\n", "<p><tt>", "</tt></p>" );
  269. }
  270. #
  271. # parse arguments. see usage for what arguments are expected.
  272. #
  273. sub parse_args {
  274. $i = 0;
  275. while( $i < @ARGV ){
  276. if ( $ARGV[$i] eq '--threaded' ) {
  277. $js_threaded = 1;
  278. } elsif ( $ARGV[$i] eq '--d' ) {
  279. $js_debug = 1;
  280. } elsif ( $ARGV[$i] eq '--14' ) {
  281. $js_version = '14';
  282. } elsif ( $ARGV[$i] eq '--v' ) {
  283. $js_verbose = 1;
  284. } elsif ( $ARGV[$i] eq '-f' ) {
  285. $js_output = $ARGV[++$i];
  286. } elsif ( $ARGV[$i] eq '--o' ) {
  287. $get_output = 1;
  288. } elsif ($ARGV[$i] eq '--e' ) {
  289. $js_errors = 1;
  290. } elsif ($ARGV[$i] eq '--q' ) {
  291. $js_quiet = 1;
  292. } elsif ($ARGV[$i] eq '--h' ) {
  293. die &usage;
  294. } elsif ( $ARGV[$i] eq '-E' ) {
  295. $js_exe_full_path = $ARGV[$i+1];
  296. $i++;
  297. } else {
  298. die &usage;
  299. }
  300. $i++;
  301. }
  302. #
  303. # if no output options are provided, show some output and write to file
  304. #
  305. if ( !$js_verbose && !$js_output && !$get_output ) {
  306. $get_output = 1;
  307. }
  308. }
  309. #
  310. # print the arguments that this script expects
  311. #
  312. sub usage {
  313. die ("usage: $0\n" .
  314. "--q Quiet mode -- only show information for tests that failed\n".
  315. "--e Show runtime error messages for negative tests\n" .
  316. "--v Verbose output -- show all test cases (not recommended)\n" .
  317. "--o Send output to file whose generated name is based on date\n".
  318. "--d Look for a debug JavaScript executable (default is optimized)\n" .
  319. "-f <file> Redirect output to file named <file>\n"
  320. );
  321. }
  322. #
  323. # if $js_output is set, print to file as well as stdout
  324. #
  325. sub js_print {
  326. ($string, $start_tag, $end_tag) = @_;
  327. if ($js_output) {
  328. open( JS_OUTPUT, ">> ${js_output}" ) ||
  329. die "Can't open log file $js_output\n";
  330. print JS_OUTPUT "$start_tag $string $end_tag";
  331. close JS_OUTPUT;
  332. }
  333. print $string;
  334. }
  335. #
  336. # close open files
  337. #
  338. sub cleanup_env {
  339. # print out some nice stuff
  340. $end_date = &get_date;
  341. &js_print( "\nTests complete at $end_date", "<hr><tt>", "</tt>" );
  342. # print out how long it took to complete
  343. $end_time = time;
  344. $test_seconds = ( $end_time - $start_time );
  345. &js_print( "Start Date: $start_date\n", "<tt><br>" );
  346. &js_print( "End Date: $end_date\n", "<br>" );
  347. &js_print( "Test Time: $test_seconds seconds\n", "<br>" );
  348. if ($js_output ) {
  349. if ( !$js_verbose) {
  350. &js_print( "Results were written to " . $js_output ."\n",
  351. "<br>", "</tt>" );
  352. }
  353. close JS_OUTPUT;
  354. }
  355. }
  356. #
  357. # get the current date and time
  358. #
  359. sub get_date {
  360. &get_localtime;
  361. $now = $year ."/". $mon ."/". $mday ." ". $hour .":".
  362. $min .":". $sec ."\n";
  363. return $now;
  364. }
  365. sub get_localtime {
  366. ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) =
  367. localtime;
  368. $mon++;
  369. $mon = &zero_pad($mon);
  370. $year= ($year < 2000) ? "19" . $year : $year;
  371. $mday= &zero_pad($mday);
  372. $sec = &zero_pad($sec);
  373. $min = &zero_pad($min);
  374. $hour = &zero_pad($hour);
  375. }
  376. sub zero_pad {
  377. local ($string) = @_;
  378. $string = ($string < 10) ? "0" . $string : $string;
  379. return $string;
  380. }
  381. #
  382. # generate an output file name based on the date
  383. #
  384. sub get_output {
  385. &get_localtime;
  386. chdir $test_dir;
  387. $js_output = $test_dir ."/". $year .'-'. $mon .'-'. $mday ."\.1.html";
  388. $output_file_found = 0;
  389. while ( !$output_file_found ) {
  390. if ( -e $js_output ) {
  391. # get the last sequence number - everything after the dot
  392. @seq_no = split( /\./, $js_output, 2 );
  393. $js_output = $seq_no[0] .".". (++$seq_no[1]) . "\.html";
  394. } else {
  395. $output_file_found = 1;
  396. }
  397. }
  398. return $js_output;
  399. }
  400. sub js_print_suitename {
  401. if ( !$js_printed_suitename ) {
  402. &js_print( "$suite\\$subdir\n", "<hr><font size+=1><b>",
  403. "</font></b><br>" );
  404. }
  405. $js_printed_suitename = 1;
  406. }
  407. sub js_print_filename {
  408. if ( !$js_printed_filename ) {
  409. &js_print( "$js_test\n", "<b>", "</b><br>" );
  410. $js_printed_filename = 1;
  411. }
  412. }
  413. sub js_print_bugnumber {
  414. if ( !$js_printed_bugnumber ) {
  415. if ( $js_bugnumber =~ /^http/ ) {
  416. &js_print( "$js_bugnumber", "<a href=$js_bugnumber>", "</a>" );
  417. } else {
  418. &js_print( "$js_bugnumber",
  419. "<a href=http://scopus.mcom.com/bugsplat/show_bug.cgi?id=" .
  420. $js_bugnumber .">",
  421. "</a>" );
  422. }
  423. $js_printed_bugnumber = 1;
  424. }
  425. }