summaryrefslogtreecommitdiff
path: root/storage/perfschema/unittest/pfs_instr-t.cc
diff options
context:
space:
mode:
Diffstat (limited to 'storage/perfschema/unittest/pfs_instr-t.cc')
-rw-r--r--storage/perfschema/unittest/pfs_instr-t.cc231
1 files changed, 114 insertions, 117 deletions
diff --git a/storage/perfschema/unittest/pfs_instr-t.cc b/storage/perfschema/unittest/pfs_instr-t.cc
index 9ec1dcbb8ba..47a91d9bb9a 100644
--- a/storage/perfschema/unittest/pfs_instr-t.cc
+++ b/storage/perfschema/unittest/pfs_instr-t.cc
@@ -1,4 +1,4 @@
-/* Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2008, 2017, 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
@@ -18,17 +18,18 @@
#include <pfs_instr.h>
#include <pfs_stat.h>
#include <pfs_global.h>
+#include <pfs_instr_class.h>
#include <tap.h>
#include <memory.h>
-#include "stub_server_misc.h"
+PFS_global_param param;
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 +37,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 +45,25 @@ 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;
+ param.m_digest_sizing= 0;
+ param.m_session_connect_attrs_sizing= 0;
+ param.m_max_digest_length= 0;
+
+ init_event_name_sizing(& param);
rc= init_instruments(& param);
ok(rc == 0, "zero init");
@@ -61,14 +79,16 @@ 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 +96,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 +104,25 @@ 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;
+ param.m_digest_sizing= 0;
+ param.m_session_connect_attrs_sizing= 0;
+ param.m_max_digest_length= 0;
+
+ init_event_name_sizing(& param);
rc= init_instruments(& param);
ok(rc == 0, "no instances init");
@@ -120,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");
@@ -140,20 +177,27 @@ 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");
- 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, NULL, 0);
+ ok(socket == NULL, "no socket");
+ ok(socket_lost == 1, "lost 1");
+ socket= create_socket(& dummy_socket_class, NULL, NULL, 0);
+ 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 +211,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 +223,12 @@ 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 +236,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 +244,34 @@ 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;
+ param.m_digest_sizing= 0;
+ param.m_session_connect_attrs_sizing= 0;
+ param.m_max_digest_length= 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");
@@ -261,161 +331,88 @@ 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");
- table_1= create_table(& dummy_table_share, 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, NULL, 0);
+ ok(socket_2 != NULL, "socket");
+ ok(socket_lost == 0, "not lost");
+ 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, NULL, 0);
+ 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();
-
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);
- return 0;
+ return (exit_status());
}