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

Side by Side Diff: test/cctest/test-platform-linux.cc

Issue 21095008: Revert the latest set of platform changes. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « test/cctest/test-mutex.cc ('k') | test/cctest/test-platform-nullos.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 45
46 static const int kLockCounterLimit = 50; 46 static const int kLockCounterLimit = 50;
47 static int busy_lock_counter = 0; 47 static int busy_lock_counter = 0;
48 48
49 49
50 static void LoopIncrement(Mutex* mutex, int rem) { 50 static void LoopIncrement(Mutex* mutex, int rem) {
51 while (true) { 51 while (true) {
52 int count = 0; 52 int count = 0;
53 int last_count = -1; 53 int last_count = -1;
54 do { 54 do {
55 mutex->Lock(); 55 CHECK_EQ(0, mutex->Lock());
56 count = busy_lock_counter; 56 count = busy_lock_counter;
57 mutex->Unlock(); 57 CHECK_EQ(0, mutex->Unlock());
58 yield(); 58 yield();
59 } while (count % 2 == rem && count < kLockCounterLimit); 59 } while (count % 2 == rem && count < kLockCounterLimit);
60 if (count >= kLockCounterLimit) break; 60 if (count >= kLockCounterLimit) break;
61 mutex->Lock(); 61 CHECK_EQ(0, mutex->Lock());
62 CHECK_EQ(count, busy_lock_counter); 62 CHECK_EQ(count, busy_lock_counter);
63 CHECK(last_count == -1 || count == last_count + 1); 63 CHECK(last_count == -1 || count == last_count + 1);
64 busy_lock_counter++; 64 busy_lock_counter++;
65 last_count = count; 65 last_count = count;
66 mutex->Unlock(); 66 CHECK_EQ(0, mutex->Unlock());
67 yield(); 67 yield();
68 } 68 }
69 } 69 }
70 70
71 71
72 static void* RunTestBusyLock(void* arg) { 72 static void* RunTestBusyLock(void* arg) {
73 LoopIncrement(static_cast<Mutex*>(arg), 0); 73 LoopIncrement(static_cast<Mutex*>(arg), 0);
74 return 0; 74 return 0;
75 } 75 }
76 76
77 77
78 // Runs two threads that repeatedly acquire the lock and conditionally 78 // Runs two threads that repeatedly acquire the lock and conditionally
79 // increment a variable. 79 // increment a variable.
80 TEST(BusyLock) { 80 TEST(BusyLock) {
81 pthread_t other; 81 pthread_t other;
82 Mutex mutex; 82 Mutex* mutex = OS::CreateMutex();
83 int thread_created = pthread_create(&other, 83 int thread_created = pthread_create(&other,
84 NULL, 84 NULL,
85 &RunTestBusyLock, 85 &RunTestBusyLock,
86 &mutex); 86 mutex);
87 CHECK_EQ(0, thread_created); 87 CHECK_EQ(0, thread_created);
88 LoopIncrement(&mutex, 1); 88 LoopIncrement(mutex, 1);
89 pthread_join(other, NULL); 89 pthread_join(other, NULL);
90 delete mutex;
90 } 91 }
91 92
92 93
93 TEST(VirtualMemory) { 94 TEST(VirtualMemory) {
94 OS::SetUp(); 95 OS::SetUp();
95 VirtualMemory* vm = new VirtualMemory(1 * MB); 96 VirtualMemory* vm = new VirtualMemory(1 * MB);
96 CHECK(vm->IsReserved()); 97 CHECK(vm->IsReserved());
97 void* block_addr = vm->address(); 98 void* block_addr = vm->address();
98 size_t block_size = 4 * KB; 99 size_t block_size = 4 * KB;
99 CHECK(vm->Commit(block_addr, block_size, false)); 100 CHECK(vm->Commit(block_addr, block_size, false));
100 // Check whether we can write to memory. 101 // Check whether we can write to memory.
101 int* addr = static_cast<int*>(block_addr); 102 int* addr = static_cast<int*>(block_addr);
102 addr[KB-1] = 2; 103 addr[KB-1] = 2;
103 CHECK(vm->Uncommit(block_addr, block_size)); 104 CHECK(vm->Uncommit(block_addr, block_size));
104 delete vm; 105 delete vm;
105 } 106 }
106 107
107 108
108 TEST(GetCurrentProcessId) { 109 TEST(GetCurrentProcessId) {
109 OS::SetUp(); 110 OS::SetUp();
110 CHECK_EQ(static_cast<int>(getpid()), OS::GetCurrentProcessId()); 111 CHECK_EQ(static_cast<int>(getpid()), OS::GetCurrentProcessId());
111 } 112 }
OLDNEW
« no previous file with comments | « test/cctest/test-mutex.cc ('k') | test/cctest/test-platform-nullos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698