List:Commits« Previous MessageNext Message »
From:Tor Didriksen Date:July 18 2011 8:07am
Subject:bzr push into mysql-trunk branch (tor.didriksen:3265 to 3266)
View as plain text  
 3266 Tor Didriksen	2011-07-18 [merge]
      Merge 5.5 => trunk.
      Add unit tests for my_decimal_mod().
     @ unittest/gunit/CMakeLists.txt
        my_decimal test now needs server code (for error reporting)
     @ unittest/gunit/my_decimal-t.cc
        Add unit tests for my_decimal_mod().

    modified:
      mysql-test/r/func_math.result
      mysql-test/t/func_math.test
      strings/decimal.c
      unittest/gunit/CMakeLists.txt
      unittest/gunit/my_decimal-t.cc
 3265 Marc Alff	2011-07-15 [merge]
      Merge mysql-trunk-stage --> mysql-trunk

    modified:
      include/mysql/psi/psi.h
      include/mysql/psi/psi_abi_v1.h.pp
      mysql-test/suite/perfschema/r/dml_setup_objects.result
      mysql-test/suite/perfschema/r/information_schema.result
      mysql-test/suite/perfschema/r/pfs_upgrade.result
      mysql-test/suite/perfschema/r/privilege_table_io.result
      mysql-test/suite/perfschema/r/schema.result
      mysql-test/suite/perfschema/r/setup_objects.result
      mysql-test/suite/perfschema/r/table_aggregate_global_2u_2t.result
      mysql-test/suite/perfschema/r/table_aggregate_global_2u_3t.result
      mysql-test/suite/perfschema/r/table_aggregate_global_4u_2t.result
      mysql-test/suite/perfschema/r/table_aggregate_global_4u_3t.result
      mysql-test/suite/perfschema/r/table_aggregate_hist_2u_2t.result
      mysql-test/suite/perfschema/r/table_aggregate_hist_2u_3t.result
      mysql-test/suite/perfschema/r/table_aggregate_hist_4u_2t.result
      mysql-test/suite/perfschema/r/table_aggregate_hist_4u_3t.result
      mysql-test/suite/perfschema/r/table_aggregate_off.result
      mysql-test/suite/perfschema/r/table_aggregate_thread_2u_2t.result
      mysql-test/suite/perfschema/r/table_aggregate_thread_2u_3t.result
      mysql-test/suite/perfschema/r/table_aggregate_thread_4u_2t.result
      mysql-test/suite/perfschema/r/table_aggregate_thread_4u_3t.result
      mysql-test/suite/perfschema/r/table_io_aggregate_global_2u_2t.result
      mysql-test/suite/perfschema/r/table_io_aggregate_global_2u_3t.result
      mysql-test/suite/perfschema/r/table_io_aggregate_global_4u_2t.result
      mysql-test/suite/perfschema/r/table_io_aggregate_global_4u_3t.result
      mysql-test/suite/perfschema/r/table_io_aggregate_hist_2u_2t.result
      mysql-test/suite/perfschema/r/table_io_aggregate_hist_2u_3t.result
      mysql-test/suite/perfschema/r/table_io_aggregate_hist_4u_2t.result
      mysql-test/suite/perfschema/r/table_io_aggregate_hist_4u_3t.result
      mysql-test/suite/perfschema/r/table_io_aggregate_thread_2u_2t.result
      mysql-test/suite/perfschema/r/table_io_aggregate_thread_2u_3t.result
      mysql-test/suite/perfschema/r/table_io_aggregate_thread_4u_2t.result
      mysql-test/suite/perfschema/r/table_io_aggregate_thread_4u_3t.result
      mysql-test/suite/perfschema/r/table_lock_aggregate_global_2u_2t.result
      mysql-test/suite/perfschema/r/table_lock_aggregate_global_2u_3t.result
      mysql-test/suite/perfschema/r/table_lock_aggregate_global_4u_2t.result
      mysql-test/suite/perfschema/r/table_lock_aggregate_global_4u_3t.result
      mysql-test/suite/perfschema/r/table_lock_aggregate_hist_2u_2t.result
      mysql-test/suite/perfschema/r/table_lock_aggregate_hist_2u_3t.result
      mysql-test/suite/perfschema/r/table_lock_aggregate_hist_4u_2t.result
      mysql-test/suite/perfschema/r/table_lock_aggregate_hist_4u_3t.result
      mysql-test/suite/perfschema/r/table_lock_aggregate_thread_2u_2t.result
      mysql-test/suite/perfschema/r/table_lock_aggregate_thread_2u_3t.result
      mysql-test/suite/perfschema/r/table_lock_aggregate_thread_4u_2t.result
      mysql-test/suite/perfschema/r/table_lock_aggregate_thread_4u_3t.result
      mysql-test/suite/perfschema/r/table_schema.result
      mysql-test/suite/perfschema/t/dml_setup_objects.test
      mysql-test/suite/perfschema/t/privilege_table_io.test
      mysql-test/suite/perfschema/t/setup_objects.test
      mysys/psi_noop.cc
      scripts/mysql_system_tables.sql
      sql/ha_partition.cc
      sql/ha_partition.h
      sql/handler.cc
      sql/handler.h
      sql/rpl_slave.cc
      sql/sql_base.cc
      storage/perfschema/pfs.cc
      storage/perfschema/pfs_defaults.cc
      storage/perfschema/pfs_instr.cc
      storage/perfschema/pfs_instr.h
      storage/perfschema/pfs_setup_object.cc
      storage/perfschema/table_setup_objects.cc
      storage/perfschema/table_setup_objects.h
