diff options
| author | icoolidge <icoolidge@chromium.org> | 2015-04-07 12:28:09 -0700 | 
|---|---|---|
| committer | Commit bot <commit-bot@chromium.org> | 2015-04-07 19:29:33 +0000 | 
| commit | 9a4f22dbb7266733c40a632ece2ddc7eaf56e6ac (patch) | |
| tree | 0f5800569473526c088be27d07f85d9365d6da5d | |
| parent | 85eab771dc8fe433f8e3440d6abedfe7ac11f8c1 (diff) | |
| download | chromium_src-9a4f22dbb7266733c40a632ece2ddc7eaf56e6ac.zip chromium_src-9a4f22dbb7266733c40a632ece2ddc7eaf56e6ac.tar.gz chromium_src-9a4f22dbb7266733c40a632ece2ddc7eaf56e6ac.tar.bz2 | |
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}
| -rw-r--r-- | base/BUILD.gn | 2 | ||||
| -rw-r--r-- | base/base.gyp | 30 | ||||
| -rw-r--r-- | base/base_unittests.isolate | 7 | ||||
| -rw-r--r-- | base/process/memory_unittest.cc | 11 | ||||
| -rw-r--r-- | base/test/BUILD.gn | 12 | ||||
| -rw-r--r-- | base/test/malloc_wrapper.cc | 11 | ||||
| -rw-r--r-- | base/test/malloc_wrapper.h | 21 | 
7 files changed, 83 insertions, 11 deletions
| diff --git a/base/BUILD.gn b/base/BUILD.gn index 290ca8a..df06d24 100644 --- a/base/BUILD.gn +++ b/base/BUILD.gn @@ -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" ]      } diff --git a/base/base.gyp b/base/base.gyp index 5fafb4b..febbf3a 100644 --- a/base/base.gyp +++ b/base/base.gyp @@ -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': [          { diff --git a/base/base_unittests.isolate b/base/base_unittests.isolate index e329152..b1c270c 100644 --- a/base/base_unittests.isolate +++ b/base/base_unittests.isolate @@ -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': [ diff --git a/base/process/memory_unittest.cc b/base/process/memory_unittest.cc index 50ba098..2e64fd7 100644 --- a/base/process/memory_unittest.cc +++ b/base/process/memory_unittest.cc @@ -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 diff --git a/base/test/BUILD.gn b/base/test/BUILD.gn index c4356cb..6872aff 100644 --- a/base/test/BUILD.gn +++ b/base/test/BUILD.gn @@ -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 = [ diff --git a/base/test/malloc_wrapper.cc b/base/test/malloc_wrapper.cc new file mode 100644 index 0000000..eb280a3 --- /dev/null +++ b/base/test/malloc_wrapper.cc @@ -0,0 +1,11 @@ +// 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); +} diff --git a/base/test/malloc_wrapper.h b/base/test/malloc_wrapper.h new file mode 100644 index 0000000..0fa7dbb --- /dev/null +++ b/base/test/malloc_wrapper.h @@ -0,0 +1,21 @@ +// 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_ | 
