Bug #60110 Do more THD and global initialization for unit testing
Submitted: 11 Feb 2011 7:22 Modified: 24 Mar 2011 22:21
Reporter: Tor Didriksen Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Tests Severity:S3 (Non-critical)
Version:5.6+ OS:Any
Assigned to: Tor Didriksen CPU Architecture:Any

[11 Feb 2011 7:22] Tor Didriksen
Description:
THD::variables need to be initialized
Need to run more of the global initialization in mysqld.cc

How to repeat:
This simple unit test

TEST_F(ItemTest, ItemFuncSetUserVar)
{
  const longlong val1= 1;
  Item_decimal *item_dec1= new Item_decimal(val1, false);
  LEX_STRING var_name= { C_STRING_WITH_LEN("a") };
  Item_func_set_user_var *user_var=
    new Item_func_set_user_var(var_name, item_dec1);
  EXPECT_FALSE(user_var->set_entry(m_thd, true));
  EXPECT_FALSE(user_var->fix_fields(m_thd, NULL));
  EXPECT_EQ(val1, user_var->val_int());
}

Will segfault:

#0  0x0000000000823239 in calc_hash (hash=0x1302a10, key=0xaf3bb0 "a", length=1) at /export/home/didrik/repo/trunk/mysys/hash.c:46
#1  0x0000000000823780 in my_hash_first (hash=0x1302a10, key=0xaf3bb0 "a", length=1, current_record=0x7fffffffdd7c)
    at /export/home/didrik/repo/trunk/mysys/hash.c:247
#2  0x00000000008236a2 in my_hash_search (hash=0x1302a10, key=0xaf3bb0 "a", length=1) at /export/home/didrik/repo/trunk/mysys/hash.c:215
#3  0x00000000004c4b3d in get_variable (hash=0x1302a10, name=..., create_if_not_exists=true) at /export/home/didrik/repo/trunk/sql/item_func.cc:4151
#4  0x00000000004c4d26 in Item_func_set_user_var::set_entry (this=0x1305ca0, thd=0x1302470, create_if_not_exists=true)
    at /export/home/didrik/repo/trunk/sql/item_func.cc:4202
#5  0x0000000000441bc9 in (anonymous namespace)::ItemTest_ItemFuncSetUserVar_Test::TestBody (this=0x1301980)
    at /export/home/didrik/repo/trunk/unittest/gunit/item-t.cc:194
#6  0x0000000000ad70f3 in testing::Test::Run (this=0x1301980) at /export/home/didrik/repo/trunk/source_downloads/gtest-1.5.0/src/gtest.cc:2095
#7  0x0000000000ad769d in testing::internal::TestInfoImpl::Run (this=0x13016c0)
    at /export/home/didrik/repo/trunk/source_downloads/gtest-1.5.0/src/gtest.cc:2314
#8  0x0000000000ad7cb2 in testing::TestCase::Run (this=0x12fd5e0) at /export/home/didrik/repo/trunk/source_downloads/gtest-1.5.0/src/gtest.cc:2420

Suggested fix:
See description.

This is a followup to
Bug #59794  Enable unit testing of classes which depend on a working THD environment
[24 Mar 2011 22:21] Paul DuBois
Changes for test suite. No changelog entry needed.

CHANGESET - http://lists.mysql.com/commits/131710