Skip to content

Commit

Permalink
[unittest] PS-269: Initial Percona Server 8.0.12 tree
Browse files Browse the repository at this point in the history
-----------------------------------------------------------

PS-7949 Fix memry leak in gcs_xcom_control_interface-t test

https://jira.percona.com/browse/PS-7949

-----------------------------------------------------------

PS-7949 Fix memory leaks in temptable::Allocator tests

https://jira.percona.com/browse/PS-7949

-----------------------------------------------------------

PS-8978: Merge MySQL 8.0.35 - Fix linking issue using `WITH_VALGRIND=ON`

Fix the following issue when `lld` is not detected or `-DUSE_LD_LLD=OFF` is used:
```
/usr/bin/ld: CMakeFiles/merge_large_tests-t.dir/dd_sdi-t.cc.o: warning: relocation against `_ZThn56_N2dd10Index_impl15se_private_dataEv' in read-only section `.text._ZN12sdi_unittestL11mock_dd_objEPN2dd5IndexEPNS0_6ColumnE'
/usr/bin/ld: CMakeFiles/merge_large_tests-t.dir/dd_sdi-t.cc.o: relocation R_X86_64_PC32 against symbol `_ZThn56_N2dd11Column_impl15se_private_dataEv' can not be used when making a PIE object; recompile with -fPIE
```
  • Loading branch information
