MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:Tor Didriksen Date:November 12 2009 8:25am
Subject:bzr commit into mysql-6.0-codebase-bugfixing branch (tor.didriksen:3640)
View as plain text  
#At file:///export/home/didrik/mysqldev-6.0-codebase/6.0-codebase-bf-gtest/my-6.0-codebase-bugfixing-gtest/ based on revid:tor.didriksen@stripped

 3640 Tor Didriksen	2009-11-12
      Move gunit stuff to a separate directory

    added:
      unittest/gunit/
      unittest/gunit/Makefile.am
    renamed:
      sql/gunit_test_main.cc => unittest/gunit/gunit_test_main.cc
      sql/mdl-t.cc => unittest/gunit/mdl_mytap-t.cc
      sql/mdl_test.cc => unittest/gunit/mdl-t.cc
      sql/sql_list_test.cc => unittest/gunit/sql_list-t.cc
      sql/tap_event_listener.cc => unittest/gunit/tap_event_listener.cc
      sql/thread.cc => unittest/gunit/thread_utils.cc
      sql/thread.h => unittest/gunit/thread_utils.h
      sql/thread_test.cc => unittest/gunit/thread_utils-t.cc
    modified:
      configure.in
      sql/Makefile.am
      unittest/Makefile.am
      unittest/gunit/mdl_mytap-t.cc
      unittest/gunit/mdl-t.cc
      unittest/gunit/sql_list-t.cc
      unittest/gunit/thread_utils.cc
      unittest/gunit/thread_utils-t.cc
