-
Notifications
You must be signed in to change notification settings - Fork 4k
/
Copy pathtest_mysql_runtime_error.cc
149 lines (133 loc) · 5.98 KB
/
test_mysql_runtime_error.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/* Copyright (c) 2018, 2023, Oracle and/or its affiliates.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
as published by the Free Software Foundation.
This program is also distributed with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have included with MySQL.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License, version 2.0, for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
#include <assert.h>
#include <mysql/components/component_implementation.h>
#include <mysql/components/services/udf_registration.h>
#include <mysqld_error.h>
#include <stdio.h>
namespace mysql_runtime_error { // To avoid ODR asan error
#include <mysql/components/services/mysql_runtime_error_service.h>
REQUIRES_SERVICE_PLACEHOLDER(mysql_runtime_error);
REQUIRES_SERVICE_PLACEHOLDER(udf_registration);
BEGIN_COMPONENT_PROVIDES(test_mysql_runtime_error)
END_COMPONENT_PROVIDES();
BEGIN_COMPONENT_REQUIRES(test_mysql_runtime_error)
REQUIRES_SERVICE(mysql_runtime_error), REQUIRES_SERVICE(udf_registration),
END_COMPONENT_REQUIRES();
static long long test_mysql_runtime_error_udf(UDF_INIT *, UDF_ARGS *args,
unsigned char *,
unsigned char *error) {
if (args->arg_count > 0 && args->arg_type[0] == INT_RESULT) {
switch (*(reinterpret_cast<long long *>(args->args[0]))) {
case 0:
/* Checking mysql_runtime_error service through utility api */
mysql_error_service_emit_printf(
mysql_service_mysql_runtime_error, ER_COMPONENTS_UNLOAD_NOT_LOADED,
0,
"This is to test the mysql_runtime_error service"
" using utility function");
break;
case 1:
/* Checking mysql_runtime_error service, similar signature as my_error
api. This need REQUIRES_SERVICE_PLACEHOLDER(mysql_runtime_error)
definition. */
mysql_error_service_printf(
ER_COMPONENTS_UNLOAD_NOT_LOADED, 0,
"This is to test the mysql_runtime_error service");
break;
case 3:
/* Checking mysql_runtime_error service through utility api */
mysql_error_service_emit_printf(
mysql_service_mysql_runtime_error,
ER_COMPONENTS_UNLOAD_CANT_UNREGISTER_SERVICE, 0,
"This is to test the mysql_runtime_error service",
" using utility function");
break;
case 4:
/* Checking mysql_runtime_error service through utility api */
mysql_error_service_emit_printf(mysql_service_mysql_runtime_error,
ER_INVALID_THREAD_PRIORITY, 0, 123,
"Test", "Test group", 0, 99);
break;
case 5:
/* Checking mysql_runtime_error service through utility api */
mysql_error_service_emit_printf(mysql_service_mysql_runtime_error,
ER_REGEXP_TIME_OUT, 0);
break;
case 6:
/* Checking mysql_runtime_error service through utility api */
mysql_error_service_emit_printf(mysql_service_mysql_runtime_error,
ER_TOO_LONG_KEY, 0, 1024);
break;
case 7:
/* Checking mysql_runtime_error service through utility api */
mysql_error_service_printf(
ER_COMPONENTS_UNLOAD_CANT_UNREGISTER_SERVICE, 0,
"This is to test the mysql_runtime_error service",
" using utility function");
break;
case 8:
/* Checking mysql_runtime_error service through utility api */
mysql_error_service_printf(ER_INVALID_THREAD_PRIORITY, 0, 123, "Test",
"Test group", 0, 99);
break;
case 9:
/* Checking mysql_runtime_error service through utility api */
mysql_error_service_printf(ER_REGEXP_TIME_OUT, 0);
break;
case 10:
/* Checking mysql_runtime_error service through utility api */
mysql_error_service_printf(ER_TOO_LONG_KEY, 0, 1024);
break;
case 2:
/* default mysql_runtime_error service, This can be checked with
minimal_chassis work log(wl#11080) */
break;
}
} else
*error = 1;
return 0;
}
static mysql_service_status_t init() {
if (mysql_service_udf_registration->udf_register(
"test_mysql_runtime_error", INT_RESULT,
reinterpret_cast<Udf_func_any>(test_mysql_runtime_error_udf), nullptr,
nullptr)) {
fprintf(stderr, "Can't register the test_mysql_runtime_error UDF\n");
return 1;
}
return 0;
}
static mysql_service_status_t deinit() {
int was_present = 0;
if (mysql_service_udf_registration->udf_unregister("test_mysql_runtime_error",
&was_present)) {
fprintf(stderr, "Can't unregister the test_mysql_runtime_error UDF\n");
return 1;
}
return 0; /* success */
}
BEGIN_COMPONENT_METADATA(test_mysql_runtime_error)
METADATA("mysql.author", "Oracle Corporation"),
METADATA("mysql.license", "GPL"), METADATA("test_property", "1"),
END_COMPONENT_METADATA();
DECLARE_COMPONENT(test_mysql_runtime_error, "mysql:test_mysql_runtime_error")
init, deinit END_DECLARE_COMPONENT();
DECLARE_LIBRARY_COMPONENTS &COMPONENT_REF(test_mysql_runtime_error)
END_DECLARE_LIBRARY_COMPONENTS
} // namespace mysql_runtime_error