mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1121297 (Part 1) - Move VolatileBuffer into libxul. r=glandium
--HG-- rename : memory/mozalloc/VolatileBuffer.h => memory/volatile/VolatileBuffer.h rename : memory/mozalloc/VolatileBufferAshmem.cpp => memory/volatile/VolatileBufferAshmem.cpp rename : memory/mozalloc/VolatileBufferFallback.cpp => memory/volatile/VolatileBufferFallback.cpp rename : memory/mozalloc/VolatileBufferOSX.cpp => memory/volatile/VolatileBufferOSX.cpp rename : memory/mozalloc/VolatileBufferWindows.cpp => memory/volatile/VolatileBufferWindows.cpp rename : memory/mozalloc/moz.build => memory/volatile/moz.build rename : memory/mozalloc/tests/TestVolatileBuffer.cpp => memory/volatile/tests/TestVolatileBuffer.cpp rename : memory/mozalloc/tests/moz.build => memory/volatile/tests/moz.build
This commit is contained in:
parent
f8e600eaae
commit
b10bbeee4d
2
CLOBBER
2
CLOBBER
@ -22,4 +22,4 @@
|
||||
# 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
|
||||
|
@ -10,7 +10,6 @@ EXPORTS.mozilla += [
|
||||
'mozalloc.h',
|
||||
'mozalloc_abort.h',
|
||||
'mozalloc_oom.h',
|
||||
'VolatileBuffer.h',
|
||||
]
|
||||
|
||||
if CONFIG['MOZ_MSVC_STL_WRAP__RAISE'] or CONFIG['MOZ_MSVC_STL_WRAP__Throw']:
|
||||
@ -40,23 +39,6 @@ UNIFIED_SOURCES += [
|
||||
'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:
|
||||
@ -66,8 +48,6 @@ else:
|
||||
# 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
|
||||
|
@ -1,143 +0,0 @@
|
||||
/* 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 "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)
|
||||
{
|
||||
ScopedXPCOM xpcom("VolatileBufferTests");
|
||||
if (xpcom.failed()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
RefPtr<VolatileBuffer> heapbuf = new VolatileBuffer();
|
||||
if (!heapbuf || !heapbuf->Init(512)) {
|
||||
fail("Failed to initialize VolatileBuffer");
|
||||
return 1;
|
||||
}
|
||||
|
||||
{
|
||||
VolatileBufferPtr<char> ptr(heapbuf);
|
||||
if (ptr.WasBufferPurged()) {
|
||||
fail("Buffer was immediately purged after initialization");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!ptr) {
|
||||
fail("Didn't get a pointer");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
RefPtr<VolatileBuffer> buf = new VolatileBuffer();
|
||||
if (!buf || !buf->Init(16384)) {
|
||||
fail("Failed to initialize VolatileBuffer");
|
||||
return 1;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
#elif defined(XP_DARWIN)
|
||||
int state;
|
||||
vm_purgable_control(mach_task_self(), (vm_address_t)NULL,
|
||||
VM_PURGABLE_PURGE_ALL, &state);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
if (!buf->NonHeapSizeOfExcludingThis()) {
|
||||
fail("Buffer should not be allocated on heap");
|
||||
return 1;
|
||||
}
|
||||
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
VolatileBufferPtr<char> ptr(buf);
|
||||
if (ptr.WasBufferPurged()) {
|
||||
fail("Buffer still purged after lock");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -42,7 +42,7 @@
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
class MOZALLOC_EXPORT VolatileBuffer : public RefCounted<VolatileBuffer>
|
||||
class VolatileBuffer : public RefCounted<VolatileBuffer>
|
||||
{
|
||||
friend class VolatileBufferPtr_base;
|
||||
public:
|
@ -27,9 +27,13 @@ bool VolatileBuffer::Init(size_t aSize, size_t aAlignment)
|
||||
|
||||
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
|
@ -2,10 +2,6 @@
|
||||
* 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"
|
33
memory/volatile/moz.build
Normal file
33
memory/volatile/moz.build
Normal file
@ -0,0 +1,33 @@
|
||||
# -*- 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 += [
|
||||
'VolatileBuffer.h',
|
||||
]
|
||||
|
||||
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',
|
||||
]
|
||||
|
||||
FINAL_LIBRARY = 'xul'
|
||||
|
||||
TEST_DIRS += ['tests']
|
||||
|
||||
FAIL_ON_WARNINGS = True
|
102
memory/volatile/tests/TestVolatileBuffer.cpp
Normal file
102
memory/volatile/tests/TestVolatileBuffer.cpp
Normal file
@ -0,0 +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 "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;
|
||||
|
||||
TEST(VolatileBufferTest, HeapVolatileBuffersWork)
|
||||
{
|
||||
RefPtr<VolatileBuffer> heapbuf = new VolatileBuffer();
|
||||
|
||||
ASSERT_TRUE(heapbuf) << "Failed to create VolatileBuffer";
|
||||
ASSERT_TRUE(heapbuf->Init(512)) << "Failed to initialize VolatileBuffer";
|
||||
|
||||
VolatileBufferPtr<char> ptr(heapbuf);
|
||||
|
||||
EXPECT_FALSE(ptr.WasBufferPurged())
|
||||
<< "Buffer should not be purged immediately after initialization";
|
||||
EXPECT_TRUE(ptr) << "Couldn't get pointer from VolatileBufferPtr";
|
||||
}
|
||||
|
||||
TEST(VolatileBufferTest, RealVolatileBuffersWork)
|
||||
{
|
||||
RefPtr<VolatileBuffer> buf = new VolatileBuffer();
|
||||
|
||||
ASSERT_TRUE(buf) << "Failed to create VolatileBuffer";
|
||||
ASSERT_TRUE(buf->Init(16384)) << "Failed to initialize VolatileBuffer";
|
||||
|
||||
const char teststr[] = "foobar";
|
||||
|
||||
{
|
||||
VolatileBufferPtr<char> ptr(buf);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
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;
|
||||
#endif
|
||||
|
||||
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);
|
||||
|
||||
EXPECT_FALSE(ptr.WasBufferPurged()) << "Buffer still purged after lock";
|
||||
}
|
||||
}
|
@ -4,6 +4,10 @@
|
||||
# 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
|
Loading…
Reference in New Issue
Block a user