You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1236 lines
34 KiB

15 years ago
18 years ago
18 years ago
18 years ago
  1. # -*- cperl -*-
  2. # Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; version 2 of the License.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program; if not, write to the Free Software
  15. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. # This is a library file used by the Perl version of mysql-test-run,
  17. # and is part of the translation of the Bourne shell script with the
  18. # same name.
  19. package mtr_cases;
  20. use strict;
  21. use base qw(Exporter);
  22. our @EXPORT= qw(collect_option collect_test_cases);
  23. use mtr_report;
  24. use mtr_match;
  25. # Options used for the collect phase
  26. our $start_from;
  27. our $print_testcases;
  28. our $skip_rpl;
  29. our $do_test;
  30. our $skip_test;
  31. our $skip_combinations;
  32. our $binlog_format;
  33. our $enable_disabled;
  34. our $default_storage_engine;
  35. our $opt_with_ndbcluster_only;
  36. our $defaults_file;
  37. our $defaults_extra_file;
  38. our $quick_collect;
  39. # Set to 1 if you want the tests to override
  40. # default storage engine settings, and use MyISAM
  41. # as default. (temporary option used in connection
  42. # with the change of default storage engine to InnoDB)
  43. our $default_myisam= 1;
  44. sub collect_option {
  45. my ($opt, $value)= @_;
  46. # Evaluate $opt as string to use "Getopt::Long::Callback legacy API"
  47. my $opt_name = "$opt";
  48. # Convert - to _ in option name
  49. $opt_name =~ s/-/_/g;
  50. no strict 'refs';
  51. ${$opt_name}= $value;
  52. }
  53. use File::Basename;
  54. use File::Spec::Functions qw / splitdir /;
  55. use IO::File();
  56. use My::Config;
  57. use My::Platform;
  58. use My::Test;
  59. use My::Find;
  60. require "mtr_misc.pl";
  61. # Precompiled regex's for tests to do or skip
  62. my $do_test_reg;
  63. my $skip_test_reg;
  64. # Related to adding InnoDB plugin combinations
  65. my $lib_innodb_plugin;
  66. my $do_innodb_plugin;
  67. # If "Quick collect", set to 1 once a test to run has been found.
  68. my $some_test_found;
  69. sub init_pattern {
  70. my ($from, $what)= @_;
  71. return undef unless defined $from;
  72. if ( $from =~ /^[a-z0-9\.]*$/ ) {
  73. # Does not contain any regex (except . that we allow as
  74. # separator betwen suite and testname), make the pattern match
  75. # beginning of string
  76. $from= "^$from";
  77. mtr_verbose("$what='$from'");
  78. }
  79. # Check that pattern is a valid regex
  80. eval { "" =~/$from/; 1 } or
  81. mtr_error("Invalid regex '$from' passed to $what\nPerl says: $@");
  82. return $from;
  83. }
  84. ##############################################################################
  85. #
  86. # Collect information about test cases to be run
  87. #
  88. ##############################################################################
  89. sub collect_test_cases ($$$$) {
  90. my $opt_reorder= shift; # True if we're reordering tests
  91. my $suites= shift; # Semicolon separated list of test suites
  92. my $opt_cases= shift;
  93. my $opt_skip_test_list= shift;
  94. my $cases= []; # Array of hash(one hash for each testcase)
  95. $do_test_reg= init_pattern($do_test, "--do-test");
  96. $skip_test_reg= init_pattern($skip_test, "--skip-test");
  97. $lib_innodb_plugin=
  98. my_find_file($::basedir,
  99. ["storage/innodb_plugin", "storage/innodb_plugin/.libs",
  100. "lib/mysql/plugin", "lib/plugin"],
  101. ["ha_innodb_plugin.dll", "ha_innodb_plugin.so",
  102. "ha_innodb_plugin.sl"],
  103. NOT_REQUIRED);
  104. $do_innodb_plugin= ($::mysql_version_id >= 50100 &&
  105. !(IS_WINDOWS && $::opt_embedded_server) &&
  106. $lib_innodb_plugin);
  107. # If not reordering, we also shouldn't group by suites, unless
  108. # no test cases were named.
  109. # This also effects some logic in the loop following this.
  110. if ($opt_reorder or !@$opt_cases)
  111. {
  112. foreach my $suite (split(",", $suites))
  113. {
  114. push(@$cases, collect_one_suite($suite, $opt_cases, $opt_skip_test_list));
  115. last if $some_test_found;
  116. }
  117. }
  118. if ( @$opt_cases )
  119. {
  120. # A list of tests was specified on the command line
  121. # Check that the tests specified was found
  122. # in at least one suite
  123. foreach my $test_name_spec ( @$opt_cases )
  124. {
  125. my $found= 0;
  126. my ($sname, $tname, $extension)= split_testname($test_name_spec);
  127. foreach my $test ( @$cases )
  128. {
  129. last unless $opt_reorder;
  130. # test->{name} is always in suite.name format
  131. if ( $test->{name} =~ /^$sname.*\.$tname$/ )
  132. {
  133. $found= 1;
  134. last;
  135. }
  136. }
  137. if ( not $found )
  138. {
  139. $sname= "main" if !$opt_reorder and !$sname;
  140. mtr_error("Could not find '$tname' in '$suites' suite(s)") unless $sname;
  141. # If suite was part of name, find it there, may come with combinations
  142. my @this_case = collect_one_suite($sname, [ $tname ]);
  143. if (@this_case)
  144. {
  145. push (@$cases, @this_case);
  146. }
  147. else
  148. {
  149. mtr_error("Could not find '$tname' in '$sname' suite");
  150. }
  151. }
  152. }
  153. }
  154. if ( $opt_reorder && !$quick_collect)
  155. {
  156. # Reorder the test cases in an order that will make them faster to run
  157. # Make a mapping of test name to a string that represents how that test
  158. # should be sorted among the other tests. Put the most important criterion
  159. # first, then a sub-criterion, then sub-sub-criterion, etc.
  160. foreach my $tinfo (@$cases)
  161. {
  162. my @criteria = ();
  163. #
  164. # Append the criteria for sorting, in order of importance.
  165. #
  166. push(@criteria, "ndb=" . ($tinfo->{'ndb_test'} ? "A" : "B"));
  167. push(@criteria, $tinfo->{template_path});
  168. # Group test with equal options together.
  169. # Ending with "~" makes empty sort later than filled
  170. my $opts= $tinfo->{'master_opt'} ? $tinfo->{'master_opt'} : [];
  171. push(@criteria, join("!", sort @{$opts}) . "~");
  172. # Add slave opts if any
  173. if ($tinfo->{'slave_opt'})
  174. {
  175. push(@criteria, join("!", sort @{$tinfo->{'slave_opt'}}));
  176. }
  177. # This sorts tests with force-restart *before* identical tests
  178. push(@criteria, $tinfo->{force_restart} ? "force-restart" : "no-restart");
  179. $tinfo->{criteria}= join(" ", @criteria);
  180. }
  181. @$cases = sort {$a->{criteria} cmp $b->{criteria}; } @$cases;
  182. # For debugging the sort-order
  183. # foreach my $tinfo (@$cases)
  184. # {
  185. # my $tname= $tinfo->{name} . ' ' . $tinfo->{combination};
  186. # my $crit= $tinfo->{criteria};
  187. # print("$tname\n\t$crit\n");
  188. # }
  189. }
  190. if (defined $print_testcases){
  191. print_testcases(@$cases);
  192. exit(1);
  193. }
  194. return $cases;
  195. }
  196. # Returns (suitename, testname, extension)
  197. sub split_testname {
  198. my ($test_name)= @_;
  199. # If .test file name is used, get rid of directory part
  200. $test_name= basename($test_name) if $test_name =~ /\.test$/;
  201. # Now split name on .'s
  202. my @parts= split(/\./, $test_name);
  203. if (@parts == 1){
  204. # Only testname given, ex: alias
  205. return (undef , $parts[0], undef);
  206. } elsif (@parts == 2) {
  207. # Either testname.test or suite.testname given
  208. # Ex. main.alias or alias.test
  209. if ($parts[1] eq "test")
  210. {
  211. return (undef , $parts[0], $parts[1]);
  212. }
  213. else
  214. {
  215. return ($parts[0], $parts[1], undef);
  216. }
  217. } elsif (@parts == 3) {
  218. # Fully specified suitename.testname.test
  219. # ex main.alias.test
  220. return ( $parts[0], $parts[1], $parts[2]);
  221. }
  222. mtr_error("Illegal format of test name: $test_name");
  223. }
  224. sub collect_one_suite($)
  225. {
  226. my $suite= shift; # Test suite name
  227. my $opt_cases= shift;
  228. my $opt_skip_test_list= shift;
  229. my @cases; # Array of hash
  230. mtr_verbose("Collecting: $suite");
  231. my $suitedir= "$::glob_mysql_test_dir"; # Default
  232. if ( $suite ne "main" )
  233. {
  234. # Allow suite to be path to "some dir" if $suite has at least
  235. # one directory part
  236. if ( -d $suite and splitdir($suite) > 1 ){
  237. $suitedir= $suite;
  238. mtr_report(" - from '$suitedir'");
  239. }
  240. else
  241. {
  242. $suitedir= my_find_dir($::basedir,
  243. ["share/mysql-test/suite",
  244. "mysql-test/suite",
  245. "mysql-test",
  246. # Look in storage engine specific suite dirs
  247. "storage/*/mysql-test-suites"
  248. ],
  249. [$suite]);
  250. }
  251. mtr_verbose("suitedir: $suitedir");
  252. }
  253. my $testdir= "$suitedir/t";
  254. my $resdir= "$suitedir/r";
  255. # Check if t/ exists
  256. if (-d $testdir){
  257. # t/ exists
  258. if ( -d $resdir )
  259. {
  260. # r/exists
  261. }
  262. else
  263. {
  264. # No r/, use t/ as result dir
  265. $resdir= $testdir;
  266. }
  267. }
  268. else {
  269. # No t/ dir => there can' be any r/ dir
  270. mtr_error("Can't have r/ dir without t/") if -d $resdir;
  271. # No t/ or r/ => use suitedir
  272. $resdir= $testdir= $suitedir;
  273. }
  274. mtr_verbose("testdir: $testdir");
  275. mtr_verbose("resdir: $resdir");
  276. # ----------------------------------------------------------------------
  277. # Build a hash of disabled testcases for this suite
  278. # ----------------------------------------------------------------------
  279. my %disabled;
  280. my @disabled_collection= @{$opt_skip_test_list} if defined @{$opt_skip_test_list};
  281. unshift (@disabled_collection, "$testdir/disabled.def");
  282. for my $skip (@disabled_collection)
  283. {
  284. if ( open(DISABLED, $skip ) )
  285. {
  286. while ( <DISABLED> )
  287. {
  288. chomp;
  289. if ( /^\s*(\S+)\s*:\s*(.*?)\s*$/ )
  290. {
  291. $disabled{$1}= $2 if not exists $disabled{$1};
  292. }
  293. }
  294. close DISABLED;
  295. }
  296. }
  297. # Read suite.opt file
  298. my $suite_opt_file= "$testdir/suite.opt";
  299. my $suite_opts= [];
  300. if ( -f $suite_opt_file )
  301. {
  302. $suite_opts= opts_from_file($suite_opt_file);
  303. }
  304. if ( @$opt_cases )
  305. {
  306. # Collect in specified order
  307. foreach my $test_name_spec ( @$opt_cases )
  308. {
  309. my ($sname, $tname, $extension)= split_testname($test_name_spec);
  310. # The test name parts have now been defined
  311. #print " suite_name: $sname\n";
  312. #print " tname: $tname\n";
  313. #print " extension: $extension\n";
  314. # Check cirrect suite if suitename is defined
  315. next if (defined $sname and $suite ne $sname);
  316. if ( defined $extension )
  317. {
  318. my $full_name= "$testdir/$tname.$extension";
  319. # Extension was specified, check if the test exists
  320. if ( ! -f $full_name)
  321. {
  322. # This is only an error if suite was specified, otherwise it
  323. # could exist in another suite
  324. mtr_error("Test '$full_name' was not found in suite '$sname'")
  325. if $sname;
  326. next;
  327. }
  328. }
  329. else
  330. {
  331. # No extension was specified, use default
  332. $extension= "test";
  333. my $full_name= "$testdir/$tname.$extension";
  334. # Test not found here, could exist in other suite
  335. next if ( ! -f $full_name );
  336. }
  337. push(@cases,
  338. collect_one_test_case($suitedir,
  339. $testdir,
  340. $resdir,
  341. $suite,
  342. $tname,
  343. "$tname.$extension",
  344. \%disabled,
  345. $suite_opts));
  346. }
  347. }
  348. else
  349. {
  350. opendir(TESTDIR, $testdir) or mtr_error("Can't open dir \"$testdir\": $!");
  351. foreach my $elem ( sort readdir(TESTDIR) )
  352. {
  353. my $tname= mtr_match_extension($elem, 'test');
  354. next unless defined $tname;
  355. # Skip tests that does not match the --do-test= filter
  356. next if ($do_test_reg and not $tname =~ /$do_test_reg/o);
  357. push(@cases,
  358. collect_one_test_case($suitedir,
  359. $testdir,
  360. $resdir,
  361. $suite,
  362. $tname,
  363. $elem,
  364. \%disabled,
  365. $suite_opts));
  366. }
  367. closedir TESTDIR;
  368. }
  369. # Return empty list if no testcases found
  370. return if (@cases == 0);
  371. # ----------------------------------------------------------------------
  372. # Read combinations for this suite and build testcases x combinations
  373. # if any combinations exists
  374. # ----------------------------------------------------------------------
  375. if ( ! $skip_combinations && ! $quick_collect )
  376. {
  377. my @combinations;
  378. my $combination_file= "$suitedir/combinations";
  379. #print "combination_file: $combination_file\n";
  380. if (@::opt_combinations)
  381. {
  382. # take the combination from command-line
  383. mtr_verbose("Take the combination from command line");
  384. foreach my $combination (@::opt_combinations) {
  385. my $comb= {};
  386. $comb->{name}= $combination;
  387. push(@{$comb->{comb_opt}}, $combination);
  388. push(@combinations, $comb);
  389. }
  390. }
  391. elsif (-f $combination_file )
  392. {
  393. # Read combinations file in my.cnf format
  394. mtr_verbose("Read combinations file");
  395. my $config= My::Config->new($combination_file);
  396. foreach my $group ($config->groups()) {
  397. my $comb= {};
  398. $comb->{name}= $group->name();
  399. foreach my $option ( $group->options() ) {
  400. push(@{$comb->{comb_opt}}, $option->option());
  401. }
  402. push(@combinations, $comb);
  403. }
  404. }
  405. if (@combinations)
  406. {
  407. print " - adding combinations for $suite\n";
  408. #print_testcases(@cases);
  409. my @new_cases;
  410. foreach my $comb (@combinations)
  411. {
  412. foreach my $test (@cases)
  413. {
  414. next if ( $test->{'skip'} );
  415. # Skip this combination if the values it provides
  416. # already are set in master_opt or slave_opt
  417. if (My::Options::is_set($test->{master_opt}, $comb->{comb_opt}) &&
  418. My::Options::is_set($test->{slave_opt}, $comb->{comb_opt}) ){
  419. next;
  420. }
  421. # Copy test options
  422. my $new_test= My::Test->new();
  423. while (my ($key, $value) = each(%$test)) {
  424. if (ref $value eq "ARRAY") {
  425. push(@{$new_test->{$key}}, @$value);
  426. } else {
  427. $new_test->{$key}= $value;
  428. }
  429. }
  430. # Append the combination options to master_opt and slave_opt
  431. push(@{$new_test->{master_opt}}, @{$comb->{comb_opt}});
  432. push(@{$new_test->{slave_opt}}, @{$comb->{comb_opt}});
  433. # Add combination name short name
  434. $new_test->{combination}= $comb->{name};
  435. # Add the new test to new test cases list
  436. push(@new_cases, $new_test);
  437. }
  438. }
  439. # Add the plain test if it was not already added
  440. # as part of a combination
  441. my %added;
  442. foreach my $new_test (@new_cases){
  443. $added{$new_test->{name}}= 1;
  444. }
  445. foreach my $test (@cases){
  446. push(@new_cases, $test) unless $added{$test->{name}};
  447. }
  448. #print_testcases(@new_cases);
  449. @cases= @new_cases;
  450. #print_testcases(@cases);
  451. }
  452. }
  453. optimize_cases(\@cases);
  454. #print_testcases(@cases);
  455. return @cases;
  456. }
  457. #
  458. # Loop through all test cases
  459. # - optimize which test to run by skipping unnecessary ones
  460. # - update settings if necessary
  461. #
  462. sub optimize_cases {
  463. my ($cases)= @_;
  464. foreach my $tinfo ( @$cases )
  465. {
  466. # Skip processing if already marked as skipped
  467. next if $tinfo->{skip};
  468. # =======================================================
  469. # If a special binlog format was selected with
  470. # --mysqld=--binlog-format=x, skip all test that does not
  471. # support it
  472. # =======================================================
  473. #print "binlog_format: $binlog_format\n";
  474. if (defined $binlog_format )
  475. {
  476. # =======================================================
  477. # Fixed --binlog-format=x specified on command line
  478. # =======================================================
  479. if ( defined $tinfo->{'binlog_formats'} )
  480. {
  481. #print "binlog_formats: ". join(", ", @{$tinfo->{binlog_formats}})."\n";
  482. # The test supports different binlog formats
  483. # check if the selected one is ok
  484. my $supported=
  485. grep { $_ eq $binlog_format } @{$tinfo->{'binlog_formats'}};
  486. if ( !$supported )
  487. {
  488. $tinfo->{'skip'}= 1;
  489. $tinfo->{'comment'}=
  490. "Doesn't support --binlog-format='$binlog_format'";
  491. }
  492. }
  493. }
  494. else
  495. {
  496. # =======================================================
  497. # Use dynamic switching of binlog format
  498. # =======================================================
  499. # Get binlog-format used by this test from master_opt
  500. my $test_binlog_format;
  501. foreach my $opt ( @{$tinfo->{master_opt}} ) {
  502. $test_binlog_format=
  503. mtr_match_prefix($opt, "--binlog-format=") || $test_binlog_format;
  504. }
  505. if (defined $test_binlog_format and
  506. defined $tinfo->{binlog_formats} )
  507. {
  508. my $supported=
  509. grep { $_ eq $test_binlog_format } @{$tinfo->{'binlog_formats'}};
  510. if ( !$supported )
  511. {
  512. $tinfo->{'skip'}= 1;
  513. $tinfo->{'comment'}=
  514. "Doesn't support --binlog-format='$test_binlog_format'";
  515. next;
  516. }
  517. }
  518. }
  519. # =======================================================
  520. # Check that engine selected by
  521. # --default-storage-engine=<engine> is supported
  522. # =======================================================
  523. my %builtin_engines = ('myisam' => 1, 'memory' => 1, 'csv' => 1);
  524. foreach my $opt ( @{$tinfo->{master_opt}} ) {
  525. my $default_engine=
  526. mtr_match_prefix($opt, "--default-storage-engine=");
  527. # Allow use of uppercase, convert to all lower case
  528. $default_engine =~ tr/A-Z/a-z/;
  529. if (defined $default_engine){
  530. #print " $tinfo->{name}\n";
  531. #print " - The test asked to use '$default_engine'\n";
  532. #my $engine_value= $::mysqld_variables{$default_engine};
  533. #print " - The mysqld_variables says '$engine_value'\n";
  534. if ( ! exists $::mysqld_variables{$default_engine} and
  535. ! exists $builtin_engines{$default_engine} )
  536. {
  537. $tinfo->{'skip'}= 1;
  538. $tinfo->{'comment'}=
  539. "'$default_engine' not supported";
  540. }
  541. $tinfo->{'ndb_test'}= 1
  542. if ( $default_engine =~ /^ndb/i );
  543. $tinfo->{'innodb_test'}= 1
  544. if ( $default_engine =~ /^innodb/i );
  545. }
  546. }
  547. if ($quick_collect && ! $tinfo->{'skip'})
  548. {
  549. $some_test_found= 1;
  550. return;
  551. }
  552. }
  553. }
  554. #
  555. # Read options from the given opt file and append them as an array
  556. # to $tinfo->{$opt_name}
  557. #
  558. sub process_opts_file {
  559. my ($tinfo, $opt_file, $opt_name)= @_;
  560. if ( -f $opt_file )
  561. {
  562. my $opts= opts_from_file($opt_file);
  563. foreach my $opt ( @$opts )
  564. {
  565. my $value;
  566. # The opt file is used both to send special options to the mysqld
  567. # as well as pass special test case specific options to this
  568. # script
  569. $value= mtr_match_prefix($opt, "--timezone=");
  570. if ( defined $value )
  571. {
  572. $tinfo->{'timezone'}= $value;
  573. next;
  574. }
  575. $value= mtr_match_prefix($opt, "--result-file=");
  576. if ( defined $value )
  577. {
  578. # Specifies the file mysqltest should compare
  579. # output against
  580. $tinfo->{'result_file'}= "r/$value.result";
  581. next;
  582. }
  583. $value= mtr_match_prefix($opt, "--config-file-template=");
  584. if ( defined $value)
  585. {
  586. # Specifies the configuration file to use for this test
  587. $tinfo->{'template_path'}= dirname($tinfo->{path})."/$value";
  588. next;
  589. }
  590. # If we set default time zone, remove the one we have
  591. $value= mtr_match_prefix($opt, "--default-time-zone=");
  592. if ( defined $value )
  593. {
  594. # Set timezone for this test case to something different
  595. $tinfo->{'timezone'}= "GMT-8";
  596. # Fallthrough, add the --default-time-zone option
  597. }
  598. # The --restart option forces a restart even if no special
  599. # option is set. If the options are the same as next testcase
  600. # there is no need to restart after the testcase
  601. # has completed
  602. if ( $opt eq "--force-restart" )
  603. {
  604. $tinfo->{'force_restart'}= 1;
  605. next;
  606. }
  607. $value= mtr_match_prefix($opt, "--testcase-timeout=");
  608. if ( defined $value ) {
  609. # Overrides test case timeout for this test
  610. $tinfo->{'case-timeout'}= $value;
  611. next;
  612. }
  613. # Ok, this was a real option, add it
  614. push(@{$tinfo->{$opt_name}}, $opt);
  615. }
  616. }
  617. }
  618. ##############################################################################
  619. #
  620. # Collect information about a single test case
  621. #
  622. ##############################################################################
  623. sub collect_one_test_case {
  624. my $suitedir= shift;
  625. my $testdir= shift;
  626. my $resdir= shift;
  627. my $suitename= shift;
  628. my $tname= shift;
  629. my $filename= shift;
  630. my $disabled= shift;
  631. my $suite_opts= shift;
  632. #print "collect_one_test_case\n";
  633. #print " suitedir: $suitedir\n";
  634. #print " testdir: $testdir\n";
  635. #print " resdir: $resdir\n";
  636. #print " suitename: $suitename\n";
  637. #print " tname: $tname\n";
  638. #print " filename: $filename\n";
  639. # ----------------------------------------------------------------------
  640. # Check --start-from
  641. # ----------------------------------------------------------------------
  642. if ( $start_from )
  643. {
  644. # start_from can be specified as [suite.].testname_prefix
  645. my ($suite, $test, $ext)= split_testname($start_from);
  646. if ( $suite and $suitename lt $suite){
  647. return; # Skip silently
  648. }
  649. if ( $tname lt $test ){
  650. return; # Skip silently
  651. }
  652. }
  653. # ----------------------------------------------------------------------
  654. # Set defaults
  655. # ----------------------------------------------------------------------
  656. my $tinfo= My::Test->new
  657. (
  658. name => "$suitename.$tname",
  659. shortname => $tname,
  660. path => "$testdir/$filename",
  661. );
  662. my $result_file= "$resdir/$tname.result";
  663. if (-f $result_file) {
  664. # Allow nonexistsing result file
  665. # in that case .test must issue "exit" otherwise test
  666. # should fail by default
  667. $tinfo->{result_file}= $result_file;
  668. }
  669. else {
  670. # No .result file exist
  671. # Remember the path where it should be
  672. # saved in case of --record
  673. $tinfo->{record_file}= $result_file;
  674. }
  675. # ----------------------------------------------------------------------
  676. # Skip some tests but include in list, just mark them as skipped
  677. # ----------------------------------------------------------------------
  678. if ( $skip_test_reg and $tname =~ /$skip_test_reg/o )
  679. {
  680. $tinfo->{'skip'}= 1;
  681. return $tinfo;
  682. }
  683. # ----------------------------------------------------------------------
  684. # Check for disabled tests
  685. # ----------------------------------------------------------------------
  686. my $marked_as_disabled= 0;
  687. if ( $disabled->{$tname} or $disabled->{"$suitename.$tname"} )
  688. {
  689. # Test was marked as disabled in suites disabled.def file
  690. $marked_as_disabled= 1;
  691. # Test name may have been disabled with or without suite name part
  692. $tinfo->{'comment'}= $disabled->{$tname} ||
  693. $disabled->{"$suitename.$tname"};
  694. }
  695. my $disabled_file= "$testdir/$tname.disabled";
  696. if ( -f $disabled_file )
  697. {
  698. $marked_as_disabled= 1;
  699. $tinfo->{'comment'}= mtr_fromfile($disabled_file);
  700. }
  701. if ( $marked_as_disabled )
  702. {
  703. if ( $enable_disabled )
  704. {
  705. # User has selected to run all disabled tests
  706. mtr_report(" - $tinfo->{name} wil be run although it's been disabled\n",
  707. " due to '$tinfo->{comment}'");
  708. }
  709. else
  710. {
  711. $tinfo->{'skip'}= 1;
  712. $tinfo->{'disable'}= 1; # Sub type of 'skip'
  713. return $tinfo;
  714. }
  715. }
  716. # ----------------------------------------------------------------------
  717. # Append suite extra options to both master and slave
  718. # ----------------------------------------------------------------------
  719. push(@{$tinfo->{'master_opt'}}, @$suite_opts);
  720. push(@{$tinfo->{'slave_opt'}}, @$suite_opts);
  721. #-----------------------------------------------------------------------
  722. # Check for test specific config file
  723. #-----------------------------------------------------------------------
  724. my $test_cnf_file= "$testdir/$tname.cnf";
  725. if ( -f $test_cnf_file) {
  726. # Specifies the configuration file to use for this test
  727. $tinfo->{'template_path'}= $test_cnf_file;
  728. }
  729. # ----------------------------------------------------------------------
  730. # Check for test specific config file
  731. # ----------------------------------------------------------------------
  732. my $test_cnf_file= "$testdir/$tname.cnf";
  733. if ( -f $test_cnf_file ) {
  734. # Specifies the configuration file to use for this test
  735. $tinfo->{'template_path'}= $test_cnf_file;
  736. }
  737. # ----------------------------------------------------------------------
  738. # master sh
  739. # ----------------------------------------------------------------------
  740. my $master_sh= "$testdir/$tname-master.sh";
  741. if ( -f $master_sh )
  742. {
  743. if ( IS_WIN32PERL )
  744. {
  745. $tinfo->{'skip'}= 1;
  746. $tinfo->{'comment'}= "No tests with sh scripts on Windows";
  747. return $tinfo;
  748. }
  749. else
  750. {
  751. $tinfo->{'master_sh'}= $master_sh;
  752. }
  753. }
  754. # ----------------------------------------------------------------------
  755. # slave sh
  756. # ----------------------------------------------------------------------
  757. my $slave_sh= "$testdir/$tname-slave.sh";
  758. if ( -f $slave_sh )
  759. {
  760. if ( IS_WIN32PERL )
  761. {
  762. $tinfo->{'skip'}= 1;
  763. $tinfo->{'comment'}= "No tests with sh scripts on Windows";
  764. return $tinfo;
  765. }
  766. else
  767. {
  768. $tinfo->{'slave_sh'}= $slave_sh;
  769. }
  770. }
  771. # ----------------------------------------------------------------------
  772. # <tname>.slave-mi
  773. # ----------------------------------------------------------------------
  774. mtr_error("$tname: slave-mi not supported anymore")
  775. if ( -f "$testdir/$tname.slave-mi");
  776. tags_from_test_file($tinfo,"$testdir/${tname}.test");
  777. if ( defined $default_storage_engine )
  778. {
  779. # Different default engine is used
  780. # tag test to require that engine
  781. $tinfo->{'ndb_test'}= 1
  782. if ( $default_storage_engine =~ /^ndb/i );
  783. $tinfo->{'innodb_test'}= 1
  784. if ( $default_storage_engine =~ /^innodb/i );
  785. }
  786. if ( $tinfo->{'big_test'} and ! $::opt_big_test )
  787. {
  788. $tinfo->{'skip'}= 1;
  789. $tinfo->{'comment'}= "Test needs 'big-test' option";
  790. return $tinfo
  791. }
  792. if ( $tinfo->{'need_debug'} && ! $::debug_compiled_binaries )
  793. {
  794. $tinfo->{'skip'}= 1;
  795. $tinfo->{'comment'}= "Test needs debug binaries";
  796. return $tinfo
  797. }
  798. if ( $tinfo->{'ndb_test'} )
  799. {
  800. # This is a NDB test
  801. if ( $::opt_skip_ndbcluster == 2 )
  802. {
  803. # Ndb is not supported, skip it
  804. $tinfo->{'skip'}= 1;
  805. $tinfo->{'comment'}= "No ndbcluster support or ndb tests not enabled";
  806. return $tinfo;
  807. }
  808. elsif ( $::opt_skip_ndbcluster )
  809. {
  810. # All ndb test's should be skipped
  811. $tinfo->{'skip'}= 1;
  812. $tinfo->{'comment'}= "No ndbcluster tests(--skip-ndbcluster)";
  813. return $tinfo;
  814. }
  815. }
  816. else
  817. {
  818. # This is not a ndb test
  819. if ( $opt_with_ndbcluster_only )
  820. {
  821. # Only the ndb test should be run, all other should be skipped
  822. $tinfo->{'skip'}= 1;
  823. $tinfo->{'comment'}= "Only ndbcluster tests";
  824. return $tinfo;
  825. }
  826. }
  827. if ($tinfo->{'federated_test'})
  828. {
  829. # This is a test that needs federated, enable it
  830. push(@{$tinfo->{'master_opt'}}, "--loose-federated");
  831. push(@{$tinfo->{'slave_opt'}}, "--loose-federated");
  832. }
  833. if ( $tinfo->{'innodb_test'} )
  834. {
  835. # This is a test that needs innodb
  836. if ( $::mysqld_variables{'innodb'} eq "OFF" ||
  837. ! exists $::mysqld_variables{'innodb'} )
  838. {
  839. # innodb is not supported, skip it
  840. $tinfo->{'skip'}= 1;
  841. # This comment is checked for running with innodb plugin (see above),
  842. # please keep that in mind if changing the text.
  843. $tinfo->{'comment'}= "No innodb support";
  844. # But continue processing if we may run it with innodb plugin
  845. return $tinfo unless $do_innodb_plugin;
  846. }
  847. }
  848. elsif ($default_myisam)
  849. {
  850. # This is a temporary fix to allow non-innodb tests to run even if
  851. # the default storage engine is innodb.
  852. push(@{$tinfo->{'master_opt'}}, "--default-storage-engine=MyISAM");
  853. push(@{$tinfo->{'slave_opt'}}, "--default-storage-engine=MyISAM");
  854. }
  855. if ( $tinfo->{'need_binlog'} )
  856. {
  857. if (grep(/^--skip-log-bin/, @::opt_extra_mysqld_opt) )
  858. {
  859. $tinfo->{'skip'}= 1;
  860. $tinfo->{'comment'}= "Test needs binlog";
  861. return $tinfo;
  862. }
  863. }
  864. else
  865. {
  866. # Test does not need binlog, add --skip-binlog to
  867. # the options used when starting
  868. push(@{$tinfo->{'master_opt'}}, "--loose-skip-log-bin");
  869. push(@{$tinfo->{'slave_opt'}}, "--loose-skip-log-bin");
  870. }
  871. if ( $tinfo->{'rpl_test'} )
  872. {
  873. if ( $skip_rpl )
  874. {
  875. $tinfo->{'skip'}= 1;
  876. $tinfo->{'comment'}= "No replication tests(--skip-rpl)";
  877. return $tinfo;
  878. }
  879. }
  880. if ( $::opt_embedded_server )
  881. {
  882. if ( $tinfo->{'not_embedded'} )
  883. {
  884. $tinfo->{'skip'}= 1;
  885. $tinfo->{'comment'}= "Not run for embedded server";
  886. return $tinfo;
  887. }
  888. }
  889. if ( $tinfo->{'need_ssl'} )
  890. {
  891. # This is a test that needs ssl
  892. if ( ! $::opt_ssl_supported ) {
  893. # SSL is not supported, skip it
  894. $tinfo->{'skip'}= 1;
  895. $tinfo->{'comment'}= "No SSL support";
  896. return $tinfo;
  897. }
  898. }
  899. # ----------------------------------------------------------------------
  900. # Find config file to use if not already selected in <testname>.opt file
  901. # ----------------------------------------------------------------------
  902. if (defined $defaults_file) {
  903. # Using same config file for all tests
  904. $tinfo->{template_path}= $defaults_file;
  905. }
  906. elsif (! $tinfo->{template_path} )
  907. {
  908. my $config= "$suitedir/my.cnf";
  909. if (! -f $config )
  910. {
  911. # assume default.cnf will be used
  912. $config= "include/default_my.cnf";
  913. # Suite has no config, autodetect which one to use
  914. if ( $tinfo->{rpl_test} ){
  915. $config= "suite/rpl/my.cnf";
  916. if ( $tinfo->{ndb_test} ){
  917. $config= "suite/rpl_ndb/my.cnf";
  918. }
  919. }
  920. elsif ( $tinfo->{ndb_test} ){
  921. $config= "suite/ndb/my.cnf";
  922. }
  923. }
  924. $tinfo->{template_path}= $config;
  925. }
  926. # Set extra config file to use
  927. if (defined $defaults_extra_file) {
  928. $tinfo->{extra_template_path}= $defaults_extra_file;
  929. }
  930. # ----------------------------------------------------------------------
  931. # Append mysqld extra options to both master and slave
  932. # ----------------------------------------------------------------------
  933. push(@{$tinfo->{'master_opt'}}, @::opt_extra_mysqld_opt);
  934. push(@{$tinfo->{'slave_opt'}}, @::opt_extra_mysqld_opt);
  935. # ----------------------------------------------------------------------
  936. # Add master opts, extra options only for master
  937. # ----------------------------------------------------------------------
  938. process_opts_file($tinfo, "$testdir/$tname-master.opt", 'master_opt');
  939. # ----------------------------------------------------------------------
  940. # Add slave opts, list of extra option only for slave
  941. # ----------------------------------------------------------------------
  942. process_opts_file($tinfo, "$testdir/$tname-slave.opt", 'slave_opt');
  943. return $tinfo;
  944. }
  945. # List of tags in the .test files that if found should set
  946. # the specified value in "tinfo"
  947. my @tags=
  948. (
  949. ["include/have_binlog_format_row.inc", "binlog_formats", ["row"]],
  950. ["include/have_binlog_format_statement.inc", "binlog_formats", ["statement"]],
  951. ["include/have_binlog_format_mixed.inc", "binlog_formats", ["mixed"]],
  952. ["include/have_binlog_format_mixed_or_row.inc",
  953. "binlog_formats", ["mixed", "row"]],
  954. ["include/have_binlog_format_mixed_or_statement.inc",
  955. "binlog_formats", ["mixed", "statement"]],
  956. ["include/have_binlog_format_row_or_statement.inc",
  957. "binlog_formats", ["row", "statement"]],
  958. ["include/have_log_bin.inc", "need_binlog", 1],
  959. ["include/have_innodb.inc", "innodb_test", 1],
  960. ["include/big_test.inc", "big_test", 1],
  961. ["include/have_debug.inc", "need_debug", 1],
  962. ["include/have_ndb.inc", "ndb_test", 1],
  963. ["include/have_multi_ndb.inc", "ndb_test", 1],
  964. ["include/master-slave.inc", "rpl_test", 1],
  965. ["include/ndb_master-slave.inc", "rpl_test", 1],
  966. ["include/ndb_master-slave.inc", "ndb_test", 1],
  967. ["federated.inc", "federated_test", 1],
  968. ["include/not_embedded.inc", "not_embedded", 1],
  969. ["include/have_ssl.inc", "need_ssl", 1],
  970. );
  971. sub tags_from_test_file {
  972. my $tinfo= shift;
  973. my $file= shift;
  974. #mtr_verbose("$file");
  975. my $F= IO::File->new($file) or mtr_error("can't open file \"$file\": $!");
  976. while ( my $line= <$F> )
  977. {
  978. # Skip line if it start's with #
  979. next if ( $line =~ /^#/ );
  980. # Match this line against tag in "tags" array
  981. foreach my $tag (@tags)
  982. {
  983. if ( index($line, $tag->[0]) >= 0 )
  984. {
  985. # Tag matched, assign value to "tinfo"
  986. $tinfo->{"$tag->[1]"}= $tag->[2];
  987. }
  988. }
  989. # If test sources another file, open it as well
  990. if ( $line =~ /^\-\-([[:space:]]*)source(.*)$/ or
  991. $line =~ /^([[:space:]]*)source(.*);$/ )
  992. {
  993. my $value= $2;
  994. $value =~ s/^\s+//; # Remove leading space
  995. $value =~ s/[[:space:]]+$//; # Remove ending space
  996. # Sourced file may exist relative to test or
  997. # in global location
  998. foreach my $sourced_file (dirname($file). "/$value",
  999. "$::glob_mysql_test_dir/$value")
  1000. {
  1001. if ( -f $sourced_file )
  1002. {
  1003. # Only source the file if it exists, we may get
  1004. # false positives in the regexes above if someone
  1005. # writes "source nnnn;" in a test case(such as mysqltest.test)
  1006. tags_from_test_file($tinfo, $sourced_file);
  1007. last;
  1008. }
  1009. }
  1010. }
  1011. }
  1012. }
  1013. sub unspace {
  1014. my $string= shift;
  1015. my $quote= shift;
  1016. $string =~ s/[ \t]/\x11/g;
  1017. return "$quote$string$quote";
  1018. }
  1019. sub opts_from_file ($) {
  1020. my $file= shift;
  1021. open(FILE,"<",$file) or mtr_error("can't open file \"$file\": $!");
  1022. my @args;
  1023. while ( <FILE> )
  1024. {
  1025. chomp;
  1026. # --init_connect=set @a='a\\0c'
  1027. s/^\s+//; # Remove leading space
  1028. s/\s+$//; # Remove ending space
  1029. # This is strange, but we need to fill whitespace inside
  1030. # quotes with something, to remove later. We do this to
  1031. # be able to split on space. Else, we have trouble with
  1032. # options like
  1033. #
  1034. # --someopt="--insideopt1 --insideopt2"
  1035. #
  1036. # But still with this, we are not 100% sure it is right,
  1037. # we need a shell to do it right.
  1038. s/\'([^\'\"]*)\'/unspace($1,"\x0a")/ge;
  1039. s/\"([^\'\"]*)\"/unspace($1,"\x0b")/ge;
  1040. s/\'([^\'\"]*)\'/unspace($1,"\x0a")/ge;
  1041. s/\"([^\'\"]*)\"/unspace($1,"\x0b")/ge;
  1042. foreach my $arg (split(/[ \t]+/))
  1043. {
  1044. $arg =~ tr/\x11\x0a\x0b/ \'\"/; # Put back real chars
  1045. # The outermost quotes has to go
  1046. $arg =~ s/^([^\'\"]*)\'(.*)\'([^\'\"]*)$/$1$2$3/
  1047. or $arg =~ s/^([^\'\"]*)\"(.*)\"([^\'\"]*)$/$1$2$3/;
  1048. $arg =~ s/\\\\/\\/g;
  1049. # Do not pass empty string since my_getopt is not capable to handle it.
  1050. if (length($arg)) {
  1051. push(@args, $arg);
  1052. }
  1053. }
  1054. }
  1055. close FILE;
  1056. return \@args;
  1057. }
  1058. sub print_testcases {
  1059. my (@cases)= @_;
  1060. print "=" x 60, "\n";
  1061. foreach my $test (@cases){
  1062. $test->print_test();
  1063. }
  1064. print "=" x 60, "\n";
  1065. }
  1066. 1;