=== modified file 'mysql-test/r/func_math.result'
--- a/mysql-test/r/func_math.result	2011-05-26 10:13:07 +0000
+++ b/mysql-test/r/func_math.result	2011-07-18 08:06:21 +0000
@@ -699,3 +699,13 @@ select (1.175494351E-37 div 1.7976931348
 0
 Warnings:
 Warning	1292	Truncated incorrect DECIMAL value: ''
+#
+# Bug#12537160 ASSERTION FAILED:
+# STOP0 <= &TO->BUF[TO->LEN] WITH LARGE NUMBER.
+#
+select 999999999999999999999999999999999999999999999999999999999999999999999999999999999 % 0.1 as foo;
+foo
+0.0
+select 999999999999999999999999999999999999999999999999999999999999999999999999999999999 % 0.0 as foo;
+foo
+NULL

=== modified file 'mysql-test/t/func_math.test'
--- a/mysql-test/t/func_math.test	2011-05-26 10:13:07 +0000
+++ b/mysql-test/t/func_math.test	2011-07-18 08:06:21 +0000
@@ -536,3 +536,14 @@ SELECT 1 div null;
 --echo # Bug #11792200 - DIVIDING LARGE NUMBERS CAUSES STACK CORRUPTIONS
 --echo #
 select (1.175494351E-37 div 1.7976931348623157E+308);
+
+--echo #
+--echo # Bug#12537160 ASSERTION FAILED:
+--echo # STOP0 <= &TO->BUF[TO->LEN] WITH LARGE NUMBER.
+--echo #
+
+let $nine_81=
+999999999999999999999999999999999999999999999999999999999999999999999999999999999;
+
+eval select $nine_81 % 0.1 as foo;
+eval select $nine_81 % 0.0 as foo;

=== modified file 'strings/decimal.c'
--- a/strings/decimal.c	2011-07-04 00:25:46 +0000
+++ b/strings/decimal.c	2011-07-18 08:06:21 +0000
@@ -2191,7 +2191,6 @@ static int do_div_mod(const decimal_t *f
   }
   buf0=to->buf;
   stop0=buf0+intg0+frac0;
-  DBUG_ASSERT(stop0 <= &to->buf[to->len]);
   if (likely(div_mod))
     while (dintg++ < 0 && buf0 < &to->buf[to->len])
     {
@@ -2286,7 +2285,10 @@ static int do_div_mod(const decimal_t *f
       }
     }
     if (likely(div_mod))
+    {
+      DBUG_ASSERT(buf0 < to->buf + to->len);
       *buf0=(dec1)guess;
+    }
     dcarry= *start1;
     start1++;
   }

