1 | /* Copyright (c) 2008, 2017, 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 Foundation, |
14 | 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */ |
15 | |
16 | #include <my_global.h> |
17 | #include <my_pthread.h> |
18 | #include <pfs_server.h> |
19 | #include <pfs_instr_class.h> |
20 | #include <pfs_instr.h> |
21 | #include <pfs_global.h> |
22 | #include <tap.h> |
23 | |
24 | #include <string.h> |
25 | #include <memory.h> |
26 | |
27 | #include "stub_print_error.h" |
28 | #include "stub_pfs_defaults.h" |
29 | |
30 | void unload_performance_schema(); |
31 | |
32 | /* test helpers, to simulate the setup */ |
33 | |
34 | void setup_thread(PSI_thread *t, bool enabled) |
35 | { |
36 | PFS_thread *t2= (PFS_thread*) t; |
37 | t2->m_enabled= enabled; |
38 | } |
39 | |
40 | /* test helpers, to inspect data */ |
41 | |
42 | PFS_file* lookup_file_by_name(const char* name) |
43 | { |
44 | uint i; |
45 | PFS_file *pfs; |
46 | size_t len= strlen(name); |
47 | size_t dirlen; |
48 | const char *filename; |
49 | size_t filename_length;; |
50 | |
51 | for (i= 0; i < file_max; i++) |
52 | { |
53 | pfs= & file_array[i]; |
54 | if (pfs->m_lock.is_populated()) |
55 | { |
56 | /* |
57 | When a file "foo" is instrumented, the name is normalized |
58 | to "/path/to/current/directory/foo", so we remove the |
59 | directory name here to find it back. |
60 | */ |
61 | dirlen= dirname_length(pfs->m_filename); |
62 | filename= pfs->m_filename + dirlen; |
63 | filename_length= pfs->m_filename_length - dirlen; |
64 | if ((len == filename_length) && |
65 | (strncmp(name, filename, filename_length) == 0)) |
66 | return pfs; |
67 | } |
68 | } |
69 | |
70 | return NULL; |
71 | } |
72 | |
73 | /* tests */ |
74 | |
75 | void test_bootstrap() |
76 | { |
77 | void *psi; |
78 | void *psi_2; |
79 | PSI_bootstrap *boot; |
80 | PFS_global_param param; |
81 | |
82 | diag("test_bootstrap" ); |
83 | |
84 | memset(& param, 0xFF, sizeof(param)); |
85 | param.m_enabled= true; |
86 | param.m_mutex_class_sizing= 0; |
87 | param.m_rwlock_class_sizing= 0; |
88 | param.m_cond_class_sizing= 0; |
89 | param.m_thread_class_sizing= 0; |
90 | param.m_table_share_sizing= 0; |
91 | param.m_file_class_sizing= 0; |
92 | param.m_socket_class_sizing= 0; |
93 | param.m_mutex_sizing= 0; |
94 | param.m_rwlock_sizing= 0; |
95 | param.m_cond_sizing= 0; |
96 | param.m_thread_sizing= 0; |
97 | param.m_table_sizing= 0; |
98 | param.m_file_sizing= 0; |
99 | param.m_file_handle_sizing= 0; |
100 | param.m_socket_sizing= 0; |
101 | param.m_events_waits_history_sizing= 0; |
102 | param.m_events_waits_history_long_sizing= 0; |
103 | param.m_setup_actor_sizing= 0; |
104 | param.m_setup_object_sizing= 0; |
105 | param.m_user_sizing= 0; |
106 | param.m_account_sizing= 0; |
107 | param.m_host_sizing= 0; |
108 | param.m_stage_class_sizing= 0; |
109 | param.m_events_stages_history_sizing= 0; |
110 | param.m_events_stages_history_long_sizing= 0; |
111 | param.m_statement_class_sizing= 0; |
112 | param.m_events_statements_history_sizing= 0; |
113 | param.m_events_statements_history_long_sizing= 0; |
114 | param.m_digest_sizing= 0; |
115 | param.m_session_connect_attrs_sizing= 0; |
116 | param.m_max_digest_length= 0; |
117 | |
118 | boot= initialize_performance_schema(& param); |
119 | ok(boot != NULL, "boot" ); |
120 | ok(boot->get_interface != NULL, "boot->get_interface" ); |
121 | |
122 | psi= boot->get_interface(0); |
123 | ok(psi == NULL, "no version 0" ); |
124 | |
125 | psi= boot->get_interface(PSI_VERSION_1); |
126 | ok(psi != NULL, "version 1" ); |
127 | |
128 | psi_2= boot->get_interface(PSI_VERSION_2); |
129 | ok(psi_2 == NULL, "version 2" ); |
130 | |
131 | unload_performance_schema(); |
132 | } |
133 | |
134 | /* |
135 | Not a test, helper for testing pfs.cc |
136 | */ |
137 | PSI * load_perfschema() |
138 | { |
139 | void *psi; |
140 | PSI_bootstrap *boot; |
141 | PFS_global_param param; |
142 | |
143 | memset(& param, 0xFF, sizeof(param)); |
144 | param.m_enabled= true; |
145 | param.m_mutex_class_sizing= 10; |
146 | param.m_rwlock_class_sizing= 10; |
147 | param.m_cond_class_sizing= 10; |
148 | param.m_thread_class_sizing= 10; |
149 | param.m_table_share_sizing= 10; |
150 | param.m_file_class_sizing= 10; |
151 | param.m_socket_class_sizing= 10; |
152 | param.m_mutex_sizing= 10; |
153 | param.m_rwlock_sizing= 10; |
154 | param.m_cond_sizing= 10; |
155 | param.m_thread_sizing= 10; |
156 | param.m_table_sizing= 10; |
157 | param.m_file_sizing= 10; |
158 | param.m_file_handle_sizing= 50; |
159 | param.m_socket_sizing= 10; |
160 | param.m_events_waits_history_sizing= 10; |
161 | param.m_events_waits_history_long_sizing= 10; |
162 | param.m_setup_actor_sizing= 0; |
163 | param.m_setup_object_sizing= 0; |
164 | param.m_user_sizing= 0; |
165 | param.m_account_sizing= 0; |
166 | param.m_host_sizing= 0; |
167 | param.m_stage_class_sizing= 0; |
168 | param.m_events_stages_history_sizing= 0; |
169 | param.m_events_stages_history_long_sizing= 0; |
170 | param.m_statement_class_sizing= 0; |
171 | param.m_events_statements_history_sizing= 0; |
172 | param.m_events_statements_history_long_sizing= 0; |
173 | param.m_digest_sizing= 0; |
174 | param.m_session_connect_attrs_sizing= 0; |
175 | param.m_max_digest_length= 0; |
176 | |
177 | /* test_bootstrap() covered this, assuming it just works */ |
178 | boot= initialize_performance_schema(& param); |
179 | psi= boot->get_interface(PSI_VERSION_1); |
180 | |
181 | /* Reset every consumer to a known state */ |
182 | flag_global_instrumentation= true; |
183 | flag_thread_instrumentation= true; |
184 | |
185 | return (PSI*) psi; |
186 | } |
187 | |
188 | void unload_performance_schema() |
189 | { |
190 | cleanup_table_share(); |
191 | cleanup_instruments(); |
192 | cleanup_sync_class(); |
193 | cleanup_thread_class(); |
194 | cleanup_table_share(); |
195 | cleanup_file_class(); |
196 | cleanup_stage_class(); |
197 | cleanup_statement_class(); |
198 | cleanup_socket_class(); |
199 | cleanup_events_waits_history_long(); |
200 | cleanup_events_stages_history_long(); |
201 | cleanup_events_statements_history_long(); |
202 | cleanup_table_share_hash(); |
203 | cleanup_file_hash(); |
204 | cleanup_digest(); |
205 | |
206 | shutdown_performance_schema(); |
207 | } |
208 | |
209 | void test_bad_registration() |
210 | { |
211 | PSI *psi; |
212 | |
213 | diag("test_bad_registration" ); |
214 | |
215 | psi= load_perfschema(); |
216 | |
217 | /* |
218 | Test that length('wait/synch/mutex/' (17) + category + '/' (1)) < 32 |
219 | --> category can be up to 13 chars for a mutex. |
220 | */ |
221 | |
222 | PSI_mutex_key dummy_mutex_key= 9999; |
223 | PSI_mutex_info bad_mutex_1[]= |
224 | { |
225 | { & dummy_mutex_key, "X" , 0} |
226 | }; |
227 | |
228 | psi->register_mutex("/" , bad_mutex_1, 1); |
229 | ok(dummy_mutex_key == 0, "zero key" ); |
230 | dummy_mutex_key= 9999; |
231 | psi->register_mutex("a/" , bad_mutex_1, 1); |
232 | ok(dummy_mutex_key == 0, "zero key" ); |
233 | dummy_mutex_key= 9999; |
234 | psi->register_mutex("/b" , bad_mutex_1, 1); |
235 | ok(dummy_mutex_key == 0, "zero key" ); |
236 | dummy_mutex_key= 9999; |
237 | psi->register_mutex("a/b" , bad_mutex_1, 1); |
238 | ok(dummy_mutex_key == 0, "zero key" ); |
239 | dummy_mutex_key= 9999; |
240 | psi->register_mutex("12345678901234" , bad_mutex_1, 1); |
241 | ok(dummy_mutex_key == 0, "zero key" ); |
242 | dummy_mutex_key= 9999; |
243 | psi->register_mutex("1234567890123" , bad_mutex_1, 1); |
244 | ok(dummy_mutex_key == 1, "assigned key" ); |
245 | |
246 | /* |
247 | Test that length('wait/synch/mutex/' (17) + category + '/' (1) + name) <= 128 |
248 | --> category + name can be up to 110 chars for a mutex. |
249 | */ |
250 | |
251 | dummy_mutex_key= 9999; |
252 | PSI_mutex_info bad_mutex_2[]= |
253 | { |
254 | { & dummy_mutex_key, |
255 | /* 110 chars name */ |
256 | "12345678901234567890123456789012345678901234567890" |
257 | "12345678901234567890123456789012345678901234567890" |
258 | "1234567890" , |
259 | 0} |
260 | }; |
261 | |
262 | psi->register_mutex("X" , bad_mutex_2, 1); |
263 | ok(dummy_mutex_key == 0, "zero key" ); |
264 | |
265 | dummy_mutex_key= 9999; |
266 | PSI_mutex_info bad_mutex_3[]= |
267 | { |
268 | { & dummy_mutex_key, |
269 | /* 109 chars name */ |
270 | "12345678901234567890123456789012345678901234567890" |
271 | "12345678901234567890123456789012345678901234567890" |
272 | "123456789" , |
273 | 0} |
274 | }; |
275 | |
276 | psi->register_mutex("XX" , bad_mutex_3, 1); |
277 | ok(dummy_mutex_key == 0, "zero key" ); |
278 | |
279 | psi->register_mutex("X" , bad_mutex_3, 1); |
280 | ok(dummy_mutex_key == 2, "assigned key" ); |
281 | |
282 | /* |
283 | Test that length('wait/synch/rwlock/' (18) + category + '/' (1)) < 32 |
284 | --> category can be up to 12 chars for a rwlock. |
285 | */ |
286 | |
287 | PSI_rwlock_key dummy_rwlock_key= 9999; |
288 | PSI_rwlock_info bad_rwlock_1[]= |
289 | { |
290 | { & dummy_rwlock_key, "X" , 0} |
291 | }; |
292 | |
293 | psi->register_rwlock("/" , bad_rwlock_1, 1); |
294 | ok(dummy_rwlock_key == 0, "zero key" ); |
295 | dummy_rwlock_key= 9999; |
296 | psi->register_rwlock("a/" , bad_rwlock_1, 1); |
297 | ok(dummy_rwlock_key == 0, "zero key" ); |
298 | dummy_rwlock_key= 9999; |
299 | psi->register_rwlock("/b" , bad_rwlock_1, 1); |
300 | ok(dummy_rwlock_key == 0, "zero key" ); |
301 | dummy_rwlock_key= 9999; |
302 | psi->register_rwlock("a/b" , bad_rwlock_1, 1); |
303 | ok(dummy_rwlock_key == 0, "zero key" ); |
304 | dummy_rwlock_key= 9999; |
305 | psi->register_rwlock("1234567890123" , bad_rwlock_1, 1); |
306 | ok(dummy_rwlock_key == 0, "zero key" ); |
307 | dummy_rwlock_key= 9999; |
308 | psi->register_rwlock("123456789012" , bad_rwlock_1, 1); |
309 | ok(dummy_rwlock_key == 1, "assigned key" ); |
310 | |
311 | /* |
312 | Test that length('wait/synch/rwlock/' (18) + category + '/' (1) + name) <= 128 |
313 | --> category + name can be up to 109 chars for a rwlock. |
314 | */ |
315 | |
316 | dummy_rwlock_key= 9999; |
317 | PSI_rwlock_info bad_rwlock_2[]= |
318 | { |
319 | { & dummy_rwlock_key, |
320 | /* 109 chars name */ |
321 | "12345678901234567890123456789012345678901234567890" |
322 | "12345678901234567890123456789012345678901234567890" |
323 | "123456789" , |
324 | 0} |
325 | }; |
326 | |
327 | psi->register_rwlock("X" , bad_rwlock_2, 1); |
328 | ok(dummy_rwlock_key == 0, "zero key" ); |
329 | |
330 | dummy_rwlock_key= 9999; |
331 | PSI_rwlock_info bad_rwlock_3[]= |
332 | { |
333 | { & dummy_rwlock_key, |
334 | /* 108 chars name */ |
335 | "12345678901234567890123456789012345678901234567890" |
336 | "12345678901234567890123456789012345678901234567890" |
337 | "12345678" , |
338 | 0} |
339 | }; |
340 | |
341 | psi->register_rwlock("XX" , bad_rwlock_3, 1); |
342 | ok(dummy_rwlock_key == 0, "zero key" ); |
343 | |
344 | psi->register_rwlock("X" , bad_rwlock_3, 1); |
345 | ok(dummy_rwlock_key == 2, "assigned key" ); |
346 | |
347 | /* |
348 | Test that length('wait/synch/cond/' (16) + category + '/' (1)) < 32 |
349 | --> category can be up to 14 chars for a cond. |
350 | */ |
351 | |
352 | PSI_cond_key dummy_cond_key= 9999; |
353 | PSI_cond_info bad_cond_1[]= |
354 | { |
355 | { & dummy_cond_key, "X" , 0} |
356 | }; |
357 | |
358 | psi->register_cond("/" , bad_cond_1, 1); |
359 | ok(dummy_cond_key == 0, "zero key" ); |
360 | dummy_cond_key= 9999; |
361 | psi->register_cond("a/" , bad_cond_1, 1); |
362 | ok(dummy_cond_key == 0, "zero key" ); |
363 | dummy_cond_key= 9999; |
364 | psi->register_cond("/b" , bad_cond_1, 1); |
365 | ok(dummy_cond_key == 0, "zero key" ); |
366 | dummy_cond_key= 9999; |
367 | psi->register_cond("a/b" , bad_cond_1, 1); |
368 | ok(dummy_cond_key == 0, "zero key" ); |
369 | dummy_cond_key= 9999; |
370 | psi->register_cond("123456789012345" , bad_cond_1, 1); |
371 | ok(dummy_cond_key == 0, "zero key" ); |
372 | dummy_cond_key= 9999; |
373 | psi->register_cond("12345678901234" , bad_cond_1, 1); |
374 | ok(dummy_cond_key == 1, "assigned key" ); |
375 | |
376 | /* |
377 | Test that length('wait/synch/cond/' (16) + category + '/' (1) + name) <= 128 |
378 | --> category + name can be up to 111 chars for a cond. |
379 | */ |
380 | |
381 | dummy_cond_key= 9999; |
382 | PSI_cond_info bad_cond_2[]= |
383 | { |
384 | { & dummy_cond_key, |
385 | /* 111 chars name */ |
386 | "12345678901234567890123456789012345678901234567890" |
387 | "12345678901234567890123456789012345678901234567890" |
388 | "12345678901" , |
389 | 0} |
390 | }; |
391 | |
392 | psi->register_cond("X" , bad_cond_2, 1); |
393 | ok(dummy_cond_key == 0, "zero key" ); |
394 | |
395 | dummy_cond_key= 9999; |
396 | PSI_cond_info bad_cond_3[]= |
397 | { |
398 | { & dummy_cond_key, |
399 | /* 110 chars name */ |
400 | "12345678901234567890123456789012345678901234567890" |
401 | "12345678901234567890123456789012345678901234567890" |
402 | "1234567890" , |
403 | 0} |
404 | }; |
405 | |
406 | psi->register_cond("XX" , bad_cond_3, 1); |
407 | ok(dummy_cond_key == 0, "zero key" ); |
408 | |
409 | psi->register_cond("X" , bad_cond_3, 1); |
410 | ok(dummy_cond_key == 2, "assigned key" ); |
411 | |
412 | /* |
413 | Test that length('thread/' (7) + category + '/' (1)) < 32 |
414 | --> category can be up to 23 chars for a thread. |
415 | */ |
416 | |
417 | PSI_thread_key dummy_thread_key= 9999; |
418 | PSI_thread_info bad_thread_1[]= |
419 | { |
420 | { & dummy_thread_key, "X" , 0} |
421 | }; |
422 | |
423 | psi->register_thread("/" , bad_thread_1, 1); |
424 | ok(dummy_thread_key == 0, "zero key" ); |
425 | dummy_thread_key= 9999; |
426 | psi->register_thread("a/" , bad_thread_1, 1); |
427 | ok(dummy_thread_key == 0, "zero key" ); |
428 | dummy_thread_key= 9999; |
429 | psi->register_thread("/b" , bad_thread_1, 1); |
430 | ok(dummy_thread_key == 0, "zero key" ); |
431 | dummy_thread_key= 9999; |
432 | psi->register_thread("a/b" , bad_thread_1, 1); |
433 | ok(dummy_thread_key == 0, "zero key" ); |
434 | dummy_thread_key= 9999; |
435 | psi->register_thread("123456789012345678901234" , bad_thread_1, 1); |
436 | ok(dummy_thread_key == 0, "zero key" ); |
437 | dummy_thread_key= 9999; |
438 | psi->register_thread("12345678901234567890123" , bad_thread_1, 1); |
439 | ok(dummy_thread_key == 1, "assigned key" ); |
440 | |
441 | /* |
442 | Test that length('thread/' (7) + category + '/' (1) + name) <= 128 |
443 | --> category + name can be up to 120 chars for a thread. |
444 | */ |
445 | |
446 | dummy_thread_key= 9999; |
447 | PSI_thread_info bad_thread_2[]= |
448 | { |
449 | { & dummy_thread_key, |
450 | /* 120 chars name */ |
451 | "12345678901234567890123456789012345678901234567890" |
452 | "12345678901234567890123456789012345678901234567890" |
453 | "12345678901234567890" , |
454 | 0} |
455 | }; |
456 | |
457 | psi->register_thread("X" , bad_thread_2, 1); |
458 | ok(dummy_thread_key == 0, "zero key" ); |
459 | |
460 | dummy_thread_key= 9999; |
461 | PSI_thread_info bad_thread_3[]= |
462 | { |
463 | { & dummy_thread_key, |
464 | /* 119 chars name */ |
465 | "12345678901234567890123456789012345678901234567890" |
466 | "12345678901234567890123456789012345678901234567890" |
467 | "1234567890123456789" , |
468 | 0} |
469 | }; |
470 | |
471 | psi->register_thread("XX" , bad_thread_3, 1); |
472 | ok(dummy_thread_key == 0, "zero key" ); |
473 | |
474 | psi->register_thread("X" , bad_thread_3, 1); |
475 | ok(dummy_thread_key == 2, "assigned key" ); |
476 | |
477 | /* |
478 | Test that length('wait/io/file/' (13) + category + '/' (1)) < 32 |
479 | --> category can be up to 17 chars for a file. |
480 | */ |
481 | |
482 | PSI_file_key dummy_file_key= 9999; |
483 | PSI_file_info bad_file_1[]= |
484 | { |
485 | { & dummy_file_key, "X" , 0} |
486 | }; |
487 | |
488 | psi->register_file("/" , bad_file_1, 1); |
489 | ok(dummy_file_key == 0, "zero key" ); |
490 | dummy_file_key= 9999; |
491 | psi->register_file("a/" , bad_file_1, 1); |
492 | ok(dummy_file_key == 0, "zero key" ); |
493 | dummy_file_key= 9999; |
494 | psi->register_file("/b" , bad_file_1, 1); |
495 | ok(dummy_file_key == 0, "zero key" ); |
496 | dummy_file_key= 9999; |
497 | psi->register_file("a/b" , bad_file_1, 1); |
498 | ok(dummy_file_key == 0, "zero key" ); |
499 | dummy_file_key= 9999; |
500 | psi->register_file("123456789012345678" , bad_file_1, 1); |
501 | ok(dummy_file_key == 0, "zero key" ); |
502 | dummy_file_key= 9999; |
503 | psi->register_file("12345678901234567" , bad_file_1, 1); |
504 | ok(dummy_file_key == 1, "assigned key" ); |
505 | |
506 | /* |
507 | Test that length('wait/io/file/' (13) + category + '/' (1) + name) <= 128 |
508 | --> category + name can be up to 114 chars for a file. |
509 | */ |
510 | |
511 | dummy_file_key= 9999; |
512 | PSI_file_info bad_file_2[]= |
513 | { |
514 | { & dummy_file_key, |
515 | /* 114 chars name */ |
516 | "12345678901234567890123456789012345678901234567890" |
517 | "12345678901234567890123456789012345678901234567890" |
518 | "12345678901234" , |
519 | 0} |
520 | }; |
521 | |
522 | psi->register_file("X" , bad_file_2, 1); |
523 | ok(dummy_file_key == 0, "zero key" ); |
524 | |
525 | dummy_file_key= 9999; |
526 | PSI_file_info bad_file_3[]= |
527 | { |
528 | { & dummy_file_key, |
529 | /* 113 chars name */ |
530 | "12345678901234567890123456789012345678901234567890" |
531 | "12345678901234567890123456789012345678901234567890" |
532 | "1234567890123" , |
533 | 0} |
534 | }; |
535 | |
536 | psi->register_file("XX" , bad_file_3, 1); |
537 | ok(dummy_file_key == 0, "zero key" ); |
538 | |
539 | psi->register_file("X" , bad_file_3, 1); |
540 | ok(dummy_file_key == 2, "assigned key" ); |
541 | |
542 | /* |
543 | Test that length('wait/io/socket/' (15) + category + '/' (1)) < 32 |
544 | --> category can be up to 15 chars for a socket. |
545 | */ |
546 | |
547 | PSI_socket_key dummy_socket_key= 9999; |
548 | PSI_socket_info bad_socket_1[]= |
549 | { |
550 | { & dummy_socket_key, "X" , 0} |
551 | }; |
552 | |
553 | psi->register_socket("/" , bad_socket_1, 1); |
554 | ok(dummy_socket_key == 0, "zero key" ); |
555 | dummy_socket_key= 9999; |
556 | psi->register_socket("a/" , bad_socket_1, 1); |
557 | ok(dummy_socket_key == 0, "zero key" ); |
558 | dummy_socket_key= 9999; |
559 | psi->register_socket("/b" , bad_socket_1, 1); |
560 | ok(dummy_socket_key == 0, "zero key" ); |
561 | dummy_socket_key= 9999; |
562 | psi->register_socket("a/b" , bad_socket_1, 1); |
563 | ok(dummy_socket_key == 0, "zero key" ); |
564 | dummy_socket_key= 9999; |
565 | psi->register_socket("1234567890123456" , bad_socket_1, 1); |
566 | ok(dummy_socket_key == 0, "zero key" ); |
567 | dummy_socket_key= 9999; |
568 | psi->register_socket("123456789012345" , bad_socket_1, 1); |
569 | ok(dummy_socket_key == 1, "assigned key" ); |
570 | |
571 | /* |
572 | Test that length('wait/io/socket/' (15) + category + '/' (1) + name) <= 128 |
573 | --> category + name can be up to 112 chars for a socket. |
574 | */ |
575 | |
576 | dummy_socket_key= 9999; |
577 | PSI_socket_info bad_socket_2[]= |
578 | { |
579 | { & dummy_socket_key, |
580 | /* 112 chars name */ |
581 | "12345678901234567890123456789012345678901234567890" |
582 | "12345678901234567890123456789012345678901234567890" |
583 | "123456789012" , |
584 | 0} |
585 | }; |
586 | |
587 | psi->register_socket("X" , bad_socket_2, 1); |
588 | ok(dummy_socket_key == 0, "zero key" ); |
589 | |
590 | dummy_socket_key= 9999; |
591 | PSI_socket_info bad_socket_3[]= |
592 | { |
593 | { & dummy_socket_key, |
594 | /* 111 chars name */ |
595 | "12345678901234567890123456789012345678901234567890" |
596 | "12345678901234567890123456789012345678901234567890" |
597 | "12345678901" , |
598 | 0} |
599 | }; |
600 | |
601 | psi->register_socket("XX" , bad_socket_3, 1); |
602 | ok(dummy_socket_key == 0, "zero key" ); |
603 | |
604 | psi->register_socket("X" , bad_socket_3, 1); |
605 | ok(dummy_socket_key == 2, "assigned key" ); |
606 | |
607 | unload_performance_schema(); |
608 | } |
609 | |
610 | void test_init_disabled() |
611 | { |
612 | PSI *psi; |
613 | |
614 | diag("test_init_disabled" ); |
615 | |
616 | psi= load_perfschema(); |
617 | |
618 | PSI_mutex_key mutex_key_A; |
619 | PSI_mutex_info all_mutex[]= |
620 | { |
621 | { & mutex_key_A, "M-A" , 0} |
622 | }; |
623 | |
624 | PSI_rwlock_key rwlock_key_A; |
625 | PSI_rwlock_info all_rwlock[]= |
626 | { |
627 | { & rwlock_key_A, "RW-A" , 0} |
628 | }; |
629 | |
630 | PSI_cond_key cond_key_A; |
631 | PSI_cond_info all_cond[]= |
632 | { |
633 | { & cond_key_A, "C-A" , 0} |
634 | }; |
635 | |
636 | PSI_file_key file_key_A; |
637 | PSI_file_info all_file[]= |
638 | { |
639 | { & file_key_A, "F-A" , 0} |
640 | }; |
641 | |
642 | PSI_socket_key socket_key_A; |
643 | PSI_socket_info all_socket[]= |
644 | { |
645 | { & socket_key_A, "S-A" , 0} |
646 | }; |
647 | |
648 | PSI_thread_key thread_key_1; |
649 | PSI_thread_info all_thread[]= |
650 | { |
651 | { & thread_key_1, "T-1" , 0} |
652 | }; |
653 | |
654 | psi->register_mutex("test" , all_mutex, 1); |
655 | psi->register_rwlock("test" , all_rwlock, 1); |
656 | psi->register_cond("test" , all_cond, 1); |
657 | psi->register_file("test" , all_file, 1); |
658 | psi->register_socket("test" , all_socket, 1); |
659 | psi->register_thread("test" , all_thread, 1); |
660 | |
661 | PFS_mutex_class *mutex_class_A; |
662 | PFS_rwlock_class *rwlock_class_A; |
663 | PFS_cond_class *cond_class_A; |
664 | PFS_file_class *file_class_A; |
665 | PFS_socket_class *socket_class_A; |
666 | PSI_mutex *mutex_A1; |
667 | PSI_rwlock *rwlock_A1; |
668 | PSI_cond *cond_A1; |
669 | PFS_file *file_A1; |
670 | PSI_socket *socket_A1; |
671 | PSI_thread *thread_1; |
672 | |
673 | /* Preparation */ |
674 | |
675 | thread_1= psi->new_thread(thread_key_1, NULL, 0); |
676 | ok(thread_1 != NULL, "T-1" ); |
677 | psi->set_thread_id(thread_1, 1); |
678 | |
679 | mutex_class_A= find_mutex_class(mutex_key_A); |
680 | ok(mutex_class_A != NULL, "mutex class A" ); |
681 | |
682 | rwlock_class_A= find_rwlock_class(rwlock_key_A); |
683 | ok(rwlock_class_A != NULL, "rwlock class A" ); |
684 | |
685 | cond_class_A= find_cond_class(cond_key_A); |
686 | ok(cond_class_A != NULL, "cond class A" ); |
687 | |
688 | file_class_A= find_file_class(file_key_A); |
689 | ok(file_class_A != NULL, "file class A" ); |
690 | |
691 | socket_class_A= find_socket_class(socket_key_A); |
692 | ok(socket_class_A != NULL, "socket class A" ); |
693 | |
694 | /* Pretend thread T-1 is running, and disabled, with thread_instrumentation */ |
695 | /* ------------------------------------------------------------------------ */ |
696 | |
697 | psi->set_thread(thread_1); |
698 | setup_thread(thread_1, false); |
699 | |
700 | /* disabled M-A + disabled T-1: no instrumentation */ |
701 | |
702 | mutex_class_A->m_enabled= false; |
703 | mutex_A1= psi->init_mutex(mutex_key_A, NULL); |
704 | ok(mutex_A1 == NULL, "mutex_A1 not instrumented" ); |
705 | |
706 | /* enabled M-A + disabled T-1: instrumentation (for later) */ |
707 | |
708 | mutex_class_A->m_enabled= true; |
709 | mutex_A1= psi->init_mutex(mutex_key_A, NULL); |
710 | ok(mutex_A1 != NULL, "mutex_A1 instrumented" ); |
711 | |
712 | /* broken key + disabled T-1: no instrumentation */ |
713 | |
714 | mutex_class_A->m_enabled= true; |
715 | mutex_A1= psi->init_mutex(0, NULL); |
716 | ok(mutex_A1 == NULL, "mutex key 0 not instrumented" ); |
717 | mutex_A1= psi->init_mutex(99, NULL); |
718 | ok(mutex_A1 == NULL, "broken mutex key not instrumented" ); |
719 | |
720 | /* disabled RW-A + disabled T-1: no instrumentation */ |
721 | |
722 | rwlock_class_A->m_enabled= false; |
723 | rwlock_A1= psi->init_rwlock(rwlock_key_A, NULL); |
724 | ok(rwlock_A1 == NULL, "rwlock_A1 not instrumented" ); |
725 | |
726 | /* enabled RW-A + disabled T-1: instrumentation (for later) */ |
727 | |
728 | rwlock_class_A->m_enabled= true; |
729 | rwlock_A1= psi->init_rwlock(rwlock_key_A, NULL); |
730 | ok(rwlock_A1 != NULL, "rwlock_A1 instrumented" ); |
731 | |
732 | /* broken key + disabled T-1: no instrumentation */ |
733 | |
734 | rwlock_class_A->m_enabled= true; |
735 | rwlock_A1= psi->init_rwlock(0, NULL); |
736 | ok(rwlock_A1 == NULL, "rwlock key 0 not instrumented" ); |
737 | rwlock_A1= psi->init_rwlock(99, NULL); |
738 | ok(rwlock_A1 == NULL, "broken rwlock key not instrumented" ); |
739 | |
740 | /* disabled C-A + disabled T-1: no instrumentation */ |
741 | |
742 | cond_class_A->m_enabled= false; |
743 | cond_A1= psi->init_cond(cond_key_A, NULL); |
744 | ok(cond_A1 == NULL, "cond_A1 not instrumented" ); |
745 | |
746 | /* enabled C-A + disabled T-1: instrumentation (for later) */ |
747 | |
748 | cond_class_A->m_enabled= true; |
749 | cond_A1= psi->init_cond(cond_key_A, NULL); |
750 | ok(cond_A1 != NULL, "cond_A1 instrumented" ); |
751 | |
752 | /* broken key + disabled T-1: no instrumentation */ |
753 | |
754 | cond_class_A->m_enabled= true; |
755 | cond_A1= psi->init_cond(0, NULL); |
756 | ok(cond_A1 == NULL, "cond key 0 not instrumented" ); |
757 | cond_A1= psi->init_cond(99, NULL); |
758 | ok(cond_A1 == NULL, "broken cond key not instrumented" ); |
759 | |
760 | /* disabled F-A + disabled T-1: no instrumentation */ |
761 | |
762 | file_class_A->m_enabled= false; |
763 | psi->create_file(file_key_A, "foo" , (File) 12); |
764 | file_A1= lookup_file_by_name("foo" ); |
765 | ok(file_A1 == NULL, "not instrumented" ); |
766 | |
767 | /* enabled F-A + disabled T-1: no instrumentation */ |
768 | |
769 | file_class_A->m_enabled= true; |
770 | psi->create_file(file_key_A, "foo" , (File) 12); |
771 | file_A1= lookup_file_by_name("foo" ); |
772 | ok(file_A1 == NULL, "not instrumented" ); |
773 | |
774 | /* broken key + disabled T-1: no instrumentation */ |
775 | |
776 | file_class_A->m_enabled= true; |
777 | psi->create_file(0, "foo" , (File) 12); |
778 | file_A1= lookup_file_by_name("foo" ); |
779 | ok(file_A1 == NULL, "not instrumented" ); |
780 | psi->create_file(99, "foo" , (File) 12); |
781 | file_A1= lookup_file_by_name("foo" ); |
782 | ok(file_A1 == NULL, "not instrumented" ); |
783 | |
784 | /* disabled S-A + disabled T-1: no instrumentation */ |
785 | |
786 | socket_class_A->m_enabled= false; |
787 | socket_A1= psi->init_socket(socket_key_A, NULL, NULL, 0); |
788 | ok(socket_A1 == NULL, "socket_A1 not instrumented" ); |
789 | |
790 | /* enabled S-A + disabled T-1: instrumentation (for later) */ |
791 | |
792 | socket_class_A->m_enabled= true; |
793 | socket_A1= psi->init_socket(socket_key_A, NULL, NULL, 0); |
794 | ok(socket_A1 != NULL, "socket_A1 instrumented" ); |
795 | |
796 | /* broken key + disabled T-1: no instrumentation */ |
797 | |
798 | socket_class_A->m_enabled= true; |
799 | socket_A1= psi->init_socket(0, NULL, NULL, 0); |
800 | ok(socket_A1 == NULL, "socket key 0 not instrumented" ); |
801 | socket_A1= psi->init_socket(99, NULL, NULL, 0); |
802 | ok(socket_A1 == NULL, "broken socket key not instrumented" ); |
803 | |
804 | /* Pretend thread T-1 is enabled */ |
805 | /* ----------------------------- */ |
806 | |
807 | setup_thread(thread_1, true); |
808 | |
809 | /* disabled M-A + enabled T-1: no instrumentation */ |
810 | |
811 | mutex_class_A->m_enabled= false; |
812 | mutex_A1= psi->init_mutex(mutex_key_A, NULL); |
813 | ok(mutex_A1 == NULL, "not instrumented" ); |
814 | |
815 | /* enabled M-A + enabled T-1: instrumentation */ |
816 | |
817 | mutex_class_A->m_enabled= true; |
818 | mutex_A1= psi->init_mutex(mutex_key_A, NULL); |
819 | ok(mutex_A1 != NULL, "instrumented" ); |
820 | psi->destroy_mutex(mutex_A1); |
821 | |
822 | /* broken key + enabled T-1: no instrumentation */ |
823 | |
824 | mutex_class_A->m_enabled= true; |
825 | mutex_A1= psi->init_mutex(0, NULL); |
826 | ok(mutex_A1 == NULL, "not instrumented" ); |
827 | mutex_A1= psi->init_mutex(99, NULL); |
828 | ok(mutex_A1 == NULL, "not instrumented" ); |
829 | |
830 | /* disabled RW-A + enabled T-1: no instrumentation */ |
831 | |
832 | rwlock_class_A->m_enabled= false; |
833 | rwlock_A1= psi->init_rwlock(rwlock_key_A, NULL); |
834 | ok(rwlock_A1 == NULL, "not instrumented" ); |
835 | |
836 | /* enabled RW-A + enabled T-1: instrumentation */ |
837 | |
838 | rwlock_class_A->m_enabled= true; |
839 | rwlock_A1= psi->init_rwlock(rwlock_key_A, NULL); |
840 | ok(rwlock_A1 != NULL, "instrumented" ); |
841 | psi->destroy_rwlock(rwlock_A1); |
842 | |
843 | /* broken key + enabled T-1: no instrumentation */ |
844 | |
845 | rwlock_class_A->m_enabled= true; |
846 | rwlock_A1= psi->init_rwlock(0, NULL); |
847 | ok(rwlock_A1 == NULL, "not instrumented" ); |
848 | rwlock_A1= psi->init_rwlock(99, NULL); |
849 | ok(rwlock_A1 == NULL, "not instrumented" ); |
850 | |
851 | /* disabled C-A + enabled T-1: no instrumentation */ |
852 | |
853 | cond_class_A->m_enabled= false; |
854 | cond_A1= psi->init_cond(cond_key_A, NULL); |
855 | ok(cond_A1 == NULL, "not instrumented" ); |
856 | |
857 | /* enabled C-A + enabled T-1: instrumentation */ |
858 | |
859 | cond_class_A->m_enabled= true; |
860 | cond_A1= psi->init_cond(cond_key_A, NULL); |
861 | ok(cond_A1 != NULL, "instrumented" ); |
862 | psi->destroy_cond(cond_A1); |
863 | |
864 | /* broken key + enabled T-1: no instrumentation */ |
865 | |
866 | cond_class_A->m_enabled= true; |
867 | cond_A1= psi->init_cond(0, NULL); |
868 | ok(cond_A1 == NULL, "not instrumented" ); |
869 | cond_A1= psi->init_cond(99, NULL); |
870 | ok(cond_A1 == NULL, "not instrumented" ); |
871 | |
872 | /* disabled F-A + enabled T-1: no instrumentation */ |
873 | |
874 | file_class_A->m_enabled= false; |
875 | psi->create_file(file_key_A, "foo" , (File) 12); |
876 | file_A1= lookup_file_by_name("foo" ); |
877 | ok(file_A1 == NULL, "not instrumented" ); |
878 | |
879 | /* enabled F-A + open failed + enabled T-1: no instrumentation */ |
880 | |
881 | file_class_A->m_enabled= true; |
882 | psi->create_file(file_key_A, "foo" , (File) -1); |
883 | file_A1= lookup_file_by_name("foo" ); |
884 | ok(file_A1 == NULL, "not instrumented" ); |
885 | |
886 | /* enabled F-A + out-of-descriptors + enabled T-1: no instrumentation */ |
887 | |
888 | file_class_A->m_enabled= true; |
889 | psi->create_file(file_key_A, "foo" , (File) 65000); |
890 | file_A1= lookup_file_by_name("foo" ); |
891 | ok(file_A1 == NULL, "not instrumented" ); |
892 | ok(file_handle_lost == 1, "lost a file handle" ); |
893 | file_handle_lost= 0; |
894 | |
895 | /* enabled F-A + enabled T-1: instrumentation */ |
896 | |
897 | file_class_A->m_enabled= true; |
898 | psi->create_file(file_key_A, "foo-instrumented" , (File) 12); |
899 | file_A1= lookup_file_by_name("foo-instrumented" ); |
900 | ok(file_A1 != NULL, "file_A1 instrumented" ); |
901 | |
902 | /* broken key + enabled T-1: no instrumentation */ |
903 | |
904 | file_class_A->m_enabled= true; |
905 | psi->create_file(0, "foo" , (File) 12); |
906 | file_A1= lookup_file_by_name("foo" ); |
907 | ok(file_A1 == NULL, "file key 0 not instrumented" ); |
908 | psi->create_file(99, "foo" , (File) 12); |
909 | file_A1= lookup_file_by_name("foo" ); |
910 | ok(file_A1 == NULL, "broken file key not instrumented" ); |
911 | |
912 | /* disabled S-A + enabled T-1: no instrumentation */ |
913 | |
914 | socket_class_A->m_enabled= false; |
915 | ok(socket_A1 == NULL, "not instrumented" ); |
916 | |
917 | /* enabled S-A + enabled T-1: instrumentation */ |
918 | |
919 | socket_class_A->m_enabled= true; |
920 | socket_A1= psi->init_socket(socket_key_A, NULL, NULL, 0); |
921 | ok(socket_A1 != NULL, "instrumented" ); |
922 | psi->destroy_socket(socket_A1); |
923 | |
924 | /* broken key + enabled T-1: no instrumentation */ |
925 | |
926 | socket_class_A->m_enabled= true; |
927 | socket_A1= psi->init_socket(0, NULL, NULL, 0); |
928 | ok(socket_A1 == NULL, "not instrumented" ); |
929 | socket_A1= psi->init_socket(99, NULL, NULL, 0); |
930 | ok(socket_A1 == NULL, "not instrumented" ); |
931 | |
932 | /* Pretend the running thread is not instrumented */ |
933 | /* ---------------------------------------------- */ |
934 | |
935 | psi->delete_current_thread(); |
936 | |
937 | /* disabled M-A + unknown thread: no instrumentation */ |
938 | |
939 | mutex_class_A->m_enabled= false; |
940 | mutex_A1= psi->init_mutex(mutex_key_A, NULL); |
941 | ok(mutex_A1 == NULL, "mutex_A1 not instrumented" ); |
942 | |
943 | /* enabled M-A + unknown thread: instrumentation (for later) */ |
944 | |
945 | mutex_class_A->m_enabled= true; |
946 | mutex_A1= psi->init_mutex(mutex_key_A, NULL); |
947 | ok(mutex_A1 != NULL, "mutex_A1 instrumented" ); |
948 | |
949 | /* broken key + unknown thread: no instrumentation */ |
950 | |
951 | mutex_class_A->m_enabled= true; |
952 | mutex_A1= psi->init_mutex(0, NULL); |
953 | ok(mutex_A1 == NULL, "mutex key 0 not instrumented" ); |
954 | mutex_A1= psi->init_mutex(99, NULL); |
955 | ok(mutex_A1 == NULL, "broken mutex key not instrumented" ); |
956 | |
957 | /* disabled RW-A + unknown thread: no instrumentation */ |
958 | |
959 | rwlock_class_A->m_enabled= false; |
960 | rwlock_A1= psi->init_rwlock(rwlock_key_A, NULL); |
961 | ok(rwlock_A1 == NULL, "rwlock_A1 not instrumented" ); |
962 | |
963 | /* enabled RW-A + unknown thread: instrumentation (for later) */ |
964 | |
965 | rwlock_class_A->m_enabled= true; |
966 | rwlock_A1= psi->init_rwlock(rwlock_key_A, NULL); |
967 | ok(rwlock_A1 != NULL, "rwlock_A1 instrumented" ); |
968 | |
969 | /* broken key + unknown thread: no instrumentation */ |
970 | |
971 | rwlock_class_A->m_enabled= true; |
972 | rwlock_A1= psi->init_rwlock(0, NULL); |
973 | ok(rwlock_A1 == NULL, "rwlock key 0 not instrumented" ); |
974 | rwlock_A1= psi->init_rwlock(99, NULL); |
975 | ok(rwlock_A1 == NULL, "broken rwlock key not instrumented" ); |
976 | |
977 | /* disabled C-A + unknown thread: no instrumentation */ |
978 | |
979 | cond_class_A->m_enabled= false; |
980 | cond_A1= psi->init_cond(cond_key_A, NULL); |
981 | ok(cond_A1 == NULL, "cond_A1 not instrumented" ); |
982 | |
983 | /* enabled C-A + unknown thread: instrumentation (for later) */ |
984 | |
985 | cond_class_A->m_enabled= true; |
986 | cond_A1= psi->init_cond(cond_key_A, NULL); |
987 | ok(cond_A1 != NULL, "cond_A1 instrumented" ); |
988 | |
989 | /* broken key + unknown thread: no instrumentation */ |
990 | |
991 | cond_class_A->m_enabled= true; |
992 | cond_A1= psi->init_cond(0, NULL); |
993 | ok(cond_A1 == NULL, "cond key 0 not instrumented" ); |
994 | cond_A1= psi->init_cond(99, NULL); |
995 | ok(cond_A1 == NULL, "broken cond key not instrumented" ); |
996 | |
997 | /* disabled F-A + unknown thread: no instrumentation */ |
998 | |
999 | file_class_A->m_enabled= false; |
1000 | psi->create_file(file_key_A, "foo" , (File) 12); |
1001 | file_A1= lookup_file_by_name("foo" ); |
1002 | ok(file_A1 == NULL, "not instrumented" ); |
1003 | |
1004 | /* enabled F-A + unknown thread: no instrumentation */ |
1005 | |
1006 | file_class_A->m_enabled= true; |
1007 | psi->create_file(file_key_A, "foo" , (File) 12); |
1008 | file_A1= lookup_file_by_name("foo" ); |
1009 | ok(file_A1 == NULL, "not instrumented" ); |
1010 | |
1011 | /* broken key + unknown thread: no instrumentation */ |
1012 | |
1013 | file_class_A->m_enabled= true; |
1014 | psi->create_file(0, "foo" , (File) 12); |
1015 | file_A1= lookup_file_by_name("foo" ); |
1016 | ok(file_A1 == NULL, "not instrumented" ); |
1017 | psi->create_file(99, "foo" , (File) 12); |
1018 | file_A1= lookup_file_by_name("foo" ); |
1019 | ok(file_A1 == NULL, "not instrumented" ); |
1020 | |
1021 | /* disabled S-A + unknown thread: no instrumentation */ |
1022 | |
1023 | socket_class_A->m_enabled= false; |
1024 | socket_A1= psi->init_socket(socket_key_A, NULL, NULL, 0); |
1025 | ok(socket_A1 == NULL, "socket_A1 not instrumented" ); |
1026 | |
1027 | /* enabled S-A + unknown thread: instrumentation (for later) */ |
1028 | |
1029 | socket_class_A->m_enabled= true; |
1030 | socket_A1= psi->init_socket(socket_key_A, NULL, NULL, 0); |
1031 | ok(socket_A1 != NULL, "socket_A1 instrumented" ); |
1032 | |
1033 | /* broken key + unknown thread: no instrumentation */ |
1034 | |
1035 | socket_class_A->m_enabled= true; |
1036 | socket_A1= psi->init_socket(0, NULL, NULL, 0); |
1037 | ok(socket_A1 == NULL, "socket key 0 not instrumented" ); |
1038 | socket_A1= psi->init_socket(99, NULL, NULL, 0); |
1039 | ok(socket_A1 == NULL, "broken socket key not instrumented" ); |
1040 | |
1041 | unload_performance_schema(); |
1042 | } |
1043 | |
1044 | void test_locker_disabled() |
1045 | { |
1046 | PSI *psi; |
1047 | |
1048 | diag("test_locker_disabled" ); |
1049 | |
1050 | psi= load_perfschema(); |
1051 | |
1052 | PSI_mutex_key mutex_key_A; |
1053 | PSI_mutex_info all_mutex[]= |
1054 | { |
1055 | { & mutex_key_A, "M-A" , 0} |
1056 | }; |
1057 | |
1058 | PSI_rwlock_key rwlock_key_A; |
1059 | PSI_rwlock_info all_rwlock[]= |
1060 | { |
1061 | { & rwlock_key_A, "RW-A" , 0} |
1062 | }; |
1063 | |
1064 | PSI_cond_key cond_key_A; |
1065 | PSI_cond_info all_cond[]= |
1066 | { |
1067 | { & cond_key_A, "C-A" , 0} |
1068 | }; |
1069 | |
1070 | PSI_file_key file_key_A; |
1071 | PSI_file_info all_file[]= |
1072 | { |
1073 | { & file_key_A, "F-A" , 0} |
1074 | }; |
1075 | |
1076 | PSI_socket_key socket_key_A; |
1077 | PSI_socket_info all_socket[]= |
1078 | { |
1079 | { & socket_key_A, "S-A" , 0} |
1080 | }; |
1081 | |
1082 | PSI_thread_key thread_key_1; |
1083 | PSI_thread_info all_thread[]= |
1084 | { |
1085 | { & thread_key_1, "T-1" , 0} |
1086 | }; |
1087 | |
1088 | psi->register_mutex("test" , all_mutex, 1); |
1089 | psi->register_rwlock("test" , all_rwlock, 1); |
1090 | psi->register_cond("test" , all_cond, 1); |
1091 | psi->register_file("test" , all_file, 1); |
1092 | psi->register_socket("test" , all_socket, 1); |
1093 | psi->register_thread("test" , all_thread, 1); |
1094 | |
1095 | PFS_mutex_class *mutex_class_A; |
1096 | PFS_rwlock_class *rwlock_class_A; |
1097 | PFS_cond_class *cond_class_A; |
1098 | PFS_file_class *file_class_A; |
1099 | PFS_socket_class *socket_class_A; |
1100 | PSI_mutex *mutex_A1; |
1101 | PSI_rwlock *rwlock_A1; |
1102 | PSI_cond *cond_A1; |
1103 | PSI_file *file_A1; |
1104 | PSI_socket *socket_A1; |
1105 | PSI_thread *thread_1; |
1106 | |
1107 | /* Preparation */ |
1108 | |
1109 | thread_1= psi->new_thread(thread_key_1, NULL, 0); |
1110 | ok(thread_1 != NULL, "T-1" ); |
1111 | psi->set_thread_id(thread_1, 1); |
1112 | |
1113 | mutex_class_A= find_mutex_class(mutex_key_A); |
1114 | ok(mutex_class_A != NULL, "mutex info A" ); |
1115 | |
1116 | rwlock_class_A= find_rwlock_class(rwlock_key_A); |
1117 | ok(rwlock_class_A != NULL, "rwlock info A" ); |
1118 | |
1119 | cond_class_A= find_cond_class(cond_key_A); |
1120 | ok(cond_class_A != NULL, "cond info A" ); |
1121 | |
1122 | file_class_A= find_file_class(file_key_A); |
1123 | ok(file_class_A != NULL, "file info A" ); |
1124 | |
1125 | socket_class_A= find_socket_class(socket_key_A); |
1126 | ok(socket_class_A != NULL, "socket info A" ); |
1127 | |
1128 | /* Pretend thread T-1 is running, and enabled */ |
1129 | /* ------------------------------------------ */ |
1130 | |
1131 | psi->set_thread(thread_1); |
1132 | setup_thread(thread_1, true); |
1133 | |
1134 | /* Enable all instruments, instantiate objects */ |
1135 | |
1136 | mutex_class_A->m_enabled= true; |
1137 | mutex_A1= psi->init_mutex(mutex_key_A, NULL); |
1138 | ok(mutex_A1 != NULL, "instrumented" ); |
1139 | |
1140 | rwlock_class_A->m_enabled= true; |
1141 | rwlock_A1= psi->init_rwlock(rwlock_key_A, NULL); |
1142 | ok(rwlock_A1 != NULL, "instrumented" ); |
1143 | |
1144 | cond_class_A->m_enabled= true; |
1145 | cond_A1= psi->init_cond(cond_key_A, NULL); |
1146 | ok(cond_A1 != NULL, "instrumented" ); |
1147 | |
1148 | file_class_A->m_enabled= true; |
1149 | psi->create_file(file_key_A, "foo" , (File) 12); |
1150 | file_A1= (PSI_file*) lookup_file_by_name("foo" ); |
1151 | ok(file_A1 != NULL, "instrumented" ); |
1152 | |
1153 | socket_class_A->m_enabled= true; |
1154 | socket_A1= psi->init_socket(socket_key_A, NULL, NULL, 0); |
1155 | ok(socket_A1 != NULL, "instrumented" ); |
1156 | |
1157 | /* Socket lockers require a thread owner */ |
1158 | psi->set_socket_thread_owner(socket_A1); |
1159 | |
1160 | PSI_mutex_locker *mutex_locker; |
1161 | PSI_mutex_locker_state mutex_state; |
1162 | PSI_rwlock_locker *rwlock_locker; |
1163 | PSI_rwlock_locker_state rwlock_state; |
1164 | PSI_cond_locker *cond_locker; |
1165 | PSI_cond_locker_state cond_state; |
1166 | PSI_file_locker *file_locker; |
1167 | PSI_file_locker_state file_state; |
1168 | PSI_socket_locker *socket_locker; |
1169 | PSI_socket_locker_state socket_state; |
1170 | |
1171 | /* Pretend thread T-1 is disabled */ |
1172 | /* ------------------------------ */ |
1173 | |
1174 | setup_thread(thread_1, false); |
1175 | flag_events_waits_current= true; |
1176 | mutex_class_A->m_enabled= true; |
1177 | rwlock_class_A->m_enabled= true; |
1178 | cond_class_A->m_enabled= true; |
1179 | file_class_A->m_enabled= true; |
1180 | socket_class_A->m_enabled= true; |
1181 | |
1182 | mutex_locker= psi->start_mutex_wait(&mutex_state, mutex_A1, PSI_MUTEX_LOCK, "foo.cc" , 12); |
1183 | ok(mutex_locker == NULL, "no locker (T-1 disabled)" ); |
1184 | rwlock_locker= psi->start_rwlock_rdwait(&rwlock_state, rwlock_A1, PSI_RWLOCK_READLOCK, "foo.cc" , 12); |
1185 | ok(rwlock_locker == NULL, "no locker (T-1 disabled)" ); |
1186 | cond_locker= psi->start_cond_wait(&cond_state, cond_A1, mutex_A1, PSI_COND_WAIT, "foo.cc" , 12); |
1187 | ok(cond_locker == NULL, "no locker (T-1 disabled)" ); |
1188 | file_locker= psi->get_thread_file_name_locker(&file_state, file_key_A, PSI_FILE_OPEN, "xxx" , NULL); |
1189 | ok(file_locker == NULL, "no locker (T-1 disabled)" ); |
1190 | file_locker= psi->get_thread_file_stream_locker(&file_state, file_A1, PSI_FILE_READ); |
1191 | ok(file_locker == NULL, "no locker (T-1 disabled)" ); |
1192 | file_locker= psi->get_thread_file_descriptor_locker(&file_state, (File) 12, PSI_FILE_READ); |
1193 | ok(file_locker == NULL, "no locker (T-1 disabled)" ); |
1194 | socket_locker= psi->start_socket_wait(&socket_state, socket_A1, PSI_SOCKET_SEND, 12, "foo.cc" , 12); |
1195 | ok(socket_locker == NULL, "no locker (T-1 disabled)" ); |
1196 | |
1197 | /* Pretend the global consumer is disabled */ |
1198 | /* --------------------------------------- */ |
1199 | |
1200 | setup_thread(thread_1, true); |
1201 | flag_global_instrumentation= false; |
1202 | mutex_class_A->m_enabled= true; |
1203 | rwlock_class_A->m_enabled= true; |
1204 | cond_class_A->m_enabled= true; |
1205 | file_class_A->m_enabled= true; |
1206 | socket_class_A->m_enabled= true; |
1207 | update_instruments_derived_flags(); |
1208 | |
1209 | mutex_locker= psi->start_mutex_wait(&mutex_state, mutex_A1, PSI_MUTEX_LOCK, "foo.cc" , 12); |
1210 | ok(mutex_locker == NULL, "no locker (global disabled)" ); |
1211 | rwlock_locker= psi->start_rwlock_rdwait(&rwlock_state, rwlock_A1, PSI_RWLOCK_READLOCK, "foo.cc" , 12); |
1212 | ok(rwlock_locker == NULL, "no locker (global disabled)" ); |
1213 | cond_locker= psi->start_cond_wait(&cond_state, cond_A1, mutex_A1, PSI_COND_WAIT, "foo.cc" , 12); |
1214 | ok(cond_locker == NULL, "no locker (global disabled)" ); |
1215 | file_locker= psi->get_thread_file_name_locker(&file_state, file_key_A, PSI_FILE_OPEN, "xxx" , NULL); |
1216 | ok(file_locker == NULL, "no locker (global disabled)" ); |
1217 | file_locker= psi->get_thread_file_stream_locker(&file_state, file_A1, PSI_FILE_READ); |
1218 | ok(file_locker == NULL, "no locker (global disabled)" ); |
1219 | file_locker= psi->get_thread_file_descriptor_locker(&file_state, (File) 12, PSI_FILE_READ); |
1220 | ok(file_locker == NULL, "no locker (global disabled)" ); |
1221 | socket_locker= psi->start_socket_wait(&socket_state, socket_A1, PSI_SOCKET_SEND, 12, "foo.cc" , 12); |
1222 | ok(socket_locker == NULL, "no locker (global disabled)" ); |
1223 | |
1224 | /* Pretend the mode is global, counted only */ |
1225 | /* ---------------------------------------- */ |
1226 | |
1227 | setup_thread(thread_1, true); |
1228 | flag_global_instrumentation= true; |
1229 | flag_thread_instrumentation= false; |
1230 | mutex_class_A->m_enabled= true; |
1231 | mutex_class_A->m_timed= false; |
1232 | rwlock_class_A->m_enabled= true; |
1233 | rwlock_class_A->m_timed= false; |
1234 | cond_class_A->m_enabled= true; |
1235 | cond_class_A->m_timed= false; |
1236 | file_class_A->m_enabled= true; |
1237 | file_class_A->m_timed= false; |
1238 | socket_class_A->m_enabled= true; |
1239 | socket_class_A->m_timed= false; |
1240 | update_instruments_derived_flags(); |
1241 | |
1242 | mutex_locker= psi->start_mutex_wait(&mutex_state, mutex_A1, PSI_MUTEX_LOCK, "foo.cc" , 12); |
1243 | ok(mutex_locker == NULL, "no locker (global counted)" ); |
1244 | rwlock_locker= psi->start_rwlock_rdwait(&rwlock_state, rwlock_A1, PSI_RWLOCK_READLOCK, "foo.cc" , 12); |
1245 | ok(rwlock_locker == NULL, "no locker (global counted)" ); |
1246 | cond_locker= psi->start_cond_wait(&cond_state, cond_A1, mutex_A1, PSI_COND_WAIT, "foo.cc" , 12); |
1247 | ok(cond_locker == NULL, "no locker (global counted)" ); |
1248 | file_locker= psi->get_thread_file_name_locker(&file_state, file_key_A, PSI_FILE_OPEN, "xxx" , NULL); |
1249 | ok(file_locker != NULL, "locker (global counted)" ); |
1250 | psi->start_file_wait(file_locker, 10, __FILE__, __LINE__); |
1251 | psi->end_file_wait(file_locker, 10); |
1252 | file_locker= psi->get_thread_file_stream_locker(&file_state, file_A1, PSI_FILE_READ); |
1253 | ok(file_locker != NULL, "locker (global counted)" ); |
1254 | psi->start_file_wait(file_locker, 10, __FILE__, __LINE__); |
1255 | psi->end_file_wait(file_locker, 10); |
1256 | file_locker= psi->get_thread_file_descriptor_locker(&file_state, (File) 12, PSI_FILE_READ); |
1257 | ok(file_locker != NULL, "locker (global counted)" ); |
1258 | psi->start_file_wait(file_locker, 10, __FILE__, __LINE__); |
1259 | psi->end_file_wait(file_locker, 10); |
1260 | /* The null locker shortcut applies only to socket ops with no byte count */ |
1261 | socket_locker= psi->start_socket_wait(&socket_state, socket_A1, PSI_SOCKET_BIND, 0, "foo.cc" , 12); |
1262 | ok(socket_locker == NULL, "no locker (global counted)" ); |
1263 | |
1264 | /* TODO */ |
1265 | |
1266 | /* Pretend the instrument is disabled */ |
1267 | /* ---------------------------------- */ |
1268 | |
1269 | setup_thread(thread_1, true); |
1270 | flag_global_instrumentation= true; |
1271 | flag_events_waits_current= true; |
1272 | mutex_class_A->m_enabled= false; |
1273 | rwlock_class_A->m_enabled= false; |
1274 | cond_class_A->m_enabled= false; |
1275 | file_class_A->m_enabled= false; |
1276 | socket_class_A->m_enabled= false; |
1277 | update_instruments_derived_flags(); |
1278 | |
1279 | mutex_locker= psi->start_mutex_wait(&mutex_state, mutex_A1, PSI_MUTEX_LOCK, "foo.cc" , 12); |
1280 | ok(mutex_locker == NULL, "no locker" ); |
1281 | rwlock_locker= psi->start_rwlock_rdwait(&rwlock_state, rwlock_A1, PSI_RWLOCK_READLOCK, "foo.cc" , 12); |
1282 | ok(rwlock_locker == NULL, "no locker" ); |
1283 | cond_locker= psi->start_cond_wait(&cond_state, cond_A1, mutex_A1, PSI_COND_WAIT, "foo.cc" , 12); |
1284 | ok(cond_locker == NULL, "no locker" ); |
1285 | file_locker= psi->get_thread_file_name_locker(&file_state, file_key_A, PSI_FILE_OPEN, "xxx" , NULL); |
1286 | ok(file_locker == NULL, "no locker" ); |
1287 | file_locker= psi->get_thread_file_stream_locker(&file_state, file_A1, PSI_FILE_READ); |
1288 | ok(file_locker == NULL, "no locker" ); |
1289 | file_locker= psi->get_thread_file_descriptor_locker(&file_state, (File) 12, PSI_FILE_READ); |
1290 | ok(file_locker == NULL, "no locker" ); |
1291 | socket_locker= psi->start_socket_wait(&socket_state, socket_A1, PSI_SOCKET_SEND, 12, "foo.cc" , 12); |
1292 | ok(socket_locker == NULL, "no locker" ); |
1293 | |
1294 | /* Pretend everything is enabled and timed */ |
1295 | /* --------------------------------------- */ |
1296 | |
1297 | setup_thread(thread_1, true); |
1298 | flag_global_instrumentation= true; |
1299 | flag_thread_instrumentation= true; |
1300 | flag_events_waits_current= true; |
1301 | mutex_class_A->m_enabled= true; |
1302 | mutex_class_A->m_timed= true; |
1303 | rwlock_class_A->m_enabled= true; |
1304 | rwlock_class_A->m_timed= true; |
1305 | cond_class_A->m_enabled= true; |
1306 | cond_class_A->m_timed= true; |
1307 | file_class_A->m_enabled= true; |
1308 | file_class_A->m_timed= true; |
1309 | socket_class_A->m_enabled= true; |
1310 | socket_class_A->m_timed= true; |
1311 | update_instruments_derived_flags(); |
1312 | |
1313 | mutex_locker= psi->start_mutex_wait(&mutex_state, mutex_A1, PSI_MUTEX_LOCK, __FILE__, __LINE__); |
1314 | ok(mutex_locker != NULL, "locker" ); |
1315 | psi->end_mutex_wait(mutex_locker, 0); |
1316 | rwlock_locker= psi->start_rwlock_rdwait(&rwlock_state, rwlock_A1, PSI_RWLOCK_READLOCK, __FILE__, __LINE__); |
1317 | ok(rwlock_locker != NULL, "locker" ); |
1318 | psi->end_rwlock_rdwait(rwlock_locker, 0); |
1319 | cond_locker= psi->start_cond_wait(&cond_state, cond_A1, mutex_A1, PSI_COND_WAIT, __FILE__, __LINE__); |
1320 | ok(cond_locker != NULL, "locker" ); |
1321 | psi->end_cond_wait(cond_locker, 0); |
1322 | file_locker= psi->get_thread_file_name_locker(&file_state, file_key_A, PSI_FILE_STREAM_OPEN, "xxx" , NULL); |
1323 | ok(file_locker != NULL, "locker" ); |
1324 | psi->start_file_open_wait(file_locker, __FILE__, __LINE__); |
1325 | psi->end_file_open_wait(file_locker, NULL); |
1326 | file_locker= psi->get_thread_file_stream_locker(&file_state, file_A1, PSI_FILE_READ); |
1327 | ok(file_locker != NULL, "locker" ); |
1328 | psi->start_file_wait(file_locker, 10, __FILE__, __LINE__); |
1329 | psi->end_file_wait(file_locker, 10); |
1330 | file_locker= psi->get_thread_file_descriptor_locker(&file_state, (File) 12, PSI_FILE_READ); |
1331 | ok(file_locker != NULL, "locker" ); |
1332 | psi->start_file_wait(file_locker, 10, __FILE__, __LINE__); |
1333 | psi->end_file_wait(file_locker, 10); |
1334 | socket_locker= psi->start_socket_wait(&socket_state, socket_A1, PSI_SOCKET_SEND, 12, "foo.cc" , 12); |
1335 | ok(socket_locker != NULL, "locker" ); |
1336 | psi->end_socket_wait(socket_locker, 10); |
1337 | |
1338 | /* Pretend the socket does not have a thread owner */ |
1339 | /* ---------------------------------------------- */ |
1340 | |
1341 | socket_class_A->m_enabled= true; |
1342 | socket_A1= psi->init_socket(socket_key_A, NULL, NULL, 0); |
1343 | ok(socket_A1 != NULL, "instrumented" ); |
1344 | /* Socket thread owner has not been set */ |
1345 | socket_locker= psi->start_socket_wait(&socket_state, socket_A1, PSI_SOCKET_SEND, 12, "foo.cc" , 12); |
1346 | ok(socket_locker != NULL, "locker (owner not used)" ); |
1347 | psi->end_socket_wait(socket_locker, 10); |
1348 | |
1349 | /* Pretend the running thread is not instrumented */ |
1350 | /* ---------------------------------------------- */ |
1351 | |
1352 | psi->delete_current_thread(); |
1353 | flag_events_waits_current= true; |
1354 | mutex_class_A->m_enabled= true; |
1355 | rwlock_class_A->m_enabled= true; |
1356 | cond_class_A->m_enabled= true; |
1357 | file_class_A->m_enabled= true; |
1358 | socket_class_A->m_enabled= true; |
1359 | update_instruments_derived_flags(); |
1360 | |
1361 | mutex_locker= psi->start_mutex_wait(&mutex_state, mutex_A1, PSI_MUTEX_LOCK, "foo.cc" , 12); |
1362 | ok(mutex_locker == NULL, "no locker" ); |
1363 | rwlock_locker= psi->start_rwlock_rdwait(&rwlock_state, rwlock_A1, PSI_RWLOCK_READLOCK, "foo.cc" , 12); |
1364 | ok(rwlock_locker == NULL, "no locker" ); |
1365 | cond_locker= psi->start_cond_wait(&cond_state, cond_A1, mutex_A1, PSI_COND_WAIT, "foo.cc" , 12); |
1366 | ok(cond_locker == NULL, "no locker" ); |
1367 | file_locker= psi->get_thread_file_name_locker(&file_state, file_key_A, PSI_FILE_OPEN, "xxx" , NULL); |
1368 | ok(file_locker == NULL, "no locker" ); |
1369 | file_locker= psi->get_thread_file_stream_locker(&file_state, file_A1, PSI_FILE_READ); |
1370 | ok(file_locker == NULL, "no locker" ); |
1371 | file_locker= psi->get_thread_file_descriptor_locker(&file_state, (File) 12, PSI_FILE_READ); |
1372 | ok(file_locker == NULL, "no locker" ); |
1373 | socket_locker= psi->start_socket_wait(&socket_state, socket_A1, PSI_SOCKET_SEND, 12, "foo.cc" , 12); |
1374 | ok(socket_locker == NULL, "no locker" ); |
1375 | |
1376 | unload_performance_schema(); |
1377 | } |
1378 | |
1379 | void test_file_instrumentation_leak() |
1380 | { |
1381 | PSI *psi; |
1382 | |
1383 | diag("test_file_instrumentation_leak" ); |
1384 | |
1385 | psi= load_perfschema(); |
1386 | |
1387 | PSI_file_key file_key_A; |
1388 | PSI_file_key file_key_B; |
1389 | PSI_file_info all_file[]= |
1390 | { |
1391 | { & file_key_A, "F-A" , 0}, |
1392 | { & file_key_B, "F-B" , 0} |
1393 | }; |
1394 | |
1395 | PSI_thread_key thread_key_1; |
1396 | PSI_thread_info all_thread[]= |
1397 | { |
1398 | { & thread_key_1, "T-1" , 0} |
1399 | }; |
1400 | |
1401 | psi->register_file("test" , all_file, 2); |
1402 | psi->register_thread("test" , all_thread, 1); |
1403 | |
1404 | PFS_file_class *file_class_A; |
1405 | PFS_file_class *file_class_B; |
1406 | PSI_file_locker_state file_state; |
1407 | PSI_thread *thread_1; |
1408 | |
1409 | /* Preparation */ |
1410 | |
1411 | thread_1= psi->new_thread(thread_key_1, NULL, 0); |
1412 | ok(thread_1 != NULL, "T-1" ); |
1413 | psi->set_thread_id(thread_1, 1); |
1414 | |
1415 | file_class_A= find_file_class(file_key_A); |
1416 | ok(file_class_A != NULL, "file info A" ); |
1417 | |
1418 | file_class_B= find_file_class(file_key_B); |
1419 | ok(file_class_B != NULL, "file info B" ); |
1420 | |
1421 | psi->set_thread(thread_1); |
1422 | |
1423 | /* Pretend everything is enabled */ |
1424 | /* ----------------------------- */ |
1425 | |
1426 | setup_thread(thread_1, true); |
1427 | flag_events_waits_current= true; |
1428 | file_class_A->m_enabled= true; |
1429 | file_class_B->m_enabled= true; |
1430 | |
1431 | PSI_file_locker *file_locker; |
1432 | |
1433 | /* Simulate OPEN + READ of 100 bytes + CLOSE on descriptor 12 */ |
1434 | |
1435 | file_locker= psi->get_thread_file_name_locker(&file_state, file_key_A, PSI_FILE_OPEN, "AAA" , NULL); |
1436 | ok(file_locker != NULL, "locker" ); |
1437 | psi->start_file_open_wait(file_locker, __FILE__, __LINE__); |
1438 | psi->end_file_open_wait_and_bind_to_descriptor(file_locker, 12); |
1439 | |
1440 | file_locker= psi->get_thread_file_descriptor_locker(&file_state, (File) 12, PSI_FILE_READ); |
1441 | ok(file_locker != NULL, "locker" ); |
1442 | psi->start_file_wait(file_locker, 100, __FILE__, __LINE__); |
1443 | psi->end_file_wait(file_locker, 100); |
1444 | |
1445 | file_locker= psi->get_thread_file_descriptor_locker(&file_state, (File) 12, PSI_FILE_CLOSE); |
1446 | ok(file_locker != NULL, "locker" ); |
1447 | psi->start_file_wait(file_locker, 0, __FILE__, __LINE__); |
1448 | psi->end_file_wait(file_locker, 0); |
1449 | |
1450 | /* Simulate uninstrumented-OPEN + WRITE on descriptor 24 */ |
1451 | |
1452 | file_locker= psi->get_thread_file_descriptor_locker(&file_state, (File) 24, PSI_FILE_WRITE); |
1453 | ok(file_locker == NULL, "no locker, since the open was not instrumented" ); |
1454 | |
1455 | /* |
1456 | Simulate uninstrumented-OPEN + WRITE on descriptor 12 : |
1457 | the instrumentation should not leak (don't charge the file io on unknown B to "AAA") |
1458 | */ |
1459 | |
1460 | file_locker= psi->get_thread_file_descriptor_locker(&file_state, (File) 12, PSI_FILE_WRITE); |
1461 | ok(file_locker == NULL, "no locker, no leak" ); |
1462 | |
1463 | unload_performance_schema(); |
1464 | } |
1465 | |
1466 | void test_enabled() |
1467 | { |
1468 | #ifdef LATER |
1469 | PSI *psi; |
1470 | |
1471 | diag("test_enabled" ); |
1472 | |
1473 | psi= load_perfschema(); |
1474 | |
1475 | PSI_mutex_key mutex_key_A; |
1476 | PSI_mutex_key mutex_key_B; |
1477 | PSI_mutex_info all_mutex[]= |
1478 | { |
1479 | { & mutex_key_A, "M-A" , 0}, |
1480 | { & mutex_key_B, "M-B" , 0} |
1481 | }; |
1482 | |
1483 | PSI_rwlock_key rwlock_key_A; |
1484 | PSI_rwlock_key rwlock_key_B; |
1485 | PSI_rwlock_info all_rwlock[]= |
1486 | { |
1487 | { & rwlock_key_A, "RW-A" , 0}, |
1488 | { & rwlock_key_B, "RW-B" , 0} |
1489 | }; |
1490 | |
1491 | PSI_cond_key cond_key_A; |
1492 | PSI_cond_key cond_key_B; |
1493 | PSI_cond_info all_cond[]= |
1494 | { |
1495 | { & cond_key_A, "C-A" , 0}, |
1496 | { & cond_key_B, "C-B" , 0} |
1497 | }; |
1498 | |
1499 | unload_performance_schema(); |
1500 | #endif |
1501 | } |
1502 | |
1503 | void test_event_name_index() |
1504 | { |
1505 | PSI *psi; |
1506 | PSI_bootstrap *boot; |
1507 | PFS_global_param param; |
1508 | |
1509 | diag("test_event_name_index" ); |
1510 | |
1511 | memset(& param, 0xFF, sizeof(param)); |
1512 | param.m_enabled= true; |
1513 | |
1514 | /* NOTE: Need to add 3 to each index: table io, table lock, idle */ |
1515 | |
1516 | /* Per mutex info waits should be at [0..9] */ |
1517 | param.m_mutex_class_sizing= 10; |
1518 | /* Per rwlock info waits should be at [10..29] */ |
1519 | param.m_rwlock_class_sizing= 20; |
1520 | /* Per cond info waits should be at [30..69] */ |
1521 | param.m_cond_class_sizing= 40; |
1522 | /* Per file info waits should be at [70..149] */ |
1523 | param.m_file_class_sizing= 80; |
1524 | /* Per socket info waits should be at [150..309] */ |
1525 | param.m_socket_class_sizing= 160; |
1526 | /* Per table info waits should be at [310] */ |
1527 | param.m_table_share_sizing= 320; |
1528 | |
1529 | param.m_thread_class_sizing= 0; |
1530 | param.m_user_sizing= 0; |
1531 | param.m_account_sizing= 0; |
1532 | param.m_host_sizing= 0; |
1533 | param.m_stage_class_sizing= 0; |
1534 | param.m_events_stages_history_sizing= 0; |
1535 | param.m_events_stages_history_long_sizing= 0; |
1536 | param.m_statement_class_sizing= 0; |
1537 | param.m_events_statements_history_sizing= 0; |
1538 | param.m_events_statements_history_long_sizing= 0; |
1539 | param.m_digest_sizing= 0; |
1540 | param.m_session_connect_attrs_sizing= 0; |
1541 | param.m_max_digest_length= 0; |
1542 | |
1543 | param.m_mutex_sizing= 0; |
1544 | param.m_rwlock_sizing= 0; |
1545 | param.m_cond_sizing= 0; |
1546 | param.m_thread_sizing= 0; |
1547 | param.m_table_sizing= 0; |
1548 | param.m_file_sizing= 0; |
1549 | param.m_file_handle_sizing= 0; |
1550 | param.m_socket_sizing= 0; |
1551 | param.m_events_waits_history_sizing= 0; |
1552 | param.m_events_waits_history_long_sizing= 0; |
1553 | param.m_setup_actor_sizing= 0; |
1554 | param.m_setup_object_sizing= 0; |
1555 | |
1556 | boot= initialize_performance_schema(& param); |
1557 | ok(boot != NULL, "bootstrap" ); |
1558 | psi= (PSI*) boot->get_interface(PSI_VERSION_1); |
1559 | ok(psi != NULL, "psi" ); |
1560 | |
1561 | PFS_mutex_class *mutex_class; |
1562 | PSI_mutex_key dummy_mutex_key_1; |
1563 | PSI_mutex_key dummy_mutex_key_2; |
1564 | PSI_mutex_info dummy_mutexes[]= |
1565 | { |
1566 | { & dummy_mutex_key_1, "M-1" , 0}, |
1567 | { & dummy_mutex_key_2, "M-2" , 0} |
1568 | }; |
1569 | |
1570 | psi->register_mutex("X" , dummy_mutexes, 2); |
1571 | mutex_class= find_mutex_class(dummy_mutex_key_1); |
1572 | ok(mutex_class != NULL, "mutex class 1" ); |
1573 | ok(mutex_class->m_event_name_index == 3, "index 3" ); |
1574 | mutex_class= find_mutex_class(dummy_mutex_key_2); |
1575 | ok(mutex_class != NULL, "mutex class 2" ); |
1576 | ok(mutex_class->m_event_name_index == 4, "index 4" ); |
1577 | |
1578 | PFS_rwlock_class *rwlock_class; |
1579 | PSI_rwlock_key dummy_rwlock_key_1; |
1580 | PSI_rwlock_key dummy_rwlock_key_2; |
1581 | PSI_rwlock_info dummy_rwlocks[]= |
1582 | { |
1583 | { & dummy_rwlock_key_1, "RW-1" , 0}, |
1584 | { & dummy_rwlock_key_2, "RW-2" , 0} |
1585 | }; |
1586 | |
1587 | psi->register_rwlock("X" , dummy_rwlocks, 2); |
1588 | rwlock_class= find_rwlock_class(dummy_rwlock_key_1); |
1589 | ok(rwlock_class != NULL, "rwlock class 1" ); |
1590 | ok(rwlock_class->m_event_name_index == 13, "index 13" ); |
1591 | rwlock_class= find_rwlock_class(dummy_rwlock_key_2); |
1592 | ok(rwlock_class != NULL, "rwlock class 2" ); |
1593 | ok(rwlock_class->m_event_name_index == 14, "index 14" ); |
1594 | |
1595 | PFS_cond_class *cond_class; |
1596 | PSI_cond_key dummy_cond_key_1; |
1597 | PSI_cond_key dummy_cond_key_2; |
1598 | PSI_cond_info dummy_conds[]= |
1599 | { |
1600 | { & dummy_cond_key_1, "C-1" , 0}, |
1601 | { & dummy_cond_key_2, "C-2" , 0} |
1602 | }; |
1603 | |
1604 | psi->register_cond("X" , dummy_conds, 2); |
1605 | cond_class= find_cond_class(dummy_cond_key_1); |
1606 | ok(cond_class != NULL, "cond class 1" ); |
1607 | ok(cond_class->m_event_name_index == 33, "index 33" ); |
1608 | cond_class= find_cond_class(dummy_cond_key_2); |
1609 | ok(cond_class != NULL, "cond class 2" ); |
1610 | ok(cond_class->m_event_name_index == 34, "index 34" ); |
1611 | |
1612 | PFS_file_class *file_class; |
1613 | PSI_file_key dummy_file_key_1; |
1614 | PSI_file_key dummy_file_key_2; |
1615 | PSI_file_info dummy_files[]= |
1616 | { |
1617 | { & dummy_file_key_1, "F-1" , 0}, |
1618 | { & dummy_file_key_2, "F-2" , 0} |
1619 | }; |
1620 | |
1621 | psi->register_file("X" , dummy_files, 2); |
1622 | file_class= find_file_class(dummy_file_key_1); |
1623 | ok(file_class != NULL, "file class 1" ); |
1624 | ok(file_class->m_event_name_index == 73, "index 73" ); |
1625 | file_class= find_file_class(dummy_file_key_2); |
1626 | ok(file_class != NULL, "file class 2" ); |
1627 | ok(file_class->m_event_name_index == 74, "index 74" ); |
1628 | |
1629 | PFS_socket_class *socket_class; |
1630 | PSI_socket_key dummy_socket_key_1; |
1631 | PSI_socket_key dummy_socket_key_2; |
1632 | PSI_socket_info dummy_sockets[]= |
1633 | { |
1634 | { & dummy_socket_key_1, "S-1" , 0}, |
1635 | { & dummy_socket_key_2, "S-2" , 0} |
1636 | }; |
1637 | |
1638 | psi->register_socket("X" , dummy_sockets, 2); |
1639 | socket_class= find_socket_class(dummy_socket_key_1); |
1640 | ok(socket_class != NULL, "socket class 1" ); |
1641 | ok(socket_class->m_event_name_index == 153, "index 153" ); |
1642 | socket_class= find_socket_class(dummy_socket_key_2); |
1643 | ok(socket_class != NULL, "socket class 2" ); |
1644 | ok(socket_class->m_event_name_index == 154, "index 154" ); |
1645 | |
1646 | ok(global_table_io_class.m_event_name_index == 0, "index 0" ); |
1647 | ok(global_table_lock_class.m_event_name_index == 1, "index 1" ); |
1648 | ok(wait_class_max= 313, "313 event names" ); // 3 global classes |
1649 | } |
1650 | |
1651 | void do_all_tests() |
1652 | { |
1653 | /* Using initialize_performance_schema(), no partial init needed. */ |
1654 | |
1655 | test_bootstrap(); |
1656 | test_bad_registration(); |
1657 | test_init_disabled(); |
1658 | test_locker_disabled(); |
1659 | test_file_instrumentation_leak(); |
1660 | test_event_name_index(); |
1661 | } |
1662 | |
1663 | int main(int argc, char **argv) |
1664 | { |
1665 | plan(216); |
1666 | MY_INIT(argv[0]); |
1667 | do_all_tests(); |
1668 | my_end(0); |
1669 | return (exit_status()); |
1670 | } |
1671 | |