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.

1267 lines
35 KiB

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