=== modified file 'unittest/gunit/CMakeLists.txt'
--- a/unittest/gunit/CMakeLists.txt	2011-07-03 23:56:47 +0000
+++ b/unittest/gunit/CMakeLists.txt	2011-07-18 08:06:21 +0000
@@ -211,7 +211,6 @@ SET(TESTS
   mdl
   mdl_mytap
   my_bitmap
-  my_decimal
   my_regex
   sql_list
   sql_plist
@@ -221,6 +220,7 @@ SET(TESTS
 # Add tests (link them with gunit library and the server libraries) 
 SET(SERVER_TESTS
   item
+  my_decimal
   opt_range
 )
 

=== modified file 'unittest/gunit/my_decimal-t.cc'
--- a/unittest/gunit/my_decimal-t.cc	2011-07-07 13:01:34 +0000
+++ b/unittest/gunit/my_decimal-t.cc	2011-07-18 08:06:21 +0000
@@ -16,17 +16,47 @@
 #include "my_config.h"
 #include <gtest/gtest.h>
 
+#include "test_utils.h"
+
 #include <my_decimal.h>
 
 namespace {
 
+using my_testing::Server_initializer;
+using my_testing::Mock_error_handler;
+
 class DecimalTest : public ::testing::Test
 {
 protected:
+  static void SetUpTestCase()
+  {
+    Server_initializer::SetUpTestCase();
+  }
+
+  static void TearDownTestCase()
+  {
+    Server_initializer::TearDownTestCase();
+  }
+
+  virtual void SetUp()
+  {
+    initializer.SetUp();
+  }
+
+  virtual void TearDown()
+  {
+    initializer.TearDown();
+  }
+
+  THD *thd() { return initializer.thd(); }
+
+  Server_initializer initializer;
+
   my_decimal d1;
   my_decimal d2;
 };
 
+
 TEST_F(DecimalTest, CopyAndCompare)
 {
   ulonglong val= 42;
@@ -70,4 +100,128 @@ TEST_F(DecimalTest, Swap)
   EXPECT_EQ(0, my_decimal_cmp(&d1, &d2copy));
 }
 
+
+
+int chars_2_decimal(const char *chars, my_decimal *to)
+{
+  char *end= strend(chars);
+  return string2decimal(chars, to, &end);
+}
+
+
+/*
+  This is a simple iterative implementation based on addition and subtraction,
+  for verifying the result of decimal_mod().
+
+  decimal_mod() says:
+  DESCRIPTION
+    the modulus R in    R = M mod N
+    is defined as
+
+    0 <= |R| < |M|
+    sign R == sign M
+    R = M - k*N, where k is integer
+
+    thus, there's no requirement for M or N to be integers
+ */
+int decimal_modulo(uint mask,
+                   my_decimal *res,
+                   const my_decimal *m,
+                   const my_decimal *n)
+{
+  my_decimal abs_m(*m);
+  my_decimal abs_n(*n);
+  abs_m.sign(false);
+  abs_n.sign(false);
+
+  my_decimal r;
+  my_decimal k1(abs_n);
+  my_decimal kn(decimal_zero);
+  my_decimal next_r(abs_m);
+  int ret;
+  do
+  {
+    r= next_r;
+
+    my_decimal res;
+    if ((ret= my_decimal_add(E_DEC_FATAL_ERROR, &res, &k1, &kn)) != E_DEC_OK)
+    {
+      ADD_FAILURE();
+      return ret;
+    }
+    kn= res;
+
+    if ((ret= my_decimal_sub(E_DEC_FATAL_ERROR,
+                             &next_r, &abs_m, &kn) != E_DEC_OK))
+    {
+      ADD_FAILURE();
+      return ret;
+    }
+  } while (my_decimal_cmp(&next_r, &decimal_zero) >= 0);
+  r.sign(m->sign());
+  *res= r;
+  return 0;
+}
+
+
+struct Mod_data
+{
+  const char *a;
+  const char *b;
+  const char *result;
+};
+
+Mod_data mod_test_input[]=
+{
+  { "234"     , "10",      "4"      },
+  { "234.567" , "10.555",  "2.357"  },
+  { "-234.567", "10.555",  "-2.357" },
+  { "234.567" , "-10.555", "2.357"  },
+  { "-234.567", "-10.555", "-2.357" },
+  { "999"     , "0.1",     "0.0"    },
+  { "999"     , "0.7",     "0.1"    },
+  { "10"      , "123",     "10"     },
+  { NULL, NULL, NULL}
+};
+
+
+TEST_F(DecimalTest, Modulo)
+{
+  my_decimal expected_result;
+  my_decimal xxx_result;
+  my_decimal mod_result;
+  char buff_x[DECIMAL_MAX_STR_LENGTH];
+  char buff_m[DECIMAL_MAX_STR_LENGTH];
+
+  for (Mod_data *pd= mod_test_input; pd->a; ++pd)
+  {
+    int bufsz_x= sizeof(buff_x);
+    int bufsz_m= sizeof(buff_m);
+
+    EXPECT_EQ(0, chars_2_decimal(pd->a, &d1));
+    EXPECT_EQ(0, chars_2_decimal(pd->b, &d2));
+    EXPECT_EQ(0, chars_2_decimal(pd->result, &expected_result));
+
+    EXPECT_EQ(0, my_decimal_mod(E_DEC_FATAL_ERROR, &mod_result, &d1, &d2));
+    EXPECT_EQ(0, decimal2string(&mod_result, buff_m, &bufsz_m, 0, 0, 0));
+    EXPECT_EQ(0, my_decimal_cmp(&expected_result, &mod_result))
+      << " a:" << pd->a
+      << " b:" << pd->b
+      << " expected:" << pd->result
+      << " got mod:" << buff_m
+      ;
+
+    EXPECT_EQ(0, decimal_modulo(E_DEC_FATAL_ERROR, &xxx_result, &d1, &d2));
+    EXPECT_EQ(0, decimal2string(&xxx_result, buff_x, &bufsz_x, 0, 0, 0));
+    EXPECT_EQ(0, my_decimal_cmp(&expected_result, &xxx_result))
+      << " a:" << pd->a
+      << " b:" << pd->b
+      << " expected:" << pd->result
+      << " got mod:" << buff_m
+      << " got xxx:" << buff_x
+      ;
+  }
+
+}
+
 }

No bundle (reason: useless for push emails).
Thread
bzr push into mysql-trunk branch (tor.didriksen:3265 to 3266) Tor Didriksen18 Jul