1if ($log_expected_matches) {
2  --echo [log_grep.inc] file: $log_file pattern: $grep_pattern expected_matches: $log_expected_matches
3}
4if (!$log_expected_matches) {
5  --echo [log_grep.inc] file: $log_file pattern: $grep_pattern
6}
7--let LOG_GREP_PERL_RESULT=$MYSQL_TMP_DIR/log_grep_perl_result.test
8perl;
9
10  open my $command_file, ">", "$ENV{'LOG_GREP_PERL_RESULT'}" or die "Cannot create file";
11
12  $log_file=           $ENV{'log_file'};
13  $log_file_full_path= $ENV{'log_file_full_path'};
14  $log_slow_rate_test= $ENV{'log_slow_rate_test'};
15  open(FILE, "$log_file_full_path")
16    or die("Cannot open file $log_file_full_path: $!\n");
17
18  if ($log_slow_rate_test) {
19    $one= 0;
20    $two= 0;
21    $three= 0;
22    while(<FILE>) {
23      $one++   if(/'connection_one'/);
24      $two++   if(/'connection_two'/);
25      $three++ if(/'connection_three'/);
26    }
27    $sum= $one + $two + $three;
28    $zero= 0;
29    if ($one == 0) {
30      $zero++;
31    }
32    if ($two == 0) {
33      $zero++;
34    }
35    if ($three == 0) {
36      $zero++;
37    }
38    print "[log_grep.inc] sum:  $sum\n";
39    print "[log_grep.inc] zero: $zero\n";
40  }
41  else {
42    $grep_pattern=       $ENV{'grep_pattern'};
43    $lines= 0;
44    while(<FILE>) {
45      $lines++ if (/$grep_pattern/);
46    }
47    $log_expected_matches= $ENV{'log_expected_matches'};
48    if ($log_expected_matches) {
49      if ($log_expected_matches != $lines) {
50        print "[log_grep.inc] ERROR: expected matches: $log_expected_matches, actual matches: $lines\n";
51        print "[log_grep.inc] log file at $log_file_full_path\n";
52        close(FILE);
53        open(FILE, "$log_file_full_path")
54          or die("Cannot open file $log_file_full_path: $!\n");
55        while (<FILE>) {
56          print ;
57        }
58        print $command_file "--let \$log_grep_failed= 1;\n";
59      } else {
60        print "[log_grep.inc] found expected match count: $log_expected_matches\n";
61      }
62    } else {
63      print "[log_grep.inc] lines:   $lines\n";
64    }
65  }
66  close(FILE);
67  close($command_file);
68EOF
69--source $LOG_GREP_PERL_RESULT
70--remove_file $LOG_GREP_PERL_RESULT
71if ($log_grep_failed)
72{
73  SHOW SESSION STATUS LIKE 'Slow_queries';
74  SHOW GLOBAL VARIABLES LIKE 'log%';
75  SHOW GLOBAL VARIABLES LIKE 'long_query_time';
76  SHOW GLOBAL VARIABLES LIKE 'min_examined_row_limit';
77  SHOW GLOBAL VARIABLES LIKE 'query_cache%';
78  SHOW GLOBAL VARIABLES LIKE 'slow_query%';
79  SHOW SESSION VARIABLES LIKE 'log%';
80  SHOW SESSION VARIABLES LIKE 'long_query_time';
81  SHOW SESSION VARIABLES LIKE 'min_examined_row_limit';
82  SHOW SESSION VARIABLES LIKE 'query_cache%';
83  SHOW SESSION VARIABLES LIKE 'slow_query%';
84  --die Testcase failed!
85}
86