MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:Tor Didriksen Date:September 28 2009 12:33pm
Subject:bzr commit into mysql-6.0-codebase-bugfixing branch (tor.didriksen:3624)
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:alik@stripped

 3624 Tor Didriksen	2009-09-28
      move gtest changes to 6.0 codebase

    added:
      sql/sql_alloc_error_handler.cc
      sql/sql_list_test.cc
      sql/thr_malloc.h
    modified:
      .bzrignore
      libmysqld/Makefile.am
      sql/Makefile.am
      sql/thr_malloc.cc
=== modified file '.bzrignore'
--- a/.bzrignore	2009-09-25 14:29:56 +0000
+++ b/.bzrignore	2009-09-28 12:33:17 +0000
@@ -1,4 +1,5 @@
 *-t
+*_test
 *.Plo
 *.Po
 *.Tpo
@@ -621,6 +622,7 @@ libmysqld/sp_pcontext.cc
 libmysqld/sp_rcontext.cc
 libmysqld/spatial.cc
 libmysqld/sql_acl.cc
+libmysqld/sql_alloc_error_handler.cc
 libmysqld/sql_analyse.cc
 libmysqld/sql_audit.cc
 libmysqld/sql_base.cc

=== modified file 'libmysqld/Makefile.am'
--- a/libmysqld/Makefile.am	2009-09-25 14:15:30 +0000
+++ b/libmysqld/Makefile.am	2009-09-28 12:33:17 +0000
@@ -74,6 +74,7 @@ sqlsources = derror.cc field.cc field_co
 	sql_prepare.cc sql_derived.cc sql_rename.cc \
 	sql_select.cc sql_do.cc sql_show.cc set_var.cc \
 	sql_string.cc sql_table.cc sql_test.cc sql_udf.cc \
+	sql_alloc_error_handler.cc \
 	sql_update.cc sql_yacc.cc table.cc thr_malloc.cc time.cc \
 	unireg.cc uniques.cc sql_union.cc hash_filo.cc \
 	spatial.cc gstream.cc sql_help.cc tztime.cc sql_cursor.cc \

=== modified file 'sql/Makefile.am'
--- a/sql/Makefile.am	2009-09-25 14:15:30 +0000
+++ b/sql/Makefile.am	2009-09-28 12:33:17 +0000
@@ -126,6 +126,7 @@ noinst_HEADERS =	item.h item_func.h item
 mysqld_SOURCES =	sql_lex.cc sql_handler.cc sql_partition.cc \
 			item.cc item_sum.cc item_buff.cc item_func.cc \
 			item_cmpfunc.cc item_strfunc.cc item_timefunc.cc \
+			sql_alloc_error_handler.cc \
 			thr_malloc.cc item_create.cc item_subselect.cc \
 			item_row.cc item_geofunc.cc item_xmlfunc.cc \
 			field.cc strfunc.cc key.cc sql_class.cc sql_list.cc \
@@ -209,6 +210,29 @@ 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 \
+		thr_malloc.o
+
+# TODO(didrik): Include this target in 'make all'
+# and use a test runner (ala ../unittest/unit.pl) to run all tests.
+test-gunit: sql_list_test
+
+# The convention is to have tests for foo.cc in foo_test.cc
+sql_list_test: sql_list_test.cc sql_list.o $(UNIT_TEST_LIBS) $(UNIT_TEST_OBJS)
+	$(CXX) -o $@ $(UNIT_TEST_FLAGS) $< \
+	sql_list.o $(UNIT_TEST_OBJS) $(UNIT_TEST_LIBS) $(LIBS)
+
+# Experimental END
+
+
 # These are listed in 'nodist_mysqld_SOURCES'
 link_sources:
 	rm -f mini_client_errors.c

=== added file 'sql/sql_alloc_error_handler.cc'
--- a/sql/sql_alloc_error_handler.cc	1970-01-01 00:00:00 +0000
+++ b/sql/sql_alloc_error_handler.cc	2009-09-28 12:33:17 +0000
@@ -0,0 +1,48 @@
+/* Copyright (C) 2009 Sun Microsystems, Inc.
+
+   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 */
+
+#include "mysql_priv.h"
+
+extern "C" {
+  void sql_alloc_error_handler(void)
+  {
+    sql_print_error("%s", ER(ER_OUT_OF_RESOURCES));
+
+    THD *thd= current_thd;
+    if (thd && !thd->is_error())
+    {
+      /*
+        This thread is Out Of Memory.
+        An OOM condition is a fatal error.
+        It should not be caught by error handlers in stored procedures.
+        Also, recording that SQL condition in the condition area could
+        cause more memory allocations, which in turn could raise more
+        OOM conditions, causing recursion in the error handling code itself.
+        As a result, my_error() should not be invoked, and the
+        thread diagnostics area is set to an error status directly.
+        Note that Diagnostics_area::set_error_status() is safe,
+        since it does not call any memory allocation routines.
+        The visible result for a client application will be:
+        - a query fails with an ER_OUT_OF_RESOURCES error,
+        returned in the error packet.
+        - SHOW ERROR/SHOW WARNINGS may be empty.
+      */
+      thd->stmt_da->set_error_status(thd,
+                                     ER_OUT_OF_RESOURCES,
+                                     ER(ER_OUT_OF_RESOURCES),
+                                     NULL);
+    }
+  }
+}

