16 #include <my_global.h>
17 #include <my_pthread.h>
27 #include "stub_print_error.h"
28 #include "stub_pfs_defaults.h"
29 #include "stub_server_misc.h"
33 void setup_thread(PSI_thread *t,
bool enabled)
45 uint len= strlen(name);
48 uint filename_length;;
63 if ((len == filename_length) &&
64 (strncmp(name, filename, filename_length) == 0))
81 diag(
"test_bootstrap");
83 memset(& param, 0xFF,
sizeof(param));
117 ok(boot != NULL,
"boot");
121 ok(psi == NULL,
"no version 0");
124 ok(psi != NULL,
"version 1");
127 ok(psi_2 == NULL,
"version 2");
135 PSI * load_perfschema()
141 memset(& param, 0xFF,
sizeof(param));
185 void test_bad_registration()
189 diag(
"test_bad_registration");
191 psi= load_perfschema();
198 PSI_mutex_key dummy_mutex_key= 9999;
199 PSI_mutex_info bad_mutex_1[]=
201 { & dummy_mutex_key,
"X", 0}
204 psi->register_mutex(
"/", bad_mutex_1, 1);
205 ok(dummy_mutex_key == 0,
"zero key");
206 dummy_mutex_key= 9999;
207 psi->register_mutex(
"a/", bad_mutex_1, 1);
208 ok(dummy_mutex_key == 0,
"zero key");
209 dummy_mutex_key= 9999;
210 psi->register_mutex(
"/b", bad_mutex_1, 1);
211 ok(dummy_mutex_key == 0,
"zero key");
212 dummy_mutex_key= 9999;
213 psi->register_mutex(
"a/b", bad_mutex_1, 1);
214 ok(dummy_mutex_key == 0,
"zero key");
215 dummy_mutex_key= 9999;
216 psi->register_mutex(
"12345678901234", bad_mutex_1, 1);
217 ok(dummy_mutex_key == 0,
"zero key");
218 dummy_mutex_key= 9999;
219 psi->register_mutex(
"1234567890123", bad_mutex_1, 1);
220 ok(dummy_mutex_key == 1,
"assigned key");
227 dummy_mutex_key= 9999;
228 PSI_mutex_info bad_mutex_2[]=
232 "12345678901234567890123456789012345678901234567890"
233 "12345678901234567890123456789012345678901234567890"
238 psi->register_mutex(
"X", bad_mutex_2, 1);
239 ok(dummy_mutex_key == 0,
"zero key");
241 dummy_mutex_key= 9999;
242 PSI_mutex_info bad_mutex_3[]=
246 "12345678901234567890123456789012345678901234567890"
247 "12345678901234567890123456789012345678901234567890"
252 psi->register_mutex(
"XX", bad_mutex_3, 1);
253 ok(dummy_mutex_key == 0,
"zero key");
255 psi->register_mutex(
"X", bad_mutex_3, 1);
256 ok(dummy_mutex_key == 2,
"assigned key");
263 PSI_rwlock_key dummy_rwlock_key= 9999;
264 PSI_rwlock_info bad_rwlock_1[]=
266 { & dummy_rwlock_key,
"X", 0}
269 psi->register_rwlock(
"/", bad_rwlock_1, 1);
270 ok(dummy_rwlock_key == 0,
"zero key");
271 dummy_rwlock_key= 9999;
272 psi->register_rwlock(
"a/", bad_rwlock_1, 1);
273 ok(dummy_rwlock_key == 0,
"zero key");
274 dummy_rwlock_key= 9999;
275 psi->register_rwlock(
"/b", bad_rwlock_1, 1);
276 ok(dummy_rwlock_key == 0,
"zero key");
277 dummy_rwlock_key= 9999;
278 psi->register_rwlock(
"a/b", bad_rwlock_1, 1);
279 ok(dummy_rwlock_key == 0,
"zero key");
280 dummy_rwlock_key= 9999;
281 psi->register_rwlock(
"1234567890123", bad_rwlock_1, 1);
282 ok(dummy_rwlock_key == 0,
"zero key");
283 dummy_rwlock_key= 9999;
284 psi->register_rwlock(
"123456789012", bad_rwlock_1, 1);
285 ok(dummy_rwlock_key == 1,
"assigned key");
292 dummy_rwlock_key= 9999;
293 PSI_rwlock_info bad_rwlock_2[]=
295 { & dummy_rwlock_key,
297 "12345678901234567890123456789012345678901234567890"
298 "12345678901234567890123456789012345678901234567890"
303 psi->register_rwlock(
"X", bad_rwlock_2, 1);
304 ok(dummy_rwlock_key == 0,
"zero key");
306 dummy_rwlock_key= 9999;
307 PSI_rwlock_info bad_rwlock_3[]=
309 { & dummy_rwlock_key,
311 "12345678901234567890123456789012345678901234567890"
312 "12345678901234567890123456789012345678901234567890"
317 psi->register_rwlock(
"XX", bad_rwlock_3, 1);
318 ok(dummy_rwlock_key == 0,
"zero key");
320 psi->register_rwlock(
"X", bad_rwlock_3, 1);
321 ok(dummy_rwlock_key == 2,
"assigned key");
328 PSI_cond_key dummy_cond_key= 9999;
329 PSI_cond_info bad_cond_1[]=
331 { & dummy_cond_key,
"X", 0}
334 psi->register_cond(
"/", bad_cond_1, 1);
335 ok(dummy_cond_key == 0,
"zero key");
336 dummy_cond_key= 9999;
337 psi->register_cond(
"a/", bad_cond_1, 1);
338 ok(dummy_cond_key == 0,
"zero key");
339 dummy_cond_key= 9999;
340 psi->register_cond(
"/b", bad_cond_1, 1);
341 ok(dummy_cond_key == 0,
"zero key");
342 dummy_cond_key= 9999;
343 psi->register_cond(
"a/b", bad_cond_1, 1);
344 ok(dummy_cond_key == 0,
"zero key");
345 dummy_cond_key= 9999;
346 psi->register_cond(
"123456789012345", bad_cond_1, 1);
347 ok(dummy_cond_key == 0,
"zero key");
348 dummy_cond_key= 9999;
349 psi->register_cond(
"12345678901234", bad_cond_1, 1);
350 ok(dummy_cond_key == 1,
"assigned key");
357 dummy_cond_key= 9999;
358 PSI_cond_info bad_cond_2[]=
362 "12345678901234567890123456789012345678901234567890"
363 "12345678901234567890123456789012345678901234567890"
368 psi->register_cond(
"X", bad_cond_2, 1);
369 ok(dummy_cond_key == 0,
"zero key");
371 dummy_cond_key= 9999;
372 PSI_cond_info bad_cond_3[]=
376 "12345678901234567890123456789012345678901234567890"
377 "12345678901234567890123456789012345678901234567890"
382 psi->register_cond(
"XX", bad_cond_3, 1);
383 ok(dummy_cond_key == 0,
"zero key");
385 psi->register_cond(
"X", bad_cond_3, 1);
386 ok(dummy_cond_key == 2,
"assigned key");
393 PSI_thread_key dummy_thread_key= 9999;
394 PSI_thread_info bad_thread_1[]=
396 { & dummy_thread_key,
"X", 0}
399 psi->register_thread(
"/", bad_thread_1, 1);
400 ok(dummy_thread_key == 0,
"zero key");
401 dummy_thread_key= 9999;
402 psi->register_thread(
"a/", bad_thread_1, 1);
403 ok(dummy_thread_key == 0,
"zero key");
404 dummy_thread_key= 9999;
405 psi->register_thread(
"/b", bad_thread_1, 1);
406 ok(dummy_thread_key == 0,
"zero key");
407 dummy_thread_key= 9999;
408 psi->register_thread(
"a/b", bad_thread_1, 1);
409 ok(dummy_thread_key == 0,
"zero key");
410 dummy_thread_key= 9999;
411 psi->register_thread(
"123456789012345678901234", bad_thread_1, 1);
412 ok(dummy_thread_key == 0,
"zero key");
413 dummy_thread_key= 9999;
414 psi->register_thread(
"12345678901234567890123", bad_thread_1, 1);
415 ok(dummy_thread_key == 1,
"assigned key");
422 dummy_thread_key= 9999;
423 PSI_thread_info bad_thread_2[]=
425 { & dummy_thread_key,
427 "12345678901234567890123456789012345678901234567890"
428 "12345678901234567890123456789012345678901234567890"
429 "12345678901234567890",
433 psi->register_thread(
"X", bad_thread_2, 1);
434 ok(dummy_thread_key == 0,
"zero key");
436 dummy_thread_key= 9999;
437 PSI_thread_info bad_thread_3[]=
439 { & dummy_thread_key,
441 "12345678901234567890123456789012345678901234567890"
442 "12345678901234567890123456789012345678901234567890"
443 "1234567890123456789",
447 psi->register_thread(
"XX", bad_thread_3, 1);
448 ok(dummy_thread_key == 0,
"zero key");
450 psi->register_thread(
"X", bad_thread_3, 1);
451 ok(dummy_thread_key == 2,
"assigned key");
458 PSI_file_key dummy_file_key= 9999;
459 PSI_file_info bad_file_1[]=
461 { & dummy_file_key,
"X", 0}
464 psi->register_file(
"/", bad_file_1, 1);
465 ok(dummy_file_key == 0,
"zero key");
466 dummy_file_key= 9999;
467 psi->register_file(
"a/", bad_file_1, 1);
468 ok(dummy_file_key == 0,
"zero key");
469 dummy_file_key= 9999;
470 psi->register_file(
"/b", bad_file_1, 1);
471 ok(dummy_file_key == 0,
"zero key");
472 dummy_file_key= 9999;
473 psi->register_file(
"a/b", bad_file_1, 1);
474 ok(dummy_file_key == 0,
"zero key");
475 dummy_file_key= 9999;
476 psi->register_file(
"123456789012345678", bad_file_1, 1);
477 ok(dummy_file_key == 0,
"zero key");
478 dummy_file_key= 9999;
479 psi->register_file(
"12345678901234567", bad_file_1, 1);
480 ok(dummy_file_key == 1,
"assigned key");
487 dummy_file_key= 9999;
488 PSI_file_info bad_file_2[]=
492 "12345678901234567890123456789012345678901234567890"
493 "12345678901234567890123456789012345678901234567890"
498 psi->register_file(
"X", bad_file_2, 1);
499 ok(dummy_file_key == 0,
"zero key");
501 dummy_file_key= 9999;
502 PSI_file_info bad_file_3[]=
506 "12345678901234567890123456789012345678901234567890"
507 "12345678901234567890123456789012345678901234567890"
512 psi->register_file(
"XX", bad_file_3, 1);
513 ok(dummy_file_key == 0,
"zero key");
515 psi->register_file(
"X", bad_file_3, 1);
516 ok(dummy_file_key == 2,
"assigned key");
523 PSI_socket_key dummy_socket_key= 9999;
524 PSI_socket_info bad_socket_1[]=
526 { & dummy_socket_key,
"X", 0}
529 psi->register_socket(
"/", bad_socket_1, 1);
530 ok(dummy_socket_key == 0,
"zero key");
531 dummy_socket_key= 9999;
532 psi->register_socket(
"a/", bad_socket_1, 1);
533 ok(dummy_socket_key == 0,
"zero key");
534 dummy_socket_key= 9999;
535 psi->register_socket(
"/b", bad_socket_1, 1);
536 ok(dummy_socket_key == 0,
"zero key");
537 dummy_socket_key= 9999;
538 psi->register_socket(
"a/b", bad_socket_1, 1);
539 ok(dummy_socket_key == 0,
"zero key");
540 dummy_socket_key= 9999;
541 psi->register_socket(
"1234567890123456", bad_socket_1, 1);
542 ok(dummy_socket_key == 0,
"zero key");
543 dummy_socket_key= 9999;
544 psi->register_socket(
"123456789012345", bad_socket_1, 1);
545 ok(dummy_socket_key == 1,
"assigned key");
552 dummy_socket_key= 9999;
553 PSI_socket_info bad_socket_2[]=
555 { & dummy_socket_key,
557 "12345678901234567890123456789012345678901234567890"
558 "12345678901234567890123456789012345678901234567890"
563 psi->register_socket(
"X", bad_socket_2, 1);
564 ok(dummy_socket_key == 0,
"zero key");
566 dummy_socket_key= 9999;
567 PSI_socket_info bad_socket_3[]=
569 { & dummy_socket_key,
571 "12345678901234567890123456789012345678901234567890"
572 "12345678901234567890123456789012345678901234567890"
577 psi->register_socket(
"XX", bad_socket_3, 1);
578 ok(dummy_socket_key == 0,
"zero key");
580 psi->register_socket(
"X", bad_socket_3, 1);
581 ok(dummy_socket_key == 2,
"assigned key");
587 void test_init_disabled()
591 diag(
"test_init_disabled");
593 psi= load_perfschema();
595 PSI_mutex_key mutex_key_A;
596 PSI_mutex_info all_mutex[]=
598 { & mutex_key_A,
"M-A", 0}
601 PSI_rwlock_key rwlock_key_A;
602 PSI_rwlock_info all_rwlock[]=
604 { & rwlock_key_A,
"RW-A", 0}
607 PSI_cond_key cond_key_A;
608 PSI_cond_info all_cond[]=
610 { & cond_key_A,
"C-A", 0}
613 PSI_file_key file_key_A;
614 PSI_file_info all_file[]=
616 { & file_key_A,
"F-A", 0}
619 PSI_socket_key socket_key_A;
620 PSI_socket_info all_socket[]=
622 { & socket_key_A,
"S-A", 0}
625 PSI_thread_key thread_key_1;
626 PSI_thread_info all_thread[]=
628 { & thread_key_1,
"T-1", 0}
631 psi->register_mutex(
"test", all_mutex, 1);
632 psi->register_rwlock(
"test", all_rwlock, 1);
633 psi->register_cond(
"test", all_cond, 1);
634 psi->register_file(
"test", all_file, 1);
635 psi->register_socket(
"test", all_socket, 1);
636 psi->register_thread(
"test", all_thread, 1);
644 PSI_rwlock *rwlock_A1;
647 PSI_socket *socket_A1;
648 PSI_thread *thread_1;
652 thread_1= psi->new_thread(thread_key_1, NULL, 0);
653 ok(thread_1 != NULL,
"T-1");
654 psi->set_thread_id(thread_1, 1);
657 ok(mutex_class_A != NULL,
"mutex class A");
660 ok(rwlock_class_A != NULL,
"rwlock class A");
663 ok(cond_class_A != NULL,
"cond class A");
666 ok(file_class_A != NULL,
"file class A");
669 ok(socket_class_A != NULL,
"socket class A");
674 psi->set_thread(thread_1);
675 setup_thread(thread_1,
false);
680 mutex_A1= psi->init_mutex(mutex_key_A, NULL);
681 ok(mutex_A1 == NULL,
"mutex_A1 not instrumented");
686 mutex_A1= psi->init_mutex(mutex_key_A, NULL);
687 ok(mutex_A1 != NULL,
"mutex_A1 instrumented");
692 mutex_A1= psi->init_mutex(0, NULL);
693 ok(mutex_A1 == NULL,
"mutex key 0 not instrumented");
694 mutex_A1= psi->init_mutex(99, NULL);
695 ok(mutex_A1 == NULL,
"broken mutex key not instrumented");
700 rwlock_A1= psi->init_rwlock(rwlock_key_A, NULL);
701 ok(rwlock_A1 == NULL,
"rwlock_A1 not instrumented");
706 rwlock_A1= psi->init_rwlock(rwlock_key_A, NULL);
707 ok(rwlock_A1 != NULL,
"rwlock_A1 instrumented");
712 rwlock_A1= psi->init_rwlock(0, NULL);
713 ok(rwlock_A1 == NULL,
"rwlock key 0 not instrumented");
714 rwlock_A1= psi->init_rwlock(99, NULL);
715 ok(rwlock_A1 == NULL,
"broken rwlock key not instrumented");
720 cond_A1= psi->init_cond(cond_key_A, NULL);
721 ok(cond_A1 == NULL,
"cond_A1 not instrumented");
726 cond_A1= psi->init_cond(cond_key_A, NULL);
727 ok(cond_A1 != NULL,
"cond_A1 instrumented");
732 cond_A1= psi->init_cond(0, NULL);
733 ok(cond_A1 == NULL,
"cond key 0 not instrumented");
734 cond_A1= psi->init_cond(99, NULL);
735 ok(cond_A1 == NULL,
"broken cond key not instrumented");
740 psi->create_file(file_key_A,
"foo", (File) 12);
741 file_A1= lookup_file_by_name(
"foo");
742 ok(file_A1 == NULL,
"not instrumented");
747 psi->create_file(file_key_A,
"foo", (File) 12);
748 file_A1= lookup_file_by_name(
"foo");
749 ok(file_A1 == NULL,
"not instrumented");
754 psi->create_file(0,
"foo", (File) 12);
755 file_A1= lookup_file_by_name(
"foo");
756 ok(file_A1 == NULL,
"not instrumented");
757 psi->create_file(99,
"foo", (File) 12);
758 file_A1= lookup_file_by_name(
"foo");
759 ok(file_A1 == NULL,
"not instrumented");
764 socket_A1= psi->init_socket(socket_key_A, NULL, NULL, 0);
765 ok(socket_A1 == NULL,
"socket_A1 not instrumented");
770 socket_A1= psi->init_socket(socket_key_A, NULL, NULL, 0);
771 ok(socket_A1 != NULL,
"socket_A1 instrumented");
776 socket_A1= psi->init_socket(0, NULL, NULL, 0);
777 ok(socket_A1 == NULL,
"socket key 0 not instrumented");
778 socket_A1= psi->init_socket(99, NULL, NULL, 0);
779 ok(socket_A1 == NULL,
"broken socket key not instrumented");
784 setup_thread(thread_1,
true);
789 mutex_A1= psi->init_mutex(mutex_key_A, NULL);
790 ok(mutex_A1 == NULL,
"not instrumented");
795 mutex_A1= psi->init_mutex(mutex_key_A, NULL);
796 ok(mutex_A1 != NULL,
"instrumented");
797 psi->destroy_mutex(mutex_A1);
802 mutex_A1= psi->init_mutex(0, NULL);
803 ok(mutex_A1 == NULL,
"not instrumented");
804 mutex_A1= psi->init_mutex(99, NULL);
805 ok(mutex_A1 == NULL,
"not instrumented");
810 rwlock_A1= psi->init_rwlock(rwlock_key_A, NULL);
811 ok(rwlock_A1 == NULL,
"not instrumented");
816 rwlock_A1= psi->init_rwlock(rwlock_key_A, NULL);
817 ok(rwlock_A1 != NULL,
"instrumented");
818 psi->destroy_rwlock(rwlock_A1);
823 rwlock_A1= psi->init_rwlock(0, NULL);
824 ok(rwlock_A1 == NULL,
"not instrumented");
825 rwlock_A1= psi->init_rwlock(99, NULL);
826 ok(rwlock_A1 == NULL,
"not instrumented");
831 cond_A1= psi->init_cond(cond_key_A, NULL);
832 ok(cond_A1 == NULL,
"not instrumented");
837 cond_A1= psi->init_cond(cond_key_A, NULL);
838 ok(cond_A1 != NULL,
"instrumented");
839 psi->destroy_cond(cond_A1);
844 cond_A1= psi->init_cond(0, NULL);
845 ok(cond_A1 == NULL,
"not instrumented");
846 cond_A1= psi->init_cond(99, NULL);
847 ok(cond_A1 == NULL,
"not instrumented");
852 psi->create_file(file_key_A,
"foo", (File) 12);
853 file_A1= lookup_file_by_name(
"foo");
854 ok(file_A1 == NULL,
"not instrumented");
859 psi->create_file(file_key_A,
"foo", (File) -1);
860 file_A1= lookup_file_by_name(
"foo");
861 ok(file_A1 == NULL,
"not instrumented");
866 psi->create_file(file_key_A,
"foo", (File) 65000);
867 file_A1= lookup_file_by_name(
"foo");
868 ok(file_A1 == NULL,
"not instrumented");
875 psi->create_file(file_key_A,
"foo-instrumented", (File) 12);
876 file_A1= lookup_file_by_name(
"foo-instrumented");
877 ok(file_A1 != NULL,
"file_A1 instrumented");
882 psi->create_file(0,
"foo", (File) 12);
883 file_A1= lookup_file_by_name(
"foo");
884 ok(file_A1 == NULL,
"file key 0 not instrumented");
885 psi->create_file(99,
"foo", (File) 12);
886 file_A1= lookup_file_by_name(
"foo");
887 ok(file_A1 == NULL,
"broken file key not instrumented");
892 ok(socket_A1 == NULL,
"not instrumented");
897 socket_A1= psi->init_socket(socket_key_A, NULL, NULL, 0);
898 ok(socket_A1 != NULL,
"instrumented");
899 psi->destroy_socket(socket_A1);
904 socket_A1= psi->init_socket(0, NULL, NULL, 0);
905 ok(socket_A1 == NULL,
"not instrumented");
906 socket_A1= psi->init_socket(99, NULL, NULL, 0);
907 ok(socket_A1 == NULL,
"not instrumented");
912 psi->delete_current_thread();
917 mutex_A1= psi->init_mutex(mutex_key_A, NULL);
918 ok(mutex_A1 == NULL,
"mutex_A1 not instrumented");
923 mutex_A1= psi->init_mutex(mutex_key_A, NULL);
924 ok(mutex_A1 != NULL,
"mutex_A1 instrumented");
929 mutex_A1= psi->init_mutex(0, NULL);
930 ok(mutex_A1 == NULL,
"mutex key 0 not instrumented");
931 mutex_A1= psi->init_mutex(99, NULL);
932 ok(mutex_A1 == NULL,
"broken mutex key not instrumented");
937 rwlock_A1= psi->init_rwlock(rwlock_key_A, NULL);
938 ok(rwlock_A1 == NULL,
"rwlock_A1 not instrumented");
943 rwlock_A1= psi->init_rwlock(rwlock_key_A, NULL);
944 ok(rwlock_A1 != NULL,
"rwlock_A1 instrumented");
949 rwlock_A1= psi->init_rwlock(0, NULL);
950 ok(rwlock_A1 == NULL,
"rwlock key 0 not instrumented");
951 rwlock_A1= psi->init_rwlock(99, NULL);
952 ok(rwlock_A1 == NULL,
"broken rwlock key not instrumented");
957 cond_A1= psi->init_cond(cond_key_A, NULL);
958 ok(cond_A1 == NULL,
"cond_A1 not instrumented");
963 cond_A1= psi->init_cond(cond_key_A, NULL);
964 ok(cond_A1 != NULL,
"cond_A1 instrumented");
969 cond_A1= psi->init_cond(0, NULL);
970 ok(cond_A1 == NULL,
"cond key 0 not instrumented");
971 cond_A1= psi->init_cond(99, NULL);
972 ok(cond_A1 == NULL,
"broken cond key not instrumented");
977 psi->create_file(file_key_A,
"foo", (File) 12);
978 file_A1= lookup_file_by_name(
"foo");
979 ok(file_A1 == NULL,
"not instrumented");
984 psi->create_file(file_key_A,
"foo", (File) 12);
985 file_A1= lookup_file_by_name(
"foo");
986 ok(file_A1 == NULL,
"not instrumented");
991 psi->create_file(0,
"foo", (File) 12);
992 file_A1= lookup_file_by_name(
"foo");
993 ok(file_A1 == NULL,
"not instrumented");
994 psi->create_file(99,
"foo", (File) 12);
995 file_A1= lookup_file_by_name(
"foo");
996 ok(file_A1 == NULL,
"not instrumented");
1001 socket_A1= psi->init_socket(socket_key_A, NULL, NULL, 0);
1002 ok(socket_A1 == NULL,
"socket_A1 not instrumented");
1007 socket_A1= psi->init_socket(socket_key_A, NULL, NULL, 0);
1008 ok(socket_A1 != NULL,
"socket_A1 instrumented");
1013 socket_A1= psi->init_socket(0, NULL, NULL, 0);
1014 ok(socket_A1 == NULL,
"socket key 0 not instrumented");
1015 socket_A1= psi->init_socket(99, NULL, NULL, 0);
1016 ok(socket_A1 == NULL,
"broken socket key not instrumented");
1021 void test_locker_disabled()
1025 diag(
"test_locker_disabled");
1027 psi= load_perfschema();
1029 PSI_mutex_key mutex_key_A;
1030 PSI_mutex_info all_mutex[]=
1032 { & mutex_key_A,
"M-A", 0}
1035 PSI_rwlock_key rwlock_key_A;
1036 PSI_rwlock_info all_rwlock[]=
1038 { & rwlock_key_A,
"RW-A", 0}
1041 PSI_cond_key cond_key_A;
1042 PSI_cond_info all_cond[]=
1044 { & cond_key_A,
"C-A", 0}
1047 PSI_file_key file_key_A;
1048 PSI_file_info all_file[]=
1050 { & file_key_A,
"F-A", 0}
1053 PSI_socket_key socket_key_A;
1054 PSI_socket_info all_socket[]=
1056 { & socket_key_A,
"S-A", 0}
1059 PSI_thread_key thread_key_1;
1060 PSI_thread_info all_thread[]=
1062 { & thread_key_1,
"T-1", 0}
1065 psi->register_mutex(
"test", all_mutex, 1);
1066 psi->register_rwlock(
"test", all_rwlock, 1);
1067 psi->register_cond(
"test", all_cond, 1);
1068 psi->register_file(
"test", all_file, 1);
1069 psi->register_socket(
"test", all_socket, 1);
1070 psi->register_thread(
"test", all_thread, 1);
1077 PSI_mutex *mutex_A1;
1078 PSI_rwlock *rwlock_A1;
1081 PSI_socket *socket_A1;
1082 PSI_thread *thread_1;
1086 thread_1= psi->new_thread(thread_key_1, NULL, 0);
1087 ok(thread_1 != NULL,
"T-1");
1088 psi->set_thread_id(thread_1, 1);
1091 ok(mutex_class_A != NULL,
"mutex info A");
1094 ok(rwlock_class_A != NULL,
"rwlock info A");
1097 ok(cond_class_A != NULL,
"cond info A");
1100 ok(file_class_A != NULL,
"file info A");
1103 ok(socket_class_A != NULL,
"socket info A");
1108 psi->set_thread(thread_1);
1109 setup_thread(thread_1,
true);
1114 mutex_A1= psi->init_mutex(mutex_key_A, NULL);
1115 ok(mutex_A1 != NULL,
"instrumented");
1118 rwlock_A1= psi->init_rwlock(rwlock_key_A, NULL);
1119 ok(rwlock_A1 != NULL,
"instrumented");
1122 cond_A1= psi->init_cond(cond_key_A, NULL);
1123 ok(cond_A1 != NULL,
"instrumented");
1126 psi->create_file(file_key_A,
"foo", (File) 12);
1127 file_A1= (PSI_file*) lookup_file_by_name(
"foo");
1128 ok(file_A1 != NULL,
"instrumented");
1131 socket_A1= psi->init_socket(socket_key_A, NULL, NULL, 0);
1132 ok(socket_A1 != NULL,
"instrumented");
1135 psi->set_socket_thread_owner(socket_A1);
1137 PSI_mutex_locker *mutex_locker;
1138 PSI_mutex_locker_state mutex_state;
1139 PSI_rwlock_locker *rwlock_locker;
1140 PSI_rwlock_locker_state rwlock_state;
1141 PSI_cond_locker *cond_locker;
1142 PSI_cond_locker_state cond_state;
1143 PSI_file_locker *file_locker;
1144 PSI_file_locker_state file_state;
1145 PSI_socket_locker *socket_locker;
1146 PSI_socket_locker_state socket_state;
1151 setup_thread(thread_1,
false);
1159 mutex_locker= psi->start_mutex_wait(&mutex_state, mutex_A1, PSI_MUTEX_LOCK,
"foo.cc", 12);
1160 ok(mutex_locker == NULL,
"no locker (T-1 disabled)");
1161 rwlock_locker= psi->start_rwlock_rdwait(&rwlock_state, rwlock_A1, PSI_RWLOCK_READLOCK,
"foo.cc", 12);
1162 ok(rwlock_locker == NULL,
"no locker (T-1 disabled)");
1163 cond_locker= psi->start_cond_wait(&cond_state, cond_A1, mutex_A1, PSI_COND_WAIT,
"foo.cc", 12);
1164 ok(cond_locker == NULL,
"no locker (T-1 disabled)");
1165 file_locker= psi->get_thread_file_name_locker(&file_state, file_key_A, PSI_FILE_OPEN,
"xxx", NULL);
1166 ok(file_locker == NULL,
"no locker (T-1 disabled)");
1167 file_locker= psi->get_thread_file_stream_locker(&file_state, file_A1, PSI_FILE_READ);
1168 ok(file_locker == NULL,
"no locker (T-1 disabled)");
1169 file_locker= psi->get_thread_file_descriptor_locker(&file_state, (File) 12, PSI_FILE_READ);
1170 ok(file_locker == NULL,
"no locker (T-1 disabled)");
1171 socket_locker= psi->start_socket_wait(&socket_state, socket_A1, PSI_SOCKET_SEND, 12,
"foo.cc", 12);
1172 ok(socket_locker == NULL,
"no locker (T-1 disabled)");
1177 setup_thread(thread_1,
true);
1186 mutex_locker= psi->start_mutex_wait(&mutex_state, mutex_A1, PSI_MUTEX_LOCK,
"foo.cc", 12);
1187 ok(mutex_locker == NULL,
"no locker (global disabled)");
1188 rwlock_locker= psi->start_rwlock_rdwait(&rwlock_state, rwlock_A1, PSI_RWLOCK_READLOCK,
"foo.cc", 12);
1189 ok(rwlock_locker == NULL,
"no locker (global disabled)");
1190 cond_locker= psi->start_cond_wait(&cond_state, cond_A1, mutex_A1, PSI_COND_WAIT,
"foo.cc", 12);
1191 ok(cond_locker == NULL,
"no locker (global disabled)");
1192 file_locker= psi->get_thread_file_name_locker(&file_state, file_key_A, PSI_FILE_OPEN,
"xxx", NULL);
1193 ok(file_locker == NULL,
"no locker (global disabled)");
1194 file_locker= psi->get_thread_file_stream_locker(&file_state, file_A1, PSI_FILE_READ);
1195 ok(file_locker == NULL,
"no locker (global disabled)");
1196 file_locker= psi->get_thread_file_descriptor_locker(&file_state, (File) 12, PSI_FILE_READ);
1197 ok(file_locker == NULL,
"no locker (global disabled)");
1198 socket_locker= psi->start_socket_wait(&socket_state, socket_A1, PSI_SOCKET_SEND, 12,
"foo.cc", 12);
1199 ok(socket_locker == NULL,
"no locker (global disabled)");
1204 setup_thread(thread_1,
true);
1208 mutex_class_A->
m_timed=
false;
1210 rwlock_class_A->
m_timed=
false;
1216 socket_class_A->
m_timed=
false;
1219 mutex_locker= psi->start_mutex_wait(&mutex_state, mutex_A1, PSI_MUTEX_LOCK,
"foo.cc", 12);
1220 ok(mutex_locker == NULL,
"no locker (global counted)");
1221 rwlock_locker= psi->start_rwlock_rdwait(&rwlock_state, rwlock_A1, PSI_RWLOCK_READLOCK,
"foo.cc", 12);
1222 ok(rwlock_locker == NULL,
"no locker (global counted)");
1223 cond_locker= psi->start_cond_wait(&cond_state, cond_A1, mutex_A1, PSI_COND_WAIT,
"foo.cc", 12);
1224 ok(cond_locker == NULL,
"no locker (global counted)");
1225 file_locker= psi->get_thread_file_name_locker(&file_state, file_key_A, PSI_FILE_OPEN,
"xxx", NULL);
1226 ok(file_locker != NULL,
"locker (global counted)");
1227 psi->start_file_wait(file_locker, 10, __FILE__, __LINE__);
1228 psi->end_file_wait(file_locker, 10);
1229 file_locker= psi->get_thread_file_stream_locker(&file_state, file_A1, PSI_FILE_READ);
1230 ok(file_locker != NULL,
"locker (global counted)");
1231 psi->start_file_wait(file_locker, 10, __FILE__, __LINE__);
1232 psi->end_file_wait(file_locker, 10);
1233 file_locker= psi->get_thread_file_descriptor_locker(&file_state, (File) 12, PSI_FILE_READ);
1234 ok(file_locker != NULL,
"locker (global counted)");
1235 psi->start_file_wait(file_locker, 10, __FILE__, __LINE__);
1236 psi->end_file_wait(file_locker, 10);
1238 socket_locker= psi->start_socket_wait(&socket_state, socket_A1, PSI_SOCKET_BIND, 0,
"foo.cc", 12);
1239 ok(socket_locker == NULL,
"no locker (global counted)");
1246 setup_thread(thread_1,
true);
1256 mutex_locker= psi->start_mutex_wait(&mutex_state, mutex_A1, PSI_MUTEX_LOCK,
"foo.cc", 12);
1257 ok(mutex_locker == NULL,
"no locker");
1258 rwlock_locker= psi->start_rwlock_rdwait(&rwlock_state, rwlock_A1, PSI_RWLOCK_READLOCK,
"foo.cc", 12);
1259 ok(rwlock_locker == NULL,
"no locker");
1260 cond_locker= psi->start_cond_wait(&cond_state, cond_A1, mutex_A1, PSI_COND_WAIT,
"foo.cc", 12);
1261 ok(cond_locker == NULL,
"no locker");
1262 file_locker= psi->get_thread_file_name_locker(&file_state, file_key_A, PSI_FILE_OPEN,
"xxx", NULL);
1263 ok(file_locker == NULL,
"no locker");
1264 file_locker= psi->get_thread_file_stream_locker(&file_state, file_A1, PSI_FILE_READ);
1265 ok(file_locker == NULL,
"no locker");
1266 file_locker= psi->get_thread_file_descriptor_locker(&file_state, (File) 12, PSI_FILE_READ);
1267 ok(file_locker == NULL,
"no locker");
1268 socket_locker= psi->start_socket_wait(&socket_state, socket_A1, PSI_SOCKET_SEND, 12,
"foo.cc", 12);
1269 ok(socket_locker == NULL,
"no locker");
1274 setup_thread(thread_1,
true);
1281 rwlock_class_A->
m_timed=
true;
1287 socket_class_A->
m_timed=
true;
1290 mutex_locker= psi->start_mutex_wait(&mutex_state, mutex_A1, PSI_MUTEX_LOCK, __FILE__, __LINE__);
1291 ok(mutex_locker != NULL,
"locker");
1292 psi->end_mutex_wait(mutex_locker, 0);
1293 rwlock_locker= psi->start_rwlock_rdwait(&rwlock_state, rwlock_A1, PSI_RWLOCK_READLOCK, __FILE__, __LINE__);
1294 ok(rwlock_locker != NULL,
"locker");
1295 psi->end_rwlock_rdwait(rwlock_locker, 0);
1296 cond_locker= psi->start_cond_wait(&cond_state, cond_A1, mutex_A1, PSI_COND_WAIT, __FILE__, __LINE__);
1297 ok(cond_locker != NULL,
"locker");
1298 psi->end_cond_wait(cond_locker, 0);
1299 file_locker= psi->get_thread_file_name_locker(&file_state, file_key_A, PSI_FILE_STREAM_OPEN,
"xxx", NULL);
1300 ok(file_locker != NULL,
"locker");
1301 psi->start_file_open_wait(file_locker, __FILE__, __LINE__);
1302 psi->end_file_open_wait(file_locker, NULL);
1303 file_locker= psi->get_thread_file_stream_locker(&file_state, file_A1, PSI_FILE_READ);
1304 ok(file_locker != NULL,
"locker");
1305 psi->start_file_wait(file_locker, 10, __FILE__, __LINE__);
1306 psi->end_file_wait(file_locker, 10);
1307 file_locker= psi->get_thread_file_descriptor_locker(&file_state, (File) 12, PSI_FILE_READ);
1308 ok(file_locker != NULL,
"locker");
1309 psi->start_file_wait(file_locker, 10, __FILE__, __LINE__);
1310 psi->end_file_wait(file_locker, 10);
1311 socket_locker= psi->start_socket_wait(&socket_state, socket_A1, PSI_SOCKET_SEND, 12,
"foo.cc", 12);
1312 ok(socket_locker != NULL,
"locker");
1313 psi->end_socket_wait(socket_locker, 10);
1319 socket_A1= psi->init_socket(socket_key_A, NULL, NULL, 0);
1320 ok(socket_A1 != NULL,
"instrumented");
1322 socket_locker= psi->start_socket_wait(&socket_state, socket_A1, PSI_SOCKET_SEND, 12,
"foo.cc", 12);
1323 ok(socket_locker == NULL,
"no locker (no thread owner)");
1328 psi->delete_current_thread();
1337 mutex_locker= psi->start_mutex_wait(&mutex_state, mutex_A1, PSI_MUTEX_LOCK,
"foo.cc", 12);
1338 ok(mutex_locker == NULL,
"no locker");
1339 rwlock_locker= psi->start_rwlock_rdwait(&rwlock_state, rwlock_A1, PSI_RWLOCK_READLOCK,
"foo.cc", 12);
1340 ok(rwlock_locker == NULL,
"no locker");
1341 cond_locker= psi->start_cond_wait(&cond_state, cond_A1, mutex_A1, PSI_COND_WAIT,
"foo.cc", 12);
1342 ok(cond_locker == NULL,
"no locker");
1343 file_locker= psi->get_thread_file_name_locker(&file_state, file_key_A, PSI_FILE_OPEN,
"xxx", NULL);
1344 ok(file_locker == NULL,
"no locker");
1345 file_locker= psi->get_thread_file_stream_locker(&file_state, file_A1, PSI_FILE_READ);
1346 ok(file_locker == NULL,
"no locker");
1347 file_locker= psi->get_thread_file_descriptor_locker(&file_state, (File) 12, PSI_FILE_READ);
1348 ok(file_locker == NULL,
"no locker");
1349 socket_locker= psi->start_socket_wait(&socket_state, socket_A1, PSI_SOCKET_SEND, 12,
"foo.cc", 12);
1350 ok(socket_locker == NULL,
"no locker");
1355 void test_file_instrumentation_leak()
1359 diag(
"test_file_instrumentation_leak");
1361 psi= load_perfschema();
1363 PSI_file_key file_key_A;
1364 PSI_file_key file_key_B;
1365 PSI_file_info all_file[]=
1367 { & file_key_A,
"F-A", 0},
1368 { & file_key_B,
"F-B", 0}
1371 PSI_thread_key thread_key_1;
1372 PSI_thread_info all_thread[]=
1374 { & thread_key_1,
"T-1", 0}
1377 psi->register_file(
"test", all_file, 2);
1378 psi->register_thread(
"test", all_thread, 1);
1382 PSI_file_locker_state file_state;
1383 PSI_thread *thread_1;
1387 thread_1= psi->new_thread(thread_key_1, NULL, 0);
1388 ok(thread_1 != NULL,
"T-1");
1389 psi->set_thread_id(thread_1, 1);
1392 ok(file_class_A != NULL,
"file info A");
1395 ok(file_class_B != NULL,
"file info B");
1397 psi->set_thread(thread_1);
1402 setup_thread(thread_1,
true);
1407 PSI_file_locker *file_locker;
1411 file_locker= psi->get_thread_file_name_locker(&file_state, file_key_A, PSI_FILE_OPEN,
"AAA", NULL);
1412 ok(file_locker != NULL,
"locker");
1413 psi->start_file_open_wait(file_locker, __FILE__, __LINE__);
1414 psi->end_file_open_wait_and_bind_to_descriptor(file_locker, 12);
1416 file_locker= psi->get_thread_file_descriptor_locker(&file_state, (File) 12, PSI_FILE_READ);
1417 ok(file_locker != NULL,
"locker");
1418 psi->start_file_wait(file_locker, 100, __FILE__, __LINE__);
1419 psi->end_file_wait(file_locker, 100);
1421 file_locker= psi->get_thread_file_descriptor_locker(&file_state, (File) 12, PSI_FILE_CLOSE);
1422 ok(file_locker != NULL,
"locker");
1423 psi->start_file_wait(file_locker, 0, __FILE__, __LINE__);
1424 psi->end_file_wait(file_locker, 0);
1428 file_locker= psi->get_thread_file_descriptor_locker(&file_state, (File) 24, PSI_FILE_WRITE);
1429 ok(file_locker == NULL,
"no locker, since the open was not instrumented");
1436 file_locker= psi->get_thread_file_descriptor_locker(&file_state, (File) 12, PSI_FILE_WRITE);
1437 ok(file_locker == NULL,
"no locker, no leak");
1447 diag(
"test_enabled");
1449 psi= load_perfschema();
1451 PSI_mutex_key mutex_key_A;
1452 PSI_mutex_key mutex_key_B;
1453 PSI_mutex_info all_mutex[]=
1455 { & mutex_key_A,
"M-A", 0},
1456 { & mutex_key_B,
"M-B", 0}
1459 PSI_rwlock_key rwlock_key_A;
1460 PSI_rwlock_key rwlock_key_B;
1461 PSI_rwlock_info all_rwlock[]=
1463 { & rwlock_key_A,
"RW-A", 0},
1464 { & rwlock_key_B,
"RW-B", 0}
1467 PSI_cond_key cond_key_A;
1468 PSI_cond_key cond_key_B;
1469 PSI_cond_info all_cond[]=
1471 { & cond_key_A,
"C-A", 0},
1472 { & cond_key_B,
"C-B", 0}
1479 void test_event_name_index()
1485 diag(
"test_event_name_index");
1487 memset(& param, 0xFF,
sizeof(param));
1532 ok(boot != NULL,
"bootstrap");
1534 ok(psi != NULL,
"psi");
1537 PSI_mutex_key dummy_mutex_key_1;
1538 PSI_mutex_key dummy_mutex_key_2;
1539 PSI_mutex_info dummy_mutexes[]=
1541 { & dummy_mutex_key_1,
"M-1", 0},
1542 { & dummy_mutex_key_2,
"M-2", 0}
1545 psi->register_mutex(
"X", dummy_mutexes, 2);
1547 ok(mutex_class != NULL,
"mutex class 1");
1550 ok(mutex_class != NULL,
"mutex class 2");
1554 PSI_rwlock_key dummy_rwlock_key_1;
1555 PSI_rwlock_key dummy_rwlock_key_2;
1556 PSI_rwlock_info dummy_rwlocks[]=
1558 { & dummy_rwlock_key_1,
"RW-1", 0},
1559 { & dummy_rwlock_key_2,
"RW-2", 0}
1562 psi->register_rwlock(
"X", dummy_rwlocks, 2);
1564 ok(rwlock_class != NULL,
"rwlock class 1");
1567 ok(rwlock_class != NULL,
"rwlock class 2");
1571 PSI_cond_key dummy_cond_key_1;
1572 PSI_cond_key dummy_cond_key_2;
1573 PSI_cond_info dummy_conds[]=
1575 { & dummy_cond_key_1,
"C-1", 0},
1576 { & dummy_cond_key_2,
"C-2", 0}
1579 psi->register_cond(
"X", dummy_conds, 2);
1581 ok(cond_class != NULL,
"cond class 1");
1584 ok(cond_class != NULL,
"cond class 2");
1588 PSI_file_key dummy_file_key_1;
1589 PSI_file_key dummy_file_key_2;
1590 PSI_file_info dummy_files[]=
1592 { & dummy_file_key_1,
"F-1", 0},
1593 { & dummy_file_key_2,
"F-2", 0}
1596 psi->register_file(
"X", dummy_files, 2);
1598 ok(file_class != NULL,
"file class 1");
1601 ok(file_class != NULL,
"file class 2");
1605 PSI_socket_key dummy_socket_key_1;
1606 PSI_socket_key dummy_socket_key_2;
1607 PSI_socket_info dummy_sockets[]=
1609 { & dummy_socket_key_1,
"S-1", 0},
1610 { & dummy_socket_key_2,
"S-2", 0}
1613 psi->register_socket(
"X", dummy_sockets, 2);
1615 ok(socket_class != NULL,
"socket class 1");
1618 ok(socket_class != NULL,
"socket class 2");
1623 ok(wait_class_max= 313,
"313 event names");
1631 test_bad_registration();
1632 test_init_disabled();
1633 test_locker_disabled();
1634 test_file_instrumentation_leak();
1635 test_event_name_index();
1638 int main(
int,
char **)