Skip to content

Commit 8f7c496

Browse files
committedFeb 24, 2023
8302810: NMT gtests don't correctly check for marked ranges
Reviewed-by: gziemski, dholmes
1 parent 1a07871 commit 8f7c496

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed
 

‎test/hotspot/gtest/nmt/test_nmt_cornercases.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
* Copyright (c) 2022 SAP SE. All rights reserved.
3-
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2022, 2023 SAP SE. All rights reserved.
3+
* Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
66
* 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) {
6969
EXPECT_NULL(p2);
7070

7171
// original allocation should still be intact
72-
GtestUtils::check_range(p, first_size);
72+
EXPECT_RANGE_IS_MARKED(p, first_size);
7373
if (nmt_enabled) {
7474
check_expected_malloc_header(p, mtTest, first_size);
7575
}
@@ -102,14 +102,14 @@ static void* do_realloc(void* p, size_t old_size, size_t new_size, uint8_t old_c
102102

103103
// Check old content, and possibly zapped area (if block grew)
104104
if (old_size < new_size) {
105-
GtestUtils::check_range((char*)p2, old_size, old_content);
105+
EXPECT_RANGE_IS_MARKED_WITH(p2, old_size, old_content);
106106
#ifdef ASSERT
107107
if (MemTracker::enabled()) {
108-
GtestUtils::check_range((char*)p2 + old_size, new_size - old_size, uninitBlockPad);
108+
EXPECT_RANGE_IS_MARKED_WITH((char*)p2 + old_size, new_size - old_size, uninitBlockPad);
109109
}
110110
#endif
111111
} else {
112-
GtestUtils::check_range((char*)p2, new_size, old_content);
112+
EXPECT_RANGE_IS_MARKED_WITH(p2, new_size, old_content);
113113
}
114114

115115
return p2;

‎test/hotspot/gtest/testutils.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
3-
* Copyright (c) 2021 SAP SE. All rights reserved.
2+
* Copyright (c) 2021, 2023 SAP SE. All rights reserved.
3+
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
66
* 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) {
4040
}
4141
}
4242

43-
bool GtestUtils::check_range(const void* p, size_t s, uint8_t expected) {
43+
bool GtestUtils::is_range_marked(const void* p, size_t s, uint8_t expected) {
4444
if (p == NULL || s == 0) {
4545
return true;
4646
}

‎test/hotspot/gtest/testutils.hpp

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
3-
* Copyright (c) 2021 SAP SE. All rights reserved.
2+
* Copyright (c) 2021, 2023 SAP SE. All rights reserved.
3+
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
66
* This code is free software; you can redistribute it and/or modify it
@@ -39,16 +39,18 @@ class GtestUtils : public AllStatic {
3939
// Given a memory range, check that the whole range is filled with the expected byte.
4040
// If not, hex dump around first non-matching address and return false.
4141
// If p == NULL or size == 0, returns true.
42-
static bool check_range(const void* p, size_t s, uint8_t expected);
42+
static bool is_range_marked(const void* p, size_t s, uint8_t expected);
4343

4444
// Convenience method with a predefined byte mark.
45-
static void mark_range(void* p, size_t s) { mark_range_with(p, s, 32); }
46-
static bool check_range(const void* p, size_t s) { return check_range(p, s, 32); }
45+
static void mark_range(void* p, size_t s) { mark_range_with(p, s, 32); }
46+
static bool is_range_marked(const void* p, size_t s) { return is_range_marked(p, s, 32); }
4747

4848
};
4949

50-
#define ASSERT_RANGE_IS_MARKED_WITH(p, size, mark) ASSERT_TRUE(GtestUtils::check_range(p, size, mark))
51-
#define ASSERT_RANGE_IS_MARKED(p, size) ASSERT_TRUE(GtestUtils::check_range(p, size))
50+
#define ASSERT_RANGE_IS_MARKED_WITH(p, size, mark) ASSERT_TRUE(GtestUtils::is_range_marked(p, size, mark))
51+
#define ASSERT_RANGE_IS_MARKED(p, size) ASSERT_TRUE(GtestUtils::is_range_marked(p, size))
52+
#define EXPECT_RANGE_IS_MARKED_WITH(p, size, mark) EXPECT_TRUE(GtestUtils::is_range_marked(p, size, mark))
53+
#define EXPECT_RANGE_IS_MARKED(p, size) EXPECT_TRUE(GtestUtils::is_range_marked(p, size))
5254

5355
// Mimicking the official ASSERT_xx and EXPECT_xx counterparts of the googletest suite.
5456
// (ASSERT|EXPECT)_NOT_NULL: check that the given pointer is not NULL

0 commit comments

Comments
 (0)
Please sign in to comment.