=== added file 'sql/sql_list_test.cc'
--- a/sql/sql_list_test.cc	1970-01-01 00:00:00 +0000
+++ b/sql/sql_list_test.cc	2009-09-28 12:33:17 +0000
@@ -0,0 +1,211 @@
+/* Copyright (C) 2009 Sun Microsystems, Inc.
+
+   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 simple example of how to use the google unit test framework.
+
+  For an introduction to the constructs used below, see:
+  http://code.google.com/p/googletest/wiki/GoogleTestPrimer
+*/
+
+// Must include gtest first, since MySQL source has macros for min() etc ....
+#include <gtest/gtest.h>
+
+#include "sql_list.h"
+
+#include "thr_malloc.h"
+#include "sql_string.h"
+#include "sql_error.h"
+#include <my_pthread.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;
+}
+
+// A simple helper function to insert values into a List.
+template <class T, int size>
+void insert_values(T (&array)[size], List<T> *list)
+{
+  for (int ix= 0; ix < size; ++ix)
+  {
+    EXPECT_FALSE(list->push_back(&array[ix]));
+  }
+}
+
+/*
+  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).
+*/
+class Sql_list_test : public ::testing::Test
+{
+protected:
+  Sql_list_test() : 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));
+    MEM_ROOT *root= *my_pthread_getspecific_ptr(MEM_ROOT**, THR_MALLOC);
+    ASSERT_EQ(root, pm);
+  }
+
+  virtual void TearDown()
+  {
+    free_root(&m_mem_root, MYF(0));
+  }
+
+  static void SetUpTestCase()
+  {
+    pthread_key_create(&THR_THD, NULL);
+    pthread_key_create(&THR_MALLOC, NULL);
+  }
+
+  MEM_ROOT m_mem_root;
+  List<int> m_int_list;
+  List_iterator<int> m_int_list_iter;
+};
+
+
+// Tests that we can construct and destruct lists.
+TEST_F(Sql_list_test, construct_and_destruct)
+{
+  EXPECT_TRUE(m_int_list.is_empty());
+  List<int> *p_int_list= new List<int>;
+  EXPECT_TRUE(p_int_list->is_empty());
+  delete p_int_list;
+}
+
+
+// Tests basic operations push and pop.
+TEST_F(Sql_list_test, basic_operations)
+{
+  int i1= 1;
+  int i2= 2;
+  EXPECT_FALSE(m_int_list.push_front(&i1));
+  EXPECT_FALSE(m_int_list.push_back(&i2));
+  EXPECT_FALSE(m_int_list.is_empty());
+  EXPECT_EQ(2, m_int_list.elements);
+
+  EXPECT_EQ(&i1, m_int_list.head());
+  EXPECT_EQ(&i1, m_int_list.pop());
+  EXPECT_EQ(&i2, m_int_list.head());
+  EXPECT_EQ(&i2, m_int_list.pop());
+  EXPECT_TRUE(m_int_list.is_empty()) << "The list should be empty now!";
+}
+
+
+// Tests list copying.
+TEST_F(Sql_list_test, deep_copy)
+{
+  int values[] = {11, 22, 33, 42, 5};
+  insert_values(values, &m_int_list);
+  MEM_ROOT *mem_root= (MEM_ROOT*) malloc(1 << 20);
+  init_alloc_root(mem_root, 4096, 4096);
+  List<int> list_copy(m_int_list, mem_root);
+  EXPECT_EQ(list_copy.elements, m_int_list.elements);
+  while (!list_copy.is_empty())
+  {
+    EXPECT_EQ(*m_int_list.pop(), *list_copy.pop());
+  }
+  EXPECT_TRUE(m_int_list.is_empty());
+  free(mem_root);
+}
+
+
+// Tests that we can iterate over values.
+TEST_F(Sql_list_test, iterate)
+{
+  int values[] = {3, 2, 1};
+  insert_values(values, &m_int_list);
+  for (int ix= 0; ix < array_size(values); ++ix)
+  {
+    EXPECT_EQ(values[ix], *m_int_list_iter++);
+  }
+  m_int_list_iter.init(m_int_list);
+  int *value;
+  int value_number= 0;
+  while ((value= m_int_list_iter++))
+  {
+    EXPECT_EQ(values[value_number++], *value);
+  }
+}
+
+
+// A simple helper class for testing intrusive lists.
+class Linked_node : public ilink
+{
+public:
+  Linked_node(int val) : m_value(val) {}
+  int get_value() const { return m_value; }
+private:
+  int m_value;
+};
+
+
+// An example of a test without any fixture.
+TEST(Sql_ilist_test, construct_and_destruct)
+{
+  I_List<Linked_node> i_list;
+  I_List_iterator<Linked_node> i_list_iter(i_list);
+  EXPECT_TRUE(i_list.is_empty());
+  EXPECT_EQ(0, i_list_iter++);
+}
+
+
+// Tests iteration over intrusive lists.
+TEST(Sql_ilist_test, iterate)
+{
+  I_List<Linked_node> i_list;
+  I_List_iterator<Linked_node> i_list_iter(i_list);
+  int values[] = {11, 22, 33, 42, 5};
+  for (int ix= 0; ix < array_size(values); ++ix)
+  {
+    i_list.push_back(new Linked_node(values[ix]));
+  }
+
+  Linked_node *node;
+  int value_number= 0;
+  while ((node= i_list_iter++))
+  {
+    EXPECT_EQ(values[value_number++], node->get_value());
+  }
+}
+
+}  // namespace
+
+int main(int argc, char **argv) {
+  ::testing::InitGoogleTest(&argc, argv);
+  MY_INIT(argv[0]);
+  return RUN_ALL_TESTS();
+}

