From: Tor Didriksen Date: December 7 2012 12:53pm Subject: bzr push into mysql-trunk branch (tor.didriksen:5186 to 5187) List-Archive: http://lists.mysql.com/commits/145463 Message-Id: <20121207125326.546.83402.5187@atum07.no.oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 5187 Tor Didriksen 2012-12-07 [merge] merge 5.6 => trunk removed: unittest/mysys/ unittest/mysys/CMakeLists.txt unittest/mysys/waiting_threads-t.c unittest/strings/ renamed: unittest/mysys/base64-t.c => unittest/gunit/mysys_base64-t.cc unittest/mysys/lf-t.c => unittest/gunit/mysys_lf-t.cc unittest/mysys/my_atomic-t.c => unittest/gunit/mysys_my_atomic-t.cc unittest/mysys/my_malloc-t.c => unittest/gunit/mysys_my_malloc-t.cc unittest/mysys/my_rdtsc-t.c => unittest/gunit/mysys_my_rdtsc-t.cc unittest/mysys/my_vsnprintf-t.c => unittest/gunit/mysys_my_vsnprintf-t.cc unittest/mysys/thr_template.c => unittest/gunit/thr_template.cc unittest/strings/strings-t.c => unittest/gunit/like_range-t.cc modified: CMakeLists.txt include/my_atomic.h unittest/gunit/CMakeLists.txt unittest/gunit/bounded_queue-t.cc unittest/gunit/mysys_base64-t.cc unittest/gunit/mysys_lf-t.cc unittest/gunit/mysys_my_atomic-t.cc unittest/gunit/mysys_my_malloc-t.cc unittest/gunit/mysys_my_rdtsc-t.cc unittest/gunit/mysys_my_vsnprintf-t.cc unittest/gunit/thr_template.cc unittest/gunit/like_range-t.cc 5186 Oystein Grovlen 2012-12-07 [merge] Empty merge === modified file 'CMakeLists.txt' --- a/CMakeLists.txt 2012-11-21 12:44:48 +0000 +++ b/CMakeLists.txt 2012-12-07 12:51:42 +0000 @@ -374,7 +374,6 @@ IF(WITH_UNIT_TESTS) ADD_SUBDIRECTORY(unittest/examples) ADD_SUBDIRECTORY(unittest/mytap) ADD_SUBDIRECTORY(unittest/mytap/t) - ADD_SUBDIRECTORY(unittest/mysys) ADD_SUBDIRECTORY(unittest/gunit) ENDIF() === modified file 'include/my_atomic.h' --- a/include/my_atomic.h 2011-06-30 15:46:53 +0000 +++ b/include/my_atomic.h 2012-12-07 12:43:40 +0000 @@ -280,7 +280,9 @@ make_atomic_store(ptr) #define MY_ATOMIC_OK 0 #define MY_ATOMIC_NOT_1CPU 1 +C_MODE_START extern int my_atomic_initialize(); +C_MODE_END #endif === modified file 'unittest/gunit/CMakeLists.txt' --- a/unittest/gunit/CMakeLists.txt 2012-12-04 12:57:18 +0000 +++ b/unittest/gunit/CMakeLists.txt 2012-12-07 12:51:42 +0000 @@ -212,11 +212,18 @@ SET(TESTS dynarray filesort_buffer filesort_compare + like_range mdl my_bitmap my_error my_fileutils my_regex + mysys_base64 + mysys_lf + mysys_my_atomic + mysys_my_malloc + mysys_my_rdtsc + mysys_my_vsnprintf sql_list sql_plist sql_string === modified file 'unittest/gunit/bounded_queue-t.cc' --- a/unittest/gunit/bounded_queue-t.cc 2012-12-04 12:48:34 +0000 +++ b/unittest/gunit/bounded_queue-t.cc 2012-12-07 12:43:40 +0000 @@ -345,7 +345,7 @@ void int_keymaker(Sort_param *sp, int *t */ const int num_rows= 10000; const int row_limit= 100; -const int num_iterations= 1000; +const int num_iterations= 10; class PerfTestSmall : public ::testing::Test { === renamed file 'unittest/strings/strings-t.c' => 'unittest/gunit/like_range-t.cc' --- a/unittest/strings/strings-t.c 2012-05-02 19:09:22 +0000 +++ b/unittest/gunit/like_range-t.cc 2012-12-07 12:51:42 +0000 @@ -1,4 +1,4 @@ -/* Copyright (c) 2010, 2010, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2010, 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 @@ -13,15 +13,19 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include +// First include (the generated) my_config.h, to get correct platform defines. +#include "my_config.h" +#include + #include #include +namespace like_range_unittest { /* Test that like_range() returns well-formed results. */ -static int +static void test_like_range_for_charset(CHARSET_INFO *cs, const char *src, size_t src_len) { char min_str[32], max_str[32]; @@ -30,24 +34,21 @@ test_like_range_for_charset(CHARSET_INFO cs->coll->like_range(cs, src, src_len, '\\', '_', '%', sizeof(min_str), min_str, max_str, &min_len, &max_len); - diag("min_len=%d\tmax_len=%d\t%s", (int) min_len, (int) max_len, cs->name); + // diag("min_len=%d\tmax_len=%d\t%s", (int) min_len, (int) max_len, cs->name); min_well_formed_len= cs->cset->well_formed_len(cs, min_str, min_str + min_len, 10000, &error); max_well_formed_len= cs->cset->well_formed_len(cs, max_str, max_str + max_len, 10000, &error); - if (min_len != min_well_formed_len) - diag("Bad min_str: min_well_formed_len=%d min_str[%d]=0x%02X", - (int) min_well_formed_len, (int) min_well_formed_len, - (uchar) min_str[min_well_formed_len]); - if (max_len != max_well_formed_len) - diag("Bad max_str: max_well_formed_len=%d max_str[%d]=0x%02X", - (int) max_well_formed_len, (int) max_well_formed_len, - (uchar) max_str[max_well_formed_len]); - return - min_len == min_well_formed_len && - max_len == max_well_formed_len ? 0 : 1; + EXPECT_EQ(min_len, min_well_formed_len) + << "Bad min_str: min_well_formed_len=" << min_well_formed_len + << " min_str[" << min_well_formed_len << "]=" + << (uchar) min_str[min_well_formed_len]; + EXPECT_EQ(max_len, max_well_formed_len) + << "Bad max_str: max_well_formed_len=" << max_well_formed_len + << " max_str[" << max_well_formed_len << "]=" + << (uchar) max_str[max_well_formed_len]; } @@ -92,23 +93,27 @@ static CHARSET_INFO *charset_list[]= #endif }; +#if defined(GTEST_HAS_PARAM_TEST) -int main() +class LikeRangeTest : public ::testing::TestWithParam { - size_t i, failed= 0; - - plan(1); - diag("Testing my_like_range_xxx() functions"); - - for (i= 0; i < array_elements(charset_list); i++) +protected: + virtual void SetUp() { - CHARSET_INFO *cs= charset_list[i]; - if (test_like_range_for_charset(cs, "abc%", 4)) - { - ++failed; - diag("Failed for %s", cs->name); - } + m_charset= GetParam(); } - ok(failed == 0, "Testing my_like_range_xxx() functions"); - return exit_status(); + CHARSET_INFO *m_charset; +}; + +INSTANTIATE_TEST_CASE_P(Foo1, LikeRangeTest, + ::testing::ValuesIn(charset_list)); + + +TEST_P(LikeRangeTest, TestLikeRange) +{ + test_like_range_for_charset(m_charset, "abc%", 4); +} + +#endif + } === renamed file 'unittest/mysys/base64-t.c' => 'unittest/gunit/mysys_base64-t.cc' --- a/unittest/mysys/base64-t.c 2011-09-07 10:08:09 +0000 +++ b/unittest/gunit/mysys_base64-t.cc 2012-12-07 12:43:40 +0000 @@ -1,4 +1,4 @@ -/* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2003, 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 @@ -13,24 +13,25 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +// First include (the generated) my_config.h, to get correct platform defines. +#include "my_config.h" +#include + #include #include #include -#include #include -#define BASE64_LOOP_COUNT 500 -#define BASE64_ROWS 4 /* Number of ok(..) */ +namespace mysys_base64_unittest { + +const int BASE64_LOOP_COUNT= 500; -int -main(void) +TEST(Mysys, Base64) { int i, cmp; size_t j, k, l, dst_len, needed_length; MY_INIT("base64-t"); - plan(BASE64_LOOP_COUNT * BASE64_ROWS); - for (i= 0; i < BASE64_LOOP_COUNT; i++) { /* Create source data */ @@ -52,22 +53,23 @@ main(void) str= (char *) malloc(needed_length); for (k= 0; k < needed_length; k++) str[k]= 0xff; /* Fill memory to check correct NUL termination */ - ok(base64_encode(src, src_len, str) == 0, - "base64_encode: size %d", i); - ok(needed_length == strlen(str) + 1, - "base64_needed_encoded_length: size %d", i); + EXPECT_EQ(0, base64_encode(src, src_len, str)) + << "base64_encode: size " << i; + EXPECT_EQ(needed_length, strlen(str) + 1) + << "base64_needed_encoded_length: " << i; /* Decode */ dst= (char *) malloc(base64_needed_decoded_length(strlen(str))); dst_len= base64_decode(str, strlen(str), dst, NULL, 0); - ok(dst_len == src_len, "Comparing lengths"); + EXPECT_EQ(dst_len, src_len) << "Comparing lengths"; cmp= memcmp(src, dst, src_len); - ok(cmp == 0, "Comparing encode-decode result"); + EXPECT_EQ(0, cmp) << "Comparing encode-decode result"; if (cmp != 0) { char buf[80]; - diag(" --------- src --------- --------- dst ---------"); + ADD_FAILURE() << + " --------- src --------- --------- dst ---------"; for (k= 0; k 'unittest/gunit/mysys_lf-t.cc' --- a/unittest/mysys/lf-t.c 2011-10-11 04:27:52 +0000 +++ b/unittest/gunit/mysys_lf-t.cc 2012-12-07 12:43:40 +0000 @@ -1,4 +1,4 @@ -/* Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2008, 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 @@ -19,7 +19,18 @@ Unit tests for lock-free algorithms of mysys */ -#include "thr_template.c" +// First include (the generated) my_config.h, to get correct platform defines. +#include "my_config.h" +#include + +#include +#include +#include + + +namespace mysys_lf_unittest { + +#include "thr_template.cc" #include @@ -99,8 +110,6 @@ pthread_handler_t test_lf_alloc(void *ar if (--N == 0) { - diag("%d mallocs, %d pins in stack", - lf_allocator.mallocs, lf_allocator.pinbox.pins_in_array); #ifdef MY_LF_EXTRA_DEBUG bad|= lf_allocator.mallocs - lf_alloc_pool_count(&lf_allocator); #endif @@ -113,7 +122,7 @@ pthread_handler_t test_lf_alloc(void *ar return 0; } -#define N_TLH 1000 +const int N_TLH= 1000; pthread_handler_t test_lf_hash(void *arg) { int m= (*(int *)arg)/(2*N_TLH); @@ -154,9 +163,6 @@ pthread_handler_t test_lf_hash(void *arg if (--N == 0) { - diag("%d mallocs, %d pins in stack, %d hash size, %d inserts", - lf_hash.alloc.mallocs, lf_hash.alloc.pinbox.pins_in_array, - lf_hash.size, inserts); bad|= lf_hash.count; } if (!--running_threads) mysql_cond_signal(&cond); @@ -169,26 +175,46 @@ pthread_handler_t test_lf_hash(void *arg void do_tests() { - plan(7); - lf_alloc_init(&lf_allocator, sizeof(TLA), offsetof(TLA, not_used)); lf_hash_init(&lf_hash, sizeof(int), LF_HASH_UNIQUE, 0, sizeof(int), 0, &my_charset_bin); bad= my_atomic_initialize(); - ok(!bad, "my_atomic_initialize() returned %d", bad); + EXPECT_FALSE(bad) << "my_atomic_initialize() returned " << bad; with_my_thread_init= 1; - test_concurrently("lf_pinbox (with my_thread_init)", test_lf_pinbox, N= THREADS, CYCLES); - test_concurrently("lf_alloc (with my_thread_init)", test_lf_alloc, N= THREADS, CYCLES); - test_concurrently("lf_hash (with my_thread_init)", test_lf_hash, N= THREADS, CYCLES/10); + test_concurrently("lf_pinbox (with my_thread_init)", + test_lf_pinbox, N= THREADS, CYCLES); + test_concurrently("lf_alloc (with my_thread_init)", + test_lf_alloc, N= THREADS, CYCLES); + test_concurrently("lf_hash (with my_thread_init)", + test_lf_hash, N= THREADS, CYCLES/10); with_my_thread_init= 0; - test_concurrently("lf_pinbox (without my_thread_init)", test_lf_pinbox, N= THREADS, CYCLES); - test_concurrently("lf_alloc (without my_thread_init)", test_lf_alloc, N= THREADS, CYCLES); - test_concurrently("lf_hash (without my_thread_init)", test_lf_hash, N= THREADS, CYCLES/10); + test_concurrently("lf_pinbox (without my_thread_init)", + test_lf_pinbox, N= THREADS, CYCLES); + test_concurrently("lf_alloc (without my_thread_init)", + test_lf_alloc, N= THREADS, CYCLES); + test_concurrently("lf_hash (without my_thread_init)", + test_lf_hash, N= THREADS, CYCLES/10); lf_hash_destroy(&lf_hash); lf_alloc_destroy(&lf_allocator); } + +TEST(Mysys, LockFree) +{ + mysql_mutex_init(0, &mutex, 0); + mysql_cond_init(0, &cond, NULL); + pthread_attr_init(&thr_attr); + pthread_attr_setdetachstate(&thr_attr, PTHREAD_CREATE_DETACHED); + + do_tests(); + + mysql_mutex_destroy(&mutex); + mysql_cond_destroy(&cond); + pthread_attr_destroy(&thr_attr); +} + +} === renamed file 'unittest/mysys/my_atomic-t.c' => 'unittest/gunit/mysys_my_atomic-t.cc' --- a/unittest/mysys/my_atomic-t.c 2012-02-16 09:51:14 +0000 +++ b/unittest/gunit/mysys_my_atomic-t.cc 2012-12-07 12:43:40 +0000 @@ -1,4 +1,4 @@ -/* Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2006, 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 @@ -13,9 +13,20 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "thr_template.c" +// First include (the generated) my_config.h, to get correct platform defines. +#include "my_config.h" +#include -volatile uint32 b32; +#include +#include +#include + + +namespace mysys_my_atomic_unittest { + +#include "thr_template.cc" + +volatile int32 b32; volatile int32 c32; my_atomic_rwlock_t rwl; @@ -149,10 +160,8 @@ pthread_handler_t test_atomic_cas(void * void do_tests() { - plan(6); - bad= my_atomic_initialize(); - ok(!bad, "my_atomic_initialize() returned %d", bad); + EXPECT_FALSE(bad) << "my_atomic_initialize() returned"; my_atomic_rwlock_init(&rwl); @@ -174,10 +183,27 @@ void do_tests() volatile int64 b=0x1000200030004000LL; a64=0; my_atomic_add64(&a64, b); - ok(a64==b, "add64"); + EXPECT_EQ(a64, b) << "add64"; } a64=0; test_concurrently("my_atomic_add64", test_atomic_add64, THREADS, CYCLES); my_atomic_rwlock_destroy(&rwl); } + + +TEST(Mysys, Atomic) +{ + mysql_mutex_init(0, &mutex, 0); + mysql_cond_init(0, &cond, NULL); + pthread_attr_init(&thr_attr); + pthread_attr_setdetachstate(&thr_attr, PTHREAD_CREATE_DETACHED); + + do_tests(); + + mysql_mutex_destroy(&mutex); + mysql_cond_destroy(&cond); + pthread_attr_destroy(&thr_attr); +} + +} === renamed file 'unittest/mysys/my_malloc-t.c' => 'unittest/gunit/mysys_my_malloc-t.cc' --- a/unittest/mysys/my_malloc-t.c 2010-07-08 21:20:08 +0000 +++ b/unittest/gunit/mysys_my_malloc-t.cc 2012-12-07 12:43:40 +0000 @@ -1,4 +1,4 @@ -/* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2010, 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 @@ -13,31 +13,32 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +// First include (the generated) my_config.h, to get correct platform defines. +#include "my_config.h" +#include + #include #include -#include "tap.h" -int main(void) +namespace mysys_my_malloc_unittest { + +TEST(Mysys, Malloc) { void *p; - MY_INIT("my_malloc-t"); - - plan(4); p= my_malloc(0, MYF(0)); - ok(p != NULL, "Zero-sized block allocation."); + EXPECT_TRUE(p != NULL) << "Zero-sized block allocation."; p= my_realloc(p, 32, MYF(0)); - ok(p != NULL, "Reallocated zero-sized block."); + EXPECT_TRUE(p != NULL) << "Reallocated zero-sized block."; p= my_realloc(p, 16, MYF(0)); - ok(p != NULL, "Trimmed block."); + EXPECT_TRUE(p != NULL) << "Trimmed block."; my_free(p); p= NULL; - ok((my_free(p), 1), "Free NULL pointer."); - - return exit_status(); + my_free(p); } +} === renamed file 'unittest/mysys/my_rdtsc-t.c' => 'unittest/gunit/mysys_my_rdtsc-t.cc' --- a/unittest/mysys/my_rdtsc-t.c 2011-06-30 15:50:45 +0000 +++ b/unittest/gunit/mysys_my_rdtsc-t.cc 2012-12-07 12:43:40 +0000 @@ -1,19 +1,18 @@ -/* - Copyright (c) 2008 MySQL AB, 2009 Sun Microsystems, Inc. - Use is subject to license terms. +/* Copyright (c) 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 + 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., 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA */ - 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* rdtsc3 -- multi-platform timer code @@ -40,18 +39,35 @@ The fourth line shows overheads, e.g. ticks takes 2044 cycles. */ +// First include (the generated) my_config.h, to get correct platform defines. +#include "my_config.h" +#include + #include "my_global.h" #include "my_rdtsc.h" -#include "tap.h" -#define LOOP_COUNT 100 +namespace mysys_my_rdtsc_unittest { + +const int LOOP_COUNT= 100; + +class RDTimeStampCounter : public ::testing::Test +{ +protected: + void SetUp() + { + test_init(); + } + void test_init(); -MY_TIMER_INFO myt; + MY_TIMER_INFO myt; +}; -void test_init() + +void RDTimeStampCounter::test_init() { my_timer_init(&myt); +/* diag("----- Routine ---------------"); diag("myt.cycles.routine : %13llu", myt.cycles.routine); diag("myt.nanoseconds.routine : %13llu", myt.nanoseconds.routine); @@ -79,11 +95,11 @@ void test_init() diag("myt.microseconds.overhead : %13llu", myt.microseconds.overhead); diag("myt.milliseconds.overhead : %13llu", myt.milliseconds.overhead); diag("myt.ticks.overhead : %13llu", myt.ticks.overhead); - - ok(1, "my_timer_init() did not crash"); +*/ } -void test_cycle() + +TEST_F(RDTimeStampCounter, TestCycle) { ulonglong t1= my_timer_cycles(); ulonglong t2; @@ -102,15 +118,17 @@ void test_cycle() } /* Expect at most 1 backward, the cycle value can overflow */ - ok((backward <= 1), "The cycle timer is strictly increasing"); + EXPECT_TRUE((backward <= 1)) << "The cycle timer is strictly increasing"; if (myt.cycles.routine != 0) - ok((nonzero != 0), "The cycle timer is implemented"); + EXPECT_TRUE((nonzero != 0)) << "The cycle timer is implemented"; else - ok((nonzero == 0), "The cycle timer is not implemented and returns 0"); + EXPECT_TRUE((nonzero == 0)) + << "The cycle timer is not implemented and returns 0"; } -void test_nanosecond() + +TEST_F(RDTimeStampCounter, TestNanosecond) { ulonglong t1= my_timer_nanoseconds(); ulonglong t2; @@ -128,15 +146,17 @@ void test_nanosecond() t1= t2; } - ok((backward == 0), "The nanosecond timer is increasing"); + EXPECT_TRUE((backward == 0)) << "The nanosecond timer is increasing"; if (myt.nanoseconds.routine != 0) - ok((nonzero != 0), "The nanosecond timer is implemented"); + EXPECT_TRUE((nonzero != 0)) << "The nanosecond timer is implemented"; else - ok((nonzero == 0), "The nanosecond timer is not implemented and returns 0"); + EXPECT_TRUE((nonzero == 0)) + << "The nanosecond timer is not implemented and returns 0"; } -void test_microsecond() + +TEST_F(RDTimeStampCounter, TestMicrosecond) { ulonglong t1= my_timer_microseconds(); ulonglong t2; @@ -154,15 +174,17 @@ void test_microsecond() t1= t2; } - ok((backward == 0), "The microsecond timer is increasing"); + EXPECT_TRUE((backward == 0)) << "The microsecond timer is increasing"; if (myt.microseconds.routine != 0) - ok((nonzero != 0), "The microsecond timer is implemented"); + EXPECT_TRUE((nonzero != 0)) << "The microsecond timer is implemented"; else - ok((nonzero == 0), "The microsecond timer is not implemented and returns 0"); + EXPECT_TRUE((nonzero == 0)) + << "The microsecond timer is not implemented and returns 0"; } -void test_millisecond() + +TEST_F(RDTimeStampCounter, TestMillisecond) { ulonglong t1= my_timer_milliseconds(); ulonglong t2; @@ -180,15 +202,17 @@ void test_millisecond() t1= t2; } - ok((backward == 0), "The millisecond timer is increasing"); + EXPECT_TRUE((backward == 0)) << "The millisecond timer is increasing"; if (myt.milliseconds.routine != 0) - ok((nonzero != 0), "The millisecond timer is implemented"); + EXPECT_TRUE((nonzero != 0)) << "The millisecond timer is implemented"; else - ok((nonzero == 0), "The millisecond timer is not implemented and returns 0"); + EXPECT_TRUE((nonzero == 0)) + << "The millisecond timer is not implemented and returns 0"; } -void test_tick() + +TEST_F(RDTimeStampCounter, TestTick) { ulonglong t1= my_timer_ticks(); ulonglong t2; @@ -206,26 +230,14 @@ void test_tick() t1= t2; } - ok((backward == 0), "The tick timer is increasing"); + EXPECT_TRUE((backward == 0)) << "The tick timer is increasing"; if (myt.ticks.routine != 0) - ok((nonzero != 0), "The tick timer is implemented"); + EXPECT_TRUE((nonzero != 0)) << "The tick timer is implemented"; else - ok((nonzero == 0), "The tick timer is not implemented and returns 0"); + EXPECT_TRUE((nonzero == 0)) + << "The tick timer is not implemented and returns 0"; } -int main(int argc __attribute__((unused)), - char ** argv __attribute__((unused))) -{ - plan(11); - test_init(); - test_cycle(); - test_nanosecond(); - test_microsecond(); - test_millisecond(); - test_tick(); - - return 0; } - === renamed file 'unittest/mysys/my_vsnprintf-t.c' => 'unittest/gunit/mysys_my_vsnprintf-t.cc' --- a/unittest/mysys/my_vsnprintf-t.c 2012-03-16 09:14:17 +0000 +++ b/unittest/gunit/mysys_my_vsnprintf-t.cc 2012-12-07 12:43:40 +0000 @@ -1,4 +1,4 @@ -/* Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2003, 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 @@ -13,9 +13,14 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +// First include (the generated) my_config.h, to get correct platform defines. +#include "my_config.h" +#include + #include #include -#include + +namespace mysys_my_vsnprintf_unittest { char buf[1024]; /* let's hope that's enough */ @@ -26,13 +31,13 @@ void test1(const char *res, const char * va_start(args,fmt); len= my_vsnprintf(buf, sizeof(buf)-1, fmt, args); va_end(args); - ok(strlen(res) == len && strcmp(buf, res) == 0, "\"%s\"", buf); + EXPECT_EQ(len, strlen(res)); + EXPECT_STREQ(buf, res); } -int main(void) -{ - plan(58); +TEST(Mysys, Vsnprintf) +{ test1("Constant string", "Constant string"); @@ -121,8 +126,6 @@ int main(void) test1("G with a width (ignored) and precision: <12.35>", "G with a width (ignored) and precision: <%10.5g>", 12.3456789); - diag("================================================================"); - test1("Hello", "Hello"); test1("Hello int, 1", @@ -177,6 +180,6 @@ int main(void) test1("My `DDDD` test CCCC, `DDD`", "My %1$`s test %2$s, %1$`-.3s", "DDDD", "CCCC"); - return exit_status(); } +} === renamed file 'unittest/mysys/thr_template.c' => 'unittest/gunit/thr_template.cc' --- a/unittest/mysys/thr_template.c 2011-10-11 04:27:52 +0000 +++ b/unittest/gunit/thr_template.cc 2012-12-07 12:43:40 +0000 @@ -14,18 +14,14 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include -#include -#include -#include -volatile uint32 bad; +volatile int32 bad; pthread_attr_t thr_attr; mysql_mutex_t mutex; mysql_cond_t cond; uint running_threads; - -void do_tests(); +const int THREADS= 30; +const int CYCLES= 3000; void test_concurrently(const char *test, pthread_handler handler, int n, int m) { @@ -34,12 +30,11 @@ void test_concurrently(const char *test, bad= 0; - diag("Testing %s with %d threads, %d iterations... ", test, n, m); for (running_threads= n ; n ; n--) { if (pthread_create(&t, &thr_attr, handler, &m) != 0) { - diag("Could not create thread"); + ADD_FAILURE() << "Could not create thread"; abort(); } } @@ -49,45 +44,8 @@ void test_concurrently(const char *test, mysql_mutex_unlock(&mutex); now= my_getsystime()-now; - ok(!bad, "tested %s in %g secs (%d)", test, ((double)now)/1e7, bad); + EXPECT_FALSE(bad) + << "tested " << test + << " in " << ((double)now)/1e7 << " secs " + << "(" << bad << ")"; } - -int main(int argc __attribute__((unused)), char **argv) -{ - MY_INIT("thd_template"); - - if (argv[1] && *argv[1]) - DBUG_SET_INITIAL(argv[1]); - - mysql_mutex_init(0, &mutex, 0); - mysql_cond_init(0, &cond, 0); - pthread_attr_init(&thr_attr); - pthread_attr_setdetachstate(&thr_attr,PTHREAD_CREATE_DETACHED); - -#ifdef MY_ATOMIC_MODE_RWLOCKS -#if defined(HPUX11) || defined(__POWERPC__) /* showed to be very slow (scheduler-related) */ -#define CYCLES 300 -#else -#define CYCLES 3000 -#endif -#else -#define CYCLES 3000 -#endif -#define THREADS 30 - - diag("N CPUs: %d, atomic ops: %s", my_getncpus(), MY_ATOMIC_MODE); - - do_tests(); - - /* - workaround until we know why it crashes randomly on some machine - (BUG#22320). - */ - sleep(2); - mysql_mutex_destroy(&mutex); - mysql_cond_destroy(&cond); - pthread_attr_destroy(&thr_attr); - my_end(0); - return exit_status(); -} - === removed directory 'unittest/mysys' === removed file 'unittest/mysys/CMakeLists.txt' --- a/unittest/mysys/CMakeLists.txt 2011-06-30 15:50:45 +0000 +++ b/unittest/mysys/CMakeLists.txt 1970-01-01 00:00:00 +0000 @@ -1,32 +0,0 @@ -# Copyright (c) 2006, 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, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include - ${CMAKE_SOURCE_DIR}/sql - ${CMAKE_SOURCE_DIR}/regex - ${CMAKE_SOURCE_DIR}/extra/yassl/include - ${CMAKE_SOURCE_DIR}/unittest/mytap) - - -MACRO (MY_ADD_TEST name) - ADD_EXECUTABLE(${name}-t ${name}-t.c) - TARGET_LINK_LIBRARIES(${name}-t mytap mysys strings) - ADD_TEST(${name} ${name}-t) -ENDMACRO() - - -FOREACH(testname base64 my_vsnprintf my_atomic my_rdtsc lf waiting_threads my_malloc) - MY_ADD_TEST(${testname}) -ENDFOREACH() === removed file 'unittest/mysys/waiting_threads-t.c' --- a/unittest/mysys/waiting_threads-t.c 2011-10-11 04:27:52 +0000 +++ b/unittest/mysys/waiting_threads-t.c 1970-01-01 00:00:00 +0000 @@ -1,340 +0,0 @@ -/* 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, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - -/* - This is a unit test for the deadlock detector in mysys/waiting_thread.c and - include/waiting_thread.h. - As the detector is not used in MySQL, and the test sometimes fails on some - platforms and we don't have time to investigate/fix it, this test is - compiled but not run (see start of do_tests()). Make sure to enable it if - you use the module. -*/ - -#include "thr_template.c" -#include -#include - -/* - Random-number section. - - These functions used to be in mysys in MySQL 6.0, replacing randominit() - and my_rnd() from sql/password.c. - my_rnd_struct used to be in include/my_sys.h in MySQL 6.0, replacing - rand_struct from include/mysql_com.h. But this change has not been - back-ported to next-mr because: - - mysql_com.h is included in mysql.h so is part of the API - - assume a 3rd-party product including mysql.h and using rand_struct - - moving the definition of the struct into my_sys.h forces this product to - have to include my_sys.h which is generally unwanted. - - So for now this code stays duplicated here. -*/ - -struct my_rnd_struct { - unsigned long seed1,seed2,max_value; - double max_value_dbl; -}; - -/** Initialize random generator, see password.c:randominit() */ - -static void my_rnd_init(struct my_rnd_struct *rand_st, ulong seed1, ulong seed2) -{ -#ifdef HAVE_purify - memset((char*) rand_st, 0, sizeof(*rand_st)); /* Avoid UMC varnings */ -#endif - rand_st->max_value= 0x3FFFFFFFL; - rand_st->max_value_dbl=(double) rand_st->max_value; - rand_st->seed1=seed1%rand_st->max_value ; - rand_st->seed2=seed2%rand_st->max_value; -} - -/** Generate random number, see password.c:my_rnd() */ - -static double my_rnd(struct my_rnd_struct *rand_st) -{ - rand_st->seed1=(rand_st->seed1*3+rand_st->seed2) % rand_st->max_value; - rand_st->seed2=(rand_st->seed1+rand_st->seed2+33) % rand_st->max_value; - return (((double) rand_st->seed1)/rand_st->max_value_dbl); -} - -/* end of random-number section; start of unit test for deadlock detector */ - - -struct test_wt_thd { - WT_THD thd; - mysql_mutex_t lock; -} thds[THREADS]; - -uint i, cnt; -mysql_mutex_t lock; -mysql_cond_t thread_sync; - -ulong wt_timeout_short=100, wt_deadlock_search_depth_short=4; -ulong wt_timeout_long=10000, wt_deadlock_search_depth_long=15; - -#define reset(ARRAY) memset(ARRAY, 0, sizeof(ARRAY)) - -/* see explanation of the kill strategies in waiting_threads.h */ -enum { LATEST, RANDOM, YOUNGEST, LOCKS } kill_strategy; - -WT_RESOURCE_TYPE restype={ wt_resource_id_memcmp, 0}; - -#define rnd() ((uint)(my_rnd(&rand) * INT_MAX32)) - -/* - stress test: wait on a random number of random threads. - it always succeeds (unless crashes or hangs). -*/ -pthread_handler_t test_wt(void *arg) -{ - int m, n, i, id, res; - struct my_rnd_struct rand; - - my_thread_init(); - - mysql_mutex_lock(&mutex); - id= cnt++; - wt_thd_lazy_init(& thds[id].thd, - & wt_deadlock_search_depth_short, & wt_timeout_short, - & wt_deadlock_search_depth_long, & wt_timeout_long); - - /* now, wait for everybody to be ready to run */ - if (cnt >= THREADS) - mysql_cond_broadcast(&thread_sync); - else - while (cnt < THREADS) - mysql_cond_wait(&thread_sync, &mutex); - mysql_mutex_unlock(&mutex); - - my_rnd_init(&rand, (ulong)(intptr)&m, id); - if (kill_strategy == YOUNGEST) - thds[id].thd.weight= (ulong)~my_getsystime(); - if (kill_strategy == LOCKS) - thds[id].thd.weight= 0; - - for (m= *(int *)arg; m ; m--) - { - WT_RESOURCE_ID resid; - int blockers[THREADS/10], j, k; - - resid.value= id; - resid.type= &restype; - - res= 0; - - /* prepare for waiting for a random number of random threads */ - for (j= n= (rnd() % THREADS)/10; !res && j >= 0; j--) - { -retry: - i= rnd() % (THREADS-1); /* pick a random thread */ - if (i >= id) i++; /* with a number from 0 to THREADS-1 excluding ours */ - - for (k=n; k >=j; k--) /* the one we didn't pick before */ - if (blockers[k] == i) - goto retry; - blockers[j]= i; - - if (kill_strategy == RANDOM) - thds[id].thd.weight= rnd(); - - mysql_mutex_lock(& thds[i].lock); - res= wt_thd_will_wait_for(& thds[id].thd, & thds[i].thd, &resid); - mysql_mutex_unlock(& thds[i].lock); - } - - if (!res) - { - mysql_mutex_lock(&lock); - res= wt_thd_cond_timedwait(& thds[id].thd, &lock); - mysql_mutex_unlock(&lock); - } - - if (res) - { - mysql_mutex_lock(& thds[id].lock); - mysql_mutex_lock(&lock); - wt_thd_release_all(& thds[id].thd); - mysql_mutex_unlock(&lock); - mysql_mutex_unlock(& thds[id].lock); - if (kill_strategy == LOCKS) - thds[id].thd.weight= 0; - if (kill_strategy == YOUNGEST) - thds[id].thd.weight= (ulong)~my_getsystime(); - } - else if (kill_strategy == LOCKS) - thds[id].thd.weight++; - } - - mysql_mutex_lock(&mutex); - /* wait for everybody to finish */ - if (!--cnt) - mysql_cond_broadcast(&thread_sync); - else - while (cnt) - mysql_cond_wait(&thread_sync, &mutex); - - mysql_mutex_lock(& thds[id].lock); - mysql_mutex_lock(&lock); - wt_thd_release_all(& thds[id].thd); - mysql_mutex_unlock(&lock); - mysql_mutex_unlock(& thds[id].lock); - wt_thd_destroy(& thds[id].thd); - - if (!--running_threads) /* now, signal when everybody is done with deinit */ - mysql_cond_signal(&cond); - mysql_mutex_unlock(&mutex); - DBUG_PRINT("wt", ("exiting")); - my_thread_end(); - return 0; -} - -void do_one_test() -{ - double sum, sum0; - DBUG_ENTER("do_one_test"); - - reset(wt_cycle_stats); - reset(wt_wait_stats); - wt_success_stats=0; - cnt=0; - test_concurrently("waiting_threads", test_wt, THREADS, CYCLES); - - sum=sum0=0; - for (cnt=0; cnt < WT_CYCLE_STATS; cnt++) - sum+= wt_cycle_stats[0][cnt] + wt_cycle_stats[1][cnt]; - for (cnt=0; cnt < WT_CYCLE_STATS; cnt++) - if (wt_cycle_stats[0][cnt] + wt_cycle_stats[1][cnt] > 0) - { - sum0+=wt_cycle_stats[0][cnt] + wt_cycle_stats[1][cnt]; - diag("deadlock cycles of length %2u: %4u %4u %8.2f %%", cnt, - wt_cycle_stats[0][cnt], wt_cycle_stats[1][cnt], 1e2*sum0/sum); - } - diag("depth exceeded: %u %u", - wt_cycle_stats[0][cnt], wt_cycle_stats[1][cnt]); - for (cnt=0; cnt < WT_WAIT_STATS; cnt++) - if (wt_wait_stats[cnt]>0) - diag("deadlock waits up to %7llu us: %5u", - wt_wait_table[cnt], wt_wait_stats[cnt]); - diag("timed out: %u", wt_wait_stats[cnt]); - diag("successes: %u", wt_success_stats); - - DBUG_VOID_RETURN; -} - -void do_tests() -{ - DBUG_ENTER("do_tests"); - - skip_all(": this module is not used in MySQL"); - - plan(12); - compile_time_assert(THREADS >= 4); - - DBUG_PRINT("wt", ("================= initialization ===================")); - - bad= my_atomic_initialize(); - ok(!bad, "my_atomic_initialize() returned %d", bad); - - mysql_cond_init(0, &thread_sync, 0); - mysql_mutex_init(0, &lock, 0); - wt_init(); - for (cnt=0; cnt < THREADS; cnt++) - mysql_mutex_init(0, & thds[cnt].lock, 0); - { - WT_RESOURCE_ID resid[4]; - for (i=0; i < array_elements(resid); i++) - { - wt_thd_lazy_init(& thds[i].thd, - & wt_deadlock_search_depth_short, & wt_timeout_short, - & wt_deadlock_search_depth_long, & wt_timeout_long); - resid[i].value= i+1; - resid[i].type= &restype; - } - - DBUG_PRINT("wt", ("================= manual test ===================")); - -#define ok_wait(X,Y, R) \ - ok(wt_thd_will_wait_for(& thds[X].thd, & thds[Y].thd, &resid[R]) == 0, \ - "thd[" #X "] will wait for thd[" #Y "]") -#define ok_deadlock(X,Y,R) \ - ok(wt_thd_will_wait_for(& thds[X].thd, & thds[Y].thd, &resid[R]) == WT_DEADLOCK, \ - "thd[" #X "] will wait for thd[" #Y "] - deadlock") - - ok_wait(0,1,0); - ok_wait(0,2,0); - ok_wait(0,3,0); - - mysql_mutex_lock(&lock); - bad= wt_thd_cond_timedwait(& thds[0].thd, &lock); - mysql_mutex_unlock(&lock); - ok(bad == WT_TIMEOUT, "timeout test returned %d", bad); - - ok_wait(0,1,0); - ok_wait(1,2,1); - ok_deadlock(2,0,2); - - mysql_mutex_lock(&lock); - ok(wt_thd_cond_timedwait(& thds[0].thd, &lock) == WT_TIMEOUT, "as always"); - ok(wt_thd_cond_timedwait(& thds[1].thd, &lock) == WT_TIMEOUT, "as always"); - wt_thd_release_all(& thds[0].thd); - wt_thd_release_all(& thds[1].thd); - wt_thd_release_all(& thds[2].thd); - wt_thd_release_all(& thds[3].thd); - - for (i=0; i < array_elements(resid); i++) - { - wt_thd_release_all(& thds[i].thd); - wt_thd_destroy(& thds[i].thd); - } - mysql_mutex_unlock(&lock); - } - - wt_deadlock_search_depth_short=6; - wt_timeout_short=1000; - wt_timeout_long= 100; - wt_deadlock_search_depth_long=16; - DBUG_PRINT("wt", ("================= stress test ===================")); - - diag("timeout_short=%lu us, deadlock_search_depth_short=%lu", - wt_timeout_short, wt_deadlock_search_depth_short); - diag("timeout_long=%lu us, deadlock_search_depth_long=%lu", - wt_timeout_long, wt_deadlock_search_depth_long); - -#define test_kill_strategy(X) \ - diag("kill strategy: " #X); \ - DBUG_EXECUTE("reset_file", \ - { rewind(DBUG_FILE); my_chsize(fileno(DBUG_FILE), 0, 0, MYF(0)); }); \ - DBUG_PRINT("info", ("kill strategy: " #X)); \ - kill_strategy=X; \ - do_one_test(); - - test_kill_strategy(LATEST); - test_kill_strategy(RANDOM); - /* - these two take looong time on sol10-amd64-a - the server doesn't use this code now, so we disable these tests - - test_kill_strategy(YOUNGEST); - test_kill_strategy(LOCKS); - */ - - DBUG_PRINT("wt", ("================= cleanup ===================")); - for (cnt=0; cnt < THREADS; cnt++) - mysql_mutex_destroy(& thds[cnt].lock); - wt_end(); - mysql_mutex_destroy(&lock); - mysql_cond_destroy(&thread_sync); - DBUG_VOID_RETURN; -} === removed directory 'unittest/strings' No bundle (reason: useless for push emails).