diff options
author | Sergei Golubchik <sergii@pisem.net> | 2012-10-19 20:38:59 +0200 |
---|---|---|
committer | Sergei Golubchik <sergii@pisem.net> | 2012-10-19 20:38:59 +0200 |
commit | e1f681c99b3e5462c033aaafa94ac295e626cde2 (patch) | |
tree | 2da5eff1a0d03831c2d85b32a7bc3df6ec37b522 /unittest | |
parent | 52c84d144d3b07966d9b3bab8694eb012eef69ce (diff) | |
parent | 807fef40fffbbb8e92564a52b902b504ba8cfcdc (diff) | |
download | mariadb-git-e1f681c99b3e5462c033aaafa94ac295e626cde2.tar.gz |
10.0-base -> 10.0-monty
Diffstat (limited to 'unittest')
-rw-r--r-- | unittest/mysys/ma_dyncol-t.c | 2 | ||||
-rw-r--r-- | unittest/sql/CMakeLists.txt | 3 | ||||
-rw-r--r-- | unittest/sql/my_apc-t.cc | 228 | ||||
-rw-r--r-- | unittest/strings/strings-t.c | 2 |
4 files changed, 233 insertions, 2 deletions
diff --git a/unittest/mysys/ma_dyncol-t.c b/unittest/mysys/ma_dyncol-t.c index 11731ae81d4..4a9b687bc08 100644 --- a/unittest/mysys/ma_dyncol-t.c +++ b/unittest/mysys/ma_dyncol-t.c @@ -194,7 +194,7 @@ static CHARSET_INFO *charset_list[]= #endif #ifdef HAVE_CHARSET_utf8 &my_charset_utf8_general_ci, -#ifdef HAVE_HAVE_UCA_COLLATIONS +#ifdef HAVE_UCA_COLLATIONS &my_charset_utf8_unicode_ci, #endif &my_charset_utf8_bin, diff --git a/unittest/sql/CMakeLists.txt b/unittest/sql/CMakeLists.txt new file mode 100644 index 00000000000..36b14e9a08a --- /dev/null +++ b/unittest/sql/CMakeLists.txt @@ -0,0 +1,3 @@ + +MY_ADD_TESTS(my_apc LINK_LIBRARIES mysys EXT cc) + diff --git a/unittest/sql/my_apc-t.cc b/unittest/sql/my_apc-t.cc new file mode 100644 index 00000000000..05d6722ada4 --- /dev/null +++ b/unittest/sql/my_apc-t.cc @@ -0,0 +1,228 @@ +/* + Copyright (c) 2012, Monty Program Ab + + 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 */ + +/* + This file does standalone APC system tests. +*/ +#include <stdio.h> +#include <my_global.h> +#include <my_pthread.h> +#include <my_sys.h> + +#include <tap.h> + +/* + A fake THD with enter_cond/exit_cond and some other members. +*/ +PSI_stage_info stage_show_explain; +class THD +{ + mysql_mutex_t* thd_mutex; +public: + bool killed; + + THD() : killed(FALSE) {} + inline const char* ENTER_COND(mysql_cond_t *cond, mysql_mutex_t* mutex, + PSI_stage_info*, PSI_stage_info*) + { + mysql_mutex_assert_owner(mutex); + thd_mutex= mutex; + return NULL; + } + inline void EXIT_COND(PSI_stage_info*) + { + mysql_mutex_unlock(thd_mutex); + } +}; + +#include "../sql/my_apc.h" + +#define MY_APC_STANDALONE 1 +#include "../sql/my_apc.cc" + +volatile bool started= FALSE; +volatile bool service_should_exit= FALSE; +volatile bool requestors_should_exit=FALSE; + +/* Counters for APC calls */ +int apcs_served= 0; +int apcs_missed=0; +int apcs_timed_out=0; +mysql_mutex_t apc_counters_mutex; + +inline void increment_counter(int *var) +{ + mysql_mutex_lock(&apc_counters_mutex); + *var= *var+1; + mysql_mutex_unlock(&apc_counters_mutex); +} + +volatile bool have_errors= false; + +Apc_target apc_target; +mysql_mutex_t target_mutex; + +int int_rand(int size) +{ + return (int) (0.5 + ((double)rand() / RAND_MAX) * size); +} + +/* + APC target thread (the one that will serve the APC requests). We will have + one target. +*/ +void *test_apc_service_thread(void *ptr) +{ + my_thread_init(); + mysql_mutex_init(0, &target_mutex, MY_MUTEX_INIT_FAST); + apc_target.init(&target_mutex); + apc_target.enable(); + started= TRUE; + diag("test_apc_service_thread started"); + while (!service_should_exit) + { + //apc_target.disable(); + my_sleep(10000); + //apc_target.enable(); + for (int i = 0; i < 10 && !service_should_exit; i++) + { + apc_target.process_apc_requests(); + my_sleep(int_rand(30)); + } + } + apc_target.disable(); + apc_target.destroy(); + mysql_mutex_destroy(&target_mutex); + my_thread_end(); + pthread_exit(0); + return NULL; +} + + +/* + One APC request (to write 'value' into *where_to) +*/ +class Apc_order : public Apc_target::Apc_call +{ +public: + int value; // The value + int *where_to; // Where to write it + Apc_order(int a, int *b) : value(a), where_to(b) {} + + void call_in_target_thread() + { + my_sleep(int_rand(1000)); + *where_to = value; + increment_counter(&apcs_served); + } +}; + + +/* + APC requestor thread. It makes APC requests, and checks if they were actually + executed. +*/ +void *test_apc_requestor_thread(void *ptr) +{ + my_thread_init(); + diag("test_apc_requestor_thread started"); + THD my_thd; + + while (!requestors_should_exit) + { + int dst_value= 0; + int src_value= int_rand(4*1000*100); + /* Create an APC to do "dst_value= src_value" assignment */ + Apc_order apc_order(src_value, &dst_value); + bool timed_out; + + mysql_mutex_lock(&target_mutex); + bool res= apc_target.make_apc_call(&my_thd, &apc_order, 60, &timed_out); + if (res) + { + if (timed_out) + increment_counter(&apcs_timed_out); + else + increment_counter(&apcs_missed); + + if (dst_value != 0) + { + diag("APC was done even though return value says it wasnt!"); + have_errors= true; + } + } + else + { + if (dst_value != src_value) + { + diag("APC was not done even though return value says it was!"); + have_errors= true; + } + } + //my_sleep(300); + } + diag("test_apc_requestor_thread exiting"); + my_thread_end(); + return NULL; +} + +/* Number of APC requestor threads */ +const int N_THREADS=23; + + +int main(int args, char **argv) +{ + pthread_t service_thr; + pthread_t request_thr[N_THREADS]; + int i; + + my_thread_global_init(); + + mysql_mutex_init(0, &apc_counters_mutex, MY_MUTEX_INIT_FAST); + + plan(1); + diag("Testing APC delivery and execution"); + + pthread_create(&service_thr, NULL, test_apc_service_thread, (void*)NULL); + while (!started) + my_sleep(1000); + for (i = 0; i < N_THREADS; i++) + pthread_create(&request_thr[i], NULL, test_apc_requestor_thread, (void*)NULL); + + for (i = 0; i < 15; i++) + { + my_sleep(500*1000); + diag("%d APCs served %d missed", apcs_served, apcs_missed); + } + diag("Shutting down requestors"); + requestors_should_exit= TRUE; + for (i = 0; i < N_THREADS; i++) + pthread_join(request_thr[i], NULL); + + diag("Shutting down service"); + service_should_exit= TRUE; + pthread_join(service_thr, NULL); + + mysql_mutex_destroy(&apc_counters_mutex); + + diag("Done"); + my_thread_end(); + my_thread_global_end(); + + ok1(!have_errors); + return exit_status(); +} + diff --git a/unittest/strings/strings-t.c b/unittest/strings/strings-t.c index 7e61cb8722e..6baef0417a8 100644 --- a/unittest/strings/strings-t.c +++ b/unittest/strings/strings-t.c @@ -87,7 +87,7 @@ static CHARSET_INFO *charset_list[]= #endif #ifdef HAVE_CHARSET_utf8 &my_charset_utf8_general_ci, -#ifdef HAVE_HAVE_UCA_COLLATIONS +#ifdef HAVE_UCA_COLLATIONS &my_charset_utf8_unicode_ci, #endif &my_charset_utf8_bin, |