Commit 9a4f22db authored by icoolidge's avatar icoolidge Committed by Commit bot

Fix OutOfMemoryDeathTest.ViaSharedLibraries.

This test was invalid on modern glibc:
asprintf errors EOVERFLOW without attempting an allocation
when the size is at least INT_MAX - 32. INT_MAX - 33 is the
largest size that can attempt to trigger allocation failure,
and will not necessarily accomplish that on some systems.

Create a library that is specified to wrap malloc trivially,
to accomplish the goal of the test without external dependencies
or inconsistently implemented behavior.

BUG=428211

Review URL: https://codereview.chromium.org/1064793002

Cr-Commit-Position: refs/heads/master@{#324092}
parent 85eab771
......@@ -1348,6 +1348,8 @@ test("base_unittests") {
if (is_linux) {
sources -= [ "file_version_info_unittest.cc" ]
sources += [ "nix/xdg_util_unittest.cc" ]
deps += [ "//base/test:malloc_wrapper" ]
if (use_glib) {
configs += [ "//build/config/linux:glib" ]
}
......
......@@ -758,11 +758,17 @@
'message_loop/message_pump_glib_unittest.cc',
]
}],
['OS == "linux" and use_allocator!="none"', {
'dependencies': [
'allocator/allocator.gyp:allocator',
],
},
['OS == "linux"', {
'dependencies': [
'malloc_wrapper',
],
'conditions': [
['use_allocator!="none"', {
'dependencies': [
'allocator/allocator.gyp:allocator',
],
}],
]},
],
['OS == "win"', {
'sources!': [
......@@ -1327,6 +1333,20 @@
},
],
}],
['OS == "linux"', {
'targets': [
{
'target_name': 'malloc_wrapper',
'type': 'shared_library',
'dependencies': [
'base',
],
'sources': [
'test/malloc_wrapper.cc',
],
}
],
}],
['OS == "android"', {
'targets': [
{
......
......@@ -50,6 +50,13 @@
'read_only': 1,
},
}],
['OS=="linux"', {
'variables': {
'files': [
'<(PRODUCT_DIR)/lib/libmalloc_wrapper.so',
],
},
}],
['OS=="mac" and asan==1 and fastbuild==0', {
'variables': {
'files': [
......
......@@ -26,6 +26,7 @@
#endif
#if defined(OS_LINUX)
#include <malloc.h>
#include "base/test/malloc_wrapper.h"
#endif
#if defined(OS_WIN)
......@@ -234,13 +235,11 @@ TEST_F(OutOfMemoryDeathTest, Memalign) {
TEST_F(OutOfMemoryDeathTest, ViaSharedLibraries) {
// This tests that the run-time symbol resolution is overriding malloc for
// shared libraries (including libc itself) as well as for our code.
std::string format = base::StringPrintf("%%%zud", test_size_);
char *value = NULL;
// shared libraries as well as for our code.
ASSERT_DEATH({
SetUpInDeathAssert();
EXPECT_EQ(-1, asprintf(&value, format.c_str(), 0));
}, "");
SetUpInDeathAssert();
value_ = MallocWrapper(test_size_);
}, "");
}
#endif // OS_LINUX
......
......@@ -183,6 +183,18 @@ source_set("run_all_unittests") {
]
}
if (is_linux) {
shared_library("malloc_wrapper") {
testonly = true
sources = [
"malloc_wrapper.cc",
]
deps = [
"//base",
]
}
}
if (is_android) {
generate_jni("base_unittests_jni_headers") {
sources = [
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "malloc_wrapper.h"
#include <stdlib.h>
void* MallocWrapper(size_t size) {
return malloc(size);
}
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef BASE_TEST_MALLOC_WRAPPER_H_
#define BASE_TEST_MALLOC_WRAPPER_H_
#include "base/basictypes.h"
// BASE_EXPORT depends on COMPONENT_BUILD.
// This will always be a separate shared library, so don't use BASE_EXPORT here.
#if defined(WIN32)
#define MALLOC_WRAPPER_EXPORT __declspec(dllexport)
#else
#define MALLOC_WRAPPER_EXPORT __attribute__((visibility("default")))
#endif // defined(WIN32)
// Calls malloc directly.
MALLOC_WRAPPER_EXPORT void* MallocWrapper(size_t size);
#endif // BASE_TEST_MALLOC_WRAPPER_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment