v8  3.14.5(node0.10.28)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test-platform-nullos.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  UNIMPLEMENTED();
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  VirtualMemory* vm = new VirtualMemory(1 * MB);
71  CHECK(vm->IsReserved());
72  void* block_addr = vm->address();
73  size_t block_size = 4 * KB;
74  CHECK(vm->Commit(block_addr, block_size, false));
75  // Check whether we can write to memory.
76  int* addr = static_cast<int*>(block_addr);
77  addr[KB-1] = 2;
78  CHECK(vm->Uncommit(block_addr, block_size));
79  delete vm;
80 }
#define CHECK_EQ(expected, value)
Definition: checks.h:219
const int KB
Definition: globals.h:207
#define CHECK(condition)
Definition: checks.h:56
const int MB
Definition: d8.cc:124
#define UNIMPLEMENTED()
Definition: checks.h:48
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 use dead code elimination trace on stack replacement optimize closures cache optimized code for closures functions with arguments object loop weight for representation inference allow uint32 values on optimize frames if they are used only in safe operations track parallel recompilation enable all profiler experiments number of stack frames inspected by the profiler call recompile stub directly when self optimizing trigger profiler ticks based on counting instead of timing weight back edges by jump distance for interrupt triggering percentage of ICs that must have type info to allow optimization watch_ic_patching retry_self_opt interrupt_at_exit extra verbose compilation tracing generate extra 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 and VFP2 enable use of VFP2 instructions if available enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of MIPS FPU instructions if NULL
TEST(BusyLock)