=== modified file 'sql/thr_malloc.cc'
--- a/sql/thr_malloc.cc	2009-09-25 14:15:30 +0000
+++ b/sql/thr_malloc.cc	2009-09-28 12:33:17 +0000
@@ -16,42 +16,10 @@
 
 /* Mallocs for used in threads */
 
+#include "thr_malloc.h"
 #include "mysql_priv.h"
 
-extern "C" {
-  void sql_alloc_error_handler(void)
-  {
-    sql_print_error("%s", ER(ER_OUT_OF_RESOURCES));
-
-    THD *thd= current_thd;
-    if (thd)
-    {
-      if (! thd->is_error())
-      {
-        /*
-          This thread is Out Of Memory.
-          An OOM condition is a fatal error.
-          It should not be caught by error handlers in stored procedures.
-          Also, recording that SQL condition in the condition area could
-          cause more memory allocations, which in turn could raise more
-          OOM conditions, causing recursion in the error handling code itself.
-          As a result, my_error() should not be invoked, and the
-          thread diagnostics area is set to an error status directly.
-          Note that Diagnostics_area::set_error_status() is safe,
-          since it does not call any memory allocation routines.
-          The visible result for a client application will be:
-          - a query fails with an ER_OUT_OF_RESOURCES error,
-          returned in the error packet.
-          - SHOW ERROR/SHOW WARNINGS may be empty.
-        */
-        thd->stmt_da->set_error_status(thd,
-                                       ER_OUT_OF_RESOURCES,
-                                       ER(ER_OUT_OF_RESOURCES),
-                                       NULL);
-      }
-    }
-  }
-}
+extern "C" void sql_alloc_error_handler(void);
 
 void init_sql_alloc(MEM_ROOT *mem_root, uint block_size, uint pre_alloc)
 {

=== added file 'sql/thr_malloc.h'
--- a/sql/thr_malloc.h	1970-01-01 00:00:00 +0000
+++ b/sql/thr_malloc.h	2009-09-28 12:33:17 +0000
@@ -0,0 +1,34 @@
+/* Copyright (C) 2009 Sun Microsystems, Inc.
+
+   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 */
+
+#ifndef SQL_THR_MALLOC_INCLUDED
+#define SQL_THR_MALLOC_INCLUDED
+
+#include <my_global.h>
+#include <my_alloc.h>
+#include <m_ctype.h>
+
+void init_sql_alloc(MEM_ROOT *root, uint block_size, uint pre_alloc_size);
+void *sql_alloc(size_t);
+void *sql_calloc(size_t);
+char *sql_strdup(const char *str);
+char *sql_strmake(const char *str, size_t len);
+void *sql_memdup(const void * ptr, size_t size);
+char *sql_strmake_with_convert(const char *str, size_t arg_length,
+			       CHARSET_INFO *from_cs,
+			       size_t max_res_length,
+			       CHARSET_INFO *to_cs, size_t *result_length);
+
+#endif  // SQL_THR_MALLOC_INCLUDED


Attachment: [text/bzr-bundle] bzr/tor.didriksen@sun.com-20090928123317-77l437lpub7wih82.bundle
Thread
bzr commit into mysql-6.0-codebase-bugfixing branch (tor.didriksen:3624) Tor Didriksen28 Sep