author | Seth Fowler <seth@mozilla.com> |
Fri, 16 Jan 2015 15:47:22 -0800 | |
changeset 224346 | e10a79c4ac9f40ac9556e7ef88a60a9da9587613 |
parent 224345 | debc66b7bfe7822e79ceab4b61f1f1db7a7f80a6 |
child 224347 | 26cdb770b82117ae67655c7c4e07abad4d15ccf6 |
push id | 54192 |
push user | mfowler@mozilla.com |
push date | Sat, 17 Jan 2015 02:13:43 +0000 |
treeherder | mozilla-inbound@26cdb770b821 [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | glandium |
bugs | 1121297 |
milestone | 38.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
--- a/CLOBBER +++ b/CLOBBER @@ -17,9 +17,9 @@ # # Modifying this file will now automatically clobber the buildbot machines \o/ # # Are you updating CLOBBER because you think it's needed for your WebIDL # changes to stick? As of bug 928195, this shouldn't be necessary! Please # don't change CLOBBER for WebIDL changes any more. -Bug 1118618's backout needed a clobber +Bug 1121297 - Converted VolatileBuffer's CPP tests to GTests
--- a/memory/mozalloc/moz.build +++ b/memory/mozalloc/moz.build @@ -5,17 +5,16 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. NO_VISIBILITY_FLAGS = True EXPORTS.mozilla += [ 'fallible.h', 'mozalloc.h', 'mozalloc_abort.h', 'mozalloc_oom.h', - 'VolatileBuffer.h', ] if CONFIG['MOZ_MSVC_STL_WRAP__RAISE'] or CONFIG['MOZ_MSVC_STL_WRAP__Throw']: build_msvc_wrappers = 1 else: build_msvc_wrappers = 0 if CONFIG['WRAP_STL_INCLUDES']: @@ -35,42 +34,23 @@ if CONFIG['WRAP_STL_INCLUDES']: ] UNIFIED_SOURCES += [ 'mozalloc.cpp', 'mozalloc_abort.cpp', 'mozalloc_oom.cpp', ] -if CONFIG['OS_TARGET'] == 'Android': - UNIFIED_SOURCES += [ - 'VolatileBufferAshmem.cpp', - ] -elif CONFIG['OS_TARGET'] == 'Darwin': - UNIFIED_SOURCES += [ - 'VolatileBufferOSX.cpp', - ] -elif CONFIG['OS_TARGET'] == 'WINNT': - UNIFIED_SOURCES += [ - 'VolatileBufferWindows.cpp', - ] -else: - UNIFIED_SOURCES += [ - 'VolatileBufferFallback.cpp', - ] - if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk': Library('mozalloc') else: GeckoSharedLibrary('mozalloc', linkage=None) SDK_LIBRARY = True # The strndup declaration in string.h is in an ifdef __USE_GNU section DEFINES['_GNU_SOURCE'] = True -TEST_DIRS += ['tests'] - GENERATED_INCLUDES += ['/xpcom'] DISABLE_STL_WRAPPING = True if CONFIG['CLANG_CXX'] or CONFIG['_MSC_VER']: FAIL_ON_WARNINGS = True
rename from memory/mozalloc/VolatileBuffer.h rename to memory/volatile/VolatileBuffer.h --- a/memory/mozalloc/VolatileBuffer.h +++ b/memory/volatile/VolatileBuffer.h @@ -37,17 +37,17 @@ * API cannot tell which parts of the buffer were lost. * * VolatileBuffer is not thread safe. Do not use VolatileBufferPtrs on * different threads. */ namespace mozilla { -class MOZALLOC_EXPORT VolatileBuffer : public RefCounted<VolatileBuffer> +class VolatileBuffer : public RefCounted<VolatileBuffer> { friend class VolatileBufferPtr_base; public: MOZ_DECLARE_REFCOUNTED_TYPENAME(VolatileBuffer) VolatileBuffer(); ~VolatileBuffer(); /* aAlignment must be a multiple of the pointer size */
rename from memory/mozalloc/VolatileBufferAshmem.cpp rename to memory/volatile/VolatileBufferAshmem.cpp
rename from memory/mozalloc/VolatileBufferFallback.cpp rename to memory/volatile/VolatileBufferFallback.cpp --- a/memory/mozalloc/VolatileBufferFallback.cpp +++ b/memory/volatile/VolatileBufferFallback.cpp @@ -22,19 +22,23 @@ VolatileBuffer::VolatileBuffer() bool VolatileBuffer::Init(size_t aSize, size_t aAlignment) { MOZ_ASSERT(!mSize && !mBuf, "Init called twice"); MOZ_ASSERT(!(aAlignment % sizeof(void *)), "Alignment must be multiple of pointer size"); mSize = aSize; #if defined(MOZ_MEMORY) - posix_memalign(&mBuf, aAlignment, aSize); + if (posix_memalign(&mBuf, aAlignment, aSize) != 0) { + return false; + } #elif defined(HAVE_POSIX_MEMALIGN) - (void)moz_posix_memalign(&mBuf, aAlignment, aSize); + if (moz_posix_memalign(&mBuf, aAlignment, aSize) != 0) { + return false; + } #else #error "No memalign implementation found" #endif return !!mBuf; } VolatileBuffer::~VolatileBuffer() {
rename from memory/mozalloc/VolatileBufferWindows.cpp rename to memory/volatile/VolatileBufferWindows.cpp --- a/memory/mozalloc/VolatileBufferWindows.cpp +++ b/memory/volatile/VolatileBufferWindows.cpp @@ -1,16 +1,12 @@ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#if defined(XP_WIN) -# define MOZALLOC_EXPORT __declspec(dllexport) -#endif - #include "VolatileBuffer.h" #include "mozilla/Assertions.h" #include "mozilla/mozalloc.h" #include "mozilla/WindowsVersion.h" #include <windows.h> #ifdef MOZ_MEMORY
copy from memory/mozalloc/moz.build copy to memory/volatile/moz.build --- a/memory/mozalloc/moz.build +++ b/memory/volatile/moz.build @@ -1,50 +1,19 @@ # -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*- # vim: set filetype=python: # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. NO_VISIBILITY_FLAGS = True EXPORTS.mozilla += [ - 'fallible.h', - 'mozalloc.h', - 'mozalloc_abort.h', - 'mozalloc_oom.h', 'VolatileBuffer.h', ] -if CONFIG['MOZ_MSVC_STL_WRAP__RAISE'] or CONFIG['MOZ_MSVC_STL_WRAP__Throw']: - build_msvc_wrappers = 1 -else: - build_msvc_wrappers = 0 - -if CONFIG['WRAP_STL_INCLUDES']: - if CONFIG['GNU_CXX']: - EXPORTS.mozilla += ['throw_gcc.h'] - elif CONFIG['_MSC_VER']: - DEFINES['_HAS_EXCEPTIONS'] = 0 - if build_msvc_wrappers: - EXPORTS.mozilla += [ - 'msvc_raise_wrappers.h', - 'msvc_throw_wrapper.h', - 'throw_msvc.h', - ] - SOURCES += [ - 'msvc_raise_wrappers.cpp', - 'msvc_throw_wrapper.cpp', - ] - -UNIFIED_SOURCES += [ - 'mozalloc.cpp', - 'mozalloc_abort.cpp', - 'mozalloc_oom.cpp', -] - if CONFIG['OS_TARGET'] == 'Android': UNIFIED_SOURCES += [ 'VolatileBufferAshmem.cpp', ] elif CONFIG['OS_TARGET'] == 'Darwin': UNIFIED_SOURCES += [ 'VolatileBufferOSX.cpp', ] @@ -52,25 +21,13 @@ elif CONFIG['OS_TARGET'] == 'WINNT': UNIFIED_SOURCES += [ 'VolatileBufferWindows.cpp', ] else: UNIFIED_SOURCES += [ 'VolatileBufferFallback.cpp', ] -if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk': - Library('mozalloc') -else: - GeckoSharedLibrary('mozalloc', linkage=None) - SDK_LIBRARY = True - -# The strndup declaration in string.h is in an ifdef __USE_GNU section -DEFINES['_GNU_SOURCE'] = True +FINAL_LIBRARY = 'xul' TEST_DIRS += ['tests'] -GENERATED_INCLUDES += ['/xpcom'] - -DISABLE_STL_WRAPPING = True - -if CONFIG['CLANG_CXX'] or CONFIG['_MSC_VER']: - FAIL_ON_WARNINGS = True +FAIL_ON_WARNINGS = True
rename from memory/mozalloc/tests/TestVolatileBuffer.cpp rename to memory/volatile/tests/TestVolatileBuffer.cpp --- a/memory/mozalloc/tests/TestVolatileBuffer.cpp +++ b/memory/volatile/tests/TestVolatileBuffer.cpp @@ -1,143 +1,102 @@ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "TestHarness.h" +#include "gtest/gtest.h" #include "mozilla/VolatileBuffer.h" #include <string.h> #if defined(ANDROID) #include <fcntl.h> #include <linux/ashmem.h> #include <sys/ioctl.h> #include <sys/stat.h> #include <sys/types.h> #elif defined(XP_DARWIN) #include <mach/mach.h> #endif using namespace mozilla; -int main(int argc, char **argv) +TEST(VolatileBufferTest, HeapVolatileBuffersWork) { - ScopedXPCOM xpcom("VolatileBufferTests"); - if (xpcom.failed()) { - return 1; - } + RefPtr<VolatileBuffer> heapbuf = new VolatileBuffer(); - RefPtr<VolatileBuffer> heapbuf = new VolatileBuffer(); - if (!heapbuf || !heapbuf->Init(512)) { - fail("Failed to initialize VolatileBuffer"); - return 1; - } + ASSERT_TRUE(heapbuf) << "Failed to create VolatileBuffer"; + ASSERT_TRUE(heapbuf->Init(512)) << "Failed to initialize VolatileBuffer"; + + VolatileBufferPtr<char> ptr(heapbuf); - { - VolatileBufferPtr<char> ptr(heapbuf); - if (ptr.WasBufferPurged()) { - fail("Buffer was immediately purged after initialization"); - return 1; - } + EXPECT_FALSE(ptr.WasBufferPurged()) + << "Buffer should not be purged immediately after initialization"; + EXPECT_TRUE(ptr) << "Couldn't get pointer from VolatileBufferPtr"; +} - if (!ptr) { - fail("Didn't get a pointer"); - return 1; - } - } +TEST(VolatileBufferTest, RealVolatileBuffersWork) +{ + RefPtr<VolatileBuffer> buf = new VolatileBuffer(); - RefPtr<VolatileBuffer> buf = new VolatileBuffer(); - if (!buf || !buf->Init(16384)) { - fail("Failed to initialize VolatileBuffer"); - return 1; - } + ASSERT_TRUE(buf) << "Failed to create VolatileBuffer"; + ASSERT_TRUE(buf->Init(16384)) << "Failed to initialize VolatileBuffer"; const char teststr[] = "foobar"; { VolatileBufferPtr<char> ptr(buf); - if (ptr.WasBufferPurged()) { - fail("Buffer should not be purged immediately after initialization"); - return 1; - } - if (!ptr) { - fail("Didn't get a pointer"); - return 1; - } + EXPECT_FALSE(ptr.WasBufferPurged()) + << "Buffer should not be purged immediately after initialization"; + EXPECT_TRUE(ptr) << "Couldn't get pointer from VolatileBufferPtr"; { VolatileBufferPtr<char> ptr2(buf); - if (ptr2.WasBufferPurged()) { - fail("Failed to Lock buffer again while currently locked"); - return 1; - } - if (!ptr2) { - fail("Didn't get a pointer on the second lock"); - return 1; - } + EXPECT_FALSE(ptr.WasBufferPurged()) + << "Failed to lock buffer again while currently locked"; + ASSERT_TRUE(ptr2) << "Didn't get a pointer on the second lock"; strcpy(ptr2, teststr); } } { VolatileBufferPtr<char> ptr(buf); - if (ptr.WasBufferPurged()) { - fail("Buffer was immediately purged after unlock"); - return 1; - } - if (strcmp(ptr, teststr)) { - fail("Buffer failed to retain data after unlock"); - return 1; - } + EXPECT_FALSE(ptr.WasBufferPurged()) + << "Buffer was immediately purged after unlock"; + EXPECT_STREQ(ptr, teststr) << "Buffer failed to retain data after unlock"; } // Test purging if we know how to #if defined(MOZ_WIDGET_GONK) // This also works on Android, but we need root. int fd = open("/" ASHMEM_NAME_DEF, O_RDWR); - if (fd < 0) { - fail("Failed to open ashmem device"); - return 1; - } - if (ioctl(fd, ASHMEM_PURGE_ALL_CACHES, NULL) < 0) { - fail("Failed to purge ashmem caches"); - return 1; - } + + ASSERT_GE(fd, 0) << "Failed to open ashmem device"; + ASSERT_GE(ioctl(fd, ASHMEM_PURGE_ALL_CACHES, NULL), 0) + << "Failed to purge ashmem caches"; #elif defined(XP_DARWIN) int state; vm_purgable_control(mach_task_self(), (vm_address_t)NULL, VM_PURGABLE_PURGE_ALL, &state); #else - return 0; + return; #endif - if (!buf->NonHeapSizeOfExcludingThis()) { - fail("Buffer should not be allocated on heap"); - return 1; + EXPECT_GT(buf->NonHeapSizeOfExcludingThis(), 0ul) + << "Buffer should not be allocated on heap"; + + { + VolatileBufferPtr<char> ptr(buf); + + EXPECT_TRUE(ptr.WasBufferPurged()) + << "Buffer should not be unpurged after forced purge"; + EXPECT_STRNE(ptr, teststr) << "Purge did not actually purge data"; } { VolatileBufferPtr<char> ptr(buf); - if (!ptr.WasBufferPurged()) { - fail("Buffer should not be unpurged after forced purge"); - return 1; - } - if (!strcmp(ptr, teststr)) { - fail("Purge did not actually purge data"); - return 1; - } + EXPECT_FALSE(ptr.WasBufferPurged()) << "Buffer still purged after lock"; } - - { - VolatileBufferPtr<char> ptr(buf); - if (ptr.WasBufferPurged()) { - fail("Buffer still purged after lock"); - return 1; - } - } - - return 0; }
rename from memory/mozalloc/tests/moz.build rename to memory/volatile/tests/moz.build --- a/memory/mozalloc/tests/moz.build +++ b/memory/volatile/tests/moz.build @@ -1,9 +1,13 @@ # -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*- # vim: set filetype=python: # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. -GeckoCppUnitTests([ - 'TestVolatileBuffer', -]) +UNIFIED_SOURCES = [ + 'TestVolatileBuffer.cpp', +] + +FINAL_LIBRARY = 'xul-gtest' + +FAIL_ON_WARNINGS = True
--- a/moz.build +++ b/moz.build @@ -39,16 +39,17 @@ if not CONFIG['LIBXUL_SDK']: DIRS += ['other-licenses/android'] if CONFIG['MOZ_MEMORY']: DIRS += ['memory'] DIRS += [ 'mozglue', 'memory/mozalloc', + 'memory/volatile', ] if not CONFIG['JS_STANDALONE']: DIRS += ['xpcom/xpidl'] if CONFIG['COMPILE_ENVIRONMENT'] and not CONFIG['LIBXUL_SDK']: DIRS += ['config/external/nspr']