inikep committed Sep 25, 2024
1 parent a02213a commit f1a938a
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 19 deletions.
7 changes: 6 additions & 1 deletion unittest/gunit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ SET(TESTS
charset_bug32788301
collation_loader
cost_estimate
dbug
decimal
dns_srv_data
dphyp
Expand Down Expand Up @@ -335,6 +334,12 @@ IF(HAS_WARN_FLAG)
ADD_COMPILE_FLAGS(segfault-t.cc COMPILE_FLAGS ${HAS_WARN_FLAG})
ENDIF()

# Avoid 'requires dynamic R_X86_64_PC32 reloc' linker error for dd_sdi-t.cc
# when built with ASAN
IF(WITH_ASAN OR WITH_VALGRIND)
ADD_CXX_COMPILE_FLAGS_TO_FILES(-fPIC FILES dd_sdi-t.cc)
ENDIF()

# Warnings about missing PGO profile data are not useful for unit tests.
DISABLE_MISSING_PROFILE_WARNING()

Expand Down
2 changes: 1 addition & 1 deletion unittest/gunit/dd.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class Mock_dd_HANDLER : public Base_mock_HANDLER {
Mock_dd_HANDLER(handlerton *hton, TABLE_SHARE *share)
: Base_mock_HANDLER(hton, share) {}

virtual ~Mock_dd_HANDLER() = default;
~Mock_dd_HANDLER() override {}
};

/**
Expand Down
1 change: 1 addition & 0 deletions unittest/gunit/innodb/lob/lot0buf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ this program; if not, write to the Free Software Foundation, Inc.,

#include "lot0buf.h"
#include "mach0data.h"
#include "my_compiler.h"
#include "ut0byte.h"
#include "ut0ut.h"

Expand Down
5 changes: 0 additions & 5 deletions unittest/gunit/innodb/log0log-t.cc
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,6 @@ static bool log_test_recovery() {

} else {
srv_shutdown_state = SRV_SHUTDOWN_FLUSH_PHASE;

/* XXX: Shouldn't this be guaranteed within log0recv.cc ? */
while (srv_thread_is_active(srv_threads.m_recv_writer)) {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}

recv_sys_close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,8 @@ TEST_F(XComControlTest, JoinTestSkipOwnNodeAndCycleThroughPeerNodes) {
result = xcom_control_if->leave();
ASSERT_EQ(GCS_OK, result);
ASSERT_FALSE(xcom_control_if->is_xcom_running());

free(con);
}

TEST_F(XComControlTest, JoinTestAllPeersUnavailable) {
Expand Down
2 changes: 1 addition & 1 deletion unittest/gunit/log_timestamp-t.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include "test_utils.h"

#include <mysql/components/services/log_shared.h>
#include "../sql/log.h"
#include "sql/log.h"

// CET: 32 bytes
// date (10), 'T', time (8), '.', microseconds (6), timezone offset (6)
Expand Down
1 change: 1 addition & 0 deletions unittest/gunit/m_string-t.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ TEST(MString, HumanReadableSize) {
data_size *= 1000;
EXPECT_EQ("1025000Y", HumanReadable(data_size));
data_size *= 1000;

EXPECT_EQ("1025000000Y", HumanReadable(data_size));
data_size *=
static_cast<double>(std::numeric_limits<unsigned long long>::max());
Expand Down
6 changes: 5 additions & 1 deletion unittest/gunit/mdl-t.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3780,7 +3780,11 @@ TEST_F(MDLTest, FindLockOwner) {
Verify that correct error is reported when the MDL system exhausts the LF
Pinbox.
*/
TEST_F(MDLTest, ExhaustPinbox) {
/**
Disabled, because Percona Server allows up to 2^32 pins
and this test would take a lot of time
*/
TEST_F(MDLTest, DISABLED_ExhaustPinbox) {
for (int i = 0; i < 65535; ++i) {
MDL_context c;
EXPECT_FALSE(test_drive_fix_pins(&c));
Expand Down
3 changes: 2 additions & 1 deletion unittest/gunit/mysys_my_b_vprintf-t.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ void test1(const char *res, const char *fmt, ...) {
IO_CACHE info;
va_list args;
size_t len;
init_io_cache(&info, -1, 0, WRITE_CACHE, 0, true, MYF(0));
int init_res = init_io_cache(&info, -1, 0, WRITE_CACHE, 0, true, MYF(0));
EXPECT_EQ(init_res, 0);
memset(info.write_buffer, 0, 64); /* RECORD_CACHE_SIZE is 64K */
va_start(args, fmt);
len = my_b_vprintf(&info, fmt, args);
Expand Down
2 changes: 1 addition & 1 deletion unittest/gunit/mysys_pathfuncs-t.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ TEST(Mysys, CreateTempFile) {
File fileno = create_temp_file(dst, "/tmp", prefix, 42, UNLINK_FILE, 0);
EXPECT_GE(fileno, 0);
my_close(fileno, 0);
EXPECT_THAT(dst, MatchesRegex("/tmp/[a]+fd=[0-9]+"));
EXPECT_THAT(dst, MatchesRegex("/tmp/[a]+(fd=[0-9]+|[a-zA-Z0-9]+)"));
aset(dst, 0xaa);

char *env_tmpdir = getenv("TMPDIR");
Expand Down
39 changes: 32 additions & 7 deletions unittest/gunit/temptable_allocator-t.cc
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,26 @@ TEST_F(TempTableAllocator, block_size_cap) {
EXPECT_TRUE(shared_block.is_empty());
}

struct AllocatorRaii {
AllocatorRaii(temptable::Allocator<uint8_t> *allocator)
: m_allocator(allocator) {}

void deallocate_all() {
for (const auto &[ptr, size] : allocs) {
m_allocator->deallocate(ptr, size);
}
}

uint8_t *allocate(size_t n_elements) {
auto *ptr = m_allocator->allocate(n_elements);
allocs.emplace_back(ptr, n_elements);
return ptr;
}

temptable::Allocator<uint8_t> *m_allocator;
std::vector<std::pair<uint8_t *, size_t>> allocs;
};

TEST_F(
TempTableAllocator,
table_resource_monitor_increases_then_drops_to_0_when_allocation_is_backed_by_shared_block) {
Expand Down Expand Up @@ -694,9 +714,14 @@ TEST_F(TempTableAllocator,
shared_block_utilization_shall_not_impact_the_block_size_growth_policy) {
temptable::TableResourceMonitor table_resource_monitor(16 * 1024 * 1024);
temptable::Block shared_block;

temptable::Allocator<uint8_t> a1(&shared_block, table_resource_monitor);
temptable::Allocator<uint8_t> a2(&shared_block, table_resource_monitor);
auto r11 = a1.allocate(512_KiB);

AllocatorRaii a1_raii(&a1);
AllocatorRaii a2_raii(&a2);

auto r11 = a1_raii.allocate(512_KiB);
temptable::Block b11 = temptable::Block(temptable::Chunk(r11));
EXPECT_EQ(b11, shared_block);
EXPECT_EQ(b11.size(), shared_block.size());
Expand All @@ -708,7 +733,7 @@ TEST_F(TempTableAllocator,
// size big.
// 4. Returns a pointer from shared_block.

auto r12 = a1.allocate(256_KiB);
auto r12 = a1_raii.allocate(256_KiB);
temptable::Block b12 = temptable::Block(temptable::Chunk(r12));
EXPECT_EQ(b12, shared_block);
EXPECT_EQ(b12.size(), shared_block.size());
Expand All @@ -718,7 +743,7 @@ TEST_F(TempTableAllocator,
// 512KiB) to accomodate the 256KiB request.
// 3. Returns a pointer from shared_block.

auto r13 = a1.allocate(512_KiB);
auto r13 = a1_raii.allocate(512_KiB);
temptable::Block b13 = temptable::Block(temptable::Chunk(r13));
EXPECT_NE(b13, shared_block);
EXPECT_NE(b13, b12);
Expand All @@ -731,7 +756,7 @@ TEST_F(TempTableAllocator,
// 4. It allocates the block of 2MiB of size.
// 5. Returns a pointer from new block.

auto r21 = a2.allocate(512_KiB);
auto r21 = a2_raii.allocate(512_KiB);
temptable::Block b21 = temptable::Block(temptable::Chunk(r21));
EXPECT_NE(b21, shared_block);
EXPECT_EQ(b21.size(), 1_MiB);
Expand All @@ -743,7 +768,7 @@ TEST_F(TempTableAllocator,
// 4. It allocates the block of 1MiB of size.
// 5. Returns a pointer from new block.

auto r14 = a1.allocate(128_KiB);
auto r14 = a1_raii.allocate(128_KiB);
temptable::Block b14 = temptable::Block(temptable::Chunk(r14));
EXPECT_EQ(b14, shared_block);
EXPECT_EQ(b14.size(), shared_block.size());
Expand All @@ -753,7 +778,7 @@ TEST_F(TempTableAllocator,
// 256KiB = 256KiB) to accomodate the 128KiB request.
// 3. Returns a pointer from shared_block.

auto r15 = a1.allocate(1_MiB - 512_KiB);
auto r15 = a1_raii.allocate(1_MiB - 512_KiB);
temptable::Block b15 = temptable::Block(temptable::Chunk(r15));
EXPECT_NE(b15, shared_block);
EXPECT_EQ(b15.size(), 2_MiB);
Expand All @@ -766,7 +791,7 @@ TEST_F(TempTableAllocator,
// 4. It allocates the block of 2MiB of size.
// 3. Returns a pointer from new block.

auto r22 = a2.allocate(1_MiB);
auto r22 = a2_raii.allocate(1_MiB);
temptable::Block b22 = temptable::Block(temptable::Chunk(r22));
EXPECT_NE(b22, shared_block);
EXPECT_EQ(b22.size(), 2_MiB);
Expand Down
6 changes: 6 additions & 0 deletions unittest/gunit/temptable_storage-t.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ TEST(StorageTest, Iterate) {
}
EXPECT_EQ(0u, i);
}

// Deallocate the shared-block (allocator keeps it alive
// intentionally)
// Must be done after storage is destructed
shared_block.destroy();
});
t.join();
Expand All @@ -84,6 +88,8 @@ TEST(StorageTest, AllocatorRebind) {

alloc.deallocate(shared_eater, 1048576);

// Deallocate the shared-block (allocator keeps it alive
// intentionally)
shared_block.destroy();
};
std::thread t(thread_function);
Expand Down
4 changes: 4 additions & 0 deletions unittest/gunit/xplugin/xpl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ IF(WIN32)
SET_TARGET_PROPERTIES(${XPL_UNIT_TESTS} PROPERTIES COMPILE_FLAGS "/wd4373")
ENDIF(WIN32)

IF(MY_COMPILER_IS_CLANG)
STRING_APPEND(CMAKE_CXX_FLAGS " -Wno-deprecated")
ENDIF()

TARGET_LINK_LIBRARIES(${XPL_UNIT_TESTS}
${GCOV_LDFLAGS}
${MYSQLX_CLIENT_LIB}
Expand Down
1 change: 0 additions & 1 deletion unittest/gunit/xplugin/xpl/mysql_function_names.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,3 @@ GET_OTHER_FUNCTION_NAMES(${PROJECT_SOURCE_DIR}/sql/sql_yacc.yy OTHER_MYSQL_FUNCT

CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/mysql_function_names_t.cc.in
${MYSQLX_GENERATE_DIR}/mysql_function_names_t.cc)

0 comments on commit f1a938a

Please sign in to comment.