Merge "Fix SharedBuffer tests to pass under hwasan." am: 2d697d330f
am: 7266e44305
am: 1c8f0bad6b
Original change: https://android-review.googlesource.com/c/platform/system/core/+/1466463 Change-Id: I45d171b1a1f2a9c48f945edcb074144801be6cd5
This commit is contained in:
commit
f9ff52ef3f
1 changed files with 38 additions and 29 deletions
|
@ -23,36 +23,45 @@
|
|||
|
||||
#include "SharedBuffer.h"
|
||||
|
||||
TEST(SharedBufferTest, TestAlloc) {
|
||||
EXPECT_DEATH(android::SharedBuffer::alloc(SIZE_MAX), "");
|
||||
EXPECT_DEATH(android::SharedBuffer::alloc(SIZE_MAX - sizeof(android::SharedBuffer)), "");
|
||||
extern "C" void __hwasan_init() __attribute__((weak));
|
||||
#define SKIP_WITH_HWASAN \
|
||||
if (&__hwasan_init != 0) GTEST_SKIP()
|
||||
|
||||
// Make sure we don't die here.
|
||||
// Check that null is returned, as we are asking for the whole address space.
|
||||
android::SharedBuffer* buf =
|
||||
android::SharedBuffer::alloc(SIZE_MAX - sizeof(android::SharedBuffer) - 1);
|
||||
ASSERT_EQ(nullptr, buf);
|
||||
|
||||
buf = android::SharedBuffer::alloc(0);
|
||||
ASSERT_NE(nullptr, buf);
|
||||
ASSERT_EQ(0U, buf->size());
|
||||
buf->release();
|
||||
TEST(SharedBufferTest, alloc_death) {
|
||||
EXPECT_DEATH(android::SharedBuffer::alloc(SIZE_MAX), "");
|
||||
EXPECT_DEATH(android::SharedBuffer::alloc(SIZE_MAX - sizeof(android::SharedBuffer)), "");
|
||||
}
|
||||
|
||||
TEST(SharedBufferTest, TestEditResize) {
|
||||
android::SharedBuffer* buf = android::SharedBuffer::alloc(10);
|
||||
EXPECT_DEATH(buf->editResize(SIZE_MAX - sizeof(android::SharedBuffer)), "");
|
||||
buf = android::SharedBuffer::alloc(10);
|
||||
EXPECT_DEATH(buf->editResize(SIZE_MAX), "");
|
||||
|
||||
buf = android::SharedBuffer::alloc(10);
|
||||
// Make sure we don't die here.
|
||||
// Check that null is returned, as we are asking for the whole address space.
|
||||
buf = buf->editResize(SIZE_MAX - sizeof(android::SharedBuffer) - 1);
|
||||
ASSERT_EQ(nullptr, buf);
|
||||
|
||||
buf = android::SharedBuffer::alloc(10);
|
||||
buf = buf->editResize(0);
|
||||
ASSERT_EQ(0U, buf->size());
|
||||
buf->release();
|
||||
TEST(SharedBufferTest, alloc_null) {
|
||||
// Big enough to fail, not big enough to abort.
|
||||
SKIP_WITH_HWASAN; // hwasan has a 2GiB allocation limit.
|
||||
ASSERT_EQ(nullptr, android::SharedBuffer::alloc(SIZE_MAX / 2));
|
||||
}
|
||||
|
||||
TEST(SharedBufferTest, alloc_zero_size) {
|
||||
android::SharedBuffer* buf = android::SharedBuffer::alloc(0);
|
||||
ASSERT_NE(nullptr, buf);
|
||||
ASSERT_EQ(0U, buf->size());
|
||||
buf->release();
|
||||
}
|
||||
|
||||
TEST(SharedBufferTest, editResize_death) {
|
||||
android::SharedBuffer* buf = android::SharedBuffer::alloc(10);
|
||||
EXPECT_DEATH(buf->editResize(SIZE_MAX - sizeof(android::SharedBuffer)), "");
|
||||
buf = android::SharedBuffer::alloc(10);
|
||||
EXPECT_DEATH(buf->editResize(SIZE_MAX), "");
|
||||
}
|
||||
|
||||
TEST(SharedBufferTest, editResize_null) {
|
||||
// Big enough to fail, not big enough to abort.
|
||||
SKIP_WITH_HWASAN; // hwasan has a 2GiB allocation limit.
|
||||
android::SharedBuffer* buf = android::SharedBuffer::alloc(10);
|
||||
ASSERT_EQ(nullptr, buf->editResize(SIZE_MAX / 2));
|
||||
}
|
||||
|
||||
TEST(SharedBufferTest, editResize_zero_size) {
|
||||
android::SharedBuffer* buf = android::SharedBuffer::alloc(10);
|
||||
buf = buf->editResize(0);
|
||||
ASSERT_EQ(0U, buf->size());
|
||||
buf->release();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue