v8  3.11.10(node0.8.26)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test-platform-linux.cc
Go to the documentation of this file.
1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 //
3 // Tests of the TokenLock class from lock.h
4 
5 #include <pthread.h>
6 #include <stdlib.h>
7 #include <unistd.h> // for usleep()
8 
9 #include "v8.h"
10 
11 #include "platform.h"
12 #include "cctest.h"
13 
14 using namespace ::v8::internal;
15 
16 
17 static void yield() {
18  usleep(1);
19 }
20 
21 static const int kLockCounterLimit = 50;
22 static int busy_lock_counter = 0;
23 
24 
25 static void LoopIncrement(Mutex* mutex, int rem) {
26  while (true) {
27  int count = 0;
28  int last_count = -1;
29  do {
30  CHECK_EQ(0, mutex->Lock());
31  count = busy_lock_counter;
32  CHECK_EQ(0, mutex->Unlock());
33  yield();
34  } while (count % 2 == rem && count < kLockCounterLimit);
35  if (count >= kLockCounterLimit) break;
36  CHECK_EQ(0, mutex->Lock());
37  CHECK_EQ(count, busy_lock_counter);
38  CHECK(last_count == -1 || count == last_count + 1);
39  busy_lock_counter++;
40  last_count = count;
41  CHECK_EQ(0, mutex->Unlock());
42  yield();
43  }
44 }
45 
46 
47 static void* RunTestBusyLock(void* arg) {
48  LoopIncrement(static_cast<Mutex*>(arg), 0);
49  return 0;
50 }
51 
52 
53 // Runs two threads that repeatedly acquire the lock and conditionally
54 // increment a variable.
55 TEST(BusyLock) {
56  pthread_t other;
57  Mutex* mutex = OS::CreateMutex();
58  int thread_created = pthread_create(&other,
59  NULL,
60  &RunTestBusyLock,
61  mutex);
62  CHECK_EQ(0, thread_created);
63  LoopIncrement(mutex, 1);
64  pthread_join(other, NULL);
65  delete mutex;
66 }
67 
68 
69 TEST(VirtualMemory) {
70  OS::SetUp();
71  VirtualMemory* vm = new VirtualMemory(1 * MB);
72  CHECK(vm->IsReserved());
73  void* block_addr = vm->address();
74  size_t block_size = 4 * KB;
75  CHECK(vm->Commit(block_addr, block_size, false));
76  // Check whether we can write to memory.
77  int* addr = static_cast<int*>(block_addr);
78  addr[KB-1] = 2;
79  CHECK(vm->Uncommit(block_addr, block_size));
80  delete vm;
81 }
#define CHECK_EQ(expected, value)
Definition: checks.h:219
const int KB
Definition: globals.h:221
TEST(BusyLock)
#define CHECK(condition)
Definition: checks.h:56
const int MB
Definition: d8.cc:124
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination trace on stack replacement optimize closures functions with arguments object optimize functions containing for in loops profiler considers IC stability primitive functions trigger their own optimization re try self optimization if it failed insert an interrupt check at function exit execution budget before interrupt is triggered call count before self optimization self_optimization count_based_interrupts weighted_back_edges trace_opt emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of SAHF instruction if enable use of VFP3 instructions if available this implies enabling ARMv7 enable use of ARMv7 instructions if enable use of MIPS FPU instructions if NULL