1
/* Copyright (C) 2000-2003 MySQL AB
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
#ifndef ERROR_INJECT_SUPPORT
20
* Simple compile-time error injection module to enable easy
21
* error printing in case of a crash
23
#ifndef DRIZZLE_SERVER_ERROR_INJECTION_H
24
#define DRIZZLE_SERVER_ERROR_INJECTION_H
27
Error injector Macros to enable easy testing of recovery after failures
28
in various error cases.
30
#define ERROR_INJECT(x) 0
31
#define ERROR_INJECT_ACTION(x,action) 0
32
#define ERROR_INJECT_CRASH(x) 0
33
#define ERROR_INJECT_VALUE(x) 0
34
#define ERROR_INJECT_VALUE_ACTION(x,action) 0
35
#define ERROR_INJECT_VALUE_CRASH(x) 0
36
#define SET_ERROR_INJECT_VALUE(x)
40
inline bool check_and_unset_keyword(const char *dbug_str)
42
const char *extra_str= "-d,";
44
if (_db_strict_keyword_ (dbug_str))
46
strxmov(total_str, extra_str, dbug_str, NullS);
54
check_and_unset_inject_value(int value)
56
THD *thd= current_thd;
57
if (thd->error_inject_value == (uint)value)
59
thd->error_inject_value= 0;
68
These macros are used to insert macros from the application code.
69
The event that activates those error injections can be activated
71
SET SESSION dbug=+d,code;
73
After the error has been injected, the macros will automatically
74
remove the debug code, thus similar to using:
75
SET SESSION dbug=-d,code
78
ERROR_INJECT_CRASH will inject a crash of the MySQL Server if code
79
is set when macro is called. ERROR_INJECT_CRASH can be used in
80
if-statements, it will always return false unless of course it
81
crashes in which case it doesn't return at all.
83
ERROR_INJECT_ACTION will inject the action specified in the action
84
parameter of the macro, before performing the action the code will
85
be removed such that no more events occur. ERROR_INJECT_ACTION
86
can also be used in if-statements and always returns FALSE.
87
ERROR_INJECT can be used in a normal if-statement, where the action
88
part is performed in the if-block. The macro returns TRUE if the
89
error was activated and otherwise returns FALSE. If activated the
92
Sometimes it is necessary to perform error inject actions as a serie
93
of events. In this case one can use one variable on the THD object.
94
Thus one sets this value by using e.g. SET_ERROR_INJECT_VALUE(100).
95
Then one can later test for it by using ERROR_INJECT_CRASH_VALUE,
96
ERROR_INJECT_ACTION_VALUE and ERROR_INJECT_VALUE. This have the same
97
behaviour as the above described macros except that they use the
98
error inject value instead of a code used by debug macros.
100
#define SET_ERROR_INJECT_VALUE(x) \
101
current_thd->error_inject_value= (x)
102
#define ERROR_INJECT_ACTION(code, action) \
103
(check_and_unset_keyword(code) ? ((action), 0) : 0)
104
#define ERROR_INJECT(code) \
105
check_and_unset_keyword(code)
106
#define ERROR_INJECT_VALUE(value) \
107
check_and_unset_inject_value(value)
108
#define ERROR_INJECT_VALUE_ACTION(value,action) \
109
(check_and_unset_inject_value(value) ? (action) : 0)
110
#define ERROR_INJECT_VALUE_CRASH(value) \
111
ERROR_INJECT_VALUE_ACTION(value, (abort(), 0))
113
#endif /* DRIZZLE_SERVER_ERROR_INJECTION_H */
114
#endif /* ERROR_INJECT_SUPPORT */