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

Side by Side Diff: Source/wtf/PartitionAllocTest.cpp

Issue 23600014: Rename OS(UNIX) to OS(POSIX) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 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 unified diff | Download patch
« no previous file with comments | « Source/wtf/PageAllocator.cpp ('k') | Source/wtf/ProcessID.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 20 matching lines...) Expand all
31 #include "config.h" 31 #include "config.h"
32 #include "wtf/PartitionAlloc.h" 32 #include "wtf/PartitionAlloc.h"
33 33
34 #include "wtf/CryptographicallyRandomNumber.h" 34 #include "wtf/CryptographicallyRandomNumber.h"
35 #include "wtf/OwnArrayPtr.h" 35 #include "wtf/OwnArrayPtr.h"
36 #include "wtf/PageAllocator.h" 36 #include "wtf/PageAllocator.h"
37 #include <gtest/gtest.h> 37 #include <gtest/gtest.h>
38 #include <stdlib.h> 38 #include <stdlib.h>
39 #include <string.h> 39 #include <string.h>
40 40
41 #if OS(UNIX) 41 #if OS(POSIX)
42 #include <sys/mman.h> 42 #include <sys/mman.h>
43 43
44 #ifndef MAP_ANONYMOUS 44 #ifndef MAP_ANONYMOUS
45 #define MAP_ANONYMOUS MAP_ANON 45 #define MAP_ANONYMOUS MAP_ANON
46 #endif 46 #endif
47 #endif // OS(UNIX) 47 #endif // OS(POSIX)
48 48
49 #if !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) 49 #if !defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
50 50
51 namespace { 51 namespace {
52 52
53 static PartitionAllocator<4096> allocator; 53 static PartitionAllocator<4096> allocator;
54 54
55 static const int kTestAllocSize = sizeof(void*); 55 static const int kTestAllocSize = sizeof(void*);
56 56
57 static void RandomNumberSource(unsigned char* buf, size_t len) 57 static void RandomNumberSource(unsigned char* buf, size_t len)
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 newPtr = partitionReallocGeneric(allocator.root(), ptr, PartitionAllocator<4 096>::kMaxAllocation * 2, 1); 435 newPtr = partitionReallocGeneric(allocator.root(), ptr, PartitionAllocator<4 096>::kMaxAllocation * 2, 1);
436 EXPECT_NE(newPtr, ptr); 436 EXPECT_NE(newPtr, ptr);
437 EXPECT_EQ(newPtr, origPtr); 437 EXPECT_EQ(newPtr, origPtr);
438 newCharPtr = static_cast<char*>(newPtr); 438 newCharPtr = static_cast<char*>(newPtr);
439 EXPECT_EQ(*newCharPtr, 'F'); 439 EXPECT_EQ(*newCharPtr, 'F');
440 440
441 partitionFreeGeneric(allocator.root(), newPtr, 1); 441 partitionFreeGeneric(allocator.root(), newPtr, 1);
442 TestShutdown(); 442 TestShutdown();
443 } 443 }
444 444
445 #if OS(UNIX) 445 #if OS(POSIX)
446 446
447 // Test correct handling if our mapping collides with another. 447 // Test correct handling if our mapping collides with another.
448 TEST(WTF_PartitionAlloc, MappingCollision) 448 TEST(WTF_PartitionAlloc, MappingCollision)
449 { 449 {
450 TestSetup(); 450 TestSetup();
451 451
452 WTF::PartitionPageHeader* page1 = GetFullPage(kTestAllocSize); 452 WTF::PartitionPageHeader* page1 = GetFullPage(kTestAllocSize);
453 char* pageBase = reinterpret_cast<char*>(page1); 453 char* pageBase = reinterpret_cast<char*>(page1);
454 // Map a single system page either side of the mapping for our allocations, 454 // Map a single system page either side of the mapping for our allocations,
455 // with the goal of tripping up alignment of the next mapping. 455 // with the goal of tripping up alignment of the next mapping.
456 void* map1 = mmap(pageBase - WTF::kSystemPageSize, WTF::kSystemPageSize, PRO T_NONE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); 456 void* map1 = mmap(pageBase - WTF::kSystemPageSize, WTF::kSystemPageSize, PRO T_NONE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
457 EXPECT_TRUE(map1 && map1 != MAP_FAILED); 457 EXPECT_TRUE(map1 && map1 != MAP_FAILED);
458 void* map2 = mmap(pageBase + WTF::kSuperPageSize, WTF::kSystemPageSize, PROT _NONE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); 458 void* map2 = mmap(pageBase + WTF::kSuperPageSize, WTF::kSystemPageSize, PROT _NONE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
459 EXPECT_TRUE(map2 && map2 != MAP_FAILED); 459 EXPECT_TRUE(map2 && map2 != MAP_FAILED);
460 460
461 WTF::PartitionPageHeader* page2 = GetFullPage(kTestAllocSize); 461 WTF::PartitionPageHeader* page2 = GetFullPage(kTestAllocSize);
462 EXPECT_EQ(0u, reinterpret_cast<uintptr_t>(page2) & WTF::kPartitionPageOffset Mask); 462 EXPECT_EQ(0u, reinterpret_cast<uintptr_t>(page2) & WTF::kPartitionPageOffset Mask);
463 FreeFullPage(page2, kTestAllocSize); 463 FreeFullPage(page2, kTestAllocSize);
464 464
465 FreeFullPage(page1, kTestAllocSize); 465 FreeFullPage(page1, kTestAllocSize);
466 munmap(map1, WTF::kSystemPageSize); 466 munmap(map1, WTF::kSystemPageSize);
467 munmap(map2, WTF::kSystemPageSize); 467 munmap(map2, WTF::kSystemPageSize);
468 468
469 TestShutdown(); 469 TestShutdown();
470 } 470 }
471 471
472 #endif // OS(UNIX) 472 #endif // OS(POSIX)
473 473
474 } // namespace 474 } // namespace
475 475
476 #endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) 476 #endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
OLDNEW
« no previous file with comments | « Source/wtf/PageAllocator.cpp ('k') | Source/wtf/ProcessID.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698