diff options
author | Michael Widenius <monty@askmonty.org> | 2012-08-01 17:27:34 +0300 |
---|---|---|
committer | Michael Widenius <monty@askmonty.org> | 2012-08-01 17:27:34 +0300 |
commit | 1d0f70c2f894b27e98773a282871d32802f67964 (patch) | |
tree | 833e683e0ced29c4323c29a9d845703d4dfcd81b /storage/perfschema/unittest | |
parent | 5a86a61219826aadf8d08cbc447fe438f2bf50c3 (diff) | |
download | mariadb-git-1d0f70c2f894b27e98773a282871d32802f67964.tar.gz |
Temporary commit of merge of MariaDB 10.0-base and MySQL 5.6
Diffstat (limited to 'storage/perfschema/unittest')
-rw-r--r-- | storage/perfschema/unittest/CMakeLists.txt | 2 | ||||
-rw-r--r-- | storage/perfschema/unittest/conf.txt | 2 | ||||
-rw-r--r-- | storage/perfschema/unittest/pfs-t.cc | 561 | ||||
-rw-r--r-- | storage/perfschema/unittest/pfs_account-oom-t.cc | 116 | ||||
-rw-r--r-- | storage/perfschema/unittest/pfs_host-oom-t.cc | 116 | ||||
-rw-r--r-- | storage/perfschema/unittest/pfs_instr-oom-t.cc | 442 | ||||
-rw-r--r-- | storage/perfschema/unittest/pfs_instr-t.cc | 185 | ||||
-rw-r--r-- | storage/perfschema/unittest/pfs_instr_class-oom-t.cc | 12 | ||||
-rw-r--r-- | storage/perfschema/unittest/pfs_instr_class-t.cc | 214 | ||||
-rw-r--r-- | storage/perfschema/unittest/pfs_timer-t.cc | 20 | ||||
-rw-r--r-- | storage/perfschema/unittest/pfs_user-oom-t.cc | 116 | ||||
-rw-r--r-- | storage/perfschema/unittest/stub_pfs_defaults.h | 23 | ||||
-rw-r--r-- | storage/perfschema/unittest/stub_pfs_global.h | 21 | ||||
-rw-r--r-- | storage/perfschema/unittest/stub_print_error.h | 3 | ||||
-rw-r--r-- | storage/perfschema/unittest/stub_server_misc.h | 7 |
15 files changed, 1589 insertions, 251 deletions
diff --git a/storage/perfschema/unittest/CMakeLists.txt b/storage/perfschema/unittest/CMakeLists.txt index a9bb1c3f4f2..757bc24c566 100644 --- a/storage/perfschema/unittest/CMakeLists.txt +++ b/storage/perfschema/unittest/CMakeLists.txt @@ -24,5 +24,5 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ADD_DEFINITIONS(-DMYSQL_SERVER) -MY_ADD_TESTS(pfs_instr_class pfs_instr_class-oom pfs_instr pfs_instr-oom pfs +MY_ADD_TESTS(pfs_instr_class pfs_instr_class-oom pfs_instr pfs_instr-oom pfs_account-oom pfs_host-oom pfs_user-oom pfs EXT "cc" LINK_LIBRARIES perfschema mysys) diff --git a/storage/perfschema/unittest/conf.txt b/storage/perfschema/unittest/conf.txt index 6d262854330..8afd0b4dca7 100644 --- a/storage/perfschema/unittest/conf.txt +++ b/storage/perfschema/unittest/conf.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2009, 2010 Sun Microsystems, Inc. +# Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/storage/perfschema/unittest/pfs-t.cc b/storage/perfschema/unittest/pfs-t.cc index ea3e1aab5ec..6b30c0cc498 100644 --- a/storage/perfschema/unittest/pfs-t.cc +++ b/storage/perfschema/unittest/pfs-t.cc @@ -25,6 +25,7 @@ #include <memory.h> #include "stub_print_error.h" +#include "stub_pfs_defaults.h" #include "stub_server_misc.h" /* test helpers, to simulate the setup */ @@ -79,6 +80,7 @@ void test_bootstrap() diag("test_bootstrap"); + memset(& param, 0xFF, sizeof(param)); param.m_enabled= true; param.m_mutex_class_sizing= 0; param.m_rwlock_class_sizing= 0; @@ -86,6 +88,7 @@ void test_bootstrap() param.m_thread_class_sizing= 0; param.m_table_share_sizing= 0; param.m_file_class_sizing= 0; + param.m_socket_class_sizing= 0; param.m_mutex_sizing= 0; param.m_rwlock_sizing= 0; param.m_cond_sizing= 0; @@ -93,8 +96,21 @@ void test_bootstrap() param.m_table_sizing= 0; param.m_file_sizing= 0; param.m_file_handle_sizing= 0; + param.m_socket_sizing= 0; param.m_events_waits_history_sizing= 0; param.m_events_waits_history_long_sizing= 0; + param.m_setup_actor_sizing= 0; + param.m_setup_object_sizing= 0; + param.m_user_sizing= 0; + param.m_account_sizing= 0; + param.m_host_sizing= 0; + param.m_stage_class_sizing= 0; + param.m_events_stages_history_sizing= 0; + param.m_events_stages_history_long_sizing= 0; + param.m_statement_class_sizing= 0; + param.m_events_statements_history_sizing= 0; + param.m_events_statements_history_long_sizing= 0; + param.m_digest_sizing= 0; boot= initialize_performance_schema(& param); ok(boot != NULL, "boot"); @@ -121,6 +137,7 @@ PSI * load_perfschema() PSI_bootstrap *boot; PFS_global_param param; + memset(& param, 0xFF, sizeof(param)); param.m_enabled= true; param.m_mutex_class_sizing= 10; param.m_rwlock_class_sizing= 10; @@ -128,6 +145,7 @@ PSI * load_perfschema() param.m_thread_class_sizing= 10; param.m_table_share_sizing= 10; param.m_file_class_sizing= 10; + param.m_socket_class_sizing= 10; param.m_mutex_sizing= 10; param.m_rwlock_sizing= 10; param.m_cond_sizing= 10; @@ -135,13 +153,30 @@ PSI * load_perfschema() param.m_table_sizing= 10; param.m_file_sizing= 10; param.m_file_handle_sizing= 50; + param.m_socket_sizing= 10; param.m_events_waits_history_sizing= 10; param.m_events_waits_history_long_sizing= 10; + param.m_setup_actor_sizing= 0; + param.m_setup_object_sizing= 0; + param.m_user_sizing= 0; + param.m_account_sizing= 0; + param.m_host_sizing= 0; + param.m_stage_class_sizing= 0; + param.m_events_stages_history_sizing= 0; + param.m_events_stages_history_long_sizing= 0; + param.m_statement_class_sizing= 0; + param.m_events_statements_history_sizing= 0; + param.m_events_statements_history_long_sizing= 0; + param.m_digest_sizing= 0; /* test_bootstrap() covered this, assuming it just works */ boot= initialize_performance_schema(& param); psi= boot->get_interface(PSI_VERSION_1); + /* Reset every consumer to a known state */ + flag_global_instrumentation= true; + flag_thread_instrumentation= true; + return (PSI*) psi; } @@ -478,6 +513,72 @@ void test_bad_registration() psi->register_file("X", bad_file_3, 1); ok(dummy_file_key == 2, "assigned key"); + /* + Test that length('wait/io/socket/' (15) + category + '/' (1)) < 32 + --> category can be up to 15 chars for a socket. + */ + + PSI_socket_key dummy_socket_key= 9999; + PSI_socket_info bad_socket_1[]= + { + { & dummy_socket_key, "X", 0} + }; + + psi->register_socket("/", bad_socket_1, 1); + ok(dummy_socket_key == 0, "zero key"); + dummy_socket_key= 9999; + psi->register_socket("a/", bad_socket_1, 1); + ok(dummy_socket_key == 0, "zero key"); + dummy_socket_key= 9999; + psi->register_socket("/b", bad_socket_1, 1); + ok(dummy_socket_key == 0, "zero key"); + dummy_socket_key= 9999; + psi->register_socket("a/b", bad_socket_1, 1); + ok(dummy_socket_key == 0, "zero key"); + dummy_socket_key= 9999; + psi->register_socket("1234567890123456", bad_socket_1, 1); + ok(dummy_socket_key == 0, "zero key"); + dummy_socket_key= 9999; + psi->register_socket("123456789012345", bad_socket_1, 1); + ok(dummy_socket_key == 1, "assigned key"); + + /* + Test that length('wait/io/socket/' (15) + category + '/' (1) + name) <= 128 + --> category + name can be up to 112 chars for a socket. + */ + + dummy_socket_key= 9999; + PSI_socket_info bad_socket_2[]= + { + { & dummy_socket_key, + /* 112 chars name */ + "12345678901234567890123456789012345678901234567890" + "12345678901234567890123456789012345678901234567890" + "123456789012", + 0} + }; + + psi->register_socket("X", bad_socket_2, 1); + ok(dummy_socket_key == 0, "zero key"); + + dummy_socket_key= 9999; + PSI_socket_info bad_socket_3[]= + { + { & dummy_socket_key, + /* 111 chars name */ + "12345678901234567890123456789012345678901234567890" + "12345678901234567890123456789012345678901234567890" + "12345678901", + 0} + }; + + psi->register_socket("XX", bad_socket_3, 1); + ok(dummy_socket_key == 0, "zero key"); + + psi->register_socket("X", bad_socket_3, 1); + ok(dummy_socket_key == 2, "assigned key"); + + shutdown_performance_schema(); } @@ -513,6 +614,12 @@ void test_init_disabled() { & file_key_A, "F-A", 0} }; + PSI_socket_key socket_key_A; + PSI_socket_info all_socket[]= + { + { & socket_key_A, "S-A", 0} + }; + PSI_thread_key thread_key_1; PSI_thread_info all_thread[]= { @@ -523,16 +630,19 @@ void test_init_disabled() psi->register_rwlock("test", all_rwlock, 1); psi->register_cond("test", all_cond, 1); psi->register_file("test", all_file, 1); + psi->register_socket("test", all_socket, 1); psi->register_thread("test", all_thread, 1); PFS_mutex_class *mutex_class_A; PFS_rwlock_class *rwlock_class_A; PFS_cond_class *cond_class_A; PFS_file_class *file_class_A; + PFS_socket_class *socket_class_A; PSI_mutex *mutex_A1; PSI_rwlock *rwlock_A1; PSI_cond *cond_A1; PFS_file *file_A1; + PSI_socket *socket_A1; PSI_thread *thread_1; /* Preparation */ @@ -553,8 +663,11 @@ void test_init_disabled() file_class_A= find_file_class(file_key_A); ok(file_class_A != NULL, "file class A"); - /* Pretend thread T-1 is running, and disabled */ - /* ------------------------------------------- */ + socket_class_A= find_socket_class(socket_key_A); + ok(socket_class_A != NULL, "socket class A"); + + /* Pretend thread T-1 is running, and disabled, with thread_instrumentation */ + /* ------------------------------------------------------------------------ */ psi->set_thread(thread_1); setup_thread(thread_1, false); @@ -563,61 +676,61 @@ void test_init_disabled() mutex_class_A->m_enabled= false; mutex_A1= psi->init_mutex(mutex_key_A, NULL); - ok(mutex_A1 == NULL, "not instrumented"); + ok(mutex_A1 == NULL, "mutex_A1 not instrumented"); - /* enabled M-A + disabled T-1: no instrumentation */ + /* enabled M-A + disabled T-1: instrumentation (for later) */ mutex_class_A->m_enabled= true; mutex_A1= psi->init_mutex(mutex_key_A, NULL); - ok(mutex_A1 == NULL, "not instrumented"); + ok(mutex_A1 != NULL, "mutex_A1 instrumented"); /* broken key + disabled T-1: no instrumentation */ mutex_class_A->m_enabled= true; mutex_A1= psi->init_mutex(0, NULL); - ok(mutex_A1 == NULL, "not instrumented"); + ok(mutex_A1 == NULL, "mutex key 0 not instrumented"); mutex_A1= psi->init_mutex(99, NULL); - ok(mutex_A1 == NULL, "not instrumented"); + ok(mutex_A1 == NULL, "broken mutex key not instrumented"); /* disabled RW-A + disabled T-1: no instrumentation */ rwlock_class_A->m_enabled= false; rwlock_A1= psi->init_rwlock(rwlock_key_A, NULL); - ok(rwlock_A1 == NULL, "not instrumented"); + ok(rwlock_A1 == NULL, "rwlock_A1 not instrumented"); - /* enabled RW-A + disabled T-1: no instrumentation */ + /* enabled RW-A + disabled T-1: instrumentation (for later) */ rwlock_class_A->m_enabled= true; rwlock_A1= psi->init_rwlock(rwlock_key_A, NULL); - ok(rwlock_A1 == NULL, "not instrumented"); + ok(rwlock_A1 != NULL, "rwlock_A1 instrumented"); /* broken key + disabled T-1: no instrumentation */ rwlock_class_A->m_enabled= true; rwlock_A1= psi->init_rwlock(0, NULL); - ok(rwlock_A1 == NULL, "not instrumented"); + ok(rwlock_A1 == NULL, "rwlock key 0 not instrumented"); rwlock_A1= psi->init_rwlock(99, NULL); - ok(rwlock_A1 == NULL, "not instrumented"); + ok(rwlock_A1 == NULL, "broken rwlock key not instrumented"); /* disabled C-A + disabled T-1: no instrumentation */ cond_class_A->m_enabled= false; cond_A1= psi->init_cond(cond_key_A, NULL); - ok(cond_A1 == NULL, "not instrumented"); + ok(cond_A1 == NULL, "cond_A1 not instrumented"); - /* enabled C-A + disabled T-1: no instrumentation */ + /* enabled C-A + disabled T-1: instrumentation (for later) */ cond_class_A->m_enabled= true; cond_A1= psi->init_cond(cond_key_A, NULL); - ok(cond_A1 == NULL, "not instrumented"); + ok(cond_A1 != NULL, "cond_A1 instrumented"); /* broken key + disabled T-1: no instrumentation */ cond_class_A->m_enabled= true; cond_A1= psi->init_cond(0, NULL); - ok(cond_A1 == NULL, "not instrumented"); + ok(cond_A1 == NULL, "cond key 0 not instrumented"); cond_A1= psi->init_cond(99, NULL); - ok(cond_A1 == NULL, "not instrumented"); + ok(cond_A1 == NULL, "broken cond key not instrumented"); /* disabled F-A + disabled T-1: no instrumentation */ @@ -643,6 +756,26 @@ void test_init_disabled() file_A1= lookup_file_by_name("foo"); ok(file_A1 == NULL, "not instrumented"); + /* disabled S-A + disabled T-1: no instrumentation */ + + socket_class_A->m_enabled= false; + socket_A1= psi->init_socket(socket_key_A, NULL); + ok(socket_A1 == NULL, "socket_A1 not instrumented"); + + /* enabled S-A + disabled T-1: instrumentation (for later) */ + + socket_class_A->m_enabled= true; + socket_A1= psi->init_socket(socket_key_A, NULL); + ok(socket_A1 != NULL, "socket_A1 instrumented"); + + /* broken key + disabled T-1: no instrumentation */ + + socket_class_A->m_enabled= true; + socket_A1= psi->init_socket(0, NULL); + ok(socket_A1 == NULL, "socket key 0 not instrumented"); + socket_A1= psi->init_socket(99, NULL); + ok(socket_A1 == NULL, "broken socket key not instrumented"); + /* Pretend thread T-1 is enabled */ /* ----------------------------- */ @@ -739,17 +872,37 @@ void test_init_disabled() file_class_A->m_enabled= true; psi->create_file(file_key_A, "foo-instrumented", (File) 12); file_A1= lookup_file_by_name("foo-instrumented"); - ok(file_A1 != NULL, "instrumented"); + ok(file_A1 != NULL, "file_A1 instrumented"); /* broken key + enabled T-1: no instrumentation */ file_class_A->m_enabled= true; psi->create_file(0, "foo", (File) 12); file_A1= lookup_file_by_name("foo"); - ok(file_A1 == NULL, "not instrumented"); + ok(file_A1 == NULL, "file key 0 not instrumented"); psi->create_file(99, "foo", (File) 12); file_A1= lookup_file_by_name("foo"); - ok(file_A1 == NULL, "not instrumented"); + ok(file_A1 == NULL, "broken file key not instrumented"); + + /* disabled S-A + enabled T-1: no instrumentation */ + + socket_class_A->m_enabled= false; + ok(socket_A1 == NULL, "not instrumented"); + + /* enabled S-A + enabled T-1: instrumentation */ + + socket_class_A->m_enabled= true; + socket_A1= psi->init_socket(socket_key_A, NULL); + ok(socket_A1 != NULL, "instrumented"); + psi->destroy_socket(socket_A1); + + /* broken key + enabled T-1: no instrumentation */ + + socket_class_A->m_enabled= true; + socket_A1= psi->init_socket(0, NULL); + ok(socket_A1 == NULL, "not instrumented"); + socket_A1= psi->init_socket(99, NULL); + ok(socket_A1 == NULL, "not instrumented"); /* Pretend the running thread is not instrumented */ /* ---------------------------------------------- */ @@ -760,61 +913,61 @@ void test_init_disabled() mutex_class_A->m_enabled= false; mutex_A1= psi->init_mutex(mutex_key_A, NULL); - ok(mutex_A1 == NULL, "not instrumented"); + ok(mutex_A1 == NULL, "mutex_A1 not instrumented"); - /* enabled M-A + unknown thread: no instrumentation */ + /* enabled M-A + unknown thread: instrumentation (for later) */ mutex_class_A->m_enabled= true; mutex_A1= psi->init_mutex(mutex_key_A, NULL); - ok(mutex_A1 == NULL, "not instrumented"); + ok(mutex_A1 != NULL, "mutex_A1 instrumented"); /* broken key + unknown thread: no instrumentation */ mutex_class_A->m_enabled= true; mutex_A1= psi->init_mutex(0, NULL); - ok(mutex_A1 == NULL, "not instrumented"); + ok(mutex_A1 == NULL, "mutex key 0 not instrumented"); mutex_A1= psi->init_mutex(99, NULL); - ok(mutex_A1 == NULL, "not instrumented"); + ok(mutex_A1 == NULL, "broken mutex key not instrumented"); /* disabled RW-A + unknown thread: no instrumentation */ rwlock_class_A->m_enabled= false; rwlock_A1= psi->init_rwlock(rwlock_key_A, NULL); - ok(rwlock_A1 == NULL, "not instrumented"); + ok(rwlock_A1 == NULL, "rwlock_A1 not instrumented"); - /* enabled RW-A + unknown thread: no instrumentation */ + /* enabled RW-A + unknown thread: instrumentation (for later) */ rwlock_class_A->m_enabled= true; rwlock_A1= psi->init_rwlock(rwlock_key_A, NULL); - ok(rwlock_A1 == NULL, "not instrumented"); + ok(rwlock_A1 != NULL, "rwlock_A1 instrumented"); /* broken key + unknown thread: no instrumentation */ rwlock_class_A->m_enabled= true; rwlock_A1= psi->init_rwlock(0, NULL); - ok(rwlock_A1 == NULL, "not instrumented"); + ok(rwlock_A1 == NULL, "rwlock key 0 not instrumented"); rwlock_A1= psi->init_rwlock(99, NULL); - ok(rwlock_A1 == NULL, "not instrumented"); + ok(rwlock_A1 == NULL, "broken rwlock key not instrumented"); /* disabled C-A + unknown thread: no instrumentation */ cond_class_A->m_enabled= false; cond_A1= psi->init_cond(cond_key_A, NULL); - ok(cond_A1 == NULL, "not instrumented"); + ok(cond_A1 == NULL, "cond_A1 not instrumented"); - /* enabled C-A + unknown thread: no instrumentation */ + /* enabled C-A + unknown thread: instrumentation (for later) */ cond_class_A->m_enabled= true; cond_A1= psi->init_cond(cond_key_A, NULL); - ok(cond_A1 == NULL, "not instrumented"); + ok(cond_A1 != NULL, "cond_A1 instrumented"); /* broken key + unknown thread: no instrumentation */ cond_class_A->m_enabled= true; cond_A1= psi->init_cond(0, NULL); - ok(cond_A1 == NULL, "not instrumented"); + ok(cond_A1 == NULL, "cond key 0 not instrumented"); cond_A1= psi->init_cond(99, NULL); - ok(cond_A1 == NULL, "not instrumented"); + ok(cond_A1 == NULL, "broken cond key not instrumented"); /* disabled F-A + unknown thread: no instrumentation */ @@ -840,6 +993,26 @@ void test_init_disabled() file_A1= lookup_file_by_name("foo"); ok(file_A1 == NULL, "not instrumented"); + /* disabled S-A + unknown thread: no instrumentation */ + + socket_class_A->m_enabled= false; + socket_A1= psi->init_socket(socket_key_A, NULL); + ok(socket_A1 == NULL, "socket_A1 not instrumented"); + + /* enabled S-A + unknown thread: instrumentation (for later) */ + + socket_class_A->m_enabled= true; + socket_A1= psi->init_socket(socket_key_A, NULL); + ok(socket_A1 != NULL, "socket_A1 instrumented"); + + /* broken key + unknown thread: no instrumentation */ + + socket_class_A->m_enabled= true; + socket_A1= psi->init_socket(0, NULL); + ok(socket_A1 == NULL, "socket key 0 not instrumented"); + socket_A1= psi->init_socket(99, NULL); + ok(socket_A1 == NULL, "broken socket key not instrumented"); + shutdown_performance_schema(); } @@ -875,6 +1048,12 @@ void test_locker_disabled() { & file_key_A, "F-A", 0} }; + PSI_socket_key socket_key_A; + PSI_socket_info all_socket[]= + { + { & socket_key_A, "S-A", 0} + }; + PSI_thread_key thread_key_1; PSI_thread_info all_thread[]= { @@ -885,16 +1064,19 @@ void test_locker_disabled() psi->register_rwlock("test", all_rwlock, 1); psi->register_cond("test", all_cond, 1); psi->register_file("test", all_file, 1); + psi->register_socket("test", all_socket, 1); psi->register_thread("test", all_thread, 1); PFS_mutex_class *mutex_class_A; PFS_rwlock_class *rwlock_class_A; PFS_cond_class *cond_class_A; PFS_file_class *file_class_A; + PFS_socket_class *socket_class_A; PSI_mutex *mutex_A1; PSI_rwlock *rwlock_A1; PSI_cond *cond_A1; PSI_file *file_A1; + PSI_socket *socket_A1; PSI_thread *thread_1; /* Preparation */ @@ -915,6 +1097,9 @@ void test_locker_disabled() file_class_A= find_file_class(file_key_A); ok(file_class_A != NULL, "file info A"); + socket_class_A= find_socket_class(socket_key_A); + ok(socket_class_A != NULL, "socket info A"); + /* Pretend thread T-1 is running, and enabled */ /* ------------------------------------------ */ @@ -940,6 +1125,13 @@ void test_locker_disabled() file_A1= (PSI_file*) lookup_file_by_name("foo"); ok(file_A1 != NULL, "instrumented"); + socket_class_A->m_enabled= true; + socket_A1= psi->init_socket(socket_key_A, NULL); + ok(socket_A1 != NULL, "instrumented"); + + /* Socket lockers require a thread owner */ + psi->set_socket_thread_owner(socket_A1); + PSI_mutex_locker *mutex_locker; PSI_mutex_locker_state mutex_state; PSI_rwlock_locker *rwlock_locker; @@ -948,6 +1140,8 @@ void test_locker_disabled() PSI_cond_locker_state cond_state; PSI_file_locker *file_locker; PSI_file_locker_state file_state; + PSI_socket_locker *socket_locker; + PSI_socket_locker_state socket_state; /* Pretend thread T-1 is disabled */ /* ------------------------------ */ @@ -958,58 +1152,110 @@ void test_locker_disabled() rwlock_class_A->m_enabled= true; cond_class_A->m_enabled= true; file_class_A->m_enabled= true; - - mutex_locker= psi->get_thread_mutex_locker(&mutex_state, mutex_A1, PSI_MUTEX_LOCK); - ok(mutex_locker == NULL, "no locker"); - rwlock_locker= psi->get_thread_rwlock_locker(&rwlock_state, rwlock_A1, PSI_RWLOCK_READLOCK); - ok(rwlock_locker == NULL, "no locker"); - cond_locker= psi->get_thread_cond_locker(&cond_state, cond_A1, mutex_A1, PSI_COND_WAIT); - ok(cond_locker == NULL, "no locker"); + socket_class_A->m_enabled= true; + + mutex_locker= psi->start_mutex_wait(&mutex_state, mutex_A1, PSI_MUTEX_LOCK, "foo.cc", 12); + ok(mutex_locker == NULL, "no locker (T-1 disabled)"); + rwlock_locker= psi->start_rwlock_rdwait(&rwlock_state, rwlock_A1, PSI_RWLOCK_READLOCK, "foo.cc", 12); + ok(rwlock_locker == NULL, "no locker (T-1 disabled)"); + cond_locker= psi->start_cond_wait(&cond_state, cond_A1, mutex_A1, PSI_COND_WAIT, "foo.cc", 12); + ok(cond_locker == NULL, "no locker (T-1 disabled)"); file_locker= psi->get_thread_file_name_locker(&file_state, file_key_A, PSI_FILE_OPEN, "xxx", NULL); - ok(file_locker == NULL, "no locker"); + ok(file_locker == NULL, "no locker (T-1 disabled)"); file_locker= psi->get_thread_file_stream_locker(&file_state, file_A1, PSI_FILE_READ); - ok(file_locker == NULL, "no locker"); + ok(file_locker == NULL, "no locker (T-1 disabled)"); file_locker= psi->get_thread_file_descriptor_locker(&file_state, (File) 12, PSI_FILE_READ); - ok(file_locker == NULL, "no locker"); + ok(file_locker == NULL, "no locker (T-1 disabled)"); + socket_locker= psi->start_socket_wait(&socket_state, socket_A1, PSI_SOCKET_SEND, 12, "foo.cc", 12); + ok(socket_locker == NULL, "no locker (T-1 disabled)"); - /* Pretend the consumer is disabled */ - /* -------------------------------- */ + /* Pretend the global consumer is disabled */ + /* --------------------------------------- */ setup_thread(thread_1, true); - flag_events_waits_current= false; + flag_global_instrumentation= false; mutex_class_A->m_enabled= true; rwlock_class_A->m_enabled= true; cond_class_A->m_enabled= true; file_class_A->m_enabled= true; + socket_class_A->m_enabled= true; + update_instruments_derived_flags(); + + mutex_locker= psi->start_mutex_wait(&mutex_state, mutex_A1, PSI_MUTEX_LOCK, "foo.cc", 12); + ok(mutex_locker == NULL, "no locker (global disabled)"); + rwlock_locker= psi->start_rwlock_rdwait(&rwlock_state, rwlock_A1, PSI_RWLOCK_READLOCK, "foo.cc", 12); + ok(rwlock_locker == NULL, "no locker (global disabled)"); + cond_locker= psi->start_cond_wait(&cond_state, cond_A1, mutex_A1, PSI_COND_WAIT, "foo.cc", 12); + ok(cond_locker == NULL, "no locker (global disabled)"); + file_locker= psi->get_thread_file_name_locker(&file_state, file_key_A, PSI_FILE_OPEN, "xxx", NULL); + ok(file_locker == NULL, "no locker (global disabled)"); + file_locker= psi->get_thread_file_stream_locker(&file_state, file_A1, PSI_FILE_READ); + ok(file_locker == NULL, "no locker (global disabled)"); + file_locker= psi->get_thread_file_descriptor_locker(&file_state, (File) 12, PSI_FILE_READ); + ok(file_locker == NULL, "no locker (global disabled)"); + socket_locker= psi->start_socket_wait(&socket_state, socket_A1, PSI_SOCKET_SEND, 12, "foo.cc", 12); + ok(socket_locker == NULL, "no locker (global disabled)"); - mutex_locker= psi->get_thread_mutex_locker(&mutex_state, mutex_A1, PSI_MUTEX_LOCK); - ok(mutex_locker == NULL, "no locker"); - rwlock_locker= psi->get_thread_rwlock_locker(&rwlock_state, rwlock_A1, PSI_RWLOCK_READLOCK); - ok(rwlock_locker == NULL, "no locker"); - cond_locker= psi->get_thread_cond_locker(&cond_state, cond_A1, mutex_A1, PSI_COND_WAIT); - ok(cond_locker == NULL, "no locker"); + /* Pretend the mode is global, counted only */ + /* ---------------------------------------- */ + + setup_thread(thread_1, true); + flag_global_instrumentation= true; + flag_thread_instrumentation= false; + mutex_class_A->m_enabled= true; + mutex_class_A->m_timed= false; + rwlock_class_A->m_enabled= true; + rwlock_class_A->m_timed= false; + cond_class_A->m_enabled= true; + cond_class_A->m_timed= false; + file_class_A->m_enabled= true; + file_class_A->m_timed= false; + socket_class_A->m_enabled= true; + socket_class_A->m_timed= false; + update_instruments_derived_flags(); + + mutex_locker= psi->start_mutex_wait(&mutex_state, mutex_A1, PSI_MUTEX_LOCK, "foo.cc", 12); + ok(mutex_locker == NULL, "no locker (global counted)"); + rwlock_locker= psi->start_rwlock_rdwait(&rwlock_state, rwlock_A1, PSI_RWLOCK_READLOCK, "foo.cc", 12); + ok(rwlock_locker == NULL, "no locker (global counted)"); + cond_locker= psi->start_cond_wait(&cond_state, cond_A1, mutex_A1, PSI_COND_WAIT, "foo.cc", 12); + ok(cond_locker == NULL, "no locker (global counted)"); file_locker= psi->get_thread_file_name_locker(&file_state, file_key_A, PSI_FILE_OPEN, "xxx", NULL); - ok(file_locker == NULL, "no locker"); + ok(file_locker != NULL, "locker (global counted)"); + psi->start_file_wait(file_locker, 10, __FILE__, __LINE__); + psi->end_file_wait(file_locker, 10); file_locker= psi->get_thread_file_stream_locker(&file_state, file_A1, PSI_FILE_READ); - ok(file_locker == NULL, "no locker"); + ok(file_locker != NULL, "locker (global counted)"); + psi->start_file_wait(file_locker, 10, __FILE__, __LINE__); + psi->end_file_wait(file_locker, 10); file_locker= psi->get_thread_file_descriptor_locker(&file_state, (File) 12, PSI_FILE_READ); - ok(file_locker == NULL, "no locker"); + ok(file_locker != NULL, "locker (global counted)"); + psi->start_file_wait(file_locker, 10, __FILE__, __LINE__); + psi->end_file_wait(file_locker, 10); + /* The null locker shortcut applies only to socket ops with no byte count */ + socket_locker= psi->start_socket_wait(&socket_state, socket_A1, PSI_SOCKET_BIND, 0, "foo.cc", 12); + ok(socket_locker == NULL, "no locker (global counted)"); + + /* TODO */ /* Pretend the instrument is disabled */ /* ---------------------------------- */ setup_thread(thread_1, true); + flag_global_instrumentation= true; flag_events_waits_current= true; mutex_class_A->m_enabled= false; rwlock_class_A->m_enabled= false; cond_class_A->m_enabled= false; file_class_A->m_enabled= false; + socket_class_A->m_enabled= false; + update_instruments_derived_flags(); - mutex_locker= psi->get_thread_mutex_locker(&mutex_state, mutex_A1, PSI_MUTEX_LOCK); + mutex_locker= psi->start_mutex_wait(&mutex_state, mutex_A1, PSI_MUTEX_LOCK, "foo.cc", 12); ok(mutex_locker == NULL, "no locker"); - rwlock_locker= psi->get_thread_rwlock_locker(&rwlock_state, rwlock_A1, PSI_RWLOCK_READLOCK); + rwlock_locker= psi->start_rwlock_rdwait(&rwlock_state, rwlock_A1, PSI_RWLOCK_READLOCK, "foo.cc", 12); ok(rwlock_locker == NULL, "no locker"); - cond_locker= psi->get_thread_cond_locker(&cond_state, cond_A1, mutex_A1, PSI_COND_WAIT); + cond_locker= psi->start_cond_wait(&cond_state, cond_A1, mutex_A1, PSI_COND_WAIT, "foo.cc", 12); ok(cond_locker == NULL, "no locker"); file_locker= psi->get_thread_file_name_locker(&file_state, file_key_A, PSI_FILE_OPEN, "xxx", NULL); ok(file_locker == NULL, "no locker"); @@ -1017,28 +1263,36 @@ void test_locker_disabled() ok(file_locker == NULL, "no locker"); file_locker= psi->get_thread_file_descriptor_locker(&file_state, (File) 12, PSI_FILE_READ); ok(file_locker == NULL, "no locker"); + socket_locker= psi->start_socket_wait(&socket_state, socket_A1, PSI_SOCKET_SEND, 12, "foo.cc", 12); + ok(socket_locker == NULL, "no locker"); - /* Pretend everything is enabled */ - /* ----------------------------- */ + /* Pretend everything is enabled and timed */ + /* --------------------------------------- */ setup_thread(thread_1, true); + flag_global_instrumentation= true; + flag_thread_instrumentation= true; flag_events_waits_current= true; mutex_class_A->m_enabled= true; + mutex_class_A->m_timed= true; rwlock_class_A->m_enabled= true; + rwlock_class_A->m_timed= true; cond_class_A->m_enabled= true; + cond_class_A->m_timed= true; file_class_A->m_enabled= true; + file_class_A->m_timed= true; + socket_class_A->m_enabled= true; + socket_class_A->m_timed= true; + update_instruments_derived_flags(); - mutex_locker= psi->get_thread_mutex_locker(&mutex_state, mutex_A1, PSI_MUTEX_LOCK); + mutex_locker= psi->start_mutex_wait(&mutex_state, mutex_A1, PSI_MUTEX_LOCK, __FILE__, __LINE__); ok(mutex_locker != NULL, "locker"); - psi->start_mutex_wait(mutex_locker, __FILE__, __LINE__); psi->end_mutex_wait(mutex_locker, 0); - rwlock_locker= psi->get_thread_rwlock_locker(&rwlock_state, rwlock_A1, PSI_RWLOCK_READLOCK); + rwlock_locker= psi->start_rwlock_rdwait(&rwlock_state, rwlock_A1, PSI_RWLOCK_READLOCK, __FILE__, __LINE__); ok(rwlock_locker != NULL, "locker"); - psi->start_rwlock_rdwait(rwlock_locker, __FILE__, __LINE__); psi->end_rwlock_rdwait(rwlock_locker, 0); - cond_locker= psi->get_thread_cond_locker(&cond_state, cond_A1, mutex_A1, PSI_COND_WAIT); + cond_locker= psi->start_cond_wait(&cond_state, cond_A1, mutex_A1, PSI_COND_WAIT, __FILE__, __LINE__); ok(cond_locker != NULL, "locker"); - psi->start_cond_wait(cond_locker, __FILE__, __LINE__); psi->end_cond_wait(cond_locker, 0); file_locker= psi->get_thread_file_name_locker(&file_state, file_key_A, PSI_FILE_OPEN, "xxx", NULL); ok(file_locker != NULL, "locker"); @@ -1052,7 +1306,20 @@ void test_locker_disabled() ok(file_locker != NULL, "locker"); psi->start_file_wait(file_locker, 10, __FILE__, __LINE__); psi->end_file_wait(file_locker, 10); + socket_locker= psi->start_socket_wait(&socket_state, socket_A1, PSI_SOCKET_SEND, 12, "foo.cc", 12); + ok(socket_locker != NULL, "locker"); + psi->end_socket_wait(socket_locker, 10); + + /* Pretend the socket does not have a thread owner */ + /* ---------------------------------------------- */ + socket_class_A->m_enabled= true; + socket_A1= psi->init_socket(socket_key_A, NULL); + ok(socket_A1 != NULL, "instrumented"); + /* Socket thread owner has not been set */ + socket_locker= psi->start_socket_wait(&socket_state, socket_A1, PSI_SOCKET_SEND, 12, "foo.cc", 12); + ok(socket_locker == NULL, "no locker (no thread owner)"); + /* Pretend the running thread is not instrumented */ /* ---------------------------------------------- */ @@ -1062,12 +1329,14 @@ void test_locker_disabled() rwlock_class_A->m_enabled= true; cond_class_A->m_enabled= true; file_class_A->m_enabled= true; + socket_class_A->m_enabled= true; + update_instruments_derived_flags(); - mutex_locker= psi->get_thread_mutex_locker(&mutex_state, mutex_A1, PSI_MUTEX_LOCK); + mutex_locker= psi->start_mutex_wait(&mutex_state, mutex_A1, PSI_MUTEX_LOCK, "foo.cc", 12); ok(mutex_locker == NULL, "no locker"); - rwlock_locker= psi->get_thread_rwlock_locker(&rwlock_state, rwlock_A1, PSI_RWLOCK_READLOCK); + rwlock_locker= psi->start_rwlock_rdwait(&rwlock_state, rwlock_A1, PSI_RWLOCK_READLOCK, "foo.cc", 12); ok(rwlock_locker == NULL, "no locker"); - cond_locker= psi->get_thread_cond_locker(&cond_state, cond_A1, mutex_A1, PSI_COND_WAIT); + cond_locker= psi->start_cond_wait(&cond_state, cond_A1, mutex_A1, PSI_COND_WAIT, "foo.cc", 12); ok(cond_locker == NULL, "no locker"); file_locker= psi->get_thread_file_name_locker(&file_state, file_key_A, PSI_FILE_OPEN, "xxx", NULL); ok(file_locker == NULL, "no locker"); @@ -1075,6 +1344,8 @@ void test_locker_disabled() ok(file_locker == NULL, "no locker"); file_locker= psi->get_thread_file_descriptor_locker(&file_state, (File) 12, PSI_FILE_READ); ok(file_locker == NULL, "no locker"); + socket_locker= psi->start_socket_wait(&socket_state, socket_A1, PSI_SOCKET_SEND, 12, "foo.cc", 12); + ok(socket_locker == NULL, "no locker"); shutdown_performance_schema(); } @@ -1203,6 +1474,150 @@ void test_enabled() #endif } +void test_event_name_index() +{ + PSI *psi; + PSI_bootstrap *boot; + PFS_global_param param; + + diag("test_event_name_index"); + + memset(& param, 0xFF, sizeof(param)); + param.m_enabled= true; + + /* Per mutex info waits should be at [0..9] */ + param.m_mutex_class_sizing= 10; + /* Per rwlock info waits should be at [10..29] */ + param.m_rwlock_class_sizing= 20; + /* Per cond info waits should be at [30..69] */ + param.m_cond_class_sizing= 40; + /* Per file info waits should be at [70..149] */ + param.m_file_class_sizing= 80; + /* Per socket info waits should be at [150..309] */ + param.m_socket_class_sizing= 160; + /* Per table info waits should be at [310] */ + param.m_table_share_sizing= 320; + + param.m_thread_class_sizing= 0; + param.m_user_sizing= 0; + param.m_account_sizing= 0; + param.m_host_sizing= 0; + param.m_stage_class_sizing= 0; + param.m_events_stages_history_sizing= 0; + param.m_events_stages_history_long_sizing= 0; + param.m_statement_class_sizing= 0; + param.m_events_statements_history_sizing= 0; + param.m_events_statements_history_long_sizing= 0; + param.m_digest_sizing= 0; + + param.m_mutex_sizing= 0; + param.m_rwlock_sizing= 0; + param.m_cond_sizing= 0; + param.m_thread_sizing= 0; + param.m_table_sizing= 0; + param.m_file_sizing= 0; + param.m_file_handle_sizing= 0; + param.m_socket_sizing= 0; + param.m_events_waits_history_sizing= 0; + param.m_events_waits_history_long_sizing= 0; + param.m_setup_actor_sizing= 0; + param.m_setup_object_sizing= 0; + + boot= initialize_performance_schema(& param); + ok(boot != NULL, "bootstrap"); + psi= (PSI*) boot->get_interface(PSI_VERSION_1); + ok(psi != NULL, "psi"); + + PFS_mutex_class *mutex_class; + PSI_mutex_key dummy_mutex_key_1; + PSI_mutex_key dummy_mutex_key_2; + PSI_mutex_info dummy_mutexes[]= + { + { & dummy_mutex_key_1, "M-1", 0}, + { & dummy_mutex_key_2, "M-2", 0} + }; + + psi->register_mutex("X", dummy_mutexes, 2); + mutex_class= find_mutex_class(dummy_mutex_key_1); + ok(mutex_class != NULL, "mutex class 1"); + ok(mutex_class->m_event_name_index == 0, "index 0"); + mutex_class= find_mutex_class(dummy_mutex_key_2); + ok(mutex_class != NULL, "mutex class 2"); + ok(mutex_class->m_event_name_index == 1, "index 1"); + + PFS_rwlock_class *rwlock_class; + PSI_rwlock_key dummy_rwlock_key_1; + PSI_rwlock_key dummy_rwlock_key_2; + PSI_rwlock_info dummy_rwlocks[]= + { + { & dummy_rwlock_key_1, "RW-1", 0}, + { & dummy_rwlock_key_2, "RW-2", 0} + }; + + psi->register_rwlock("X", dummy_rwlocks, 2); + rwlock_class= find_rwlock_class(dummy_rwlock_key_1); + ok(rwlock_class != NULL, "rwlock class 1"); + ok(rwlock_class->m_event_name_index == 10, "index 10"); + rwlock_class= find_rwlock_class(dummy_rwlock_key_2); + ok(rwlock_class != NULL, "rwlock class 2"); + ok(rwlock_class->m_event_name_index == 11, "index 11"); + + PFS_cond_class *cond_class; + PSI_cond_key dummy_cond_key_1; + PSI_cond_key dummy_cond_key_2; + PSI_cond_info dummy_conds[]= + { + { & dummy_cond_key_1, "C-1", 0}, + { & dummy_cond_key_2, "C-2", 0} + }; + + psi->register_cond("X", dummy_conds, 2); + cond_class= find_cond_class(dummy_cond_key_1); + ok(cond_class != NULL, "cond class 1"); + ok(cond_class->m_event_name_index == 30, "index 30"); + cond_class= find_cond_class(dummy_cond_key_2); + ok(cond_class != NULL, "cond class 2"); + ok(cond_class->m_event_name_index == 31, "index 31"); + + PFS_file_class *file_class; + PSI_file_key dummy_file_key_1; + PSI_file_key dummy_file_key_2; + PSI_file_info dummy_files[]= + { + { & dummy_file_key_1, "F-1", 0}, + { & dummy_file_key_2, "F-2", 0} + }; + + psi->register_file("X", dummy_files, 2); + file_class= find_file_class(dummy_file_key_1); + ok(file_class != NULL, "file class 1"); + ok(file_class->m_event_name_index == 70, "index 70"); + file_class= find_file_class(dummy_file_key_2); + ok(file_class != NULL, "file class 2"); + ok(file_class->m_event_name_index == 71, "index 71"); + + PFS_socket_class *socket_class; + PSI_socket_key dummy_socket_key_1; + PSI_socket_key dummy_socket_key_2; + PSI_socket_info dummy_sockets[]= + { + { & dummy_socket_key_1, "S-1", 0}, + { & dummy_socket_key_2, "S-2", 0} + }; + + psi->register_socket("X", dummy_sockets, 2); + socket_class= find_socket_class(dummy_socket_key_1); + ok(socket_class != NULL, "socket class 1"); + ok(socket_class->m_event_name_index == 150, "index 150"); + socket_class= find_socket_class(dummy_socket_key_2); + ok(socket_class != NULL, "socket class 2"); + ok(socket_class->m_event_name_index == 151, "index 151"); + + ok(global_table_io_class.m_event_name_index == 310, "index 310"); + ok(global_table_lock_class.m_event_name_index == 311, "index 311"); + ok(wait_class_max= 313, "313 event names"); // 3 global classes +} + void do_all_tests() { /* Using initialize_performance_schema(), no partial init needed. */ @@ -1212,14 +1627,14 @@ void do_all_tests() test_init_disabled(); test_locker_disabled(); test_file_instrumentation_leak(); + test_event_name_index(); } int main(int argc, char **argv) { - plan(153); + plan(216); MY_INIT(argv[0]); do_all_tests(); my_end(0); return 0; } - diff --git a/storage/perfschema/unittest/pfs_account-oom-t.cc b/storage/perfschema/unittest/pfs_account-oom-t.cc new file mode 100644 index 00000000000..e6fddead511 --- /dev/null +++ b/storage/perfschema/unittest/pfs_account-oom-t.cc @@ -0,0 +1,116 @@ +/* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */ + +#include <my_global.h> +#include <my_pthread.h> +#include <pfs_instr.h> +#include <pfs_stat.h> +#include <pfs_global.h> +#include <pfs_account.h> +#include <tap.h> + +#include "stub_pfs_global.h" +#include "stub_server_misc.h" + +#include <string.h> /* memset */ + +void test_oom() +{ + int rc; + PFS_global_param param; + + memset(& param, 0xFF, sizeof(param)); + param.m_enabled= true; + param.m_mutex_class_sizing= 0; + param.m_rwlock_class_sizing= 0; + param.m_cond_class_sizing= 0; + param.m_thread_class_sizing= 10; + param.m_table_share_sizing= 0; + param.m_file_class_sizing= 0; + param.m_mutex_sizing= 0; + param.m_rwlock_sizing= 0; + param.m_cond_sizing= 0; + param.m_thread_sizing= 1000; + param.m_table_sizing= 0; + param.m_file_sizing= 0; + param.m_file_handle_sizing= 0; + param.m_events_waits_history_sizing= 10; + param.m_events_waits_history_long_sizing= 0; + param.m_setup_actor_sizing= 0; + param.m_setup_object_sizing= 0; + param.m_host_sizing= 0; + param.m_user_sizing= 0; + param.m_account_sizing= 1000; + param.m_stage_class_sizing= 50; + param.m_events_stages_history_sizing= 0; + param.m_events_stages_history_long_sizing= 0; + param.m_statement_class_sizing= 50; + param.m_events_statements_history_sizing= 0; + param.m_events_statements_history_long_sizing= 0; + + /* Setup */ + + stub_alloc_always_fails= false; + stub_alloc_fails_after_count= 1000; + + init_event_name_sizing(& param); + rc= init_stage_class(param.m_stage_class_sizing); + ok(rc == 0, "init stage class"); + rc= init_statement_class(param.m_statement_class_sizing); + ok(rc == 0, "init statement class"); + + /* Tests */ + + stub_alloc_fails_after_count= 1; + rc= init_account(& param); + ok(rc == 1, "oom (account)"); + cleanup_account(); + + stub_alloc_fails_after_count= 2; + rc= init_account(& param); + ok(rc == 1, "oom (account waits)"); + cleanup_account(); + + stub_alloc_fails_after_count= 3; + rc= init_account(& param); + ok(rc == 1, "oom (account stages)"); + cleanup_account(); + + stub_alloc_fails_after_count= 4; + rc= init_account(& param); + ok(rc == 1, "oom (account statements)"); + cleanup_account(); + + cleanup_statement_class(); + cleanup_stage_class(); +} + +void do_all_tests() +{ + PFS_atomic::init(); + + test_oom(); + + PFS_atomic::cleanup(); +} + +int main(int, char **) +{ + plan(6); + MY_INIT("pfs_account-oom-t"); + do_all_tests(); + return 0; +} + diff --git a/storage/perfschema/unittest/pfs_host-oom-t.cc b/storage/perfschema/unittest/pfs_host-oom-t.cc new file mode 100644 index 00000000000..075a2e6a07a --- /dev/null +++ b/storage/perfschema/unittest/pfs_host-oom-t.cc @@ -0,0 +1,116 @@ +/* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */ + +#include <my_global.h> +#include <my_pthread.h> +#include <pfs_instr.h> +#include <pfs_stat.h> +#include <pfs_global.h> +#include <pfs_host.h> +#include <tap.h> + +#include "stub_pfs_global.h" +#include "stub_server_misc.h" + +#include <string.h> /* memset */ + +void test_oom() +{ + int rc; + PFS_global_param param; + + memset(& param, 0xFF, sizeof(param)); + param.m_enabled= true; + param.m_mutex_class_sizing= 0; + param.m_rwlock_class_sizing= 0; + param.m_cond_class_sizing= 0; + param.m_thread_class_sizing= 10; + param.m_table_share_sizing= 0; + param.m_file_class_sizing= 0; + param.m_mutex_sizing= 0; + param.m_rwlock_sizing= 0; + param.m_cond_sizing= 0; + param.m_thread_sizing= 1000; + param.m_table_sizing= 0; + param.m_file_sizing= 0; + param.m_file_handle_sizing= 0; + param.m_events_waits_history_sizing= 10; + param.m_events_waits_history_long_sizing= 0; + param.m_setup_actor_sizing= 0; + param.m_setup_object_sizing= 0; + param.m_host_sizing= 1000; + param.m_user_sizing= 0; + param.m_account_sizing= 0; + param.m_stage_class_sizing= 50; + param.m_events_stages_history_sizing= 0; + param.m_events_stages_history_long_sizing= 0; + param.m_statement_class_sizing= 50; + param.m_events_statements_history_sizing= 0; + param.m_events_statements_history_long_sizing= 0; + + /* Setup */ + + stub_alloc_always_fails= false; + stub_alloc_fails_after_count= 1000; + + init_event_name_sizing(& param); + rc= init_stage_class(param.m_stage_class_sizing); + ok(rc == 0, "init stage class"); + rc= init_statement_class(param.m_statement_class_sizing); + ok(rc == 0, "init statement class"); + + /* Tests */ + + stub_alloc_fails_after_count= 1; + rc= init_host(& param); + ok(rc == 1, "oom (host)"); + cleanup_host(); + + stub_alloc_fails_after_count= 2; + rc= init_host(& param); + ok(rc == 1, "oom (host waits)"); + cleanup_host(); + + stub_alloc_fails_after_count= 3; + rc= init_host(& param); + ok(rc == 1, "oom (host stages)"); + cleanup_host(); + + stub_alloc_fails_after_count= 4; + rc= init_host(& param); + ok(rc == 1, "oom (host statements)"); + cleanup_host(); + + cleanup_statement_class(); + cleanup_stage_class(); +} + +void do_all_tests() +{ + PFS_atomic::init(); + + test_oom(); + + PFS_atomic::cleanup(); +} + +int main(int, char **) +{ + plan(6); + MY_INIT("pfs_host-oom-t"); + do_all_tests(); + return 0; +} + diff --git a/storage/perfschema/unittest/pfs_instr-oom-t.cc b/storage/perfschema/unittest/pfs_instr-oom-t.cc index 175c09bcd39..41bb4ed6c5a 100644 --- a/storage/perfschema/unittest/pfs_instr-oom-t.cc +++ b/storage/perfschema/unittest/pfs_instr-oom-t.cc @@ -18,11 +18,14 @@ #include <pfs_instr.h> #include <pfs_stat.h> #include <pfs_global.h> +#include <pfs_instr_class.h> #include <tap.h> #include "stub_pfs_global.h" #include "stub_server_misc.h" +#include <string.h> /* memset */ + void test_oom() { int rc; @@ -30,6 +33,7 @@ void test_oom() stub_alloc_always_fails= true; + memset(& param, 0xFF, sizeof(param)); param.m_enabled= true; param.m_mutex_class_sizing= 10; param.m_rwlock_class_sizing= 0; @@ -37,6 +41,7 @@ void test_oom() param.m_thread_class_sizing= 0; param.m_table_share_sizing= 0; param.m_file_class_sizing= 0; + param.m_socket_class_sizing= 0; param.m_mutex_sizing= 1000; param.m_rwlock_sizing= 0; param.m_cond_sizing= 0; @@ -44,11 +49,25 @@ void test_oom() param.m_table_sizing= 0; param.m_file_sizing= 0; param.m_file_handle_sizing= 0; + param.m_socket_sizing= 0; param.m_events_waits_history_sizing= 0; param.m_events_waits_history_long_sizing= 0; + param.m_setup_actor_sizing= 0; + param.m_setup_object_sizing= 0; + param.m_host_sizing= 0; + param.m_user_sizing= 0; + param.m_account_sizing= 0; + param.m_stage_class_sizing= 0; + param.m_events_stages_history_sizing= 0; + param.m_events_stages_history_long_sizing= 0; + param.m_statement_class_sizing= 0; + param.m_events_statements_history_sizing= 0; + param.m_events_statements_history_long_sizing= 0; + init_event_name_sizing(& param); rc= init_instruments(& param); ok(rc == 1, "oom (mutex)"); + cleanup_instruments(); param.m_enabled= true; param.m_mutex_class_sizing= 0; @@ -57,6 +76,7 @@ void test_oom() param.m_thread_class_sizing= 0; param.m_table_share_sizing= 0; param.m_file_class_sizing= 0; + param.m_socket_class_sizing= 0; param.m_mutex_sizing= 0; param.m_rwlock_sizing= 1000; param.m_cond_sizing= 0; @@ -64,11 +84,25 @@ void test_oom() param.m_table_sizing= 0; param.m_file_sizing= 0; param.m_file_handle_sizing= 0; + param.m_socket_sizing= 0; param.m_events_waits_history_sizing= 0; param.m_events_waits_history_long_sizing= 0; + param.m_setup_actor_sizing= 0; + param.m_setup_object_sizing= 0; + param.m_host_sizing= 0; + param.m_user_sizing= 0; + param.m_account_sizing= 0; + param.m_stage_class_sizing= 0; + param.m_events_stages_history_sizing= 0; + param.m_events_stages_history_long_sizing= 0; + param.m_statement_class_sizing= 0; + param.m_events_statements_history_sizing= 0; + param.m_events_statements_history_long_sizing= 0; + init_event_name_sizing(& param); rc= init_instruments(& param); ok(rc == 1, "oom (rwlock)"); + cleanup_instruments(); param.m_enabled= true; param.m_mutex_class_sizing= 0; @@ -77,6 +111,7 @@ void test_oom() param.m_thread_class_sizing= 0; param.m_table_share_sizing= 0; param.m_file_class_sizing= 0; + param.m_socket_class_sizing= 0; param.m_mutex_sizing= 0; param.m_rwlock_sizing= 0; param.m_cond_sizing= 1000; @@ -84,11 +119,25 @@ void test_oom() param.m_table_sizing= 0; param.m_file_sizing= 0; param.m_file_handle_sizing= 0; + param.m_socket_sizing= 0; param.m_events_waits_history_sizing= 0; param.m_events_waits_history_long_sizing= 0; + param.m_setup_actor_sizing= 0; + param.m_setup_object_sizing= 0; + param.m_host_sizing= 0; + param.m_user_sizing= 0; + param.m_account_sizing= 0; + param.m_stage_class_sizing= 0; + param.m_events_stages_history_sizing= 0; + param.m_events_stages_history_long_sizing= 0; + param.m_statement_class_sizing= 0; + param.m_events_statements_history_sizing= 0; + param.m_events_statements_history_long_sizing= 0; + init_event_name_sizing(& param); rc= init_instruments(& param); ok(rc == 1, "oom (cond)"); + cleanup_instruments(); param.m_enabled= true; param.m_mutex_class_sizing= 0; @@ -97,6 +146,7 @@ void test_oom() param.m_thread_class_sizing= 0; param.m_table_share_sizing= 0; param.m_file_class_sizing= 10; + param.m_socket_class_sizing= 0; param.m_mutex_sizing= 0; param.m_rwlock_sizing= 0; param.m_cond_sizing= 0; @@ -104,11 +154,58 @@ void test_oom() param.m_table_sizing= 0; param.m_file_sizing= 1000; param.m_file_handle_sizing= 1000; + param.m_socket_sizing= 0; param.m_events_waits_history_sizing= 0; param.m_events_waits_history_long_sizing= 0; + param.m_setup_actor_sizing= 0; + param.m_setup_object_sizing= 0; + param.m_host_sizing= 0; + param.m_user_sizing= 0; + param.m_account_sizing= 0; + param.m_stage_class_sizing= 0; + param.m_events_stages_history_sizing= 0; + param.m_events_stages_history_long_sizing= 0; + param.m_statement_class_sizing= 0; + param.m_events_statements_history_sizing= 0; + param.m_events_statements_history_long_sizing= 0; + init_event_name_sizing(& param); rc= init_instruments(& param); ok(rc == 1, "oom (file)"); + cleanup_instruments(); + + param.m_enabled= true; + param.m_mutex_class_sizing= 0; + param.m_rwlock_class_sizing= 0; + param.m_cond_class_sizing= 0; + param.m_thread_class_sizing= 0; + param.m_table_share_sizing= 0; + param.m_file_class_sizing= 0; + param.m_mutex_sizing= 0; + param.m_rwlock_sizing= 0; + param.m_cond_sizing= 0; + param.m_thread_sizing= 0; + param.m_table_sizing= 0; + param.m_file_sizing= 0; + param.m_file_handle_sizing= 1000; + param.m_events_waits_history_sizing= 0; + param.m_events_waits_history_long_sizing= 0; + param.m_setup_actor_sizing= 0; + param.m_setup_object_sizing= 0; + param.m_host_sizing= 0; + param.m_user_sizing= 0; + param.m_account_sizing= 0; + param.m_stage_class_sizing= 0; + param.m_events_stages_history_sizing= 0; + param.m_events_stages_history_long_sizing= 0; + param.m_statement_class_sizing= 0; + param.m_events_statements_history_sizing= 0; + param.m_events_statements_history_long_sizing= 0; + + init_event_name_sizing(& param); + rc= init_instruments(& param); + ok(rc == 1, "oom (file handle)"); + cleanup_instruments(); param.m_enabled= true; param.m_mutex_class_sizing= 0; @@ -117,6 +214,7 @@ void test_oom() param.m_thread_class_sizing= 0; param.m_table_share_sizing= 10; param.m_file_class_sizing= 0; + param.m_socket_class_sizing= 0; param.m_mutex_sizing= 0; param.m_rwlock_sizing= 0; param.m_cond_sizing= 0; @@ -124,11 +222,25 @@ void test_oom() param.m_table_sizing= 1000; param.m_file_sizing= 0; param.m_file_handle_sizing= 0; + param.m_socket_sizing= 0; param.m_events_waits_history_sizing= 0; param.m_events_waits_history_long_sizing= 0; + param.m_setup_actor_sizing= 0; + param.m_setup_object_sizing= 0; + param.m_host_sizing= 0; + param.m_user_sizing= 0; + param.m_account_sizing= 0; + param.m_stage_class_sizing= 0; + param.m_events_stages_history_sizing= 0; + param.m_events_stages_history_long_sizing= 0; + param.m_statement_class_sizing= 0; + param.m_events_statements_history_sizing= 0; + param.m_events_statements_history_long_sizing= 0; + init_event_name_sizing(& param); rc= init_instruments(& param); ok(rc == 1, "oom (table)"); + cleanup_instruments(); param.m_enabled= true; param.m_mutex_class_sizing= 0; @@ -137,6 +249,7 @@ void test_oom() param.m_thread_class_sizing= 10; param.m_table_share_sizing= 0; param.m_file_class_sizing= 0; + param.m_socket_class_sizing= 0; param.m_mutex_sizing= 0; param.m_rwlock_sizing= 0; param.m_cond_sizing= 0; @@ -144,11 +257,25 @@ void test_oom() param.m_table_sizing= 0; param.m_file_sizing= 0; param.m_file_handle_sizing= 0; + param.m_socket_sizing= 0; param.m_events_waits_history_sizing= 0; param.m_events_waits_history_long_sizing= 0; + param.m_setup_actor_sizing= 0; + param.m_setup_object_sizing= 0; + param.m_host_sizing= 0; + param.m_user_sizing= 0; + param.m_account_sizing= 0; + param.m_stage_class_sizing= 0; + param.m_events_stages_history_sizing= 0; + param.m_events_stages_history_long_sizing= 0; + param.m_statement_class_sizing= 0; + param.m_events_statements_history_sizing= 0; + param.m_events_statements_history_long_sizing= 0; + init_event_name_sizing(& param); rc= init_instruments(& param); ok(rc == 1, "oom (thread)"); + cleanup_instruments(); stub_alloc_always_fails= false; @@ -159,6 +286,7 @@ void test_oom() param.m_thread_class_sizing= 10; param.m_table_share_sizing= 0; param.m_file_class_sizing= 0; + param.m_socket_class_sizing= 0; param.m_mutex_sizing= 0; param.m_rwlock_sizing= 0; param.m_cond_sizing= 0; @@ -166,12 +294,26 @@ void test_oom() param.m_table_sizing= 0; param.m_file_sizing= 0; param.m_file_handle_sizing= 0; + param.m_socket_sizing= 0; param.m_events_waits_history_sizing= 10; param.m_events_waits_history_long_sizing= 0; + param.m_setup_actor_sizing= 0; + param.m_setup_object_sizing= 0; + param.m_host_sizing= 0; + param.m_user_sizing= 0; + param.m_account_sizing= 0; + param.m_stage_class_sizing= 0; + param.m_events_stages_history_sizing= 0; + param.m_events_stages_history_long_sizing= 0; + param.m_statement_class_sizing= 0; + param.m_events_statements_history_sizing= 0; + param.m_events_statements_history_long_sizing= 0; stub_alloc_fails_after_count= 2; + init_event_name_sizing(& param); rc= init_instruments(& param); - ok(rc == 1, "oom (thread history sizing)"); + ok(rc == 1, "oom (thread waits history sizing)"); + cleanup_instruments(); param.m_enabled= true; param.m_mutex_class_sizing= 50; @@ -180,6 +322,7 @@ void test_oom() param.m_thread_class_sizing= 10; param.m_table_share_sizing= 0; param.m_file_class_sizing= 50; + param.m_socket_class_sizing= 0; param.m_mutex_sizing= 0; param.m_rwlock_sizing= 0; param.m_cond_sizing= 0; @@ -187,14 +330,309 @@ void test_oom() param.m_table_sizing= 0; param.m_file_sizing= 0; param.m_file_handle_sizing= 0; + param.m_socket_sizing= 0; param.m_events_waits_history_sizing= 0; param.m_events_waits_history_long_sizing= 0; + param.m_setup_actor_sizing= 0; + param.m_setup_object_sizing= 0; + param.m_stage_class_sizing= 0; + param.m_events_stages_history_sizing= 0; + param.m_events_stages_history_long_sizing= 0; + param.m_statement_class_sizing= 0; + param.m_events_statements_history_sizing= 0; + param.m_events_statements_history_long_sizing= 0; stub_alloc_fails_after_count= 2; + init_event_name_sizing(& param); rc= init_instruments(& param); ok(rc == 1, "oom (per thread wait)"); + param.m_enabled= true; + param.m_mutex_class_sizing= 0; + param.m_rwlock_class_sizing= 0; + param.m_cond_class_sizing= 0; + param.m_thread_class_sizing= 0; + param.m_table_share_sizing= 0; + param.m_file_class_sizing= 0; + param.m_socket_class_sizing= 10; + param.m_mutex_sizing= 0; + param.m_rwlock_sizing= 0; + param.m_cond_sizing= 0; + param.m_thread_sizing= 0; + param.m_table_sizing= 0; + param.m_file_sizing= 0; + param.m_file_handle_sizing= 0; + param.m_socket_sizing= 1000; + param.m_events_waits_history_sizing= 0; + param.m_events_waits_history_long_sizing= 0; + param.m_setup_actor_sizing= 0; + param.m_setup_object_sizing= 0; + + init_event_name_sizing(& param); + rc= init_instruments(& param); + ok(rc == 1, "oom (socket)"); + + cleanup_instruments(); + + param.m_host_sizing= 0; + param.m_user_sizing= 0; + param.m_account_sizing= 0; + param.m_stage_class_sizing= 0; + param.m_events_stages_history_sizing= 0; + param.m_events_stages_history_long_sizing= 0; + param.m_statement_class_sizing= 0; + param.m_events_statements_history_sizing= 0; + param.m_events_statements_history_long_sizing= 0; + + stub_alloc_fails_after_count= 2; + init_event_name_sizing(& param); + rc= init_instruments(& param); + ok(rc == 1, "oom (per thread waits)"); + cleanup_instruments(); + + param.m_enabled= true; + param.m_mutex_class_sizing= 0; + param.m_rwlock_class_sizing= 0; + param.m_cond_class_sizing= 0; + param.m_thread_class_sizing= 10; + param.m_table_share_sizing= 0; + param.m_file_class_sizing= 0; + param.m_mutex_sizing= 0; + param.m_rwlock_sizing= 0; + param.m_cond_sizing= 0; + param.m_thread_sizing= 1000; + param.m_table_sizing= 0; + param.m_file_sizing= 0; + param.m_file_handle_sizing= 0; + param.m_events_waits_history_sizing= 0; + param.m_events_waits_history_long_sizing= 0; + param.m_setup_actor_sizing= 0; + param.m_setup_object_sizing= 0; + param.m_host_sizing= 0; + param.m_user_sizing= 0; + param.m_account_sizing= 0; + param.m_stage_class_sizing= 0; + param.m_events_stages_history_sizing= 10; + param.m_events_stages_history_long_sizing= 0; + param.m_statement_class_sizing= 0; + param.m_events_statements_history_sizing= 0; + param.m_events_statements_history_long_sizing= 0; + + stub_alloc_fails_after_count= 3; + init_event_name_sizing(& param); + rc= init_instruments(& param); + ok(rc == 1, "oom (thread stages history sizing)"); + cleanup_instruments(); + + param.m_enabled= true; + param.m_mutex_class_sizing= 0; + param.m_rwlock_class_sizing= 0; + param.m_cond_class_sizing= 0; + param.m_thread_class_sizing= 10; + param.m_table_share_sizing= 0; + param.m_file_class_sizing= 0; + param.m_mutex_sizing= 0; + param.m_rwlock_sizing= 0; + param.m_cond_sizing= 0; + param.m_thread_sizing= 1000; + param.m_table_sizing= 0; + param.m_file_sizing= 0; + param.m_file_handle_sizing= 0; + param.m_events_waits_history_sizing= 0; + param.m_events_waits_history_long_sizing= 0; + param.m_setup_actor_sizing= 0; + param.m_setup_object_sizing= 0; + param.m_host_sizing= 0; + param.m_user_sizing= 0; + param.m_account_sizing= 0; + param.m_stage_class_sizing= 50; + param.m_events_stages_history_sizing= 0; + param.m_events_stages_history_long_sizing= 0; + param.m_statement_class_sizing= 0; + param.m_events_statements_history_sizing= 0; + param.m_events_statements_history_long_sizing= 0; + + stub_alloc_fails_after_count= 2; + init_event_name_sizing(& param); + rc= init_instruments(& param); + ok(rc == 1, "oom (per thread stages)"); + cleanup_instruments(); + + param.m_enabled= true; + param.m_mutex_class_sizing= 0; + param.m_rwlock_class_sizing= 0; + param.m_cond_class_sizing= 0; + param.m_thread_class_sizing= 10; + param.m_table_share_sizing= 0; + param.m_file_class_sizing= 0; + param.m_mutex_sizing= 0; + param.m_rwlock_sizing= 0; + param.m_cond_sizing= 0; + param.m_thread_sizing= 1000; + param.m_table_sizing= 0; + param.m_file_sizing= 0; + param.m_file_handle_sizing= 0; + param.m_events_waits_history_sizing= 0; + param.m_events_waits_history_long_sizing= 0; + param.m_setup_actor_sizing= 0; + param.m_setup_object_sizing= 0; + param.m_host_sizing= 0; + param.m_user_sizing= 0; + param.m_account_sizing= 0; + param.m_stage_class_sizing= 0; + param.m_events_stages_history_sizing= 0; + param.m_events_stages_history_long_sizing= 0; + param.m_statement_class_sizing= 0; + param.m_events_statements_history_sizing= 10; + param.m_events_statements_history_long_sizing= 0; + + stub_alloc_fails_after_count= 2; + init_event_name_sizing(& param); + rc= init_instruments(& param); + ok(rc == 1, "oom (thread statements history sizing)"); + cleanup_instruments(); + + param.m_enabled= true; + param.m_mutex_class_sizing= 0; + param.m_rwlock_class_sizing= 0; + param.m_cond_class_sizing= 0; + param.m_thread_class_sizing= 10; + param.m_table_share_sizing= 0; + param.m_file_class_sizing= 0; + param.m_mutex_sizing= 0; + param.m_rwlock_sizing= 0; + param.m_cond_sizing= 0; + param.m_thread_sizing= 1000; + param.m_table_sizing= 0; + param.m_file_sizing= 0; + param.m_file_handle_sizing= 0; + param.m_events_waits_history_sizing= 0; + param.m_events_waits_history_long_sizing= 0; + param.m_setup_actor_sizing= 0; + param.m_setup_object_sizing= 0; + param.m_host_sizing= 0; + param.m_user_sizing= 0; + param.m_account_sizing= 0; + param.m_stage_class_sizing= 0; + param.m_events_stages_history_sizing= 0; + param.m_events_stages_history_long_sizing= 0; + param.m_statement_class_sizing= 50; + param.m_events_statements_history_sizing= 0; + param.m_events_statements_history_long_sizing= 0; + + stub_alloc_fails_after_count= 2; + init_event_name_sizing(& param); + rc= init_instruments(& param); + ok(rc == 1, "oom (per thread statements)"); + cleanup_instruments(); + + param.m_enabled= true; + param.m_mutex_class_sizing= 10; + param.m_rwlock_class_sizing= 0; + param.m_cond_class_sizing= 0; + param.m_thread_class_sizing= 0; + param.m_table_share_sizing= 0; + param.m_file_class_sizing= 0; + param.m_mutex_sizing= 0; + param.m_rwlock_sizing= 0; + param.m_cond_sizing= 0; + param.m_thread_sizing= 0; + param.m_table_sizing= 0; + param.m_file_sizing= 0; + param.m_file_handle_sizing= 0; + param.m_events_waits_history_sizing= 0; + param.m_events_waits_history_long_sizing= 0; + param.m_setup_actor_sizing= 0; + param.m_setup_object_sizing= 0; + param.m_host_sizing= 0; + param.m_user_sizing= 0; + param.m_account_sizing= 0; + param.m_stage_class_sizing= 0; + param.m_events_stages_history_sizing= 0; + param.m_events_stages_history_long_sizing= 0; + param.m_statement_class_sizing= 0; + param.m_events_statements_history_sizing= 0; + param.m_events_statements_history_long_sizing= 0; + + stub_alloc_fails_after_count= 1; + init_event_name_sizing(& param); + rc= init_instruments(& param); + ok(rc == 1, "oom (global waits)"); + cleanup_instruments(); + + param.m_enabled= true; + param.m_mutex_class_sizing= 10; + param.m_rwlock_class_sizing= 0; + param.m_cond_class_sizing= 0; + param.m_thread_class_sizing= 0; + param.m_table_share_sizing= 0; + param.m_file_class_sizing= 0; + param.m_mutex_sizing= 0; + param.m_rwlock_sizing= 0; + param.m_cond_sizing= 0; + param.m_thread_sizing= 0; + param.m_table_sizing= 0; + param.m_file_sizing= 0; + param.m_file_handle_sizing= 0; + param.m_events_waits_history_sizing= 0; + param.m_events_waits_history_long_sizing= 0; + param.m_setup_actor_sizing= 0; + param.m_setup_object_sizing= 0; + param.m_host_sizing= 0; + param.m_user_sizing= 0; + param.m_account_sizing= 0; + param.m_stage_class_sizing= 20; + param.m_events_stages_history_sizing= 0; + param.m_events_stages_history_long_sizing= 0; + param.m_statement_class_sizing= 0; + param.m_events_statements_history_sizing= 0; + param.m_events_statements_history_long_sizing= 0; + + stub_alloc_fails_after_count= 3; + init_event_name_sizing(& param); + rc= init_stage_class(param.m_stage_class_sizing); + ok(rc == 0, "init stage class"); + rc= init_instruments(& param); + ok(rc == 1, "oom (global stages)"); + cleanup_instruments(); + cleanup_stage_class(); + + param.m_enabled= true; + param.m_mutex_class_sizing= 10; + param.m_rwlock_class_sizing= 0; + param.m_cond_class_sizing= 0; + param.m_thread_class_sizing= 0; + param.m_table_share_sizing= 0; + param.m_file_class_sizing= 0; + param.m_mutex_sizing= 0; + param.m_rwlock_sizing= 0; + param.m_cond_sizing= 0; + param.m_thread_sizing= 0; + param.m_table_sizing= 0; + param.m_file_sizing= 0; + param.m_file_handle_sizing= 0; + param.m_events_waits_history_sizing= 0; + param.m_events_waits_history_long_sizing= 0; + param.m_setup_actor_sizing= 0; + param.m_setup_object_sizing= 0; + param.m_host_sizing= 0; + param.m_user_sizing= 0; + param.m_account_sizing= 0; + param.m_stage_class_sizing= 0; + param.m_events_stages_history_sizing= 0; + param.m_events_stages_history_long_sizing= 0; + param.m_statement_class_sizing= 20; + param.m_events_statements_history_sizing= 0; + param.m_events_statements_history_long_sizing= 0; + + stub_alloc_fails_after_count= 3; + init_event_name_sizing(& param); + rc= init_statement_class(param.m_statement_class_sizing); + ok(rc == 0, "init statement class"); + rc= init_instruments(& param); + ok(rc == 1, "oom (global statements)"); cleanup_instruments(); + cleanup_statement_class(); } void do_all_tests() @@ -208,7 +646,7 @@ void do_all_tests() int main(int argc, char **argv) { - plan(8); + plan(20); MY_INIT(argv[0]); do_all_tests(); my_end(0); diff --git a/storage/perfschema/unittest/pfs_instr-t.cc b/storage/perfschema/unittest/pfs_instr-t.cc index 0daf38e5fc8..b0839de70b2 100644 --- a/storage/perfschema/unittest/pfs_instr-t.cc +++ b/storage/perfschema/unittest/pfs_instr-t.cc @@ -18,6 +18,7 @@ #include <pfs_instr.h> #include <pfs_stat.h> #include <pfs_global.h> +#include <pfs_instr_class.h> #include <tap.h> #include <memory.h> @@ -29,6 +30,7 @@ void test_no_instruments() int rc; PFS_global_param param; + memset(& param, 0xFF, sizeof(param)); param.m_enabled= true; param.m_mutex_class_sizing= 0; param.m_rwlock_class_sizing= 0; @@ -36,6 +38,7 @@ void test_no_instruments() param.m_thread_class_sizing= 0; param.m_table_share_sizing= 0; param.m_file_class_sizing= 0; + param.m_socket_class_sizing= 0; param.m_mutex_sizing= 0; param.m_rwlock_sizing= 0; param.m_cond_sizing= 0; @@ -43,9 +46,22 @@ void test_no_instruments() param.m_table_sizing= 0; param.m_file_sizing= 0; param.m_file_handle_sizing= 0; + param.m_socket_sizing= 0; param.m_events_waits_history_sizing= 0; param.m_events_waits_history_long_sizing= 0; - + param.m_setup_actor_sizing= 0; + param.m_setup_object_sizing= 0; + param.m_host_sizing= 0; + param.m_user_sizing= 0; + param.m_account_sizing= 0; + param.m_stage_class_sizing= 0; + param.m_events_stages_history_sizing= 0; + param.m_events_stages_history_long_sizing= 0; + param.m_statement_class_sizing= 0; + param.m_events_statements_history_sizing= 0; + param.m_events_statements_history_long_sizing= 0; + + init_event_name_sizing(& param); rc= init_instruments(& param); ok(rc == 0, "zero init"); @@ -61,14 +77,17 @@ void test_no_instances() PFS_thread_class dummy_thread_class; PFS_file_class dummy_file_class; PFS_table_share dummy_table_share; + PFS_socket_class dummy_socket_class; PFS_mutex *mutex; PFS_rwlock *rwlock; PFS_cond *cond; PFS_thread *thread; PFS_file *file; + PFS_socket *socket; PFS_table *table; PFS_global_param param; + memset(& param, 0xFF, sizeof(param)); param.m_enabled= true; param.m_mutex_class_sizing= 1; param.m_rwlock_class_sizing= 1; @@ -76,6 +95,7 @@ void test_no_instances() param.m_thread_class_sizing= 1; param.m_table_share_sizing= 1; param.m_file_class_sizing= 1; + param.m_socket_class_sizing= 0; param.m_mutex_sizing= 0; param.m_rwlock_sizing= 0; param.m_cond_sizing= 0; @@ -83,9 +103,22 @@ void test_no_instances() param.m_table_sizing= 0; param.m_file_sizing= 0; param.m_file_handle_sizing= 0; + param.m_socket_sizing= 0; param.m_events_waits_history_sizing= 0; param.m_events_waits_history_long_sizing= 0; - + param.m_setup_actor_sizing= 0; + param.m_setup_object_sizing= 0; + param.m_host_sizing= 0; + param.m_user_sizing= 0; + param.m_account_sizing= 0; + param.m_stage_class_sizing= 0; + param.m_events_stages_history_sizing= 0; + param.m_events_stages_history_long_sizing= 0; + param.m_statement_class_sizing= 0; + param.m_events_statements_history_sizing= 0; + param.m_events_statements_history_long_sizing= 0; + + init_event_name_sizing(& param); rc= init_instruments(& param); ok(rc == 0, "no instances init"); @@ -144,16 +177,23 @@ void test_no_instances() ok(file == NULL, "no file"); ok(file_lost == 5, "lost 5"); - table= create_table(& dummy_table_share, NULL); + table= create_table(& dummy_table_share, & fake_thread, NULL); ok(table == NULL, "no table"); ok(table_lost == 1, "lost 1"); - table= create_table(& dummy_table_share, NULL); + table= create_table(& dummy_table_share, & fake_thread, NULL); ok(table == NULL, "no table"); ok(table_lost == 2, "lost 2"); + socket= create_socket(& dummy_socket_class, NULL); + ok(socket == NULL, "no socket"); + ok(socket_lost == 1, "lost 1"); + socket= create_socket(& dummy_socket_class, NULL); + ok(socket == NULL, "no socket"); + ok(socket_lost == 2, "lost 2"); + /* No result to test, just make sure it does not crash */ reset_events_waits_by_instance(); - reset_per_thread_wait_stat(); + reset_events_waits_by_thread(); cleanup_file_hash(); cleanup_instruments(); @@ -167,6 +207,7 @@ void test_with_instances() PFS_cond_class dummy_cond_class; PFS_thread_class dummy_thread_class; PFS_file_class dummy_file_class; + PFS_socket_class dummy_socket_class; PFS_table_share dummy_table_share; PFS_mutex *mutex_1; PFS_mutex *mutex_2; @@ -178,10 +219,13 @@ void test_with_instances() PFS_thread *thread_2; PFS_file *file_1; PFS_file *file_2; + PFS_socket *socket_1; + PFS_socket *socket_2; PFS_table *table_1; PFS_table *table_2; PFS_global_param param; + memset(& param, 0xFF, sizeof(param)); param.m_enabled= true; param.m_mutex_class_sizing= 1; param.m_rwlock_class_sizing= 1; @@ -189,6 +233,7 @@ void test_with_instances() param.m_thread_class_sizing= 1; param.m_table_share_sizing= 1; param.m_file_class_sizing= 1; + param.m_socket_class_sizing= 1; param.m_mutex_sizing= 2; param.m_rwlock_sizing= 2; param.m_cond_sizing= 2; @@ -196,12 +241,31 @@ void test_with_instances() param.m_table_sizing= 2; param.m_file_sizing= 2; param.m_file_handle_sizing= 100; + param.m_socket_sizing= 2; param.m_events_waits_history_sizing= 10; param.m_events_waits_history_long_sizing= 10000; - + param.m_setup_actor_sizing= 0; + param.m_setup_object_sizing= 0; + param.m_host_sizing= 0; + param.m_user_sizing= 0; + param.m_account_sizing= 0; + param.m_stage_class_sizing= 0; + param.m_events_stages_history_sizing= 0; + param.m_events_stages_history_long_sizing= 0; + param.m_statement_class_sizing= 0; + param.m_events_statements_history_sizing= 0; + param.m_events_statements_history_long_sizing= 0; + + init_event_name_sizing(& param); rc= init_instruments(& param); ok(rc == 0, "instances init"); + dummy_mutex_class.m_event_name_index= 0; + dummy_rwlock_class.m_event_name_index= 1; + dummy_cond_class.m_event_name_index= 2; + dummy_file_class.m_event_name_index= 3; + dummy_socket_class.m_event_name_index= 4; + mutex_1= create_mutex(& dummy_mutex_class, NULL); ok(mutex_1 != NULL, "mutex"); ok(mutex_lost == 0, "not lost"); @@ -294,110 +358,42 @@ void test_with_instances() ok(file_2 == NULL, "no file"); ok(file_lost == 2, "lost"); - table_1= create_table(& dummy_table_share, NULL); + socket_1= create_socket(& dummy_socket_class, NULL); + ok(socket_1 != NULL, "socket"); + ok(socket_lost == 0, "not lost"); + socket_2= create_socket(& dummy_socket_class, NULL); + ok(socket_2 != NULL, "socket"); + ok(socket_lost == 0, "not lost"); + socket_2= create_socket(& dummy_socket_class, NULL); + ok(socket_2 == NULL, "no socket"); + ok(socket_lost == 1, "lost 1"); + destroy_socket(socket_1); + socket_2= create_socket(& dummy_socket_class, NULL); + ok(socket_2 != NULL, "socket"); + ok(socket_lost == 1, "no new loss"); + + table_1= create_table(& dummy_table_share, & fake_thread, NULL); ok(table_1 != NULL, "table"); ok(table_lost == 0, "not lost"); - table_2= create_table(& dummy_table_share, NULL); + table_2= create_table(& dummy_table_share, & fake_thread, NULL); ok(table_2 != NULL, "table"); ok(table_lost == 0, "not lost"); - table_2= create_table(& dummy_table_share, NULL); + table_2= create_table(& dummy_table_share, & fake_thread, NULL); ok(table_2 == NULL, "no table"); ok(table_lost == 1, "lost 1"); destroy_table(table_1); - table_2= create_table(& dummy_table_share, NULL); + table_2= create_table(& dummy_table_share, & fake_thread, NULL); ok(table_2 != NULL, "table"); ok(table_lost == 1, "no new loss"); //TODO: test that cleanup works reset_events_waits_by_instance(); - reset_per_thread_wait_stat(); + reset_events_waits_by_thread(); cleanup_file_hash(); cleanup_instruments(); } -void test_per_thread_wait() -{ - int rc; - PFS_mutex_class dummy_mutex_class; - PFS_rwlock_class dummy_rwlock_class; - PFS_cond_class dummy_cond_class; - PFS_thread_class dummy_thread_class; - PFS_file_class dummy_file_class; - PFS_thread *thread; - PFS_single_stat_chain *base; - PFS_single_stat_chain *stat; - PFS_global_param param; - - - /* Per mutex info waits should be at [0..9] */ - mutex_class_max= 10; - /* Per rwlock info waits should be at [10..29] */ - rwlock_class_max= 20; - /* Per cond info waits should be at [30..69] */ - cond_class_max= 40; - /* Per file info waits should be at [70..149] */ - file_class_max= 80; - /* Per table info waits should be at [150..309] */ - table_share_max= 160; - - param.m_enabled= true; - param.m_mutex_class_sizing= mutex_class_max; - param.m_rwlock_class_sizing= rwlock_class_max; - param.m_cond_class_sizing= cond_class_max; - param.m_thread_class_sizing= 2; - param.m_table_share_sizing= table_share_max; - param.m_file_class_sizing= file_class_max; - param.m_mutex_sizing= 0; - param.m_rwlock_sizing= 0; - param.m_cond_sizing= 0; - param.m_thread_sizing= 2; - param.m_table_sizing= 0; - param.m_file_sizing= 0; - param.m_file_handle_sizing= 0; - param.m_events_waits_history_sizing= 10; - param.m_events_waits_history_long_sizing= 10000; - - rc= init_instruments(& param); - ok(rc == 0, "instances init"); - - thread= create_thread(& dummy_thread_class, NULL, 0); - ok(thread != NULL, "thread"); - ok(thread_lost == 0, "not lost"); - - base= & thread->m_instr_class_wait_stats[0]; - - dummy_mutex_class.m_index= 0; - stat= find_per_thread_mutex_class_wait_stat(thread, & dummy_mutex_class); - ok(base + 0 == stat, "fist mutex info slot at 0"); - dummy_mutex_class.m_index= mutex_class_max - 1; - stat= find_per_thread_mutex_class_wait_stat(thread, & dummy_mutex_class); - ok(base + 9 == stat, "last mutex info slot at 9"); - - dummy_rwlock_class.m_index= 0; - stat= find_per_thread_rwlock_class_wait_stat(thread, & dummy_rwlock_class); - ok(base + 10 == stat, "fist rwlock info slot at 10"); - dummy_rwlock_class.m_index= rwlock_class_max - 1; - stat= find_per_thread_rwlock_class_wait_stat(thread, & dummy_rwlock_class); - ok(base + 29 == stat, "last rwlock info slot at 29"); - - dummy_cond_class.m_index= 0; - stat= find_per_thread_cond_class_wait_stat(thread, & dummy_cond_class); - ok(base + 30 == stat, "fist cond info slot at 30"); - dummy_cond_class.m_index= cond_class_max - 1; - stat= find_per_thread_cond_class_wait_stat(thread, & dummy_cond_class); - ok(base + 69 == stat, "last cond info slot at 69"); - - dummy_file_class.m_index= 0; - stat= find_per_thread_file_class_wait_stat(thread, & dummy_file_class); - ok(base + 70 == stat, "fist file info slot at 70"); - dummy_file_class.m_index= file_class_max - 1; - stat= find_per_thread_file_class_wait_stat(thread, & dummy_file_class); - ok(base + 149 == stat, "last file info slot at 149"); - - cleanup_instruments(); -} - void do_all_tests() { PFS_atomic::init(); @@ -405,14 +401,13 @@ void do_all_tests() test_no_instruments(); test_no_instances(); test_with_instances(); - test_per_thread_wait(); PFS_atomic::cleanup(); } int main(int argc, char **argv) { - plan(102); + plan(103); MY_INIT(argv[0]); do_all_tests(); my_end(0); diff --git a/storage/perfschema/unittest/pfs_instr_class-oom-t.cc b/storage/perfschema/unittest/pfs_instr_class-oom-t.cc index 49f229015b8..2de83e654c5 100644 --- a/storage/perfschema/unittest/pfs_instr_class-oom-t.cc +++ b/storage/perfschema/unittest/pfs_instr_class-oom-t.cc @@ -38,11 +38,20 @@ void test_oom() ok(rc == 1, "oom (file)"); rc= init_table_share(1000); ok(rc == 1, "oom (cond)"); + rc= init_socket_class(1000); + ok(rc == 1, "oom (socket)"); + rc= init_stage_class(1000); + ok(rc == 1, "oom (stage)"); + rc= init_statement_class(1000); + ok(rc == 1, "oom (statement)"); cleanup_sync_class(); cleanup_thread_class(); cleanup_file_class(); cleanup_table_share(); + cleanup_socket_class(); + cleanup_stage_class(); + cleanup_statement_class(); } void do_all_tests() @@ -56,11 +65,10 @@ void do_all_tests() int main(int argc, char **argv) { - plan(6); + plan(9); MY_INIT(argv[0]); do_all_tests(); my_end(0); return 0; } - diff --git a/storage/perfschema/unittest/pfs_instr_class-t.cc b/storage/perfschema/unittest/pfs_instr_class-t.cc index ea50f0647d9..9e3efde656e 100644 --- a/storage/perfschema/unittest/pfs_instr_class-t.cc +++ b/storage/perfschema/unittest/pfs_instr_class-t.cc @@ -29,12 +29,14 @@ void test_no_registration() PFS_sync_key key; PFS_thread_key thread_key; PFS_file_key file_key; + PFS_socket_key socket_key; PFS_mutex_class *mutex; PFS_rwlock_class *rwlock; PFS_cond_class *cond; PFS_thread_class *thread; PFS_file_class *file; - PFS_table_share *table; + PFS_socket_class *socket; + /* PFS_table_share *table; */ rc= init_sync_class(0, 0, 0); ok(rc == 0, "zero init (sync)"); @@ -42,6 +44,8 @@ void test_no_registration() ok(rc == 0, "zero init (thread)"); rc= init_file_class(0); ok(rc == 0, "zero init (file)"); + rc= init_socket_class(0); + ok(rc == 0, "zero init (socket)"); rc= init_table_share(0); ok(rc == 0, "zero init (table)"); @@ -80,15 +84,24 @@ void test_no_registration() file_key= register_file_class("FOO", 3, 0); ok(file_key == 0, "no file registered"); + socket_key= register_socket_class("FOO", 3, 0); + ok(socket_key == 0, "no socket registered"); + socket_key= register_socket_class("BAR", 3, 0); + ok(socket_key == 0, "no socket registered"); + socket_key= register_socket_class("FOO", 3, 0); + ok(socket_key == 0, "no socket registered"); + +#ifdef LATER PFS_thread fake_thread; fake_thread.m_table_share_hash_pins= NULL; - table= find_or_create_table_share(& fake_thread, "foo_db", 6, "foo_table", 9); + table= find_or_create_table_share(& fake_thread, false, "foo_db", 6, "foo_table", 9); ok(table == NULL, "not created"); - table= find_or_create_table_share(& fake_thread, "bar_db", 6, "bar_table", 9); + table= find_or_create_table_share(& fake_thread, false, "bar_db", 6, "bar_table", 9); ok(table == NULL, "not created"); - table= find_or_create_table_share(& fake_thread, "foo_db", 6, "foo_table", 9); + table= find_or_create_table_share(& fake_thread, false, "foo_db", 6, "foo_table", 9); ok(table == NULL, "not created"); +#endif mutex= find_mutex_class(0); ok(mutex == NULL, "no mutex key 0"); @@ -125,9 +138,17 @@ void test_no_registration() file= find_file_class(9999); ok(file == NULL, "no file key 9999"); + socket= find_socket_class(0); + ok(socket == NULL, "no socket key 0"); + socket= find_socket_class(1); + ok(socket == NULL, "no socket key 1"); + socket= find_socket_class(9999); + ok(socket == NULL, "no socket key 9999"); + cleanup_sync_class(); cleanup_thread_class(); cleanup_file_class(); + cleanup_socket_class(); cleanup_table_share(); } @@ -346,8 +367,56 @@ void test_file_registration() cleanup_file_class(); } +void test_socket_registration() +{ + int rc; + PFS_socket_key key; + PFS_socket_class *socket; + + rc= init_socket_class(5); + ok(rc == 0, "room for 5 socket"); + + key= register_socket_class("FOO", 3, 0); + ok(key == 1, "foo registered"); + key= register_socket_class("BAR", 3, 0); + ok(key == 2, "bar registered"); + key= register_socket_class("FOO", 3, 0); + ok(key == 1, "foo re registered"); + key= register_socket_class("Socket-3", 8, 0); + ok(key == 3, "Socket-3 registered"); + key= register_socket_class("Socket-4", 8, 0); + ok(key == 4, "Socket-4 registered"); + key= register_socket_class("Socket-5", 8, 0); + ok(key == 5, "Socket-5 registered"); + ok(socket_class_lost == 0, "lost nothing"); + key= register_socket_class("Socket-6", 8, 0); + ok(key == 0, "Socket-6 not registered"); + ok(socket_class_lost == 1, "lost 1 socket"); + key= register_socket_class("Socket-7", 8, 0); + ok(key == 0, "Socket-7 not registered"); + ok(socket_class_lost == 2, "lost 2 socket"); + key= register_socket_class("Socket-3", 8, 0); + ok(key == 3, "Socket-3 re registered"); + ok(socket_class_lost == 2, "lost 2 socket"); + key= register_socket_class("Socket-5", 8, 0); + ok(key == 5, "Socket-5 re registered"); + ok(socket_class_lost == 2, "lost 2 socket"); + + socket= find_socket_class(0); + ok(socket == NULL, "no key 0"); + socket= find_socket_class(3); + ok(socket != NULL, "found key 3"); + ok(strncmp(socket->m_name, "Socket-3", 8) == 0, "key 3 is Socket-3"); + ok(socket->m_name_length == 8, "name length 3"); + socket= find_socket_class(9999); + ok(socket == NULL, "no key 9999"); + + cleanup_socket_class(); +} + void test_table_registration() { +#ifdef LATER PFS_table_share *table_share; PFS_table_share *table_share_2; @@ -355,7 +424,7 @@ void test_table_registration() fake_thread.m_table_share_hash_pins= NULL; table_share_lost= 0; - table_share= find_or_create_table_share(& fake_thread, "db1", 3, "t1", 2); + table_share= find_or_create_table_share(& fake_thread, false, "db1", 3, "t1", 2); ok(table_share == NULL, "not created"); ok(table_share_lost == 1, "lost the table"); @@ -363,37 +432,37 @@ void test_table_registration() init_table_share(5); init_table_share_hash(); - table_share= find_or_create_table_share(& fake_thread, "db1", 3, "t1", 2); + table_share= find_or_create_table_share(& fake_thread, false, "db1", 3, "t1", 2); ok(table_share != NULL, "created db1.t1"); ok(table_share_lost == 0, "not lost"); - table_share_2= find_or_create_table_share(& fake_thread, "db1", 3, "t1", 2); + table_share_2= find_or_create_table_share(& fake_thread, false, "db1", 3, "t1", 2); ok(table_share_2 != NULL, "found db1.t1"); ok(table_share_lost == 0, "not lost"); ok(table_share == table_share_2, "same table"); - table_share_2= find_or_create_table_share(& fake_thread, "db1", 3, "t2", 2); + table_share_2= find_or_create_table_share(& fake_thread, false, "db1", 3, "t2", 2); ok(table_share_2 != NULL, "created db1.t2"); ok(table_share_lost == 0, "not lost"); - table_share_2= find_or_create_table_share(& fake_thread, "db2", 3, "t1", 2); + table_share_2= find_or_create_table_share(& fake_thread, false, "db2", 3, "t1", 2); ok(table_share_2 != NULL, "created db2.t1"); ok(table_share_lost == 0, "not lost"); - table_share_2= find_or_create_table_share(& fake_thread, "db2", 3, "t2", 2); + table_share_2= find_or_create_table_share(& fake_thread, false, "db2", 3, "t2", 2); ok(table_share_2 != NULL, "created db2.t2"); ok(table_share_lost == 0, "not lost"); - table_share_2= find_or_create_table_share(& fake_thread, "db3", 3, "t3", 2); + table_share_2= find_or_create_table_share(& fake_thread, false, "db3", 3, "t3", 2); ok(table_share_2 != NULL, "created db3.t3"); ok(table_share_lost == 0, "not lost"); - table_share_2= find_or_create_table_share(& fake_thread, "db4", 3, "t4", 2); + table_share_2= find_or_create_table_share(& fake_thread, false, "db4", 3, "t4", 2); ok(table_share_2 == NULL, "lost db4.t4"); ok(table_share_lost == 1, "lost"); table_share_lost= 0; - table_share_2= find_or_create_table_share(& fake_thread, "db1", 3, "t2", 2); + table_share_2= find_or_create_table_share(& fake_thread, false, "db1", 3, "t2", 2); ok(table_share_2 != NULL, "found db1.t2"); ok(table_share_lost == 0, "not lost"); ok(strncmp(table_share_2->m_schema_name, "db1", 3) == 0 , "schema db1"); @@ -403,18 +472,25 @@ void test_table_registration() cleanup_table_share_hash(); cleanup_table_share(); +#endif } -void set_wait_stat(PFS_single_stat_chain *stat) +void set_wait_stat(PFS_instr_class *klass) { + PFS_single_stat *stat; + stat= & global_instr_class_waits_array[klass->m_event_name_index]; + stat->m_count= 12; stat->m_min= 5; stat->m_max= 120; stat->m_sum= 999; } -bool is_empty_stat(PFS_single_stat_chain *stat) +bool is_empty_stat(PFS_instr_class *klass) { + PFS_single_stat *stat; + stat= & global_instr_class_waits_array[klass->m_event_name_index]; + if (stat->m_count != 0) return false; if (stat->m_min != (ulonglong) -1) @@ -431,6 +507,7 @@ void test_instruments_reset() int rc; PFS_sync_key key; PFS_file_key file_key; + PFS_socket_key socket_key; PFS_mutex_class *mutex_1; PFS_mutex_class *mutex_2; PFS_mutex_class *mutex_3; @@ -443,6 +520,9 @@ void test_instruments_reset() PFS_file_class *file_1; PFS_file_class *file_2; PFS_file_class *file_3; + PFS_socket_class *socket_1; + PFS_socket_class *socket_2; + PFS_socket_class *socket_3; rc= init_sync_class(3, 3, 3); ok(rc == 0, "init (sync)"); @@ -450,6 +530,8 @@ void test_instruments_reset() ok(rc == 0, "init (thread)"); rc= init_file_class(3); ok(rc == 0, "init (file)"); + rc= init_socket_class(3); + ok(rc == 0, "init (socket)"); key= register_mutex_class("M-1", 3, 0); ok(key == 1, "mutex registered"); @@ -479,6 +561,13 @@ void test_instruments_reset() file_key= register_file_class("F-3", 3, 0); ok(file_key == 3, "file registered"); + socket_key= register_socket_class("S-1", 3, 0); + ok(socket_key == 1, "socket registered"); + socket_key= register_socket_class("S-2", 3, 0); + ok(socket_key == 2, "socket registered"); + socket_key= register_socket_class("S-3", 3, 0); + ok(socket_key == 3, "socket registered"); + mutex_1= find_mutex_class(1); ok(mutex_1 != NULL, "mutex key 1"); mutex_2= find_mutex_class(2); @@ -507,49 +596,59 @@ void test_instruments_reset() file_3= find_file_class(3); ok(file_3 != NULL, "file key 3"); - set_wait_stat(& mutex_1->m_wait_stat); - set_wait_stat(& mutex_2->m_wait_stat); - set_wait_stat(& mutex_3->m_wait_stat); - set_wait_stat(& rwlock_1->m_wait_stat); - set_wait_stat(& rwlock_2->m_wait_stat); - set_wait_stat(& rwlock_3->m_wait_stat); - set_wait_stat(& cond_1->m_wait_stat); - set_wait_stat(& cond_2->m_wait_stat); - set_wait_stat(& cond_3->m_wait_stat); - set_wait_stat(& file_1->m_wait_stat); - set_wait_stat(& file_2->m_wait_stat); - set_wait_stat(& file_3->m_wait_stat); - - ok(! is_empty_stat(& mutex_1->m_wait_stat), "mutex_1 stat is populated"); - ok(! is_empty_stat(& mutex_2->m_wait_stat), "mutex_2 stat is populated"); - ok(! is_empty_stat(& mutex_3->m_wait_stat), "mutex_3 stat is populated"); - ok(! is_empty_stat(& rwlock_1->m_wait_stat), "rwlock_1 stat is populated"); - ok(! is_empty_stat(& rwlock_2->m_wait_stat), "rwlock_2 stat is populated"); - ok(! is_empty_stat(& rwlock_3->m_wait_stat), "rwlock_3 stat is populated"); - ok(! is_empty_stat(& cond_1->m_wait_stat), "cond_1 stat is populated"); - ok(! is_empty_stat(& cond_2->m_wait_stat), "cond_2 stat is populated"); - ok(! is_empty_stat(& cond_3->m_wait_stat), "cond_3 stat is populated"); - ok(! is_empty_stat(& file_1->m_wait_stat), "file_1 stat is populated"); - ok(! is_empty_stat(& file_2->m_wait_stat), "file_2 stat is populated"); - ok(! is_empty_stat(& file_3->m_wait_stat), "file_3 stat is populated"); - - reset_instrument_class_waits(); - - ok(is_empty_stat(& mutex_1->m_wait_stat), "mutex_1 stat is cleared"); - ok(is_empty_stat(& mutex_2->m_wait_stat), "mutex_2 stat is cleared"); - ok(is_empty_stat(& mutex_3->m_wait_stat), "mutex_3 stat is cleared"); - ok(is_empty_stat(& rwlock_1->m_wait_stat), "rwlock_1 stat is cleared"); - ok(is_empty_stat(& rwlock_2->m_wait_stat), "rwlock_2 stat is cleared"); - ok(is_empty_stat(& rwlock_3->m_wait_stat), "rwlock_3 stat is cleared"); - ok(is_empty_stat(& cond_1->m_wait_stat), "cond_1 stat is cleared"); - ok(is_empty_stat(& cond_2->m_wait_stat), "cond_2 stat is cleared"); - ok(is_empty_stat(& cond_3->m_wait_stat), "cond_3 stat is cleared"); - ok(is_empty_stat(& file_1->m_wait_stat), "file_1 stat is cleared"); - ok(is_empty_stat(& file_2->m_wait_stat), "file_2 stat is cleared"); - ok(is_empty_stat(& file_3->m_wait_stat), "file_3 stat is cleared"); + socket_1= find_socket_class(1); + ok(socket_1 != NULL, "socket key 1"); + socket_2= find_socket_class(2); + ok(socket_2 != NULL, "socket key 2"); + socket_3= find_socket_class(3); + ok(socket_3 != NULL, "socket key 3"); + +#ifdef LATER + set_wait_stat(mutex_1); + set_wait_stat(mutex_2); + set_wait_stat(mutex_3); + set_wait_stat(rwlock_1); + set_wait_stat(rwlock_2); + set_wait_stat(rwlock_3); + set_wait_stat(cond_1); + set_wait_stat(cond_2); + set_wait_stat(cond_3); + set_wait_stat(file_1); + set_wait_stat(file_2); + set_wait_stat(file_3); + + ok(! is_empty_stat(mutex_1), "mutex_1 stat is populated"); + ok(! is_empty_stat(mutex_2), "mutex_2 stat is populated"); + ok(! is_empty_stat(mutex_3), "mutex_3 stat is populated"); + ok(! is_empty_stat(rwlock_1), "rwlock_1 stat is populated"); + ok(! is_empty_stat(rwlock_2), "rwlock_2 stat is populated"); + ok(! is_empty_stat(rwlock_3), "rwlock_3 stat is populated"); + ok(! is_empty_stat(cond_1), "cond_1 stat is populated"); + ok(! is_empty_stat(cond_2), "cond_2 stat is populated"); + ok(! is_empty_stat(cond_3), "cond_3 stat is populated"); + ok(! is_empty_stat(file_1), "file_1 stat is populated"); + ok(! is_empty_stat(file_2), "file_2 stat is populated"); + ok(! is_empty_stat(file_3), "file_3 stat is populated"); + + reset_global_wait_stat(); + + ok(is_empty_stat(mutex_1), "mutex_1 stat is cleared"); + ok(is_empty_stat(mutex_2), "mutex_2 stat is cleared"); + ok(is_empty_stat(mutex_3), "mutex_3 stat is cleared"); + ok(is_empty_stat(rwlock_1), "rwlock_1 stat is cleared"); + ok(is_empty_stat(rwlock_2), "rwlock_2 stat is cleared"); + ok(is_empty_stat(rwlock_3), "rwlock_3 stat is cleared"); + ok(is_empty_stat(cond_1), "cond_1 stat is cleared"); + ok(is_empty_stat(cond_2), "cond_2 stat is cleared"); + ok(is_empty_stat(cond_3), "cond_3 stat is cleared"); + ok(is_empty_stat(file_1), "file_1 stat is cleared"); + ok(is_empty_stat(file_2), "file_2 stat is cleared"); + ok(is_empty_stat(file_3), "file_3 stat is cleared"); +#endif cleanup_sync_class(); cleanup_file_class(); + cleanup_socket_class(); } void do_all_tests() @@ -562,6 +661,7 @@ void do_all_tests() test_cond_registration(); test_thread_registration(); test_file_registration(); + test_socket_registration(); test_table_registration(); test_instruments_reset(); @@ -570,11 +670,9 @@ void do_all_tests() int main(int argc, char **argv) { - plan(196); + plan(181); MY_INIT(argv[0]); do_all_tests(); my_end(0); return 0; } - - diff --git a/storage/perfschema/unittest/pfs_timer-t.cc b/storage/perfschema/unittest/pfs_timer-t.cc index 9a1c743f642..9c9ae0f75f1 100644 --- a/storage/perfschema/unittest/pfs_timer-t.cc +++ b/storage/perfschema/unittest/pfs_timer-t.cc @@ -34,26 +34,26 @@ void test_timers() init_timers(); - t1_a= get_timer_value(TIMER_NAME_CYCLE); + t1_a= get_timer_pico_value(TIMER_NAME_CYCLE); /* Wait 5 seconds */ my_sleep(5000000); - t1_b= get_timer_value(TIMER_NAME_CYCLE); + t1_b= get_timer_pico_value(TIMER_NAME_CYCLE); - t2_a= get_timer_value(TIMER_NAME_NANOSEC); + t2_a= get_timer_pico_value(TIMER_NAME_NANOSEC); my_sleep(5000000); - t2_b= get_timer_value(TIMER_NAME_NANOSEC); + t2_b= get_timer_pico_value(TIMER_NAME_NANOSEC); - t3_a= get_timer_value(TIMER_NAME_MICROSEC); + t3_a= get_timer_pico_value(TIMER_NAME_MICROSEC); my_sleep(5000000); - t3_b= get_timer_value(TIMER_NAME_MICROSEC); + t3_b= get_timer_pico_value(TIMER_NAME_MICROSEC); - t4_a= get_timer_value(TIMER_NAME_MILLISEC); + t4_a= get_timer_pico_value(TIMER_NAME_MILLISEC); my_sleep(5000000); - t4_b= get_timer_value(TIMER_NAME_MILLISEC); + t4_b= get_timer_pico_value(TIMER_NAME_MILLISEC); - t5_a= get_timer_value(TIMER_NAME_TICK); + t5_a= get_timer_pico_value(TIMER_NAME_TICK); my_sleep(5000000); - t5_b= get_timer_value(TIMER_NAME_TICK); + t5_b= get_timer_pico_value(TIMER_NAME_TICK); /* Print the timer values, for manual inspection by a human. diff --git a/storage/perfschema/unittest/pfs_user-oom-t.cc b/storage/perfschema/unittest/pfs_user-oom-t.cc new file mode 100644 index 00000000000..1faf29b753a --- /dev/null +++ b/storage/perfschema/unittest/pfs_user-oom-t.cc @@ -0,0 +1,116 @@ +/* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */ + +#include <my_global.h> +#include <my_pthread.h> +#include <pfs_instr.h> +#include <pfs_stat.h> +#include <pfs_global.h> +#include <pfs_user.h> +#include <tap.h> + +#include "stub_pfs_global.h" +#include "stub_server_misc.h" + +#include <string.h> /* memset */ + +void test_oom() +{ + int rc; + PFS_global_param param; + + memset(& param, 0xFF, sizeof(param)); + param.m_enabled= true; + param.m_mutex_class_sizing= 0; + param.m_rwlock_class_sizing= 0; + param.m_cond_class_sizing= 0; + param.m_thread_class_sizing= 10; + param.m_table_share_sizing= 0; + param.m_file_class_sizing= 0; + param.m_mutex_sizing= 0; + param.m_rwlock_sizing= 0; + param.m_cond_sizing= 0; + param.m_thread_sizing= 1000; + param.m_table_sizing= 0; + param.m_file_sizing= 0; + param.m_file_handle_sizing= 0; + param.m_events_waits_history_sizing= 10; + param.m_events_waits_history_long_sizing= 0; + param.m_setup_actor_sizing= 0; + param.m_setup_object_sizing= 0; + param.m_host_sizing= 0; + param.m_user_sizing= 1000; + param.m_account_sizing= 0; + param.m_stage_class_sizing= 50; + param.m_events_stages_history_sizing= 0; + param.m_events_stages_history_long_sizing= 0; + param.m_statement_class_sizing= 50; + param.m_events_statements_history_sizing= 0; + param.m_events_statements_history_long_sizing= 0; + + /* Setup */ + + stub_alloc_always_fails= false; + stub_alloc_fails_after_count= 1000; + + init_event_name_sizing(& param); + rc= init_stage_class(param.m_stage_class_sizing); + ok(rc == 0, "init stage class"); + rc= init_statement_class(param.m_statement_class_sizing); + ok(rc == 0, "init statement class"); + + /* Tests */ + + stub_alloc_fails_after_count= 1; + rc= init_user(& param); + ok(rc == 1, "oom (user)"); + cleanup_user(); + + stub_alloc_fails_after_count= 2; + rc= init_user(& param); + ok(rc == 1, "oom (user waits)"); + cleanup_user(); + + stub_alloc_fails_after_count= 3; + rc= init_user(& param); + ok(rc == 1, "oom (user stages)"); + cleanup_user(); + + stub_alloc_fails_after_count= 4; + rc= init_user(& param); + ok(rc == 1, "oom (user statements)"); + cleanup_user(); + + cleanup_statement_class(); + cleanup_stage_class(); +} + +void do_all_tests() +{ + PFS_atomic::init(); + + test_oom(); + + PFS_atomic::cleanup(); +} + +int main(int, char **) +{ + plan(6); + MY_INIT("pfs_user-oom-t"); + do_all_tests(); + return 0; +} + diff --git a/storage/perfschema/unittest/stub_pfs_defaults.h b/storage/perfschema/unittest/stub_pfs_defaults.h new file mode 100644 index 00000000000..042d069b367 --- /dev/null +++ b/storage/perfschema/unittest/stub_pfs_defaults.h @@ -0,0 +1,23 @@ +/* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +#include <my_global.h> +#include <pfs.h> +#include <pfs_defaults.h> + +void install_default_setup(PSI_bootstrap *) +{ +} + diff --git a/storage/perfschema/unittest/stub_pfs_global.h b/storage/perfschema/unittest/stub_pfs_global.h index 2b581f22645..34c52e18b5a 100644 --- a/storage/perfschema/unittest/stub_pfs_global.h +++ b/storage/perfschema/unittest/stub_pfs_global.h @@ -1,5 +1,4 @@ -/* Copyright (c) 2008 MySQL AB, 2010 Sun Microsystems, Inc. - Use is subject to license terms. +/* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,26 +16,34 @@ #include <my_global.h> #include <my_sys.h> #include <pfs_global.h> +#include <string.h> bool pfs_initialized= false; bool stub_alloc_always_fails= true; int stub_alloc_fails_after_count= 0; -void *pfs_malloc(size_t, myf) +void *pfs_malloc(size_t size, myf) { - static char garbage[100]; - if (stub_alloc_always_fails) return NULL; if (--stub_alloc_fails_after_count <= 0) return NULL; - return garbage; + void *ptr= malloc(size); + if (ptr != NULL) + memset(ptr, 0, size); + return ptr; +} + +void pfs_free(void *ptr) +{ + if (ptr != NULL) + free(ptr); } -void pfs_free(void *) +void pfs_print_error(const char *format, ...) { } diff --git a/storage/perfschema/unittest/stub_print_error.h b/storage/perfschema/unittest/stub_print_error.h index adfa3a62d8c..caad24e5257 100644 --- a/storage/perfschema/unittest/stub_print_error.h +++ b/storage/perfschema/unittest/stub_print_error.h @@ -1,5 +1,4 @@ -/* Copyright (c) 2008 MySQL AB, 2010 Sun Microsystems, Inc. - Use is subject to license terms. +/* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/storage/perfschema/unittest/stub_server_misc.h b/storage/perfschema/unittest/stub_server_misc.h index 17beadbb104..8b008273bd8 100644 --- a/storage/perfschema/unittest/stub_server_misc.h +++ b/storage/perfschema/unittest/stub_server_misc.h @@ -19,3 +19,10 @@ volatile bool ready_to_exit= false; +uint lower_case_table_names= 0; +CHARSET_INFO *files_charset_info= NULL; + +extern "C" void compute_md5_hash(char *, const char *, int) +{ +} + |