diff options
Diffstat (limited to 'storage/perfschema/unittest')
-rw-r--r-- | storage/perfschema/unittest/CMakeLists.txt | 37 | ||||
-rw-r--r-- | storage/perfschema/unittest/pfs-t.cc | 59 | ||||
-rw-r--r-- | storage/perfschema/unittest/pfs_account-oom-t.cc | 1 | ||||
-rw-r--r-- | storage/perfschema/unittest/pfs_connect_attr-t.cc | 345 | ||||
-rw-r--r-- | storage/perfschema/unittest/pfs_host-oom-t.cc | 1 | ||||
-rw-r--r-- | storage/perfschema/unittest/pfs_instr-oom-t.cc | 19 | ||||
-rw-r--r-- | storage/perfschema/unittest/pfs_instr-t.cc | 42 | ||||
-rw-r--r-- | storage/perfschema/unittest/pfs_instr_class-t.cc | 2 |
8 files changed, 454 insertions, 52 deletions
diff --git a/storage/perfschema/unittest/CMakeLists.txt b/storage/perfschema/unittest/CMakeLists.txt index 757bc24c566..c3a7fe5c72f 100644 --- a/storage/perfschema/unittest/CMakeLists.txt +++ b/storage/perfschema/unittest/CMakeLists.txt @@ -1,5 +1,4 @@ -# Copyright (c) 2009, 2010 Sun Microsystems, Inc. -# Use is subject to license terms. +# Copyright (c) 2009, 2012, 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 @@ -11,18 +10,44 @@ # 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 +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/include/mysql ${CMAKE_SOURCE_DIR}/regex ${CMAKE_SOURCE_DIR}/sql - ${CMAKE_SOURCE_DIR}/extra/yassl/include + ${SSL_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/unittest/mytap ${CMAKE_SOURCE_DIR}/storage/perfschema) -ADD_DEFINITIONS(-DMYSQL_SERVER) +ADD_DEFINITIONS(-DMYSQL_SERVER ${SSL_DEFINES}) 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) + +IF(WIN32) + SET(MYSQLD_EXTRA_SOURCES ${CMAKE_SOURCE_DIR}/sql/nt_servc.cc) +ENDIF() + +# We need the server libs to test the blob parser. +# Add sql_builtin.cc here, to force linkage of plugins below. +# Also add mysys/string.c (see Bug#45488) +ADD_EXECUTABLE(pfs_connect_attr-t + pfs_connect_attr-t.cc + ${CMAKE_BINARY_DIR}/sql/sql_builtin.cc + ${CMAKE_SOURCE_DIR}/mysys/string.c + ${MYSQLD_EXTRA_SOURCES} +) +ADD_DEPENDENCIES(pfs_connect_attr-t GenServerSource) +TARGET_LINK_LIBRARIES(pfs_connect_attr-t mytap perfschema) +# We need to explicitly link in everything referenced in sql/sql_builtin.cc +TARGET_LINK_LIBRARIES(pfs_connect_attr-t ${MYSQLD_STATIC_PLUGIN_LIBS}) +TARGET_LINK_LIBRARIES(pfs_connect_attr-t sql binlog rpl master slave sql) +TARGET_LINK_LIBRARIES(pfs_connect_attr-t mysys mysys_ssl) +TARGET_LINK_LIBRARIES(pfs_connect_attr-t vio ${SSL_LIBRARIES}) +TARGET_LINK_LIBRARIES(pfs_connect_attr-t strings dbug regex mysys zlib) +ADD_TEST(pfs_connect_attr pfs_connect_attr-t) + +# On windows, pfs_connect_attr-t may depend on openssl dlls. +COPY_OPENSSL_DLLS(copy_openssl_pfs_unittest) diff --git a/storage/perfschema/unittest/pfs-t.cc b/storage/perfschema/unittest/pfs-t.cc index 6b30c0cc498..31f68195f1b 100644 --- a/storage/perfschema/unittest/pfs-t.cc +++ b/storage/perfschema/unittest/pfs-t.cc @@ -111,6 +111,7 @@ void test_bootstrap() param.m_events_statements_history_sizing= 0; param.m_events_statements_history_long_sizing= 0; param.m_digest_sizing= 0; + param.m_session_connect_attrs_sizing= 0; boot= initialize_performance_schema(& param); ok(boot != NULL, "boot"); @@ -168,6 +169,7 @@ PSI * load_perfschema() param.m_events_statements_history_sizing= 0; param.m_events_statements_history_long_sizing= 0; param.m_digest_sizing= 0; + param.m_session_connect_attrs_sizing= 0; /* test_bootstrap() covered this, assuming it just works */ boot= initialize_performance_schema(& param); @@ -759,21 +761,21 @@ void test_init_disabled() /* disabled S-A + disabled T-1: no instrumentation */ socket_class_A->m_enabled= false; - socket_A1= psi->init_socket(socket_key_A, NULL); + socket_A1= psi->init_socket(socket_key_A, NULL, NULL, 0); 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); + socket_A1= psi->init_socket(socket_key_A, NULL, NULL, 0); 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); + socket_A1= psi->init_socket(0, NULL, NULL, 0); ok(socket_A1 == NULL, "socket key 0 not instrumented"); - socket_A1= psi->init_socket(99, NULL); + socket_A1= psi->init_socket(99, NULL, NULL, 0); ok(socket_A1 == NULL, "broken socket key not instrumented"); /* Pretend thread T-1 is enabled */ @@ -892,16 +894,16 @@ void test_init_disabled() /* enabled S-A + enabled T-1: instrumentation */ socket_class_A->m_enabled= true; - socket_A1= psi->init_socket(socket_key_A, NULL); + socket_A1= psi->init_socket(socket_key_A, NULL, NULL, 0); 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); + socket_A1= psi->init_socket(0, NULL, NULL, 0); ok(socket_A1 == NULL, "not instrumented"); - socket_A1= psi->init_socket(99, NULL); + socket_A1= psi->init_socket(99, NULL, NULL, 0); ok(socket_A1 == NULL, "not instrumented"); /* Pretend the running thread is not instrumented */ @@ -996,21 +998,21 @@ void test_init_disabled() /* disabled S-A + unknown thread: no instrumentation */ socket_class_A->m_enabled= false; - socket_A1= psi->init_socket(socket_key_A, NULL); + socket_A1= psi->init_socket(socket_key_A, NULL, NULL, 0); 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); + socket_A1= psi->init_socket(socket_key_A, NULL, NULL, 0); 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); + socket_A1= psi->init_socket(0, NULL, NULL, 0); ok(socket_A1 == NULL, "socket key 0 not instrumented"); - socket_A1= psi->init_socket(99, NULL); + socket_A1= psi->init_socket(99, NULL, NULL, 0); ok(socket_A1 == NULL, "broken socket key not instrumented"); shutdown_performance_schema(); @@ -1126,7 +1128,7 @@ void test_locker_disabled() ok(file_A1 != NULL, "instrumented"); socket_class_A->m_enabled= true; - socket_A1= psi->init_socket(socket_key_A, NULL); + socket_A1= psi->init_socket(socket_key_A, NULL, NULL, 0); ok(socket_A1 != NULL, "instrumented"); /* Socket lockers require a thread owner */ @@ -1294,10 +1296,10 @@ void test_locker_disabled() cond_locker= psi->start_cond_wait(&cond_state, cond_A1, mutex_A1, PSI_COND_WAIT, __FILE__, __LINE__); ok(cond_locker != NULL, "locker"); 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); + file_locker= psi->get_thread_file_name_locker(&file_state, file_key_A, PSI_FILE_STREAM_OPEN, "xxx", NULL); ok(file_locker != NULL, "locker"); psi->start_file_open_wait(file_locker, __FILE__, __LINE__); - psi->end_file_open_wait(file_locker); + psi->end_file_open_wait(file_locker, NULL); file_locker= psi->get_thread_file_stream_locker(&file_state, file_A1, PSI_FILE_READ); ok(file_locker != NULL, "locker"); psi->start_file_wait(file_locker, 10, __FILE__, __LINE__); @@ -1314,7 +1316,7 @@ void test_locker_disabled() /* ---------------------------------------------- */ socket_class_A->m_enabled= true; - socket_A1= psi->init_socket(socket_key_A, NULL); + socket_A1= psi->init_socket(socket_key_A, NULL, NULL, 0); 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); @@ -1485,6 +1487,8 @@ void test_event_name_index() memset(& param, 0xFF, sizeof(param)); param.m_enabled= true; + /* NOTE: Need to add 3 to each index: table io, table lock, idle */ + /* Per mutex info waits should be at [0..9] */ param.m_mutex_class_sizing= 10; /* Per rwlock info waits should be at [10..29] */ @@ -1509,6 +1513,7 @@ void test_event_name_index() param.m_events_statements_history_sizing= 0; param.m_events_statements_history_long_sizing= 0; param.m_digest_sizing= 0; + param.m_session_connect_attrs_sizing= 0; param.m_mutex_sizing= 0; param.m_rwlock_sizing= 0; @@ -1540,10 +1545,10 @@ void test_event_name_index() 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"); + ok(mutex_class->m_event_name_index == 3, "index 3"); 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"); + ok(mutex_class->m_event_name_index == 4, "index 4"); PFS_rwlock_class *rwlock_class; PSI_rwlock_key dummy_rwlock_key_1; @@ -1557,10 +1562,10 @@ void test_event_name_index() 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"); + ok(rwlock_class->m_event_name_index == 13, "index 13"); 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"); + ok(rwlock_class->m_event_name_index == 14, "index 14"); PFS_cond_class *cond_class; PSI_cond_key dummy_cond_key_1; @@ -1574,10 +1579,10 @@ void test_event_name_index() 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"); + ok(cond_class->m_event_name_index == 33, "index 33"); 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"); + ok(cond_class->m_event_name_index == 34, "index 34"); PFS_file_class *file_class; PSI_file_key dummy_file_key_1; @@ -1591,10 +1596,10 @@ void test_event_name_index() 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"); + ok(file_class->m_event_name_index == 73, "index 73"); 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"); + ok(file_class->m_event_name_index == 74, "index 74"); PFS_socket_class *socket_class; PSI_socket_key dummy_socket_key_1; @@ -1608,13 +1613,13 @@ void test_event_name_index() 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"); + ok(socket_class->m_event_name_index == 153, "index 153"); 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(socket_class->m_event_name_index == 154, "index 154"); - 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(global_table_io_class.m_event_name_index == 0, "index 0"); + ok(global_table_lock_class.m_event_name_index == 1, "index 1"); ok(wait_class_max= 313, "313 event names"); // 3 global classes } diff --git a/storage/perfschema/unittest/pfs_account-oom-t.cc b/storage/perfschema/unittest/pfs_account-oom-t.cc index d0c139476b0..0e48ab68ef7 100644 --- a/storage/perfschema/unittest/pfs_account-oom-t.cc +++ b/storage/perfschema/unittest/pfs_account-oom-t.cc @@ -59,6 +59,7 @@ void test_oom() param.m_statement_class_sizing= 50; param.m_events_statements_history_sizing= 0; param.m_events_statements_history_long_sizing= 0; + param.m_session_connect_attrs_sizing= 0; /* Setup */ diff --git a/storage/perfschema/unittest/pfs_connect_attr-t.cc b/storage/perfschema/unittest/pfs_connect_attr-t.cc new file mode 100644 index 00000000000..7bee1d063a1 --- /dev/null +++ b/storage/perfschema/unittest/pfs_connect_attr-t.cc @@ -0,0 +1,345 @@ +/* Copyright (c) 2008, 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_server.h> +#include <pfs_instr_class.h> +#include <pfs_instr.h> +#include <pfs_global.h> +#include <tap.h> + + +#include <string.h> +#include <memory.h> + +/* test helpers, to inspect data */ +bool read_nth_attr(const char *connect_attrs, uint connect_attrs_length, + const CHARSET_INFO *connect_attrs_cs, + uint ordinal, + char *attr_name, uint max_attr_name, + uint *attr_name_length, + char *attr_value, uint max_attr_value, + uint *attr_value_length); + +void test_blob_parser() +{ + char name[100], value[4096]; + unsigned char packet[10000], *ptr; + uint name_len, value_len, idx, packet_length; + bool result; + const CHARSET_INFO *cs= &my_charset_utf8_bin; + + diag("test_blob_parser"); + + result= read_nth_attr("", 0, cs, 0, + name, 32, &name_len, value, 1024, &value_len); + ok(result == false, "zero length blob"); + + + result= read_nth_attr("\x1", 1, cs, 0, + name, 32, &name_len, value, 1024, &value_len); + ok(result == false, "invalid key length"); + + + result= read_nth_attr("\x2k1\x1", 4, cs, 0, + name, 32, &name_len, value, 1024, &value_len); + ok(result == false, "invalid value length"); + + + result= read_nth_attr("\x2k1\x2v1", 6, cs, 0, + name, 32, &name_len, value, 1024, &value_len); + ok(result == true, "one pair return"); + ok(name_len == 2, "one pair attr name length"); + ok(!strncmp(name, "k1", name_len), "one pair attr name"); + ok(value_len == 2, "one pair value length"); + ok(!strncmp(value, "v1", value_len), "one pair value"); + + result= read_nth_attr("\x2k1\x2v1", 6, cs, 1, + name, 32, &name_len, value, 1024, &value_len); + ok(result == false, "no second arg"); + + result= read_nth_attr("\x2k1\x2v1\x2k2\x2v2", 12, cs, 1, + name, 32, &name_len, value, 1024, &value_len); + ok(result == true, "two pairs return"); + ok(name_len == 2, "two pairs attr name length"); + ok(!strncmp(name, "k2", name_len), "two pairs attr name"); + ok(value_len == 2, "two pairs value length"); + ok(!strncmp(value, "v2", value_len), "two pairs value"); + + result= read_nth_attr("\x2k1\xff\x2k2\x2v2", 12, cs, 1, + name, 32, &name_len, value, 1024, &value_len); + ok(result == false, "two pairs first value bad return"); + + result= read_nth_attr("\x2k1\x2v1\x2k2\x2v2", 10, cs, 1, + name, 32, &name_len, value, 1024, &value_len); + ok(result == false, "two pairs wrong global length"); + + result= read_nth_attr("\x21z123456789z123456789z123456789z12\x2v1", 37, cs, 0, + name, 32, &name_len, value, 1024, &value_len); + ok(result == true, "attr name overflow"); + ok(name_len == 32, "attr name overflow length"); + ok(!strncmp(name, "z123456789z123456789z123456789z1", name_len), + "attr name overflow name"); + ok(value_len == 2, "attr name overflow value length"); + ok(!strncmp(value, "v1", value_len), "attr name overflow value"); + + packet[0]= 2; + packet[1]= 'k'; + packet[2]= '1'; + ptr= net_store_length(packet + 3, 1025); + for (idx= 0; idx < 1025; idx++) + *ptr++= '0' + (idx % 10); + packet_length= (uint) (ptr - packet); + result= read_nth_attr((char *) packet, packet_length, cs, 0, + name, 32, &name_len, value, 1024, &value_len); + ok(result == true, "attr value overflow"); + ok(name_len == 2, "attr value overflow length"); + ok(!strncmp(name, "k1", name_len), "attr value overflow name"); + ok(value_len == 1024, "attr value overflow value length"); + for (idx= 0; idx < 1024; idx++) + { + if (value[idx] != (char) ('0' + (idx % 10))) + break; + } + ok (idx == 1024, "attr value overflow value"); + + result= read_nth_attr("\x21z123456789z123456789z123456789z12\x2v1\x2k2\x2v2", + 43, cs, 1, + name, 32, &name_len, value, 1024, &value_len); + ok(result == true, "prev attr name overflow"); + ok(name_len == 2, "prev attr name overflow length"); + ok(!strncmp(name, "k2", name_len), + "prev attr name overflow name"); + ok(value_len == 2, "prev attr name overflow value length"); + ok(!strncmp(value, "v2", value_len), "prev attr name overflow value"); + + + packet[1]= 'k'; + packet[2]= '1'; + packet[3]= 2; + packet[4]= 'v'; + packet[5]= '1'; + + for(idx= 251; idx < 256; idx++) + { + packet[0]= idx; + result= read_nth_attr((char *) packet, 6, cs, 0, + name, 32, &name_len, value, 1024, &value_len); + ok(result == false, "invalid string length %d", idx); + } + + memset(packet, 0, sizeof(packet)); + for (idx=0; idx < 1660 /* *6 = 9960 */; idx++) + memcpy(packet + idx * 6, "\x2k1\x2v1", 6); + result= read_nth_attr((char *) packet, 8192, cs, 1364, + name, 32, &name_len, value, 1024, &value_len); + ok(result == true, "last valid attribute %d", 1364); + result= read_nth_attr((char *) packet, 8192, cs, 1365, + name, 32, &name_len, value, 1024, &value_len); + ok(result == false, "first attribute that's cut %d", 1365); +} + +void test_multibyte_lengths() +{ + char name[100], value[4096]; + uint name_len, value_len; + bool result; + const CHARSET_INFO *cs= &my_charset_utf8_bin; + + unsigned char var_len_packet[] = { + 252, 2, 0, 'k', '1', + 253, 2, 0, 0, 'v', '1', + 254, 2, 0, 0, 0, 0, 0, 0, 0, 'k', '2', + 254, 2, 0, 0, 0, 0, 0, 0, 0, 'v', '2' + }; + + result= read_nth_attr((char *) var_len_packet, sizeof(var_len_packet), cs, 0, + name, 32, &name_len, value, 1024, &value_len); + ok(result == true, "multibyte lengths return"); + ok(name_len == 2, "multibyte lengths name length"); + ok(!strncmp(name, "k1", name_len), "multibyte lengths attr name"); + ok(value_len == 2, "multibyte lengths value length"); + ok(!strncmp(value, "v1", value_len), "multibyte lengths value"); + + result= read_nth_attr((char *) var_len_packet, sizeof(var_len_packet), cs, 1, + name, 32, &name_len, value, 1024, &value_len); + ok(result == true, "multibyte lengths second attr return"); + ok(name_len == 2, "multibyte lengths second attr name length"); + ok(!strncmp(name, "k2", name_len), "multibyte lengths second attr attr name"); + ok(value_len == 2, "multibyte lengths value length"); + ok(!strncmp(value, "v2", value_len), "multibyte lengths second attr value"); +} + + +void test_utf8_parser() +{ + /* utf8 max byte length per character is 6 */ + char name[33 * 6], value[1024 * 6], packet[1500 * 6], *ptr; + uint name_len, value_len; + bool result; + const CHARSET_INFO *cs= &my_charset_utf8_bin; + + /* note : this is encoded in utf-8 */ + const char *attr1= "Георги"; + const char *val1= "Кодинов"; + const char *attr2= "Пловдив"; + const char *val2= "България"; + + ptr= packet; + *ptr++= strlen(attr1); + memcpy(ptr, attr1, strlen(attr1)); + ptr+= strlen(attr1); + *ptr++= strlen(val1); + memcpy(ptr, val1, strlen(val1)); + ptr+= strlen(val1); + + *ptr++= strlen(attr2); + memcpy(ptr, attr2, strlen(attr2)); + ptr+= strlen(attr2); + *ptr++= strlen(val2); + memcpy(ptr, val2, strlen(val2)); + ptr+= strlen(val2); + + diag("test_utf8_parser attr pair #1"); + + result= read_nth_attr((char *) packet, ptr - packet, cs, 0, + name, sizeof(name), &name_len, + value, sizeof(value), &value_len); + ok(result == true, "return"); + ok(name_len == strlen(attr1), "name length"); + ok(!strncmp(name, attr1, name_len), "attr name"); + ok(value_len == strlen(val1), "value length"); + ok(!strncmp(value, val1, value_len), "value"); + + diag("test_utf8_parser attr pair #2"); + result= read_nth_attr((char *) packet, ptr - packet, cs, 1, + name, sizeof(name), &name_len, + value, sizeof(value), &value_len); + ok(result == true, "return"); + ok(name_len == strlen(attr2), "name length"); + ok(!strncmp(name, attr2, name_len), "attr name"); + ok(value_len == strlen(val2), "value length"); + ok(!strncmp(value, val2, value_len), "value"); +} + + +void test_utf8_parser_bad_encoding() +{ + /* utf8 max byte length per character is 3*/ + char name[33 * 3], value[1024 * 3], packet[1500 * 3], *ptr; + uint name_len, value_len; + bool result; + const CHARSET_INFO *cs= &my_charset_utf8_bin; + + /* note : this is encoded in utf-8 */ + const char *attr= "Георги"; + const char *val= "Кодинов"; + + ptr= packet; + *ptr++= strlen(attr); + memcpy(ptr, attr, strlen(attr)); + ptr[0]= 0xFA; // invalid UTF-8 char + ptr+= strlen(attr); + *ptr++= strlen(val); + memcpy(ptr, val, strlen(val)); + ptr+= strlen(val); + + diag("test_utf8_parser_bad_encoding"); + + result= read_nth_attr((char *) packet, ptr - packet, cs, 0, + name, sizeof(name), &name_len, + value, sizeof(value), &value_len); + ok(result == false, "return"); +} + +const CHARSET_INFO *cs_cp1251; + +void test_cp1251_parser() +{ + /* utf8 max byte length per character is 3*/ + char name[33 * 3], value[1024 * 3], packet[1500 * 3], *ptr; + uint name_len, value_len; + bool result; + + /* note : this is Георги in windows-1251 */ + const char *attr1= "\xc3\xe5\xee\xf0\xe3\xe8"; + /* note : this is Кодинов in windows-1251 */ + const char *val1= "\xca\xee\xe4\xe8\xed\xee\xe2"; + /* note : this is Пловдив in windows-1251 */ + const char *attr2= "\xcf\xeb\xee\xe2\xe4\xe8\xe2"; + /* note : this is България in windows-1251 */ + const char *val2= "\xc1\xfa\xeb\xe3\xe0\xf0\xe8\xff"; + + ptr= packet; + *ptr++= strlen(attr1); + memcpy(ptr, attr1, strlen(attr1)); + ptr+= strlen(attr1); + *ptr++= strlen(val1); + memcpy(ptr, val1, strlen(val1)); + ptr+= strlen(val1); + + *ptr++= strlen(attr2); + memcpy(ptr, attr2, strlen(attr2)); + ptr+= strlen(attr2); + *ptr++= strlen(val2); + memcpy(ptr, val2, strlen(val2)); + ptr+= strlen(val2); + + diag("test_cp1251_parser attr pair #1"); + + result= read_nth_attr((char *) packet, ptr - packet, cs_cp1251, 0, + name, sizeof(name), &name_len, + value, sizeof(value), &value_len); + ok(result == true, "return"); + /* need to compare to the UTF-8 equivalents */ + ok(name_len == strlen("Георги"), "name length"); + ok(!strncmp(name, "Георги", name_len), "attr name"); + ok(value_len == strlen("Кодинов"), "value length"); + ok(!strncmp(value, "Кодинов", value_len), "value"); + + diag("test_cp1251_parser attr pair #2"); + result= read_nth_attr((char *) packet, ptr - packet, cs_cp1251, 1, + name, sizeof(name), &name_len, + value, sizeof(value), &value_len); + ok(result == true, "return"); + /* need to compare to the UTF-8 equivalents */ + ok(name_len == strlen("Пловдив"), "name length"); + ok(!strncmp(name, "Пловдив", name_len), "attr name"); + ok(value_len == strlen("България"), "value length"); + ok(!strncmp(value, "България", value_len), "value"); +} + + +void do_all_tests() +{ + test_blob_parser(); + test_multibyte_lengths(); + test_utf8_parser(); + test_utf8_parser_bad_encoding(); + test_cp1251_parser(); +} + +int main(int, char **) +{ + MY_INIT("pfs_connect_attr-t"); + + cs_cp1251= get_charset_by_csname("cp1251", MY_CS_PRIMARY, MYF(0)); + if (!cs_cp1251) + diag("skipping the cp1251 tests : missing character set"); + plan(59 + (cs_cp1251 ? 10 : 0)); + 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 index a4fb36b0b08..cc445620496 100644 --- a/storage/perfschema/unittest/pfs_host-oom-t.cc +++ b/storage/perfschema/unittest/pfs_host-oom-t.cc @@ -59,6 +59,7 @@ void test_oom() param.m_statement_class_sizing= 50; param.m_events_statements_history_sizing= 0; param.m_events_statements_history_long_sizing= 0; + param.m_session_connect_attrs_sizing= 0; /* Setup */ diff --git a/storage/perfschema/unittest/pfs_instr-oom-t.cc b/storage/perfschema/unittest/pfs_instr-oom-t.cc index 41bb4ed6c5a..5d9873d7927 100644 --- a/storage/perfschema/unittest/pfs_instr-oom-t.cc +++ b/storage/perfschema/unittest/pfs_instr-oom-t.cc @@ -63,6 +63,7 @@ void test_oom() param.m_statement_class_sizing= 0; param.m_events_statements_history_sizing= 0; param.m_events_statements_history_long_sizing= 0; + param.m_session_connect_attrs_sizing= 0; init_event_name_sizing(& param); rc= init_instruments(& param); @@ -98,6 +99,7 @@ void test_oom() param.m_statement_class_sizing= 0; param.m_events_statements_history_sizing= 0; param.m_events_statements_history_long_sizing= 0; + param.m_session_connect_attrs_sizing= 0; init_event_name_sizing(& param); rc= init_instruments(& param); @@ -133,6 +135,7 @@ void test_oom() param.m_statement_class_sizing= 0; param.m_events_statements_history_sizing= 0; param.m_events_statements_history_long_sizing= 0; + param.m_session_connect_attrs_sizing= 0; init_event_name_sizing(& param); rc= init_instruments(& param); @@ -168,6 +171,7 @@ void test_oom() param.m_statement_class_sizing= 0; param.m_events_statements_history_sizing= 0; param.m_events_statements_history_long_sizing= 0; + param.m_session_connect_attrs_sizing= 0; init_event_name_sizing(& param); rc= init_instruments(& param); @@ -201,6 +205,7 @@ void test_oom() param.m_statement_class_sizing= 0; param.m_events_statements_history_sizing= 0; param.m_events_statements_history_long_sizing= 0; + param.m_session_connect_attrs_sizing= 0; init_event_name_sizing(& param); rc= init_instruments(& param); @@ -236,6 +241,7 @@ void test_oom() param.m_statement_class_sizing= 0; param.m_events_statements_history_sizing= 0; param.m_events_statements_history_long_sizing= 0; + param.m_session_connect_attrs_sizing= 0; init_event_name_sizing(& param); rc= init_instruments(& param); @@ -271,6 +277,7 @@ void test_oom() param.m_statement_class_sizing= 0; param.m_events_statements_history_sizing= 0; param.m_events_statements_history_long_sizing= 0; + param.m_session_connect_attrs_sizing= 0; init_event_name_sizing(& param); rc= init_instruments(& param); @@ -308,6 +315,7 @@ void test_oom() param.m_statement_class_sizing= 0; param.m_events_statements_history_sizing= 0; param.m_events_statements_history_long_sizing= 0; + param.m_session_connect_attrs_sizing= 0; stub_alloc_fails_after_count= 2; init_event_name_sizing(& param); @@ -341,6 +349,7 @@ void test_oom() param.m_statement_class_sizing= 0; param.m_events_statements_history_sizing= 0; param.m_events_statements_history_long_sizing= 0; + param.m_session_connect_attrs_sizing= 0; stub_alloc_fails_after_count= 2; init_event_name_sizing(& param); @@ -383,8 +392,9 @@ void test_oom() param.m_statement_class_sizing= 0; param.m_events_statements_history_sizing= 0; param.m_events_statements_history_long_sizing= 0; + param.m_session_connect_attrs_sizing= 0; - stub_alloc_fails_after_count= 2; + stub_alloc_fails_after_count= 1; init_event_name_sizing(& param); rc= init_instruments(& param); ok(rc == 1, "oom (per thread waits)"); @@ -417,6 +427,7 @@ void test_oom() param.m_statement_class_sizing= 0; param.m_events_statements_history_sizing= 0; param.m_events_statements_history_long_sizing= 0; + param.m_session_connect_attrs_sizing= 0; stub_alloc_fails_after_count= 3; init_event_name_sizing(& param); @@ -451,6 +462,7 @@ void test_oom() param.m_statement_class_sizing= 0; param.m_events_statements_history_sizing= 0; param.m_events_statements_history_long_sizing= 0; + param.m_session_connect_attrs_sizing= 0; stub_alloc_fails_after_count= 2; init_event_name_sizing(& param); @@ -485,6 +497,7 @@ void test_oom() param.m_statement_class_sizing= 0; param.m_events_statements_history_sizing= 10; param.m_events_statements_history_long_sizing= 0; + param.m_session_connect_attrs_sizing= 0; stub_alloc_fails_after_count= 2; init_event_name_sizing(& param); @@ -519,6 +532,7 @@ void test_oom() param.m_statement_class_sizing= 50; param.m_events_statements_history_sizing= 0; param.m_events_statements_history_long_sizing= 0; + param.m_session_connect_attrs_sizing= 0; stub_alloc_fails_after_count= 2; init_event_name_sizing(& param); @@ -553,6 +567,7 @@ void test_oom() param.m_statement_class_sizing= 0; param.m_events_statements_history_sizing= 0; param.m_events_statements_history_long_sizing= 0; + param.m_session_connect_attrs_sizing= 0; stub_alloc_fails_after_count= 1; init_event_name_sizing(& param); @@ -587,6 +602,7 @@ void test_oom() param.m_statement_class_sizing= 0; param.m_events_statements_history_sizing= 0; param.m_events_statements_history_long_sizing= 0; + param.m_session_connect_attrs_sizing= 0; stub_alloc_fails_after_count= 3; init_event_name_sizing(& param); @@ -624,6 +640,7 @@ void test_oom() param.m_statement_class_sizing= 20; param.m_events_statements_history_sizing= 0; param.m_events_statements_history_long_sizing= 0; + param.m_session_connect_attrs_sizing= 0; stub_alloc_fails_after_count= 3; init_event_name_sizing(& param); diff --git a/storage/perfschema/unittest/pfs_instr-t.cc b/storage/perfschema/unittest/pfs_instr-t.cc index b0839de70b2..4ef240ea819 100644 --- a/storage/perfschema/unittest/pfs_instr-t.cc +++ b/storage/perfschema/unittest/pfs_instr-t.cc @@ -60,6 +60,8 @@ void test_no_instruments() 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_session_connect_attrs_sizing= 0; init_event_name_sizing(& param); rc= init_instruments(& param); @@ -117,6 +119,8 @@ void test_no_instances() 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_session_connect_attrs_sizing= 0; init_event_name_sizing(& param); rc= init_instruments(& param); @@ -153,19 +157,19 @@ void test_no_instances() PFS_thread fake_thread; fake_thread.m_filename_hash_pins= NULL; - file= find_or_create_file(& fake_thread, & dummy_file_class, "dummy", 5); + file= find_or_create_file(& fake_thread, & dummy_file_class, "dummy", 5, true); ok(file == NULL, "no file"); ok(file_lost == 1, "lost 1"); - file= find_or_create_file(& fake_thread, & dummy_file_class, "dummy", 5); + file= find_or_create_file(& fake_thread, & dummy_file_class, "dummy", 5, true); ok(file == NULL, "no file"); ok(file_lost == 2, "lost 2"); init_file_hash(); - file= find_or_create_file(& fake_thread, & dummy_file_class, "dummy", 5); + file= find_or_create_file(& fake_thread, & dummy_file_class, "dummy", 5, true); ok(file == NULL, "no file"); ok(file_lost == 3, "lost 3"); - file= find_or_create_file(& fake_thread, & dummy_file_class, "dummy", 5); + file= find_or_create_file(& fake_thread, & dummy_file_class, "dummy", 5, true); ok(file == NULL, "no file"); ok(file_lost == 4, "lost 4"); @@ -173,7 +177,7 @@ void test_no_instances() int size= sizeof(long_file_name); memset(long_file_name, 'X', size); - file= find_or_create_file(& fake_thread, & dummy_file_class, long_file_name, size); + file= find_or_create_file(& fake_thread, & dummy_file_class, long_file_name, size, true); ok(file == NULL, "no file"); ok(file_lost == 5, "lost 5"); @@ -184,10 +188,10 @@ void test_no_instances() ok(table == NULL, "no table"); ok(table_lost == 2, "lost 2"); - socket= create_socket(& dummy_socket_class, NULL); + socket= create_socket(& dummy_socket_class, NULL, NULL, 0); ok(socket == NULL, "no socket"); ok(socket_lost == 1, "lost 1"); - socket= create_socket(& dummy_socket_class, NULL); + socket= create_socket(& dummy_socket_class, NULL, NULL, 0); ok(socket == NULL, "no socket"); ok(socket_lost == 2, "lost 2"); @@ -255,6 +259,8 @@ void test_with_instances() 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_session_connect_attrs_sizing= 0; init_event_name_sizing(& param); rc= init_instruments(& param); @@ -325,50 +331,50 @@ void test_with_instances() PFS_thread fake_thread; fake_thread.m_filename_hash_pins= NULL; - file_1= find_or_create_file(& fake_thread, & dummy_file_class, "dummy", 5); + file_1= find_or_create_file(& fake_thread, & dummy_file_class, "dummy", 5, true); ok(file_1 == NULL, "no file"); ok(file_lost == 1, "lost 1"); - file_1= find_or_create_file(& fake_thread, & dummy_file_class, "dummy", 5); + file_1= find_or_create_file(& fake_thread, & dummy_file_class, "dummy", 5, true); ok(file_1 == NULL, "no file"); ok(file_lost == 2, "lost 2"); init_file_hash(); file_lost= 0; - file_1= find_or_create_file(& fake_thread, & dummy_file_class, "dummy_A", 7); + file_1= find_or_create_file(& fake_thread, & dummy_file_class, "dummy_A", 7, true); ok(file_1 != NULL, "file"); ok(file_1->m_file_stat.m_open_count == 1, "open count 1"); ok(file_lost == 0, "not lost"); - file_2= find_or_create_file(& fake_thread, & dummy_file_class, "dummy_A", 7); + file_2= find_or_create_file(& fake_thread, & dummy_file_class, "dummy_A", 7, true); ok(file_1 == file_2, "same file"); ok(file_1->m_file_stat.m_open_count == 2, "open count 2"); ok(file_lost == 0, "not lost"); release_file(file_2); ok(file_1->m_file_stat.m_open_count == 1, "open count 1"); - file_2= find_or_create_file(& fake_thread, & dummy_file_class, "dummy_B", 7); + file_2= find_or_create_file(& fake_thread, & dummy_file_class, "dummy_B", 7, true); ok(file_2 != NULL, "file"); ok(file_lost == 0, "not lost"); - file_2= find_or_create_file(& fake_thread, & dummy_file_class, "dummy_C", 7); + file_2= find_or_create_file(& fake_thread, & dummy_file_class, "dummy_C", 7, true); ok(file_2 == NULL, "no file"); ok(file_lost == 1, "lost"); release_file(file_1); /* the file still exists, not destroyed */ ok(file_1->m_file_stat.m_open_count == 0, "open count 0"); - file_2= find_or_create_file(& fake_thread, & dummy_file_class, "dummy_D", 7); + file_2= find_or_create_file(& fake_thread, & dummy_file_class, "dummy_D", 7, true); ok(file_2 == NULL, "no file"); ok(file_lost == 2, "lost"); - socket_1= create_socket(& dummy_socket_class, NULL); + socket_1= create_socket(& dummy_socket_class, NULL, NULL, 0); ok(socket_1 != NULL, "socket"); ok(socket_lost == 0, "not lost"); - socket_2= create_socket(& dummy_socket_class, NULL); + socket_2= create_socket(& dummy_socket_class, NULL, NULL, 0); ok(socket_2 != NULL, "socket"); ok(socket_lost == 0, "not lost"); - socket_2= create_socket(& dummy_socket_class, NULL); + socket_2= create_socket(& dummy_socket_class, NULL, NULL, 0); ok(socket_2 == NULL, "no socket"); ok(socket_lost == 1, "lost 1"); destroy_socket(socket_1); - socket_2= create_socket(& dummy_socket_class, NULL); + socket_2= create_socket(& dummy_socket_class, NULL, NULL, 0); ok(socket_2 != NULL, "socket"); ok(socket_lost == 1, "no new loss"); diff --git a/storage/perfschema/unittest/pfs_instr_class-t.cc b/storage/perfschema/unittest/pfs_instr_class-t.cc index 9e3efde656e..7b3ffccffcc 100644 --- a/storage/perfschema/unittest/pfs_instr_class-t.cc +++ b/storage/perfschema/unittest/pfs_instr_class-t.cc @@ -475,6 +475,7 @@ void test_table_registration() #endif } +#ifdef LATER void set_wait_stat(PFS_instr_class *klass) { PFS_single_stat *stat; @@ -501,6 +502,7 @@ bool is_empty_stat(PFS_instr_class *klass) return false; return true; } +#endif void test_instruments_reset() { |