4719 Tor Didriksen 2012-12-04
Bug#15947828 MERGE UNIT TESTS INTO FEWER EXECUTABLES
Move some common utilities (array_size et.al.) into a common place.
Change from unnamed to named namespaces.
Caveat: gtest registers the test name in TEST and TEST_F,
so test fixture names will have to be unique across several tests.
Kept an option to have separate executables.
@ unittest/gunit/mdl_mytap-t.cc
Remove this test, we don't need it anymore.
removed:
unittest/gunit/mdl_mytap-t.cc
modified:
.bzrignore
unittest/gunit/CMakeLists.txt
unittest/gunit/alignment-t.cc
unittest/gunit/bounded_queue-t.cc
unittest/gunit/bounds_checked_array-t.cc
unittest/gunit/byteorder-t.cc
unittest/gunit/copy_info-t.cc
unittest/gunit/cost_estimate-t.cc
unittest/gunit/create_field-t.cc
unittest/gunit/dbug-t.cc
unittest/gunit/decimal-t.cc
unittest/gunit/dynarray-t.cc
unittest/gunit/field-t.cc
unittest/gunit/field_date-t.cc
unittest/gunit/field_datetime-t.cc
unittest/gunit/field_long-t.cc
unittest/gunit/field_newdecimal-t.cc
unittest/gunit/field_timestamp-t.cc
unittest/gunit/filesort_buffer-t.cc
unittest/gunit/filesort_compare-t.cc
unittest/gunit/get_diagnostics-t.cc
unittest/gunit/gunit_test_main.cc
unittest/gunit/handler-t.h
unittest/gunit/item-t.cc
unittest/gunit/item_func_now_local-t.cc
unittest/gunit/join_tab_sort-t.cc
unittest/gunit/make_sortkey-t.cc
unittest/gunit/mdl-t.cc
unittest/gunit/my_bitmap-t.cc
unittest/gunit/my_decimal-t.cc
unittest/gunit/my_error-t.cc
unittest/gunit/my_regex-t.cc
unittest/gunit/opt_range-t.cc
unittest/gunit/opt_trace-t.cc
unittest/gunit/segfault-t.cc
unittest/gunit/sql_list-t.cc
unittest/gunit/sql_plist-t.cc
unittest/gunit/sql_table-t.cc
unittest/gunit/table_cache-t.cc
unittest/gunit/test_utils.cc
unittest/gunit/test_utils.h
unittest/gunit/thread_utils-t.cc
4718 Manish Kumar 2012-12-04 [merge]
BUG#13812374 - RPL.RPL_REPORT_PORT FAILS OCCASIONALLY ON PB2
Upmerge from 5.5 -> 5.6
modified:
mysql-test/collections/default.experimental
mysql-test/suite/rpl/r/rpl_report_port.result
mysql-test/suite/rpl/t/rpl_report_port.test
=== modified file '.bzrignore'
--- a/.bzrignore 2012-06-06 10:10:17 +0000
+++ b/.bzrignore 2012-12-04 12:48:34 +0000
@@ -2979,6 +2979,8 @@ unittest/examples/.deps/simple-t.Po
unittest/examples/.deps/skip-t.Po
unittest/examples/.deps/skip_all-t.Po
unittest/examples/.deps/todo-t.Po
+unittest/gunit/merge_large_tests.cc
+unittest/gunit/merge_small_tests.cc
unittest/mysys/*.t
unittest/mysys/.deps/base64-t.Po
unittest/mysys/.deps/my_atomic-t.Po
=== modified file 'unittest/gunit/CMakeLists.txt'
--- a/unittest/gunit/CMakeLists.txt 2012-11-23 09:02:13 +0000
+++ b/unittest/gunit/CMakeLists.txt 2012-12-04 12:48:34 +0000
@@ -205,7 +205,7 @@ SET(TESTS
bounded_queue
bounds_checked_array
byteorder
- client_string
+## client_string TODO: move to a client test directory
cost_estimate
dbug
decimal
@@ -213,7 +213,6 @@ SET(TESTS
filesort_buffer
filesort_compare
mdl
- mdl_mytap
my_bitmap
my_error
my_fileutils
@@ -245,30 +244,76 @@ SET(SERVER_TESTS
table_cache
)
-FOREACH(test ${TESTS})
- ADD_EXECUTABLE(${test}-t ${test}-t.cc)
- TARGET_LINK_LIBRARIES(${test}-t gunit_small sqlgunitlib strings dbug regex)
- ADD_TEST(${test} ${test}-t)
-ENDFOREACH()
+## Merging tests into fewer executables saves *a lot* of
+## link time and disk space ...
+OPTION(MERGE_UNITTESTS "Merge tests into one executable" ON)
+IF (MERGE_UNITTESTS)
+ SET(MERGE_LARGE_TESTS ${CMAKE_CURRENT_BINARY_DIR}/merge_large_tests.cc)
+ SET(MERGE_SMALL_TESTS ${CMAKE_CURRENT_BINARY_DIR}/merge_small_tests.cc)
+ SET_SOURCE_FILES_PROPERTIES(MERGE_SMALL_TESTS MERGE_LARGE_TESTS
+ PROPERTIES GENERATED 1)
-FOREACH(test ${SERVER_TESTS})
- SET(SRC_FILES ${test}-t.cc)
+ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
+
+ FILE(WRITE ${MERGE_LARGE_TESTS} "// Merging large unit tests\n")
+ FILE(WRITE ${MERGE_SMALL_TESTS} "// Merging small unit tests\n")
+ FOREACH(test ${TESTS})
+ FILE(APPEND ${MERGE_SMALL_TESTS} "#include \"${test}-t.cc\"\n")
+ ENDFOREACH()
+ FOREACH(test ${SERVER_TESTS})
+ FILE(APPEND ${MERGE_LARGE_TESTS} "#include \"${test}-t.cc\"\n")
+ ENDFOREACH()
+
+ ADD_EXECUTABLE(merge_small_tests-t ${MERGE_SMALL_TESTS})
+ SET(SRC_FILES ${MERGE_LARGE_TESTS})
IF(WIN32)
LIST(APPEND SRC_FILES ../../sql/nt_servc.cc)
ENDIF()
- IF(test MATCHES "table_cache")
- LIST(APPEND SRC_FILES ../../storage/example/ha_example.cc)
- SET_SOURCE_FILES_PROPERTIES(
- ../../storage/example/ha_example.cc
- PROPERTIES COMPILE_FLAGS "-DDISABLE_DTRACE"
- )
- ENDIF()
- ADD_EXECUTABLE(${test}-t ${SRC_FILES})
- TARGET_LINK_LIBRARIES(${test}-t sql binlog rpl master slave sql)
- TARGET_LINK_LIBRARIES(${test}-t gunit_large strings dbug regex mysys)
- TARGET_LINK_LIBRARIES(${test}-t sql binlog rpl master slave sql)
- ADD_TEST(${test} ${test}-t)
-ENDFOREACH()
+ LIST(APPEND SRC_FILES ../../storage/example/ha_example.cc)
+ SET_SOURCE_FILES_PROPERTIES(
+ ../../storage/example/ha_example.cc
+ PROPERTIES COMPILE_FLAGS "-DDISABLE_DTRACE"
+ )
+ ADD_EXECUTABLE(merge_large_tests-t ${SRC_FILES})
+
+ TARGET_LINK_LIBRARIES(merge_small_tests-t
+ gunit_small sqlgunitlib strings dbug regex)
+ TARGET_LINK_LIBRARIES(merge_large_tests-t sql binlog rpl master slave sql)
+ TARGET_LINK_LIBRARIES(merge_large_tests-t
+ gunit_large strings dbug regex mysys)
+ TARGET_LINK_LIBRARIES(merge_large_tests-t sql binlog rpl master slave sql)
+
+ ADD_TEST(merge_large_tests merge_large_tests-t)
+ ADD_TEST(merge_small_tests merge_small_tests-t)
+
+ELSE()
+
+ FOREACH(test ${TESTS})
+ ADD_EXECUTABLE(${test}-t ${test}-t.cc)
+ TARGET_LINK_LIBRARIES(${test}-t gunit_small sqlgunitlib strings dbug regex)
+ ADD_TEST(${test} ${test}-t)
+ ENDFOREACH()
+
+ FOREACH(test ${SERVER_TESTS})
+ SET(SRC_FILES ${test}-t.cc)
+ IF(WIN32)
+ LIST(APPEND SRC_FILES ../../sql/nt_servc.cc)
+ ENDIF()
+ IF(test MATCHES "table_cache")
+ LIST(APPEND SRC_FILES ../../storage/example/ha_example.cc)
+ SET_SOURCE_FILES_PROPERTIES(
+ ../../storage/example/ha_example.cc
+ PROPERTIES COMPILE_FLAGS "-DDISABLE_DTRACE"
+ )
+ ENDIF()
+ ADD_EXECUTABLE(${test}-t ${SRC_FILES})
+ TARGET_LINK_LIBRARIES(${test}-t sql binlog rpl master slave sql)
+ TARGET_LINK_LIBRARIES(${test}-t gunit_large strings dbug regex mysys)
+ TARGET_LINK_LIBRARIES(${test}-t sql binlog rpl master slave sql)
+ ADD_TEST(${test} ${test}-t)
+ ENDFOREACH()
+
+ENDIF()
## Most executables depend on libeay32.dll (through mysys_ssl).
COPY_OPENSSL_DLLS(copy_openssl_gunit)
=== modified file 'unittest/gunit/alignment-t.cc'
--- a/unittest/gunit/alignment-t.cc 2012-11-23 09:02:13 +0000
+++ b/unittest/gunit/alignment-t.cc 2012-12-04 12:48:34 +0000
@@ -22,7 +22,7 @@
#include <algorithm>
#include <vector>
-namespace {
+namespace alignment_unittest {
/*
Testing performance penalty of accessing un-aligned data.
=== modified file 'unittest/gunit/bounded_queue-t.cc'
--- a/unittest/gunit/bounded_queue-t.cc 2011-12-20 09:51:05 +0000
+++ b/unittest/gunit/bounded_queue-t.cc 2012-12-04 12:48:34 +0000
@@ -23,7 +23,7 @@
#include "filesort_utils.h"
#include "my_sys.h"
-namespace {
+namespace bounded_queue_unittest {
const int num_elements= 14;
=== modified file 'unittest/gunit/bounds_checked_array-t.cc'
--- a/unittest/gunit/bounds_checked_array-t.cc 2012-08-08 10:23:44 +0000
+++ b/unittest/gunit/bounds_checked_array-t.cc 2012-12-04 12:48:34 +0000
@@ -19,7 +19,7 @@
#include "sql_array.h"
-namespace {
+namespace bounds_check_array_unittest {
typedef Bounds_checked_array<int> Int_array;
@@ -47,16 +47,18 @@ public:
operator<<() is needed by the EXPECT macros.
It is a template argument, so static rather than in unnamed namespace.
*/
-static inline std::ostream &operator<<(std::ostream &s, const Int_array &v)
+static inline
+std::ostream &operator<<(std::ostream &s,
+ const bounds_check_array_unittest::Int_array &v)
{
return s << "{"
- << v.array() << ", "
- << v.size()
- << "}"
+ << v.array() << ", "
+ << v.size()
+ << "}"
;
}
-namespace {
+namespace bounds_check_array_unittest {
TEST_F(BoundsCheckedArray, Empty)
{
=== modified file 'unittest/gunit/byteorder-t.cc'
--- a/unittest/gunit/byteorder-t.cc 2012-01-11 09:33:52 +0000
+++ b/unittest/gunit/byteorder-t.cc 2012-12-04 12:48:34 +0000
@@ -19,7 +19,7 @@
#include "my_global.h"
-namespace {
+namespace byteorder_unittest {
using std::numeric_limits;
=== modified file 'unittest/gunit/copy_info-t.cc'
--- a/unittest/gunit/copy_info-t.cc 2012-11-27 13:01:48 +0000
+++ b/unittest/gunit/copy_info-t.cc 2012-12-04 12:48:34 +0000
@@ -24,7 +24,7 @@
#include "test_utils.h"
#include "sql_data_change.h"
-namespace {
+namespace copy_info_unittest {
using my_testing::Server_initializer;
using my_testing::Mock_error_handler;
=== modified file 'unittest/gunit/cost_estimate-t.cc'
--- a/unittest/gunit/cost_estimate-t.cc 2011-12-20 09:51:05 +0000
+++ b/unittest/gunit/cost_estimate-t.cc 2012-12-04 12:48:34 +0000
@@ -19,7 +19,7 @@
#include "handler.h"
-namespace {
+namespace cost_estimate_unittest {
TEST(CostEstimateTest, Basics)
{
=== modified file 'unittest/gunit/create_field-t.cc'
--- a/unittest/gunit/create_field-t.cc 2012-05-07 12:05:48 +0000
+++ b/unittest/gunit/create_field-t.cc 2012-12-04 12:48:34 +0000
@@ -22,7 +22,7 @@
#include "mock_create_field.h"
-namespace {
+namespace create_field_unittest {
using my_testing::Server_initializer;
using my_testing::Mock_error_handler;
=== modified file 'unittest/gunit/dbug-t.cc'
--- a/unittest/gunit/dbug-t.cc 2012-09-26 13:52:56 +0000
+++ b/unittest/gunit/dbug-t.cc 2012-12-04 12:48:34 +0000
@@ -25,7 +25,7 @@
using thread::Notification;
using thread::Thread;
-namespace {
+namespace dbug_unittest {
#if defined(DBUG_OFF)
TEST(DebugTest, NoSuicide)
=== modified file 'unittest/gunit/decimal-t.cc'
--- a/unittest/gunit/decimal-t.cc 2012-10-30 14:40:02 +0000
+++ b/unittest/gunit/decimal-t.cc 2012-12-04 12:48:34 +0000
@@ -30,7 +30,7 @@ int decimal_shift(decimal_t *dec, int sh
}
-namespace {
+namespace decimal_unittest {
#define DIG_PER_DEC1 9
#define DIG_BASE 1000000000
=== modified file 'unittest/gunit/dynarray-t.cc'
--- a/unittest/gunit/dynarray-t.cc 2012-04-27 11:57:38 +0000
+++ b/unittest/gunit/dynarray-t.cc 2012-12-04 12:48:34 +0000
@@ -33,14 +33,6 @@
functionality of Mem_root_array.
*/
-pthread_key(MEM_ROOT**, THR_MALLOC);
-pthread_key(THD*, THR_THD);
-
-extern "C" void sql_alloc_error_handler(void)
-{
- ADD_FAILURE();
-}
-
/*
Rewrite of sort_keyuse() to comparison operator for use by std::less<>
@@ -96,7 +88,7 @@ static inline std::ostream &operator<<(s
}
-namespace {
+namespace dynarray_unittest {
/*
Cut'n paste this function from sql_select.cc,
=== modified file 'unittest/gunit/field-t.cc'
--- a/unittest/gunit/field-t.cc 2012-10-30 14:40:02 +0000
+++ b/unittest/gunit/field-t.cc 2012-12-04 12:48:34 +0000
@@ -24,7 +24,7 @@
#include "sql_time.h"
#include <my_decimal.h>
-namespace {
+namespace field_unittests {
using my_testing::Server_initializer;
using my_testing::Mock_error_handler;
@@ -475,9 +475,11 @@ void test_make_sort_key(Field *field)
}
-size_t mock_strnxfrm(const CHARSET_INFO *, uchar *, size_t, uint, const uchar *,
- size_t, uint);
-
+extern "C"
+{
+ static size_t mock_strnxfrm(const CHARSET_INFO *, uchar *, size_t,
+ uint, const uchar *, size_t, uint);
+}
class Mock_collation : public MY_COLLATION_HANDLER
{
=== modified file 'unittest/gunit/field_date-t.cc'
--- a/unittest/gunit/field_date-t.cc 2012-05-07 12:05:48 +0000
+++ b/unittest/gunit/field_date-t.cc 2012-12-04 12:48:34 +0000
@@ -23,7 +23,7 @@
#include "field.h"
-namespace {
+namespace field_date_unittests {
using my_testing::Server_initializer;
using my_testing::Mock_error_handler;
=== modified file 'unittest/gunit/field_datetime-t.cc'
--- a/unittest/gunit/field_datetime-t.cc 2012-05-07 12:05:48 +0000
+++ b/unittest/gunit/field_datetime-t.cc 2012-12-04 12:48:34 +0000
@@ -23,7 +23,7 @@
#include "field.h"
-namespace {
+namespace field_datetime_unittests {
using my_testing::Server_initializer;
using my_testing::Mock_error_handler;
=== modified file 'unittest/gunit/field_long-t.cc'
--- a/unittest/gunit/field_long-t.cc 2012-06-24 07:07:58 +0000
+++ b/unittest/gunit/field_long-t.cc 2012-12-04 12:48:34 +0000
@@ -22,7 +22,7 @@
#include "field.h"
-namespace {
+namespace field_long_unittest {
using my_testing::Server_initializer;
using my_testing::Mock_error_handler;
@@ -379,5 +379,4 @@ TEST_F(FieldLongTest, StoreNullValue)
}
}
-
}
=== modified file 'unittest/gunit/field_newdecimal-t.cc'
--- a/unittest/gunit/field_newdecimal-t.cc 2012-05-07 12:05:48 +0000
+++ b/unittest/gunit/field_newdecimal-t.cc 2012-12-04 12:48:34 +0000
@@ -25,8 +25,9 @@
type_conversion_status
store_internal_with_error_check(Field_new_decimal *field,
int conversion_err, my_decimal *value);
-namespace {
+namespace field_newdecimal_unittest {
+using my_testing::chars_2_decimal;
using my_testing::Server_initializer;
using my_testing::Mock_error_handler;
@@ -163,12 +164,6 @@ TEST_F(FieldNewDecimalTest, StoreIllegal
}
-static int chars_2_decimal(const char *chars, my_decimal *to)
-{
- char *end= strend(chars);
- return string2decimal(chars, to, &end);
-}
-
static void test_store_internal(Field_new_decimal *field,
my_decimal *value,
const char *expected_string_result,
=== modified file 'unittest/gunit/field_timestamp-t.cc'
--- a/unittest/gunit/field_timestamp-t.cc 2012-05-07 12:05:48 +0000
+++ b/unittest/gunit/field_timestamp-t.cc 2012-12-04 12:48:34 +0000
@@ -21,7 +21,7 @@
#include "mock_field_timestamp.h"
#include "test_utils.h"
-namespace {
+namespace field_timestamp_unittests {
using my_testing::Server_initializer;
=== modified file 'unittest/gunit/filesort_buffer-t.cc'
--- a/unittest/gunit/filesort_buffer-t.cc 2012-01-18 14:42:16 +0000
+++ b/unittest/gunit/filesort_buffer-t.cc 2012-12-04 12:48:34 +0000
@@ -21,7 +21,7 @@
#include "filesort_utils.h"
#include "table.h"
-namespace {
+namespace filesort_buffer_unittest {
class FileSortBufferTest : public ::testing::Test
{
=== modified file 'unittest/gunit/filesort_compare-t.cc'
--- a/unittest/gunit/filesort_compare-t.cc 2012-10-30 14:40:02 +0000
+++ b/unittest/gunit/filesort_compare-t.cc 2012-12-04 12:48:34 +0000
@@ -23,7 +23,7 @@
#include <memory>
#include <vector>
-namespace {
+namespace filesort_compare_unittest {
/*
Below are some performance microbenchmarks in order to compare our sorting
@@ -68,7 +68,7 @@ inline void int_to_bytes(uchar *s, int v
}
-TEST(AlignmentTest, IntsToBytesToInt)
+TEST(BufferAlignmentTest, IntsToBytesToInt)
{
uchar buf[10];
memset(buf, 0, sizeof(buf));
=== modified file 'unittest/gunit/get_diagnostics-t.cc'
--- a/unittest/gunit/get_diagnostics-t.cc 2012-05-07 12:05:48 +0000
+++ b/unittest/gunit/get_diagnostics-t.cc 2012-12-04 12:48:34 +0000
@@ -22,7 +22,7 @@
#include "item.h"
#include "sql_get_diagnostics.h"
-namespace {
+namespace get_diagnostics_unittest {
using my_testing::Server_initializer;
using my_testing::Mock_error_handler;
=== modified file 'unittest/gunit/gunit_test_main.cc'
--- a/unittest/gunit/gunit_test_main.cc 2012-11-23 09:02:13 +0000
+++ b/unittest/gunit/gunit_test_main.cc 2012-12-04 12:48:34 +0000
@@ -52,6 +52,17 @@ extern "C" my_bool get_one_option(int, c
} // namespace
+// Some globals needed for merge_small_tests.cc
+mysql_mutex_t LOCK_open;
+uint opt_debug_sync_timeout= 0;
+pthread_key(MEM_ROOT**,THR_MALLOC);
+pthread_key(THD*, THR_THD);
+
+extern "C" void sql_alloc_error_handler(void)
+{
+ ADD_FAILURE();
+}
+
extern void install_tap_listener();
=== modified file 'unittest/gunit/handler-t.h'
--- a/unittest/gunit/handler-t.h 2012-11-27 13:01:48 +0000
+++ b/unittest/gunit/handler-t.h 2012-12-04 12:48:34 +0000
@@ -13,6 +13,9 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA */
+#ifndef HANDLER_T_INCLUDED
+#define HANDLER_T_INCLUDED
+
// First include (the generated) my_config.h, to get correct platform defines.
#include "my_config.h"
#include <gtest/gtest.h>
@@ -51,3 +54,6 @@ public:
: handler(ht_arg, share_arg)
{}
};
+
+
+#endif // HANDLER_T_INCLUDED
=== modified file 'unittest/gunit/item-t.cc'
--- a/unittest/gunit/item-t.cc 2012-11-23 09:02:13 +0000
+++ b/unittest/gunit/item-t.cc 2012-12-04 12:48:34 +0000
@@ -26,7 +26,7 @@
#include "mock_field_timestamp.h"
-namespace {
+namespace item_unittest {
using my_testing::Server_initializer;
using my_testing::Mock_error_handler;
=== modified file 'unittest/gunit/item_func_now_local-t.cc'
--- a/unittest/gunit/item_func_now_local-t.cc 2012-05-07 12:05:48 +0000
+++ b/unittest/gunit/item_func_now_local-t.cc 2012-12-04 12:48:34 +0000
@@ -26,7 +26,7 @@
#include "rpl_handler.h" // delegates_init()
#include "tztime.h"
-namespace {
+namespace item_func_now_local_unittest {
using my_testing::Server_initializer;
using my_testing::Mock_error_handler;
=== modified file 'unittest/gunit/join_tab_sort-t.cc'
--- a/unittest/gunit/join_tab_sort-t.cc 2012-05-07 12:05:48 +0000
+++ b/unittest/gunit/join_tab_sort-t.cc 2012-12-04 12:48:34 +0000
@@ -24,7 +24,7 @@
#include <vector>
-namespace {
+namespace join_tab_sort_unittest {
using my_testing::Server_initializer;
using my_testing::Mock_error_handler;
=== modified file 'unittest/gunit/make_sortkey-t.cc'
--- a/unittest/gunit/make_sortkey-t.cc 2012-09-12 09:24:37 +0000
+++ b/unittest/gunit/make_sortkey-t.cc 2012-12-04 12:48:34 +0000
@@ -25,7 +25,7 @@
#include "filesort.h"
#include "sql_sort.h"
-namespace {
+namespace make_sortkey_unittest {
using my_testing::Server_initializer;
using my_testing::Mock_error_handler;
=== modified file 'unittest/gunit/mdl-t.cc'
--- a/unittest/gunit/mdl-t.cc 2012-09-27 14:54:18 +0000
+++ b/unittest/gunit/mdl-t.cc 2012-12-04 12:48:34 +0000
@@ -33,11 +33,6 @@
#include "thread_utils.h"
#include "test_mdl_context_owner.h"
-pthread_key(MEM_ROOT**,THR_MALLOC);
-pthread_key(THD*, THR_THD);
-mysql_mutex_t LOCK_open;
-uint opt_debug_sync_timeout= 0;
-
/*
Mock thd_wait_begin/end functions
*/
@@ -60,15 +55,6 @@ extern "C" void test_error_handler_hook(
}
/*
- A mock out-of-memory handler.
- We do not expect this to be called during testing.
-*/
-extern "C" void sql_alloc_error_handler(void)
-{
- ADD_FAILURE();
-}
-
-/*
Mock away this global function.
We don't need DEBUG_SYNC functionality in a unit test.
*/
@@ -79,10 +65,10 @@ void debug_sync(THD *thd, const char *sy
}
/*
- Putting everything in an unnamed namespace prevents any (unintentional)
+ Putting everything in a namespace prevents any (unintentional)
name clashes with the code under test.
*/
-namespace {
+namespace mdl_unittest {
using thread::Notification;
using thread::Thread;
=== removed file 'unittest/gunit/mdl_mytap-t.cc'
--- a/unittest/gunit/mdl_mytap-t.cc 2012-09-27 14:54:18 +0000
+++ b/unittest/gunit/mdl_mytap-t.cc 1970-01-01 00:00:00 +0000
@@ -1,762 +0,0 @@
-/* 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
- 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 is a port of the corresponding mdl_test.cc (written for Google Test)
- to mytap. Do a 'tkdiff mdl-t.cc mdl_mytap-t.cc' to see the differences.
- In order to illustrate (some of) the features of Google Test, I have
- added some extensions below, notably support for reporting of line
- numbers in case of failures.
- */
-
-// First include (the generated) my_config.h, to get correct platform defines.
-#include "my_config.h"
-#include <string>
-#include <iostream>
-#include <stdio.h>
-
-#include <tap.h>
-
-#include "mdl.h"
-#include <mysqld_error.h>
-
-#include "thr_malloc.h"
-#include "thread_utils.h"
-#include "test_mdl_context_owner.h"
-
-pthread_key(MEM_ROOT**,THR_MALLOC);
-pthread_key(THD*, THR_THD);
-mysql_mutex_t LOCK_open;
-uint opt_debug_sync_timeout= 0;
-
-// Reimplemented some macros from Google Test, so that the tests below
-// could be kept unchanged. No support for streaming of user messages
-// in this simplified version.
-void print_message(const char* file, int line, const char* message)
-{
- std::cout << "# " << file << ":" << line << " " << message << "\n";
-}
-
-// Some macro tricks to generate names like result123 and result456
-#define CONCAT_TOKEN_(foo, bar) CONCAT_TOKEN_IMPL_(foo, bar)
-#define CONCAT_TOKEN_IMPL_(foo, bar) foo ## bar
-#define BOOL_VAR_ CONCAT_TOKEN_(result, __LINE__)
-
-#define MESSAGE_(message) \
- print_message(__FILE__, __LINE__, message)
-
-// This is where we call the ok() function from mytap!!!
-#define TEST_BOOLEAN_(boolexpr, booltext, actual, expected, fail) \
-do { \
- const bool BOOL_VAR_ = boolexpr; \
- ok(BOOL_VAR_, BOOL_VAR_ ? "" : booltext); \
- if (!BOOL_VAR_) \
- fail("\n# Value of: " booltext \
- "\n# Actual: " #actual \
- "\n# Expected: " #expected); \
-} while(0)
-
-// Boolean assertions.
-#define EXPECT_TRUE(condition) \
- TEST_BOOLEAN_(condition, #condition, false, true, MESSAGE_)
-#define EXPECT_FALSE(condition) \
- TEST_BOOLEAN_(!(condition), #condition, true, false, MESSAGE_)
-
-
-// Some (very) simplified versions of comparison predicates.
-// There is no distinction between ASSERT and EXPECT in mytap.
-#define ASSERT_NE(val1, val2) \
- EXPECT_NE(val1, val2)
-
-// This version will not print expected or actual values for arguments.
-#define EXPECT_NE(val1, val2) \
- EXPECT_TRUE(val1 != val2)
-
-// This version will not print expected or actual values for arguments.
-#define EXPECT_EQ(val1, val2) \
- EXPECT_TRUE(val1 == val2)
-
-#define FAIL() \
- EXPECT_TRUE(1 == 0)
-
-
-/*
- Mock thd_wait_begin/end functions
-*/
-
-extern "C" void thd_wait_begin(MYSQL_THD thd, int wait_type)
-{
-}
-
-extern "C" void thd_wait_end(MYSQL_THD thd)
-{
-}
-
-/*
- A mock error handler.
-*/
-static uint expected_error= 0;
-extern "C" void test_error_handler_hook(uint err, const char *str, myf MyFlags)
-{
- EXPECT_EQ(expected_error, err);
-}
-
-/*
- A mock out-of-memory handler.
- We do not expect this to be called during testing.
-*/
-extern "C" void sql_alloc_error_handler(void)
-{
- FAIL();
-}
-
-/*
- Mock away this global function.
- We don't need DEBUG_SYNC functionality in a unit test.
- */
-void debug_sync(THD *thd, const char *sync_point_name, size_t name_len)
-{
- DBUG_PRINT("debug_sync_point", ("hit: '%s'", sync_point_name));
- FAIL();
-}
-
-/*
- Putting everything in an unnamed namespace prevents any (unintentional)
- name clashes with the code under test.
-*/
-namespace {
-
-using thread::Notification;
-using thread::Thread;
-
-const char db_name[]= "some_database";
-const char table_name1[]= "some_table1";
-const char table_name2[]= "some_table2";
-const char table_name3[]= "some_table3";
-const char table_name4[]= "some_table4";
-const ulong zero_timeout= 0;
-const ulong long_timeout= (ulong) 3600L*24L*365L;
-
-
-class MDLTest : public Test_MDL_context_owner
-{
-public:
- // Utility function to run one test case.
- typedef void (MDLTest::* Pmdl_mem)();
- static void run_one_test(Pmdl_mem member_function);
-
- // Utility function to run all the test cases.
- static int RUN_ALL_TESTS();
-
-protected:
- MDLTest()
- : m_null_ticket(NULL),
- m_null_request(NULL)
- {
- }
-
- static void SetUpTestCase()
- {
- error_handler_hook= test_error_handler_hook;
- mdl_locks_hash_partitions= MDL_LOCKS_HASH_PARTITIONS_DEFAULT;
- }
-
- void SetUp()
- {
- expected_error= 0;
- mdl_init();
- m_mdl_context.init(this);
- EXPECT_FALSE(m_mdl_context.has_locks());
- m_global_request.init(MDL_key::GLOBAL, "", "", MDL_INTENTION_EXCLUSIVE,
- MDL_TRANSACTION);
- }
-
- void TearDown()
- {
- m_mdl_context.destroy();
- mdl_destroy();
- }
-
- virtual bool notify_shared_lock(MDL_context_owner *in_use,
- bool needs_thr_lock_abort)
- {
- return in_use->notify_shared_lock(NULL, needs_thr_lock_abort);
- }
-
- // A utility member for testing single lock requests.
- void test_one_simple_shared_lock(enum_mdl_type lock_type);
-
- // We must list all the individual tests here.
- void DieWhenMTicketsNonempty();
- void DieWhenHoldingGlobalSharedLock();
- void ConstructAndDestruct();
- void OneShared();
- void OneSharedHighPrio();
- void OneSharedRead();
- void OneSharedWrite();
- void OneExclusive();
- void TwoShared();
- void SharedLocksBetweenContexts();
- void UpgradeSharedUpgradable();
- void DieUpgradeShared();
- void SavePoint();
- void ConcurrentShared();
- void ConcurrentSharedExclusive();
- void ConcurrentExclusiveShared();
- void ConcurrentUpgrade();
-
- const MDL_ticket *m_null_ticket;
- const MDL_request *m_null_request;
- MDL_context m_mdl_context;
- MDL_request m_request;
- MDL_request m_global_request;
- MDL_request_list m_request_list;
-private:
- // GTEST_DISALLOW_COPY_AND_ASSIGN_(MDLTest);
-};
-
-
-/*
- Will grab a lock on table_name of given type in the run() function.
- The two notifications are for synchronizing with the main thread.
- Does *not* take ownership of the notifications.
-*/
-class MDL_thread : public Thread, public Test_MDL_context_owner
-{
-public:
- MDL_thread(const char *table_name,
- enum_mdl_type mdl_type,
- Notification *lock_grabbed,
- Notification *release_locks)
- : m_table_name(table_name),
- m_mdl_type(mdl_type),
- m_lock_grabbed(lock_grabbed),
- m_release_locks(release_locks),
- m_ignore_notify(false)
- {
- m_mdl_context.init(this);
- }
-
- ~MDL_thread()
- {
- m_mdl_context.destroy();
- }
-
- virtual void run();
- void ignore_notify() { m_ignore_notify= true; }
-
- virtual bool notify_shared_lock(MDL_context_owner *in_use,
- bool needs_thr_lock_abort)
- {
- if (in_use)
- return in_use->notify_shared_lock(NULL, needs_thr_lock_abort);
-
- if (m_ignore_notify)
- return false;
- m_release_locks->notify();
- return true;
- }
-
-private:
- const char *m_table_name;
- enum_mdl_type m_mdl_type;
- Notification *m_lock_grabbed;
- Notification *m_release_locks;
- bool m_ignore_notify;
- MDL_context m_mdl_context;
-};
-
-
-void MDL_thread::run()
-{
- MDL_request request;
- MDL_request global_request;
- MDL_request_list request_list;
- global_request.init(MDL_key::GLOBAL, "", "", MDL_INTENTION_EXCLUSIVE,
- MDL_TRANSACTION);
- request.init(MDL_key::TABLE, db_name, m_table_name, m_mdl_type,
- MDL_TRANSACTION);
-
- request_list.push_front(&request);
- if (m_mdl_type >= MDL_SHARED_UPGRADABLE)
- request_list.push_front(&global_request);
-
- EXPECT_FALSE(m_mdl_context.acquire_locks(&request_list, long_timeout));
- EXPECT_TRUE(m_mdl_context.
- is_lock_owner(MDL_key::TABLE, db_name, m_table_name, m_mdl_type));
-
- // Tell the main thread that we have grabbed our locks.
- m_lock_grabbed->notify();
- // Hold on to locks until we are told to release them
- m_release_locks->wait_for_notification();
-
- m_mdl_context.release_transactional_locks();
-}
-
-// Google Test recommends DeathTest suffix for classes use in death tests.
-typedef MDLTest MDLDeathTest;
-
-// Our own (simplified) version of the TEST_F macro.
-#define TEST_F(FixtureClass, FunctionName) \
- void FixtureClass::FunctionName()
-
-
-/*
- The most basic test: just construct and destruct our test fixture.
- */
-TEST_F(MDLTest, ConstructAndDestruct)
-{
-}
-
-
-void MDLTest::test_one_simple_shared_lock(enum_mdl_type lock_type)
-{
- m_request.init(MDL_key::TABLE, db_name, table_name1, lock_type,
- MDL_TRANSACTION);
-
- EXPECT_EQ(lock_type, m_request.type);
- EXPECT_EQ(m_null_ticket, m_request.ticket);
-
- EXPECT_FALSE(m_mdl_context.try_acquire_lock(&m_request));
- EXPECT_NE(m_null_ticket, m_request.ticket);
- EXPECT_TRUE(m_mdl_context.has_locks());
- EXPECT_TRUE(m_mdl_context.
- is_lock_owner(MDL_key::TABLE, db_name, table_name1, lock_type));
-
- MDL_request request_2;
- request_2.init(&m_request.key, lock_type, MDL_TRANSACTION);
- EXPECT_FALSE(m_mdl_context.try_acquire_lock(&request_2));
- EXPECT_EQ(m_request.ticket, request_2.ticket);
-
- m_mdl_context.release_transactional_locks();
- EXPECT_FALSE(m_mdl_context.has_locks());
-}
-
-
-/*
- Acquires one lock of type MDL_SHARED.
- */
-TEST_F(MDLTest, OneShared)
-{
- test_one_simple_shared_lock(MDL_SHARED);
-}
-
-
-/*
- Acquires one lock of type MDL_SHARED_HIGH_PRIO.
- */
-TEST_F(MDLTest, OneSharedHighPrio)
-{
- test_one_simple_shared_lock(MDL_SHARED_HIGH_PRIO);
-}
-
-
-/*
- Acquires one lock of type MDL_SHARED_READ.
- */
-TEST_F(MDLTest, OneSharedRead)
-{
- test_one_simple_shared_lock(MDL_SHARED_READ);
-}
-
-
-/*
- Acquires one lock of type MDL_SHARED_WRITE.
- */
-TEST_F(MDLTest, OneSharedWrite)
-{
- test_one_simple_shared_lock(MDL_SHARED_WRITE);
-}
-
-
-/*
- Acquires one lock of type MDL_EXCLUSIVE.
- */
-TEST_F(MDLTest, OneExclusive)
-{
- const enum_mdl_type lock_type= MDL_EXCLUSIVE;
- m_request.init(MDL_key::TABLE, db_name, table_name1, lock_type,
- MDL_TRANSACTION);
- EXPECT_EQ(m_null_ticket, m_request.ticket);
-
- m_request_list.push_front(&m_request);
- m_request_list.push_front(&m_global_request);
-
- EXPECT_FALSE(m_mdl_context.acquire_locks(&m_request_list, long_timeout));
-
- EXPECT_NE(m_null_ticket, m_request.ticket);
- EXPECT_NE(m_null_ticket, m_global_request.ticket);
- EXPECT_TRUE(m_mdl_context.has_locks());
- EXPECT_TRUE(m_mdl_context.
- is_lock_owner(MDL_key::TABLE, db_name, table_name1, lock_type));
- EXPECT_TRUE(m_mdl_context.
- is_lock_owner(MDL_key::GLOBAL, "", "", MDL_INTENTION_EXCLUSIVE));
- EXPECT_TRUE(m_request.ticket->is_upgradable_or_exclusive());
-
- m_mdl_context.release_transactional_locks();
- EXPECT_FALSE(m_mdl_context.has_locks());
-}
-
-
-/*
- Acquires two locks, on different tables, of type MDL_SHARED.
- Verifies that they are independent.
- */
-TEST_F(MDLTest, TwoShared)
-{
- MDL_request request_2;
- m_request.init(MDL_key::TABLE, db_name, table_name1, MDL_SHARED, MDL_EXPLICIT);
- request_2.init(MDL_key::TABLE, db_name, table_name2, MDL_SHARED, MDL_EXPLICIT);
-
- EXPECT_FALSE(m_mdl_context.try_acquire_lock(&m_request));
- EXPECT_FALSE(m_mdl_context.try_acquire_lock(&request_2));
- EXPECT_TRUE(m_mdl_context.has_locks());
- ASSERT_NE(m_null_ticket, m_request.ticket);
- ASSERT_NE(m_null_ticket, request_2.ticket);
-
- EXPECT_TRUE(m_mdl_context.
- is_lock_owner(MDL_key::TABLE, db_name, table_name1, MDL_SHARED));
- EXPECT_TRUE(m_mdl_context.
- is_lock_owner(MDL_key::TABLE, db_name, table_name2, MDL_SHARED));
- EXPECT_FALSE(m_mdl_context.
- is_lock_owner(MDL_key::TABLE, db_name, table_name3, MDL_SHARED));
-
- m_mdl_context.release_lock(m_request.ticket);
- EXPECT_FALSE(m_mdl_context.
- is_lock_owner(MDL_key::TABLE, db_name, table_name1, MDL_SHARED));
- EXPECT_TRUE(m_mdl_context.has_locks());
-
- m_mdl_context.release_lock(request_2.ticket);
- EXPECT_FALSE(m_mdl_context.
- is_lock_owner(MDL_key::TABLE, db_name, table_name2, MDL_SHARED));
- EXPECT_FALSE(m_mdl_context.has_locks());
-}
-
-
-/*
- Verifies that two different contexts can acquire a shared lock
- on the same table.
- */
-TEST_F(MDLTest, SharedLocksBetweenContexts)
-{
- MDL_context mdl_context2;
- mdl_context2.init(this);
- MDL_request request_2;
- m_request.init(MDL_key::TABLE, db_name, table_name1, MDL_SHARED,
- MDL_TRANSACTION);
- request_2.init(MDL_key::TABLE, db_name, table_name1, MDL_SHARED,
- MDL_TRANSACTION);
-
- EXPECT_FALSE(m_mdl_context.try_acquire_lock(&m_request));
- EXPECT_FALSE(mdl_context2.try_acquire_lock(&request_2));
-
- EXPECT_TRUE(m_mdl_context.
- is_lock_owner(MDL_key::TABLE, db_name, table_name1, MDL_SHARED));
- EXPECT_TRUE(mdl_context2.
- is_lock_owner(MDL_key::TABLE, db_name, table_name1, MDL_SHARED));
-
- m_mdl_context.release_transactional_locks();
- mdl_context2.release_transactional_locks();
-}
-
-
-/*
- Verifies that we can upgrade a shared lock to exclusive.
- */
-TEST_F(MDLTest, UpgradeSharedUpgradable)
-{
- m_request.init(MDL_key::TABLE, db_name, table_name1, MDL_SHARED_UPGRADABLE,
- MDL_TRANSACTION);
-
- m_request_list.push_front(&m_request);
- m_request_list.push_front(&m_global_request);
-
- EXPECT_FALSE(m_mdl_context.acquire_locks(&m_request_list, long_timeout));
- EXPECT_FALSE(m_mdl_context.
- upgrade_shared_lock(m_request.ticket, MDL_EXCLUSIVE, long_timeout));
- EXPECT_EQ(MDL_EXCLUSIVE, m_request.ticket->get_type());
-
- // Another upgrade should be a no-op.
- EXPECT_FALSE(m_mdl_context.
- upgrade_shared_lock(m_request.ticket, MDL_EXCLUSIVE, long_timeout));
- EXPECT_EQ(MDL_EXCLUSIVE, m_request.ticket->get_type());
-
- m_mdl_context.release_transactional_locks();
-}
-
-
-/*
- Verifies that only upgradable locks can be upgraded to exclusive.
- */
-TEST_F(MDLDeathTest, DieUpgradeShared)
-{
- MDL_request request_2;
- m_request.init(MDL_key::TABLE, db_name, table_name1, MDL_SHARED,
- MDL_TRANSACTION);
- request_2.init(MDL_key::TABLE, db_name, table_name2, MDL_SHARED_NO_READ_WRITE,
- MDL_TRANSACTION);
-
- m_request_list.push_front(&m_request);
- m_request_list.push_front(&request_2);
- m_request_list.push_front(&m_global_request);
-
- EXPECT_FALSE(m_mdl_context.acquire_locks(&m_request_list, long_timeout));
-
-#if GTEST_HAS_DEATH_TEST && !defined(DBUG_OFF)
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
- EXPECT_DEATH_IF_SUPPORTED(m_mdl_context.
- upgrade_shared_lock(m_request.ticket,
- MDL_EXCLUSIVE,
- long_timeout),
- ".*MDL_SHARED_NO_.*");
-#endif
- EXPECT_FALSE(m_mdl_context.
- upgrade_shared_lock(request_2.ticket, MDL_EXCLUSIVE,
- long_timeout));
- m_mdl_context.release_transactional_locks();
-}
-
-
-/*
- Verfies that locks are released when we roll back to a savepoint.
- */
-TEST_F(MDLTest, SavePoint)
-{
- MDL_request request_2;
- MDL_request request_3;
- MDL_request request_4;
- m_request.init(MDL_key::TABLE, db_name, table_name1, MDL_SHARED,
- MDL_TRANSACTION);
- request_2.init(MDL_key::TABLE, db_name, table_name2, MDL_SHARED,
- MDL_TRANSACTION);
- request_3.init(MDL_key::TABLE, db_name, table_name3, MDL_SHARED,
- MDL_TRANSACTION);
- request_4.init(MDL_key::TABLE, db_name, table_name4, MDL_SHARED,
- MDL_TRANSACTION);
-
- EXPECT_FALSE(m_mdl_context.try_acquire_lock(&m_request));
- EXPECT_FALSE(m_mdl_context.try_acquire_lock(&request_2));
- MDL_savepoint savepoint= m_mdl_context.mdl_savepoint();
- EXPECT_FALSE(m_mdl_context.try_acquire_lock(&request_3));
- EXPECT_FALSE(m_mdl_context.try_acquire_lock(&request_4));
-
- EXPECT_TRUE(m_mdl_context.
- is_lock_owner(MDL_key::TABLE, db_name, table_name1, MDL_SHARED));
- EXPECT_TRUE(m_mdl_context.
- is_lock_owner(MDL_key::TABLE, db_name, table_name2, MDL_SHARED));
- EXPECT_TRUE(m_mdl_context.
- is_lock_owner(MDL_key::TABLE, db_name, table_name3, MDL_SHARED));
- EXPECT_TRUE(m_mdl_context.
- is_lock_owner(MDL_key::TABLE, db_name, table_name4, MDL_SHARED));
-
- m_mdl_context.rollback_to_savepoint(savepoint);
- EXPECT_TRUE(m_mdl_context.
- is_lock_owner(MDL_key::TABLE, db_name, table_name1, MDL_SHARED));
- EXPECT_TRUE(m_mdl_context.
- is_lock_owner(MDL_key::TABLE, db_name, table_name2, MDL_SHARED));
- EXPECT_FALSE(m_mdl_context.
- is_lock_owner(MDL_key::TABLE, db_name, table_name3, MDL_SHARED));
- EXPECT_FALSE(m_mdl_context.
- is_lock_owner(MDL_key::TABLE, db_name, table_name4, MDL_SHARED));
-
- m_mdl_context.release_transactional_locks();
- EXPECT_FALSE(m_mdl_context.
- is_lock_owner(MDL_key::TABLE, db_name, table_name1, MDL_SHARED));
- EXPECT_FALSE(m_mdl_context.
- is_lock_owner(MDL_key::TABLE, db_name, table_name2, MDL_SHARED));
-}
-
-
-/*
- Verifies that we can grab shared locks concurrently, in different threads.
- */
-TEST_F(MDLTest, ConcurrentShared)
-{
- Notification lock_grabbed;
- Notification release_locks;
- MDL_thread mdl_thread(table_name1, MDL_SHARED, &lock_grabbed, &release_locks);
- mdl_thread.start();
- lock_grabbed.wait_for_notification();
-
- m_request.init(MDL_key::TABLE, db_name, table_name1, MDL_SHARED,
- MDL_TRANSACTION);
-
- EXPECT_FALSE(m_mdl_context.acquire_lock(&m_request, long_timeout));
- EXPECT_TRUE(m_mdl_context.
- is_lock_owner(MDL_key::TABLE, db_name, table_name1, MDL_SHARED));
-
- release_locks.notify();
- mdl_thread.join();
-
- m_mdl_context.release_transactional_locks();
-}
-
-
-/*
- Verifies that we cannot grab an exclusive lock on something which
- is locked with a shared lock in a different thread.
- */
-TEST_F(MDLTest, ConcurrentSharedExclusive)
-{
- expected_error= ER_LOCK_WAIT_TIMEOUT;
-
- Notification lock_grabbed;
- Notification release_locks;
- MDL_thread mdl_thread(table_name1, MDL_SHARED, &lock_grabbed, &release_locks);
- mdl_thread.ignore_notify();
- mdl_thread.start();
- lock_grabbed.wait_for_notification();
-
- m_request.init(MDL_key::TABLE, db_name, table_name1, MDL_EXCLUSIVE,
- MDL_TRANSACTION);
-
- m_request_list.push_front(&m_request);
- m_request_list.push_front(&m_global_request);
-
- // We should *not* be able to grab the lock here.
- EXPECT_TRUE(m_mdl_context.acquire_locks(&m_request_list, zero_timeout));
- EXPECT_FALSE(m_mdl_context.
- is_lock_owner(MDL_key::TABLE,
- db_name, table_name1, MDL_EXCLUSIVE));
-
- release_locks.notify();
- mdl_thread.join();
-
- // Now we should be able to grab the lock.
- EXPECT_FALSE(m_mdl_context.acquire_locks(&m_request_list, zero_timeout));
- EXPECT_NE(m_null_ticket, m_request.ticket);
-
- m_mdl_context.release_transactional_locks();
-}
-
-
-/*
- Verifies that we cannot we cannot grab a shared lock on something which
- is locked exlusively in a different thread.
- */
-TEST_F(MDLTest, ConcurrentExclusiveShared)
-{
- Notification lock_grabbed;
- Notification release_locks;
- MDL_thread mdl_thread(table_name1, MDL_EXCLUSIVE,
- &lock_grabbed, &release_locks);
- mdl_thread.start();
- lock_grabbed.wait_for_notification();
-
- m_request.init(MDL_key::TABLE, db_name, table_name1, MDL_SHARED,
- MDL_TRANSACTION);
-
- // We should *not* be able to grab the lock here.
- EXPECT_FALSE(m_mdl_context.try_acquire_lock(&m_request));
- EXPECT_EQ(m_null_ticket, m_request.ticket);
-
- release_locks.notify();
-
- // The other thread should eventually release its locks.
- EXPECT_FALSE(m_mdl_context.acquire_lock(&m_request, long_timeout));
- EXPECT_NE(m_null_ticket, m_request.ticket);
-
- mdl_thread.join();
- m_mdl_context.release_transactional_locks();
-}
-
-
-/*
- Verifies the following scenario:
- Thread 1: grabs a shared upgradable lock.
- Thread 2: grabs a shared lock.
- Thread 1: asks for an upgrade to exclusive (needs to wait for thread 2)
- Thread 2: gets notified, and releases lock.
- Thread 1: gets the exclusive lock.
- */
-TEST_F(MDLTest, ConcurrentUpgrade)
-{
- m_request.init(MDL_key::TABLE, db_name, table_name1, MDL_SHARED_UPGRADABLE,
- MDL_TRANSACTION);
- m_request_list.push_front(&m_request);
- m_request_list.push_front(&m_global_request);
-
- EXPECT_FALSE(m_mdl_context.acquire_locks(&m_request_list, long_timeout));
- EXPECT_TRUE(m_mdl_context.
- is_lock_owner(MDL_key::TABLE,
- db_name, table_name1, MDL_SHARED_UPGRADABLE));
- EXPECT_FALSE(m_mdl_context.
- is_lock_owner(MDL_key::TABLE,
- db_name, table_name1, MDL_EXCLUSIVE));
-
- Notification lock_grabbed;
- Notification release_locks;
- MDL_thread mdl_thread(table_name1, MDL_SHARED, &lock_grabbed, &release_locks);
- mdl_thread.start();
- lock_grabbed.wait_for_notification();
-
- EXPECT_FALSE(m_mdl_context.
- upgrade_shared_lock(m_request.ticket, MDL_EXCLUSIVE,
- long_timeout));
- EXPECT_TRUE(m_mdl_context.
- is_lock_owner(MDL_key::TABLE,
- db_name, table_name1, MDL_EXCLUSIVE));
-
- mdl_thread.join();
- m_mdl_context.release_transactional_locks();
-}
-
-} // namespace
-
-
-// Creates a new fixture object for each test case.
-void MDLTest::run_one_test(Pmdl_mem member_function)
-{
- MDLTest *test_object = new MDLTest;
- test_object->SetUp();
- (test_object->*member_function)();
- test_object->TearDown();
- delete test_object;
-}
-
-
-// We have to invoke each test explicitly here, since we don't have
-// the auto-registration support from the TEST and TEST_F macros.
-int MDLTest::RUN_ALL_TESTS()
-{
- MDLTest::SetUpTestCase();
-
- run_one_test(&MDLTest::ConstructAndDestruct);
- run_one_test(&MDLTest::OneShared);
- run_one_test(&MDLTest::OneSharedHighPrio);
- run_one_test(&MDLTest::OneSharedRead);
- run_one_test(&MDLTest::OneSharedWrite);
- run_one_test(&MDLTest::OneExclusive);
- run_one_test(&MDLTest::TwoShared);
- run_one_test(&MDLTest::SharedLocksBetweenContexts);
- run_one_test(&MDLTest::UpgradeSharedUpgradable);
- run_one_test(&MDLTest::DieUpgradeShared);
- run_one_test(&MDLTest::SavePoint);
- run_one_test(&MDLTest::ConcurrentShared);
- run_one_test(&MDLTest::ConcurrentSharedExclusive);
- run_one_test(&MDLTest::ConcurrentExclusiveShared);
- run_one_test(&MDLTest::ConcurrentUpgrade);
-
- // Execute MDLTest::TearDownTestCase() here, if it is defined.
- return exit_status();
-}
-
-
-int main(int argc, char **argv) {
- // ::testing::InitGoogleTest(&argc, argv);
- MY_INIT(argv[0]);
- plan(NO_PLAN);
- return MDLTest::RUN_ALL_TESTS();
-}
=== modified file 'unittest/gunit/my_bitmap-t.cc'
--- a/unittest/gunit/my_bitmap-t.cc 2012-05-31 23:23:37 +0000
+++ b/unittest/gunit/my_bitmap-t.cc 2012-12-04 12:48:34 +0000
@@ -22,7 +22,7 @@
#include <my_pthread.h>
#include <my_bitmap.h>
-namespace {
+namespace my_bitmap_unittest {
const uint MAX_TESTED_BITMAP_SIZE= 1024;
@@ -534,8 +534,20 @@ protected:
uint bitsize;
};
+const uint test_values[]=
+{
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
+ 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
+ 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
+ 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
+ 2*32U - 1, 2*32U, 2*32U + 1,
+ 3*32U - 1, 3*32U, 3*32U + 1,
+ 4*32U - 1, 4*32U, 4*32U + 1,
+ MAX_TESTED_BITMAP_SIZE
+};
+
INSTANTIATE_TEST_CASE_P(Foo, BitMapTest,
- ::testing::Range(1U, MAX_TESTED_BITMAP_SIZE, 1U));
+ ::testing::ValuesIn(test_values));
TEST_P(BitMapTest, TestSetGetClearBit)
{
=== modified file 'unittest/gunit/my_decimal-t.cc'
--- a/unittest/gunit/my_decimal-t.cc 2012-11-30 08:39:51 +0000
+++ b/unittest/gunit/my_decimal-t.cc 2012-12-04 12:48:34 +0000
@@ -20,8 +20,9 @@
#include <my_decimal.h>
-namespace {
+namespace my_decimal_unittest {
+using my_testing::chars_2_decimal;
using my_testing::Server_initializer;
using my_testing::Mock_error_handler;
@@ -110,13 +111,6 @@ TEST_F(DecimalTest, Swap)
-int chars_2_decimal(const char *chars, my_decimal *to)
-{
- char *end= strend(chars);
- return string2decimal(chars, to, &end);
-}
-
-
TEST_F(DecimalTest, Multiply)
{
const char arg1[]=
=== modified file 'unittest/gunit/my_error-t.cc'
--- a/unittest/gunit/my_error-t.cc 2012-05-03 10:59:36 +0000
+++ b/unittest/gunit/my_error-t.cc 2012-12-04 12:48:34 +0000
@@ -21,7 +21,7 @@
#include "my_base.h" // HA_ERR_KEY_NOT_FOUND
#include <string.h>
-namespace {
+namespace my_error_unittest {
TEST(MyErrorTest, MyStrErrorSystem)
{
=== modified file 'unittest/gunit/my_regex-t.cc'
--- a/unittest/gunit/my_regex-t.cc 2011-12-20 09:51:05 +0000
+++ b/unittest/gunit/my_regex-t.cc 2012-12-04 12:48:34 +0000
@@ -26,7 +26,7 @@
and tests expected sucess/failure with basic/extended regexps etc. etc.
*/
-namespace {
+namespace my_regex_unittest {
const int NSUBS= 10;
=== modified file 'unittest/gunit/opt_range-t.cc'
--- a/unittest/gunit/opt_range-t.cc 2012-05-07 12:05:48 +0000
+++ b/unittest/gunit/opt_range-t.cc 2012-12-04 12:48:34 +0000
@@ -21,7 +21,7 @@
#include "opt_range.cc"
-namespace {
+namespace opt_range_unittest {
using my_testing::Server_initializer;
=== modified file 'unittest/gunit/opt_trace-t.cc'
--- a/unittest/gunit/opt_trace-t.cc 2012-03-21 21:19:11 +0000
+++ b/unittest/gunit/opt_trace-t.cc 2012-12-04 12:48:34 +0000
@@ -31,7 +31,7 @@
#include <sys/wait.h> // for WEXITSTATUS
#endif
-namespace {
+namespace opt_trace_unittest {
const ulonglong all_features= Opt_trace_context::default_features;
=== modified file 'unittest/gunit/segfault-t.cc'
--- a/unittest/gunit/segfault-t.cc 2012-11-23 09:02:13 +0000
+++ b/unittest/gunit/segfault-t.cc 2012-12-04 12:48:34 +0000
@@ -22,7 +22,7 @@
#include "m_string.h"
#include "hash_filo.h"
-namespace {
+namespace segfault_unittest {
using my_testing::Server_initializer;
using my_testing::Mock_error_handler;
=== modified file 'unittest/gunit/sql_list-t.cc'
--- a/unittest/gunit/sql_list-t.cc 2012-02-15 13:57:17 +0000
+++ b/unittest/gunit/sql_list-t.cc 2012-12-04 12:48:34 +0000
@@ -30,23 +30,9 @@
#include "sql_string.h"
#include "sql_error.h"
#include <my_pthread.h>
+#include "test_utils.h"
-pthread_key(MEM_ROOT**, THR_MALLOC);
-pthread_key(THD*, THR_THD);
-
-extern "C" void sql_alloc_error_handler(void)
-{
- ADD_FAILURE();
-}
-
-namespace {
-
-// A simple helper function to determine array size.
-template <class T, int size>
-int array_size(const T (&)[size])
-{
- return size;
-}
+namespace sql_list_unittest {
// A simple helper function to insert values into a List.
template <class T, int size>
=== modified file 'unittest/gunit/sql_plist-t.cc'
--- a/unittest/gunit/sql_plist-t.cc 2011-12-20 09:51:05 +0000
+++ b/unittest/gunit/sql_plist-t.cc 2012-12-04 12:48:34 +0000
@@ -18,15 +18,9 @@
#include <gtest/gtest.h>
#include "sql_plist.h"
+#include "test_utils.h"
-namespace {
-
-// A simple helper function to determine array size.
-template <class T, int size>
-int array_size(const T (&)[size])
-{
- return size;
-}
+namespace sql_plist_unittest {
// A simple helper function to insert values into a List.
template <class T, int size, class L>
=== modified file 'unittest/gunit/sql_table-t.cc'
--- a/unittest/gunit/sql_table-t.cc 2012-10-31 16:27:43 +0000
+++ b/unittest/gunit/sql_table-t.cc 2012-12-04 12:48:34 +0000
@@ -26,7 +26,7 @@
#include "rpl_handler.h" // delegates_init()
#include "sql_table.h"
-namespace {
+namespace sql_table_unittest {
using my_testing::Server_initializer;
using my_testing::Mock_error_handler;
=== modified file 'unittest/gunit/table_cache-t.cc'
--- a/unittest/gunit/table_cache-t.cc 2012-05-24 18:58:39 +0000
+++ b/unittest/gunit/table_cache-t.cc 2012-12-04 12:48:34 +0000
@@ -28,7 +28,7 @@
*/
extern handlerton *example_hton;
-namespace {
+namespace table_cache_unittest {
using my_testing::Server_initializer;
=== modified file 'unittest/gunit/test_utils.cc'
--- a/unittest/gunit/test_utils.cc 2012-10-09 12:36:52 +0000
+++ b/unittest/gunit/test_utils.cc 2012-12-04 12:48:34 +0000
@@ -22,6 +22,13 @@
namespace my_testing {
+int chars_2_decimal(const char *chars, my_decimal *to)
+{
+ char *end= strend(chars);
+ return string2decimal(chars, to, &end);
+}
+
+
/*
A mock error handler for error_handler_hook.
*/
=== modified file 'unittest/gunit/test_utils.h'
--- a/unittest/gunit/test_utils.h 2012-10-09 12:36:52 +0000
+++ b/unittest/gunit/test_utils.h 2012-12-04 12:48:34 +0000
@@ -21,10 +21,24 @@
#include "sql_class.h"
#include "set_var.h"
+extern pthread_key(MEM_ROOT**,THR_MALLOC);
+extern pthread_key(THD*, THR_THD);
+extern mysql_mutex_t LOCK_open;
+extern uint opt_debug_sync_timeout;
+extern "C" void sql_alloc_error_handler(void);
+
+// A simple helper function to determine array size.
+template <class T, int size>
+int array_size(const T (&)[size])
+{
+ return size;
+}
+
namespace my_testing {
void setup_server_for_unit_tests();
void teardown_server_for_unit_tests();
+int chars_2_decimal(const char *chars, my_decimal *to);
/*
A class which wraps the necessary setup/teardown logic for
=== modified file 'unittest/gunit/thread_utils-t.cc'
--- a/unittest/gunit/thread_utils-t.cc 2011-12-20 09:51:05 +0000
+++ b/unittest/gunit/thread_utils-t.cc 2012-12-04 12:48:34 +0000
@@ -21,14 +21,6 @@
#include "mdl.h"
-pthread_key(MEM_ROOT**,THR_MALLOC);
-pthread_key(THD*, THR_THD);
-
-extern "C" void sql_alloc_error_handler(void)
-{
- ADD_FAILURE();
-}
-
using thread::Mutex_lock;
using thread::Notification;
using thread::Thread;
No bundle (reason: useless for push emails).
| Thread |
|---|
| • bzr push into mysql-5.6 branch (tor.didriksen:4718 to 4719) Bug#15947828 | Tor Didriksen | 4 Dec |