=== modified file 'configure.in'
--- a/configure.in	2009-10-01 11:35:36 +0000
+++ b/configure.in	2009-11-12 08:25:14 +0000
@@ -3074,6 +3074,7 @@ if test -d "$srcdir/cmd-line-utils/readl
 fi
 
 AC_CONFIG_FILES(Makefile extra/Makefile mysys/Makefile mysys/tests/Makefile dnl
+ unittest/gunit/Makefile dnl
  unittest/Makefile unittest/mytap/Makefile unittest/mytap/t/Makefile dnl
  unittest/mysys/Makefile unittest/examples/Makefile unittest/backup/Makefile dnl
  strings/Makefile regex/Makefile storage/Makefile dnl

=== modified file 'sql/Makefile.am'
--- a/sql/Makefile.am	2009-10-01 11:35:36 +0000
+++ b/sql/Makefile.am	2009-11-12 08:25:14 +0000
@@ -210,55 +210,6 @@ DISTCLEANFILES =        $(EXTRA_PROGRAMS
 MAINTAINERCLEANFILES =  $(BUILT_MAINT_SRC)
 AM_YFLAGS =		-d --verbose
 
-# Experimental: Unit test with google gtest (installed in /usr/local/...)
-XXXFLAGS=$(CXXFLAGS:-fno-implicit-templates=)
-UNIT_TEST_FLAGS=$(DEFS) $(AM_CPPFLAGS) $(CPPFLAGS) $(XXXFLAGS) @NOINST_LDFLAGS@
-UNIT_TEST_LIBS= /usr/local/lib/libgtest.a \
-		$(top_srcdir)/mysys/.libs/libmysys.a \
-		$(top_srcdir)/dbug/.libs/libdbug.a \
-		$(top_srcdir)/strings/.libs/libmystrings.a 
-UNIT_TEST_OBJS= sql_state.o \
-		sql_string.o \
-		tap_event_listener.o \
-		thr_malloc.o
-GUNIT_TEST_OBJS= gunit_test_main.o $(UNIT_TEST_OBJS)
-
-if HAVE_GTEST
-noinst_PROGRAMS = \
-	mdl_test-t$(EXEEXT) \
-	mdl-t$(EXEEXT) \
-	sql_list_test-t$(EXEEXT) \
-	thread_test-t$(EXEEXT)
-endif
-
-# The convention is to have tests for foo.cc in foo_test.cc
-# Add '-t' suffix to executable name, so unittest/unit.pl will pick them up.
-# In order to remove the no-implicit-templates, we have to build these
-# executables explicitly, rather than defining foo_test_SOURCES,
-# foo_test_CXXFLAGS et.al.
-mdl_test-t$(EXEEXT): mdl_test.cc mdl.o thread.o \
-		$(UNIT_TEST_LIBS) $(GUNIT_TEST_OBJS)
-	$(CXX) -o $@ $(UNIT_TEST_FLAGS) $< \
-	mdl.o thread.o $(GUNIT_TEST_OBJS) $(UNIT_TEST_LIBS) $(LIBS)
-
-mdl-t: mdl-t.cc mdl.o thread.o $(UNIT_TEST_LIBS) $(UNIT_TEST_OBJS)
-	$(CXX) -o $@ $(UNIT_TEST_FLAGS) -I$(top_srcdir)/unittest/mytap $< \
-	$(top_srcdir)/unittest/mytap/tap.o \
-	mdl.o thread.o $(UNIT_TEST_OBJS) $(UNIT_TEST_LIBS) $(LIBS)
-
-sql_list_test-t$(EXEEXT): sql_list_test.cc sql_list.o \
-		$(UNIT_TEST_LIBS) $(GUNIT_TEST_OBJS)
-	$(CXX) -o $@ $(UNIT_TEST_FLAGS) $< \
-	sql_list.o $(GUNIT_TEST_OBJS) $(UNIT_TEST_LIBS) $(LIBS)
-
-thread_test-t$(EXEEXT): thread_test.cc thread.o \
-		$(UNIT_TEST_LIBS) $(GUNIT_TEST_OBJS)
-	$(CXX) -o $@ $(UNIT_TEST_FLAGS) $< \
-	thread.o $(GUNIT_TEST_OBJS) $(UNIT_TEST_LIBS) $(LIBS)
-
-# Experimental END
-
-
 # These are listed in 'nodist_mysqld_SOURCES'
 link_sources:
 	rm -f mini_client_errors.c

=== modified file 'unittest/Makefile.am'
--- a/unittest/Makefile.am	2009-10-01 11:35:36 +0000
+++ b/unittest/Makefile.am	2009-11-12 08:25:14 +0000
@@ -13,14 +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
 
-SUBDIRS      = mytap mysys examples backup
+SUBDIRS      = mytap mysys examples backup gunit
 
 EXTRA_DIST = unit.pl
 CLEANFILES = unit
 
 unittests  = mytap mysys backup 
 unittests += @mysql_se_unittest_dirs@  @mysql_pg_unittest_dirs@ ../dbug
-unittests += ../sql
+unittests += gunit
 
 test:
 	perl unit.pl run $(unittests)

=== added directory 'unittest/gunit'
=== added file 'unittest/gunit/Makefile.am'
--- a/unittest/gunit/Makefile.am	1970-01-01 00:00:00 +0000
+++ b/unittest/gunit/Makefile.am	2009-11-12 08:25:14 +0000
@@ -0,0 +1,49 @@
+# Experimental: Unit tests with google gtest (installed in /usr/local/...)
+
+AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/sql
+AM_LDFLAGS  = -static
+DEFS        = -DMYSQL_SERVER @DEFS@
+
+# We need to allow implicit templates when compiling gtest.h
+# TODO(didrik): substitute this from configure.
+MYSQL_EXTRA_CXXFLAGS = -fimplicit-templates
+
+UNIT_TEST_LIBS= $(top_builddir)/mysys/libmysys.la \
+		$(top_builddir)/dbug/libdbug.la \
+		$(top_builddir)/strings/libmystrings.la 
+
+UNIT_TEST_OBJS= $(top_builddir)/sql/sql_state.o \
+		$(top_builddir)/sql/sql_string.o \
+		$(top_builddir)/sql/thr_malloc.o
+
+LDADD = $(UNIT_TEST_OBJS)
+
+if HAVE_GTEST
+# TODO(didrik): substitute libgtest.la from configure.
+LDADD += libgunit.la /usr/local/lib/libgtest.la $(UNIT_TEST_LIBS)
+
+noinst_LTLIBRARIES  = libgunit.la
+libgunit_la_SOURCES = \
+	gunit_test_main.cc \
+	tap_event_listener.cc \
+	thread_utils.cc 
+
+noinst_PROGRAMS = \
+	mdl-t$(EXEEXT) \
+	mdl_mytap-t$(EXEEXT) \
+	sql_list-t$(EXEEXT) \
+	thread_utils-t$(EXEEXT)
+
+sql_list_t_LDADD       = $(top_builddir)/sql/sql_list.o $(LDADD)
+sql_list_t_SOURCES     = sql_list-t.cc
+
+mdl_t_LDADD            = $(top_builddir)/sql/mdl.o $(LDADD)
+mdl_t_SOURCES          = mdl-t.cc
+
+mdl_mytap_t_CPPFLAGS   = -I$(top_srcdir)/unittest/mytap $(AM_CPPFLAGS)
+mdl_mytap_t_LDADD      = $(top_builddir)/sql/mdl.o \
+			 $(top_builddir)/unittest/mytap/tap.o $(LDADD)
+mdl_mytap_t_SOURCES    = mdl_mytap-t.cc
+
+thread_utils_t_SOURCES = thread_utils-t.cc
+endif

=== renamed file 'sql/gunit_test_main.cc' => 'unittest/gunit/gunit_test_main.cc'
=== renamed file 'sql/mdl_test.cc' => 'unittest/gunit/mdl-t.cc'
--- a/sql/mdl_test.cc	2009-09-30 13:19:09 +0000
+++ b/unittest/gunit/mdl-t.cc	2009-11-12 08:25:14 +0000
@@ -28,7 +28,7 @@
 #include "mdl.h"
 
 #include "thr_malloc.h"
-#include "thread.h"
+#include "thread_utils.h"
 
 pthread_key(MEM_ROOT**,THR_MALLOC);
 pthread_key(THD*, THR_THD);
@@ -232,7 +232,7 @@ TEST_F(MDL_DeathTest, die_when_m_tickets
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   MDL_request *request= create_request(table_name1);
   EXPECT_FALSE(m_mdl_context.try_acquire_shared_lock(request));
-#if !defined(DBUG_OFF)
+#if GTEST_HAS_DEATH_TEST && !defined(DBUG_OFF)
   EXPECT_DEATH(m_mdl_context.destroy(), ".*Assertion .*m_tickets.is_empty.*");
 #endif
   m_mdl_context.release_all_locks();
@@ -247,7 +247,7 @@ TEST_F(MDL_DeathTest, die_when_holding_g
 {
   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
   EXPECT_FALSE(m_mdl_context.acquire_global_shared_lock());
-#if !defined(DBUG_OFF)
+#if GTEST_HAS_DEATH_TEST && !defined(DBUG_OFF)
   EXPECT_DEATH(m_mdl_context.destroy(),
                ".*Assertion .*has_global_shared_lock.*");
 #endif
@@ -445,15 +445,9 @@ TEST_F(MDL_test, upgrade_exclusive)
 
 
 /*
-  Disable this test, since assert-fails in mdl_destroy().
-  (gdb) p global_lock
-  $1 = {waiting_shared = 0,
-        active_shared = 0,
-        active_intention_exclusive = 4294967295}
-  The upgrade from SHARED to EXCLUSIVE should fail, but it does not,
-  and something is wrong with the maintenance of active_intention_exclusive.
+  Verifies that only UPGRADABLE locks can be upgraded to exclusive.
  */
-TEST_F(MDL_test, DISABLED_upgrade_shared)
+TEST_F(MDL_DeathTest, die_upgrade_shared)
 {
   MDL_request *request1= create_request(table_name1);
   MDL_request *request2= create_request(table_name2);
@@ -462,7 +456,11 @@ TEST_F(MDL_test, DISABLED_upgrade_shared
   EXPECT_FALSE(m_mdl_context.try_acquire_shared_lock(request1));
   EXPECT_FALSE(m_mdl_context.try_acquire_shared_lock(request2));
 
-  EXPECT_FALSE(request1->ticket->upgrade_shared_lock_to_exclusive());
+#if GTEST_HAS_DEATH_TEST && !defined(DBUG_OFF)
+  ::testing::FLAGS_gtest_death_test_style = "threadsafe";
+  EXPECT_DEATH_IF_SUPPORTED(request1->ticket->upgrade_shared_lock_to_exclusive(),
+                            ".*MDL_SHARED_UPGRADABLE.*");
+#endif
   EXPECT_FALSE(request2->ticket->upgrade_shared_lock_to_exclusive());
   m_mdl_context.release_lock(request1->ticket);
   m_mdl_context.release_lock(request2->ticket);

=== renamed file 'sql/mdl-t.cc' => 'unittest/gunit/mdl_mytap-t.cc'
--- a/sql/mdl-t.cc	2009-09-28 12:37:44 +0000
+++ b/unittest/gunit/mdl_mytap-t.cc	2009-11-12 08:25:14 +0000
@@ -15,7 +15,7 @@
 
 /**
    This is a port of the corresponding mdl_test.cc (written for googletest)
-   to mytap. Do a 'tkdiff mdl_test.cc mdl-t.cc' to see the differences.
+   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 googletest, I have
    added some extensions below, notably support for reporting of line
    numbers in case of failures.
@@ -28,7 +28,7 @@
 #include "mdl.h"
 
 #include "thr_malloc.h"
-#include "thread.h"
+#include "thread_utils.h"
 
 pthread_key(MEM_ROOT**,THR_MALLOC);
 pthread_key(THD*, THR_THD);
@@ -209,7 +209,7 @@ protected:
   void shared_locks_between_contexts();
   void upgrade_shared_upgradable();
   void upgrade_exclusive();
-  void DISABLED_upgrade_shared();
+  void die_upgrade_shared();
   void merge();
   void savepoint();
   void concurrent_shared();
@@ -518,15 +518,9 @@ TEST_F(MDL_test, upgrade_exclusive)
 
 
 /*
-  Disable this test, since assert-fails in mdl_destroy().
-  (gdb) p global_lock
-  $1 = {waiting_shared = 0,
-        active_shared = 0,
-        active_intention_exclusive = 4294967295}
-  The upgrade from SHARED to EXCLUSIVE should fail, but it does not,
-  and something is wrong with the maintenance of active_intention_exclusive.
+  Verifies that only UPGRADABLE locks can be upgraded to exclusive.
  */
-TEST_F(MDL_test, DISABLED_upgrade_shared)
+TEST_F(MDL_DeathTest, die_upgrade_shared)
 {
   MDL_request *request1= create_request(table_name1);
   MDL_request *request2= create_request(table_name2);
@@ -535,7 +529,10 @@ TEST_F(MDL_test, DISABLED_upgrade_shared
   EXPECT_FALSE(m_mdl_context.try_acquire_shared_lock(request1));
   EXPECT_FALSE(m_mdl_context.try_acquire_shared_lock(request2));
 
+#if GTEST_HAS_DEATH_TEST && !defined(DBUG_OFF)
+  // No support for death tests in mytap.
   EXPECT_FALSE(request1->ticket->upgrade_shared_lock_to_exclusive());
+#endif
   EXPECT_FALSE(request2->ticket->upgrade_shared_lock_to_exclusive());
   m_mdl_context.release_lock(request1->ticket);
   m_mdl_context.release_lock(request2->ticket);
@@ -756,8 +753,7 @@ int MDL_test::RUN_ALL_TESTS()
   run_one_test(&MDL_test::shared_locks_between_contexts);
   run_one_test(&MDL_test::upgrade_shared_upgradable);
   run_one_test(&MDL_test::upgrade_exclusive);
-  // googletest will not run tests with names starting with 'DISABLED_'
-  // run_one_test(&MDL_test::DISABLED_upgrade_shared);
+  run_one_test(&MDL_test::die_upgrade_shared);
   run_one_test(&MDL_test::merge);
   run_one_test(&MDL_test::savepoint);
   run_one_test(&MDL_test::concurrent_shared);

=== renamed file 'sql/sql_list_test.cc' => 'unittest/gunit/sql_list-t.cc'
--- a/sql/sql_list_test.cc	2009-09-30 13:19:09 +0000
+++ b/unittest/gunit/sql_list-t.cc	2009-11-12 08:25:14 +0000
@@ -30,7 +30,7 @@
 #include "sql_error.h"
 #include <my_pthread.h>
 
-pthread_key(MEM_ROOT**,THR_MALLOC);
+pthread_key(MEM_ROOT**, THR_MALLOC);
 pthread_key(THD*, THR_THD);
 
 extern "C" void sql_alloc_error_handler(void)
@@ -61,23 +61,23 @@ void insert_values(T (&array)[size], Lis
   The fixture for testing the MySQL List and List_iterator classes.
   A fresh instance of this class will be created for each of the
   TEST_F functions below.
-  The functions SetUp(), TearDown() and SetUpTestCase() are inherited
-  from ::testing::Test (google naming style differs from MySQL).
+  The functions SetUp(), TearDown(), SetUpTestCase(), TearDownTestCase() are
+  inherited from ::testing::Test (google naming style differs from MySQL).
 */
 class Sql_list_test : public ::testing::Test
 {
 protected:
-  Sql_list_test() : m_int_list(), m_int_list_iter(m_int_list)
+  Sql_list_test()
+    : m_mem_root_p(&m_mem_root), m_int_list(), m_int_list_iter(m_int_list)
   {
   }
 
   virtual void SetUp()
   {
-    init_sql_alloc(&m_mem_root, 1 << 10, 0);
-    MEM_ROOT *pm= &m_mem_root;
-    ASSERT_EQ(0, my_pthread_setspecific_ptr(THR_MALLOC, &pm));
+    init_sql_alloc(&m_mem_root, 1024, 0);
+    ASSERT_EQ(0, my_pthread_setspecific_ptr(THR_MALLOC, &m_mem_root_p));
     MEM_ROOT *root= *my_pthread_getspecific_ptr(MEM_ROOT**, THR_MALLOC);
-    ASSERT_EQ(root, pm);
+    ASSERT_EQ(root, m_mem_root_p);
   }
 
   virtual void TearDown()
@@ -87,13 +87,24 @@ protected:
 
   static void SetUpTestCase()
   {
-    pthread_key_create(&THR_THD, NULL);
-    pthread_key_create(&THR_MALLOC, NULL);
+    ASSERT_EQ(0, pthread_key_create(&THR_THD, NULL));
+    ASSERT_EQ(0, pthread_key_create(&THR_MALLOC, NULL));
+  }
+
+  static void TearDownTestCase()
+  {
+    ASSERT_EQ(0, pthread_key_delete(THR_THD));
+    ASSERT_EQ(0, pthread_key_delete(THR_MALLOC));
   }
 
   MEM_ROOT m_mem_root;
+  MEM_ROOT *m_mem_root_p;
   List<int> m_int_list;
   List_iterator<int> m_int_list_iter;
+
+private:
+  // Declares (but does not define) copy constructor and assignment operator.
+  GTEST_DISALLOW_COPY_AND_ASSIGN_(Sql_list_test);
 };
 
 

=== renamed file 'sql/tap_event_listener.cc' => 'unittest/gunit/tap_event_listener.cc'
=== renamed file 'sql/thread_test.cc' => 'unittest/gunit/thread_utils-t.cc'
--- a/sql/thread_test.cc	2009-09-30 13:19:09 +0000
+++ b/unittest/gunit/thread_utils-t.cc	2009-11-12 08:25:14 +0000
@@ -16,7 +16,7 @@
 // Must include gtest first, since MySQL source has macros for min() etc ....
 #include <gtest/gtest.h>
 
-#include "thread.h"
+#include "thread_utils.h"
 
 #include "mdl.h"
 

=== renamed file 'sql/thread.cc' => 'unittest/gunit/thread_utils.cc'
--- a/sql/thread.cc	2009-09-28 12:37:44 +0000
+++ b/unittest/gunit/thread_utils.cc	2009-11-12 08:25:14 +0000
@@ -13,7 +13,7 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
-#include "thread.h"
+#include "thread_utils.h"
 
 namespace thread {
 

=== renamed file 'sql/thread.h' => 'unittest/gunit/thread_utils.h'

Attachment: [text/bzr-bundle] bzr/tor.didriksen@sun.com-20091112082514-q2qiijybnh3oc8kt.bundle
Thread
bzr commit into mysql-6.0-codebase-bugfixing branch (tor.didriksen:3640) Tor Didriksen12 Nov