2 # Simple search with Perl for a pattern in some file.
4 # The advantages compared to thinkable auxiliary constructs using the
5 # mysqltest language and SQL are:
6 # 1. We do not need a running MySQL server.
7 # 2. SQL causes "noise" during debugging and increases the size of logs.
8 # Perl code does not disturb at all.
10 # The environment variables SEARCH_FILE and SEARCH_PATTERN must be set
11 # before sourcing this routine.
14 # - SEARCH_FILE and/or SEARCH_PATTERN is not set
15 # - SEARCH_FILE cannot be opened
16 # - SEARCH_FILE does not contain SEARCH_PATTERN
17 # the test will abort immediate.
18 # MTR will report something like
20 # worker[1] Using MTR_BUILD_THREAD 300, with reserved ports 13000..13009
22 # innodb.innodb_page_size [ fail ]
23 # Test ended at 2011-11-11 18:15:58
25 # CURRENT_TEST: innodb.innodb_page_size
26 # # ERROR: The file '<name>' does not contain the expected pattern <pattern>
27 # mysqltest: In included file "./include/search_pattern_in_file.inc":
28 # included from ./include/search_pattern_in_file.inc at line 36:
29 # At line 25: command "perl" failed with error 255. my_errno=175
31 # The result from queries just before the failure was:
33 # - saving '<some path>' to '<some path>'
36 # Typical use case (check invalid server startup options):
37 # let $error_log= $MYSQLTEST_VARDIR/log/my_restart.err;
39 # --remove_file $error_log
40 # let SEARCH_FILE= $error_log;
42 # let $restart_file= $MYSQLTEST_VARDIR/tmp/mysqld.1.expect;
43 # --exec echo "wait" > $restart_file
44 # --shutdown_server 10
45 # --source include/wait_until_disconnected.inc
48 # --exec $MYSQLD_CMD <whatever wrong setting> > $error_log 2>&1
49 # # The server restart aborts
50 # let SEARCH_PATTERN= \[ERROR\] Aborting;
51 # --source include/search_pattern_in_file.inc
53 # Created: 2011-11-11 mleich
58 my $search_file= $ENV{'SEARCH_FILE'} or die "SEARCH_FILE not set";
59 my $search_pattern= $ENV{'SEARCH_PATTERN'} or die "SEARCH_PATTERN not set";
60 open(FILE, "$search_file") or die("Unable to open '$search_file': $!\n");
61 read(FILE, my $file_content, 50000, 0);
63 if ( not $file_content =~ m{$search_pattern} ) {
64 die("# ERROR: The file '$search_file' does not contain the expected pattern $search_pattern\n->$file_content<-\n");