1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
#ifndef ERROR_INJECT_SUPPORT
24
* Simple compile-time error injection module to enable easy
25
* error printing in case of a crash
27
#ifndef DRIZZLE_SERVER_ERROR_INJECTION_H
28
#define DRIZZLE_SERVER_ERROR_INJECTION_H
31
Error injector Macros to enable easy testing of recovery after failures
32
in various error cases.
34
#define ERROR_INJECT(x) 0
35
#define ERROR_INJECT_ACTION(x,action) 0
36
#define ERROR_INJECT_CRASH(x) 0
37
#define ERROR_INJECT_VALUE(x) 0
38
#define ERROR_INJECT_VALUE_ACTION(x,action) 0
39
#define ERROR_INJECT_VALUE_CRASH(x) 0
40
#define SET_ERROR_INJECT_VALUE(x)
44
inline bool check_and_unset_keyword(const char *dbug_str)
46
const char *extra_str= "-d,";
48
if (_db_strict_keyword_ (dbug_str))
50
strxmov(total_str, extra_str, dbug_str, NULL);
58
check_and_unset_inject_value(int value)
60
THD *thd= current_thd;
61
if (thd->error_inject_value == (uint)value)
63
thd->error_inject_value= 0;
72
These macros are used to insert macros from the application code.
73
The event that activates those error injections can be activated
75
SET SESSION dbug=+d,code;
77
After the error has been injected, the macros will automatically
78
remove the debug code, thus similar to using:
79
SET SESSION dbug=-d,code
82
ERROR_INJECT_CRASH will inject a crash of the MySQL Server if code
83
is set when macro is called. ERROR_INJECT_CRASH can be used in
84
if-statements, it will always return false unless of course it
85
crashes in which case it doesn't return at all.
87
ERROR_INJECT_ACTION will inject the action specified in the action
88
parameter of the macro, before performing the action the code will
89
be removed such that no more events occur. ERROR_INJECT_ACTION
90
can also be used in if-statements and always returns FALSE.
91
ERROR_INJECT can be used in a normal if-statement, where the action
92
part is performed in the if-block. The macro returns TRUE if the
93
error was activated and otherwise returns FALSE. If activated the
96
Sometimes it is necessary to perform error inject actions as a serie
97
of events. In this case one can use one variable on the THD object.
98
Thus one sets this value by using e.g. SET_ERROR_INJECT_VALUE(100).
99
Then one can later test for it by using ERROR_INJECT_CRASH_VALUE,
100
ERROR_INJECT_ACTION_VALUE and ERROR_INJECT_VALUE. This have the same
101
behaviour as the above described macros except that they use the
102
error inject value instead of a code used by debug macros.
104
#define SET_ERROR_INJECT_VALUE(x) \
105
current_thd->error_inject_value= (x)
106
#define ERROR_INJECT_ACTION(code, action) \
107
(check_and_unset_keyword(code) ? ((action), 0) : 0)
108
#define ERROR_INJECT(code) \
109
check_and_unset_keyword(code)
110
#define ERROR_INJECT_VALUE(value) \
111
check_and_unset_inject_value(value)
112
#define ERROR_INJECT_VALUE_ACTION(value,action) \
113
(check_and_unset_inject_value(value) ? (action) : 0)
114
#define ERROR_INJECT_VALUE_CRASH(value) \
115
ERROR_INJECT_VALUE_ACTION(value, (abort(), 0))
117
#endif /* DRIZZLE_SERVER_ERROR_INJECTION_H */
118
#endif /* ERROR_INJECT_SUPPORT */