List:Commits« Previous MessageNext Message »
From:Guilhem Bichot Date:March 2 2011 9:30am
Subject:bzr commit into mysql-trunk branch (guilhem.bichot:3274)
View as plain text  
#At file:///home/mysql_src/bzrrepos_new/mysql-next-mr-opt-backporting-wl4800/ based on revid:guilhem.bichot@stripped

 3274 Guilhem Bichot	2011-03-02
      Testing: to trigger faulty situations, opt_trace-t.cc set some bools
      (Opt_trace_context::simulate_oom_*); those are replaced by DBUG_EXECUTE_IF.

    modified:
      sql/opt_trace.cc
      sql/opt_trace.h
      unittest/gunit/opt_trace-t.cc
=== modified file 'sql/opt_trace.cc'
--- a/sql/opt_trace.cc	2011-03-01 12:38:28 +0000
+++ b/sql/opt_trace.cc	2011-03-02 09:30:17 +0000
@@ -613,16 +613,16 @@ bool Opt_trace_stmt::open_struct(const c
   d.has_disabled_I_S= has_disabled_I_S;
   d.current_struct_empty= current_struct_empty;
   {
-    if (Opt_trace_context::simulate_oom_in_open_struct)
-      DBUG_SET("+d,simulate_out_of_memory");
+    DBUG_EXECUTE_IF("opt_trace_oom_in_open_struct",
+                    DBUG_SET("+d,simulate_out_of_memory"););
     const bool rc= stack_of_current_structs.append(d);
     /*
       If the append() above didn't trigger reallocation, we need to turn the
       symbol off by ourselves, or it could make an unrelated allocation
       fail.
     */
-    if (Opt_trace_context::simulate_oom_in_open_struct)
-      DBUG_SET("-d,simulate_out_of_memory");
+    DBUG_EXECUTE_IF("opt_trace_oom_in_open_struct",
+                    DBUG_SET("-d,simulate_out_of_memory"););
     if (unlikely(rc))
       goto err;
   }
@@ -772,7 +772,12 @@ void Opt_trace_stmt::syntax_error(const 
 {
   DBUG_PRINT("opt", ("syntax error key: %s", key));
   DBUG_ASSERT(support_I_S == YES_FOR_THIS);
-  DBUG_ASSERT(!Opt_trace_context::dbug_assert_on_syntax_error);
+#ifndef DBUG_OFF
+  bool no_assert_on_syntax_error= false;
+  DBUG_EXECUTE_IF("opt_trace_no_assert_on_syntax_error",
+                  no_assert_on_syntax_error= true;);
+  DBUG_ASSERT(no_assert_on_syntax_error);
+#endif
   /*
     Inserting some warning text into the trace below helps locating where
     things went wrong.
@@ -920,11 +925,11 @@ bool Opt_trace_stmt::Buffer::append(cons
   }
   else
   {
-    if (unlikely(Opt_trace_context::simulate_oom_in_buffers))
-      DBUG_SET("+d,simulate_out_of_memory");
+    DBUG_EXECUTE_IF("opt_trace_oom_in_buffers",
+                    DBUG_SET("+d,simulate_out_of_memory"););
     rc= string_buf.append(str, length);
-    if (unlikely(Opt_trace_context::simulate_oom_in_buffers))
-      DBUG_SET("-d,simulate_out_of_memory");
+    DBUG_EXECUTE_IF("opt_trace_oom_in_buffers",
+                    DBUG_SET("-d,simulate_out_of_memory"););
   }
   return rc;
 }
@@ -1010,15 +1015,12 @@ Opt_trace_context::default_features=
                                    Opt_trace_context::DYNAMIC_RANGE   |
                                    Opt_trace_context::REPEATED_SUBSELECT);
 
-bool Opt_trace_context::dbug_assert_on_syntax_error= true,
-  Opt_trace_context::simulate_oom_in_buffers= false,
-  Opt_trace_context::simulate_oom_in_open_struct= false,
-  Opt_trace_context::simulate_oom_in_purge= false;
 
 Opt_trace_context::Opt_trace_context() :
   current_stmt_in_gen(NULL), since_offset_0(0)
 {}
 
+
 Opt_trace_context::~Opt_trace_context()
 {
   /* There may well be some few ended traces left: */
@@ -1227,8 +1229,8 @@ void Opt_trace_context::purge_stmts(bool
         Remember to free it (as in @c free()) when possible. For now, make it
         invisible in OPTIMIZER_TRACE table.
       */
-      if (Opt_trace_context::simulate_oom_in_purge)
-        DBUG_SET("+d,simulate_out_of_memory");
+      DBUG_EXECUTE_IF("opt_trace_oom_in_purge",
+                      DBUG_SET("+d,simulate_out_of_memory"););
       if (likely(!all_stmts_to_del.append(all_stmts_for_I_S.at(idx))))
         all_stmts_for_I_S.del(idx);
       else
@@ -1239,15 +1241,21 @@ void Opt_trace_context::purge_stmts(bool
           the OPTIMIZER_TRACE table). append() above has called my_error().
         */
       }
-      if (Opt_trace_context::simulate_oom_in_purge)
-        DBUG_SET("-d,simulate_out_of_memory");
+      DBUG_EXECUTE_IF("opt_trace_oom_in_purge",
+                      DBUG_SET("-d,simulate_out_of_memory"););
     }
   }
   /* Examine list of "to be freed" traces and free what can be */
   for (idx= (all_stmts_to_del.elements() - 1) ; idx >= 0 ; idx--)
   {
     Opt_trace_stmt *stmt= all_stmts_to_del.at(idx);
-    if (!stmt->has_ended() || Opt_trace_context::simulate_oom_in_purge)
+#ifndef DBUG_OFF
+    bool skip_del= false;
+    DBUG_EXECUTE_IF("opt_trace_oom_in_purge", skip_del= true;);
+#else
+    const bool skip_del= false;
+#endif
+    if (!stmt->has_ended() || skip_del)
     {
       /*
         This trace is not finished, freeing it now would lead to use of
@@ -1268,7 +1276,7 @@ void Opt_trace_context::purge_stmts(bool
         re-consider it then (which is why this function is called in @c
         Opt_trace_stmt::end() too).
 
-        In unit testing (simulate_oom_in_purge==true) we let the list grow so
+        In unit testing, to simulate OOM, we let the list grow so
         that it consumes its pre-allocated cells and finally requires a
         (failing) allocation.
       */

=== modified file 'sql/opt_trace.h'
--- a/sql/opt_trace.h	2011-03-01 10:55:27 +0000
+++ b/sql/opt_trace.h	2011-03-02 09:30:17 +0000
@@ -539,15 +539,6 @@ public:
   bool feature_enabled (Opt_trace_context::feature_value f) const
   { return features & f; }
 
-  /// Turn this on only in unit tests for out-of-memory testing
-  static bool simulate_oom_in_buffers, simulate_oom_in_open_struct,
-    simulate_oom_in_purge;
-  /**
-     Whether a JSON syntax error should cause an assertion in debug binaries;
-     turn this off only in unit tests for bad syntax testing
-  */
-  static bool dbug_assert_on_syntax_error;
-
   /**
      Opt_trace_struct is passed Opt_trace_context*, and needs to know
      to which statement's trace to attach, so Opt_trace_context must provide

=== modified file 'unittest/gunit/opt_trace-t.cc'
--- a/unittest/gunit/opt_trace-t.cc	2011-03-01 10:55:27 +0000
+++ b/unittest/gunit/opt_trace-t.cc	2011-03-02 09:30:17 +0000
@@ -273,9 +273,9 @@ TEST_F(TraceContentTest, BuggyObject)
       ota.add(200.4);
       {
         Opt_trace_object oto1(&trace);
-        Opt_trace_context::dbug_assert_on_syntax_error= false;
+        DBUG_SET("+d,opt_trace_no_assert_on_syntax_error");
         oto1.add_alnum("one value"); // no key, which is wrong
-        Opt_trace_context::dbug_assert_on_syntax_error= true;
+        DBUG_SET("-d,opt_trace_no_assert_on_syntax_error");
       }
       ota.add_alnum("one string element");
       ota.add(true);
@@ -327,9 +327,9 @@ TEST_F(TraceContentTest, BuggyArray)
     Opt_trace_object oto(&trace);
     {
       Opt_trace_array ota(&trace, "one array");
-      Opt_trace_context::dbug_assert_on_syntax_error= false;
+      DBUG_SET("+d,opt_trace_no_assert_on_syntax_error");
       ota.add("superfluous key", 200.4); // key, which is wrong
-      Opt_trace_context::dbug_assert_on_syntax_error= true;
+      DBUG_SET("-d,opt_trace_no_assert_on_syntax_error");
     }
     oto.add("yet another key", -1000LL);
     {
@@ -651,13 +651,13 @@ void open_object(uint count, Opt_trace_c
   if (simulate_oom)
   {
     if (count == 90)
-      Opt_trace_context::simulate_oom_in_open_struct= true;
+      DBUG_SET("+d,opt_trace_oom_in_open_struct");
     /*
       Now we let 80 objects be created, so that one of them surely hits
       re-allocation and OOM failure.
     */
     if (count == 10)
-      Opt_trace_context::simulate_oom_in_open_struct= false;
+      DBUG_SET("-d,opt_trace_oom_in_open_struct");
   }
   Opt_trace_object oto(trace, key);
   open_object(count, trace, simulate_oom);
@@ -675,10 +675,10 @@ TEST_F(TraceContentTest, OOMinBuffer)
     Opt_trace_object oto(&trace);
     {
       Opt_trace_array ota(&trace, "one array");
-      Opt_trace_context::simulate_oom_in_buffers= true;
+      DBUG_SET("+d,opt_trace_oom_in_buffers");
       for (int i= 0; i < 30; i++)
         ota.add_alnum("_______________________________________________");
-      Opt_trace_context::simulate_oom_in_buffers= false;
+      DBUG_SET("-d,opt_trace_oom_in_buffers");
     }
   }
   trace.end();
@@ -720,7 +720,7 @@ TEST_F(TraceContentTest, OOMinPurge)
   Opt_trace_context trace;
   make_one_trace(&trace, "103", -3, 2);
   make_one_trace(&trace, "104", -3, 2);
-  Opt_trace_context::simulate_oom_in_purge= true;
+  DBUG_SET("+d,opt_trace_oom_in_purge");
   make_one_trace(&trace, "105", -3, 2);
   make_one_trace(&trace, "106", -3, 2);
   make_one_trace(&trace, "107", -3, 2);
@@ -740,7 +740,7 @@ TEST_F(TraceContentTest, OOMinPurge)
   make_one_trace(&trace, "121", -3, 2);
   make_one_trace(&trace, "122", -3, 2); // purge first fails here
 
-  Opt_trace_context::simulate_oom_in_purge= false;
+  DBUG_SET("-d,opt_trace_oom_in_purge");
   // 122 could not purge 119, so we should see 119 and 120
   const char *expected_traces3[]= {"119", "120", NULL};
   check(trace, expected_traces3);


Attachment: [text/bzr-bundle] bzr/guilhem.bichot@oracle.com-20110302093017-0v3a51vsthxna8ib.bundle
Thread
bzr commit into mysql-trunk branch (guilhem.bichot:3274) Guilhem Bichot2 Mar