Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(635)

Unified Diff: test/cctest/test-virtual-memory.cc

Issue 23641009: Refactor and cleanup VirtualMemory. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed nits. Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/cctest/test-spaces.cc ('k') | tools/gyp/v8.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-virtual-memory.cc
diff --git a/test/cctest/test-platform-win32.cc b/test/cctest/test-virtual-memory.cc
similarity index 59%
copy from test/cctest/test-platform-win32.cc
copy to test/cctest/test-virtual-memory.cc
index d7fdab11edc7d2f400d0542f69ede59c7e7262ef..d441835b3911e07f5d1069b38933082cd645ca12 100644
--- a/test/cctest/test-platform-win32.cc
+++ b/test/cctest/test-virtual-memory.cc
@@ -1,4 +1,4 @@
-// Copyright 2006-2008 the V8 project authors. All rights reserved.
+// Copyright 2013 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
@@ -24,35 +24,63 @@
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-//
-// Tests of the TokenLock class from lock.h
-
-#include <stdlib.h>
#include "v8.h"
-#include "platform.h"
#include "cctest.h"
-#include "win32-headers.h"
+#include "platform/virtual-memory.h"
using namespace ::v8::internal;
-TEST(VirtualMemory) {
- VirtualMemory* vm = new VirtualMemory(1 * MB);
- CHECK(vm->IsReserved());
- void* block_addr = vm->address();
- size_t block_size = 4 * KB;
- CHECK(vm->Commit(block_addr, block_size, false));
+TEST(CommitAndUncommit) {
+ static const size_t kSize = 1 * MB;
+ static const size_t kBlockSize = 4 * KB;
+ VirtualMemory vm(kSize);
+ CHECK(vm.IsReserved());
+ void* block_addr = vm.address();
+ CHECK(vm.Commit(block_addr, kBlockSize, VirtualMemory::NOT_EXECUTABLE));
// Check whether we can write to memory.
int* addr = static_cast<int*>(block_addr);
- addr[KB-1] = 2;
- CHECK(vm->Uncommit(block_addr, block_size));
- delete vm;
+ addr[5] = 2;
+ CHECK(vm.Uncommit(block_addr, kBlockSize));
+}
+
+
+TEST(Release) {
+ static const size_t kSize = 4 * KB;
+ VirtualMemory vm(kSize);
+ CHECK(vm.IsReserved());
+ CHECK_LE(kSize, vm.size());
+ CHECK_NE(NULL, vm.address());
+ vm.Release();
+ CHECK(!vm.IsReserved());
+}
+
+
+TEST(TakeControl) {
+ static const size_t kSize = 64 * KB;
+
+ VirtualMemory vm1(kSize);
+ size_t size1 = vm1.size();
+ CHECK(vm1.IsReserved());
+ CHECK_LE(kSize, size1);
+
+ VirtualMemory vm2;
+ CHECK(!vm2.IsReserved());
+
+ vm2.TakeControl(&vm1);
+ CHECK(vm2.IsReserved());
+ CHECK(!vm1.IsReserved());
+ CHECK(vm2.size() == size1);
+}
+
+
+TEST(AllocationGranularityIsPowerOf2) {
+ CHECK(IsPowerOf2(VirtualMemory::GetAllocationGranularity()));
}
-TEST(GetCurrentProcessId) {
- CHECK_EQ(static_cast<int>(::GetCurrentProcessId()),
- OS::GetCurrentProcessId());
+TEST(PageSizeIsPowerOf2) {
+ CHECK(IsPowerOf2(VirtualMemory::GetPageSize()));
}
« no previous file with comments | « test/cctest/test-spaces.cc ('k') | tools/gyp/v8.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698