8302810: NMT gtests don't correctly check for marked ranges
Reviewed-by: gziemski, dholmes
This commit is contained in:
parent
1a07871454
commit
8f7c4969c2
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2022 SAP SE. All rights reserved.
|
||||
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2022, 2023 SAP SE. All rights reserved.
|
||||
* Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -69,7 +69,7 @@ static void check_failing_realloc(size_t failing_request_size) {
|
||||
EXPECT_NULL(p2);
|
||||
|
||||
// original allocation should still be intact
|
||||
GtestUtils::check_range(p, first_size);
|
||||
EXPECT_RANGE_IS_MARKED(p, first_size);
|
||||
if (nmt_enabled) {
|
||||
check_expected_malloc_header(p, mtTest, first_size);
|
||||
}
|
||||
@ -102,14 +102,14 @@ static void* do_realloc(void* p, size_t old_size, size_t new_size, uint8_t old_c
|
||||
|
||||
// Check old content, and possibly zapped area (if block grew)
|
||||
if (old_size < new_size) {
|
||||
GtestUtils::check_range((char*)p2, old_size, old_content);
|
||||
EXPECT_RANGE_IS_MARKED_WITH(p2, old_size, old_content);
|
||||
#ifdef ASSERT
|
||||
if (MemTracker::enabled()) {
|
||||
GtestUtils::check_range((char*)p2 + old_size, new_size - old_size, uninitBlockPad);
|
||||
EXPECT_RANGE_IS_MARKED_WITH((char*)p2 + old_size, new_size - old_size, uninitBlockPad);
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
GtestUtils::check_range((char*)p2, new_size, old_content);
|
||||
EXPECT_RANGE_IS_MARKED_WITH(p2, new_size, old_content);
|
||||
}
|
||||
|
||||
return p2;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2021 SAP SE. All rights reserved.
|
||||
* Copyright (c) 2021, 2023 SAP SE. All rights reserved.
|
||||
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -40,7 +40,7 @@ void GtestUtils::mark_range_with(void* p, size_t s, uint8_t mark) {
|
||||
}
|
||||
}
|
||||
|
||||
bool GtestUtils::check_range(const void* p, size_t s, uint8_t expected) {
|
||||
bool GtestUtils::is_range_marked(const void* p, size_t s, uint8_t expected) {
|
||||
if (p == NULL || s == 0) {
|
||||
return true;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2021 SAP SE. All rights reserved.
|
||||
* Copyright (c) 2021, 2023 SAP SE. All rights reserved.
|
||||
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -39,16 +39,18 @@ public:
|
||||
// Given a memory range, check that the whole range is filled with the expected byte.
|
||||
// If not, hex dump around first non-matching address and return false.
|
||||
// If p == NULL or size == 0, returns true.
|
||||
static bool check_range(const void* p, size_t s, uint8_t expected);
|
||||
static bool is_range_marked(const void* p, size_t s, uint8_t expected);
|
||||
|
||||
// Convenience method with a predefined byte mark.
|
||||
static void mark_range(void* p, size_t s) { mark_range_with(p, s, 32); }
|
||||
static bool check_range(const void* p, size_t s) { return check_range(p, s, 32); }
|
||||
static void mark_range(void* p, size_t s) { mark_range_with(p, s, 32); }
|
||||
static bool is_range_marked(const void* p, size_t s) { return is_range_marked(p, s, 32); }
|
||||
|
||||
};
|
||||
|
||||
#define ASSERT_RANGE_IS_MARKED_WITH(p, size, mark) ASSERT_TRUE(GtestUtils::check_range(p, size, mark))
|
||||
#define ASSERT_RANGE_IS_MARKED(p, size) ASSERT_TRUE(GtestUtils::check_range(p, size))
|
||||
#define ASSERT_RANGE_IS_MARKED_WITH(p, size, mark) ASSERT_TRUE(GtestUtils::is_range_marked(p, size, mark))
|
||||
#define ASSERT_RANGE_IS_MARKED(p, size) ASSERT_TRUE(GtestUtils::is_range_marked(p, size))
|
||||
#define EXPECT_RANGE_IS_MARKED_WITH(p, size, mark) EXPECT_TRUE(GtestUtils::is_range_marked(p, size, mark))
|
||||
#define EXPECT_RANGE_IS_MARKED(p, size) EXPECT_TRUE(GtestUtils::is_range_marked(p, size))
|
||||
|
||||
// Mimicking the official ASSERT_xx and EXPECT_xx counterparts of the googletest suite.
|
||||
// (ASSERT|EXPECT)_NOT_NULL: check that the given pointer is not NULL
|
||||
|
Loading…
x
Reference in New Issue
Block a user