MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dbug-t.cc
1 /* Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
2 
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License as published by
5  the Free Software Foundation; version 2 of the License.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software
14  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
15 
16 // First include (the generated) my_config.h, to get correct platform defines.
17 #include "my_config.h"
18 #include <gtest/gtest.h>
19 
20 #include "thread_utils.h"
21 
22 #include "my_global.h"
23 #include "my_dbug.h"
24 
26 using thread::Thread;
27 
28 namespace dbug_unittest {
29 
30 #if defined(DBUG_OFF)
31 TEST(DebugTest, NoSuicide)
32 {
33  DBUG_SUICIDE();
34 }
35 #else
36 TEST(DebugDeathTest, Suicide)
37 {
38  ::testing::FLAGS_gtest_death_test_style = "threadsafe";
39  EXPECT_DEATH_IF_SUPPORTED(DBUG_SUICIDE(), "");
40 }
41 #endif
42 
43 
44 #if !defined(DBUG_OFF) && !defined(__WIN__)
45 class DbugGcovThread : public Thread
46 {
47 public:
48  DbugGcovThread(Notification *start_notification)
49  : m_start_notification(start_notification)
50  {}
51 
52  virtual void run()
53  {
54  m_start_notification->notify();
55  _db_flush_gcov_();
56  }
57 
58 private:
59  Notification *m_start_notification;
60 };
61 
62 
63 TEST(DebugFlushGcov, FlushGcovParallel)
64 {
65  Notification start_notification;
66  DbugGcovThread debug_thread(&start_notification);
67  debug_thread.start();
68 
69  // Wait for the other thread to start, then flush in parallel.
70  start_notification.wait_for_notification();
71  _db_flush_gcov_();
72  debug_thread.join();
73 }
74 #endif
75 
76 
77 #if !defined(DBUG_OFF)
78 TEST(DebugPrintTest, PrintEval)
79 {
80  int y= 0;
81 
82  // This DBUG_PRINT args should never be evaluated.
83  DBUG_PRINT("never",("%d",1/y));
84 }
85 
86 
87 TEST(DebugPrintDeathTest, PrintEval)
88 {
89  int y= 0;
90 
91  ::testing::FLAGS_gtest_death_test_style = "threadsafe";
92 
93  DBUG_SET("+d,never");
94  /*
95  The DBUG_PRINT would be evaluated resulting in floating point exception
96  killing the server.
97  */
98  EXPECT_DEATH_IF_SUPPORTED(DBUG_PRINT("never",("%d",1/y)), "");
99  DBUG_SET("");
100 }
101 
102 
103 TEST(DebugSetTest, DebugKeywordsTest)
104 {
105  char buf[1024];
106 
107  /*
108  Enable d flag, then enable debug on a keyword. The debug should
109  remain set to d and empty list of keywords indicating debug is
110  enabled for all.
111  */
112  DBUG_SET("d");
113  DBUG_SET("+d,keyword");
114  DBUG_EXPLAIN(buf, sizeof(buf));
115  EXPECT_STREQ("d", buf);
116  DBUG_SET("");
117 
118  /*
119  Set debug on a specific keyword. Debug should be enabled
120  for the keyword.
121  */
122  DBUG_SET("+d,keyword");
123  DBUG_EXPLAIN(buf, sizeof(buf));
124  EXPECT_STREQ("d,keyword", buf);
125 
126  /*
127  Remove the keyword from debug list. Debug should be
128  disabled.
129  */
130  DBUG_SET("-d,keyword");
131  DBUG_EXPLAIN(buf, sizeof(buf));
132  EXPECT_STREQ("",buf);
133  DBUG_SET("");
134 
135  /*
136  Enable debug for a keyword. Then enable debug for all
137  keywords. Debug should now be enabled for all keywords.
138  */
139  DBUG_SET("+d,keyword");
140  DBUG_SET("+d");
141  DBUG_EXPLAIN(buf,sizeof(buf));
142  EXPECT_STREQ("d",buf);
143  DBUG_SET("");
144 
145  // Add multiple debug keywords.
146  DBUG_SET("+d,keyword1");
147  DBUG_SET("+d,keyword2");
148  DBUG_EXPLAIN(buf,sizeof(buf));
149  EXPECT_STREQ("d,keyword1,keyword2",buf);
150  DBUG_SET("-d,keyword1");
151  DBUG_EXPLAIN(buf,sizeof(buf));
152  EXPECT_STREQ("d,keyword2",buf);
153  DBUG_SET("-d,keyword2");
154  DBUG_EXPLAIN(buf,sizeof(buf));
155  EXPECT_STREQ("",buf);
156  DBUG_SET("");
157 }
158 #endif /* DBUG_OFF */
159 }