MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
search_pattern_in_file.inc
1 # Purpose:
2 # Simple search with Perl for a pattern in some file.
3 #
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.
9 #
10 # The environment variables SEARCH_FILE and SEARCH_PATTERN must be set
11 # before sourcing this routine.
12 #
13 # In case of
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
19 # ....
20 # worker[1] Using MTR_BUILD_THREAD 300, with reserved ports 13000..13009
21 # main.1st [ pass ] 3
22 # innodb.innodb_page_size [ fail ]
23 # Test ended at 2011-11-11 18:15:58
24 #
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
30 #
31 # The result from queries just before the failure was:
32 # ...
33 # - saving '<some path>' to '<some path>'
34 # main.1st [ pass ] 2
35 #
36 # Typical use case (check invalid server startup options):
37 # let $error_log= $MYSQLTEST_VARDIR/log/my_restart.err;
38 # --error 0,1
39 # --remove_file $error_log
40 # let SEARCH_FILE= $error_log;
41 # # Stop the server
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
46 #
47 # --error 1
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
52 #
53 # Created: 2011-11-11 mleich
54 #
55 
56 perl;
57  use strict;
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);
62  close(FILE);
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");
65  }
66 EOF