Revision: 22911
Author: [email protected]
Date: Wed Aug 6 09:35:21 2014 UTC
Log: Refactor unit tests for the base library to use GTest.
TEST=base-unittests
BUG=v8:3489
LOG=y
[email protected], [email protected]
Review URL: https://codereview.chromium.org/448603002
http://code.google.com/p/v8/source/detail?r=22911
Added:
/branches/bleeding_edge/test/base-unittests
/branches/bleeding_edge/test/base-unittests/DEPS
/branches/bleeding_edge/test/base-unittests/base-unittests.gyp
/branches/bleeding_edge/test/base-unittests/base-unittests.status
/branches/bleeding_edge/test/base-unittests/cpu-unittest.cc
/branches/bleeding_edge/test/base-unittests/platform
/branches/bleeding_edge/test/base-unittests/platform/condition-variable-unittest.cc
/branches/bleeding_edge/test/base-unittests/platform/mutex-unittest.cc
/branches/bleeding_edge/test/base-unittests/platform/platform-unittest.cc
/branches/bleeding_edge/test/base-unittests/platform/time-unittest.cc
/branches/bleeding_edge/test/base-unittests/testcfg.py
/branches/bleeding_edge/test/base-unittests/utils
/branches/bleeding_edge/test/base-unittests/utils/random-number-generator-unittest.cc
Deleted:
/branches/bleeding_edge/test/cctest/test-condition-variable.cc
/branches/bleeding_edge/test/cctest/test-cpu-ia32.cc
/branches/bleeding_edge/test/cctest/test-cpu-x64.cc
/branches/bleeding_edge/test/cctest/test-cpu-x87.cc
/branches/bleeding_edge/test/cctest/test-cpu.cc
/branches/bleeding_edge/test/cctest/test-mutex.cc
/branches/bleeding_edge/test/cctest/test-platform-macos.cc
/branches/bleeding_edge/test/cctest/test-platform-tls.cc
/branches/bleeding_edge/test/cctest/test-time.cc
Modified:
/branches/bleeding_edge/build/all.gyp
/branches/bleeding_edge/test/cctest/cctest.gyp
/branches/bleeding_edge/test/cctest/test-platform-linux.cc
/branches/bleeding_edge/test/cctest/test-platform-win32.cc
/branches/bleeding_edge/test/cctest/test-random-number-generator.cc
/branches/bleeding_edge/test/cctest/test-threads.cc
/branches/bleeding_edge/tools/presubmit.py
/branches/bleeding_edge/tools/run-tests.py
=======================================
--- /dev/null
+++ /branches/bleeding_edge/test/base-unittests/DEPS Wed Aug 6 09:35:21
2014 UTC
@@ -0,0 +1,8 @@
+include_rules = [
+ "-include",
+ "+include/v8config.h",
+ "+include/v8stdint.h",
+ "-src",
+ "+src/base",
+ "+testing",
+]
=======================================
--- /dev/null
+++ /branches/bleeding_edge/test/base-unittests/base-unittests.gyp Wed Aug
6 09:35:21 2014 UTC
@@ -0,0 +1,32 @@
+# Copyright 2014 the V8 project authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+{
+ 'variables': {
+ 'v8_code': 1,
+ },
+ 'includes': ['../../build/toolchain.gypi', '../../build/features.gypi'],
+ 'targets': [
+ {
+ 'target_name': 'base-unittests',
+ 'type': 'executable',
+ 'dependencies': [
+ '../../testing/gmock.gyp:gmock_main',
+ '../../testing/gtest.gyp:gtest',
+ '../../tools/gyp/v8.gyp:v8_libbase',
+ ],
+ 'include_dirs': [
+ '../..',
+ ],
+ 'sources': [ ### gcmole(all) ###
+ 'cpu-unittest.cc',
+ 'platform/condition-variable-unittest.cc',
+ 'platform/mutex-unittest.cc',
+ 'platform/platform-unittest.cc',
+ 'platform/time-unittest.cc',
+ 'utils/random-number-generator-unittest.cc',
+ ],
+ },
+ ],
+}
=======================================
--- /dev/null
+++ /branches/bleeding_edge/test/base-unittests/base-unittests.status Wed
Aug 6 09:35:21 2014 UTC
@@ -0,0 +1,6 @@
+# Copyright 2014 the V8 project authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+[
+]
=======================================
--- /dev/null
+++ /branches/bleeding_edge/test/base-unittests/cpu-unittest.cc Wed Aug 6
09:35:21 2014 UTC
@@ -0,0 +1,49 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "src/base/cpu.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace v8 {
+namespace base {
+
+TEST(CPUTest, FeatureImplications) {
+ CPU cpu;
+
+ // ia32 and x64 features
+ EXPECT_TRUE(!cpu.has_sse() || cpu.has_mmx());
+ EXPECT_TRUE(!cpu.has_sse2() || cpu.has_sse());
+ EXPECT_TRUE(!cpu.has_sse3() || cpu.has_sse2());
+ EXPECT_TRUE(!cpu.has_ssse3() || cpu.has_sse3());
+ EXPECT_TRUE(!cpu.has_sse41() || cpu.has_sse3());
+ EXPECT_TRUE(!cpu.has_sse42() || cpu.has_sse41());
+
+ // arm features
+ EXPECT_TRUE(!cpu.has_vfp3_d32() || cpu.has_vfp3());
+}
+
+
+TEST(CPUTest, RequiredFeatures) {
+ CPU cpu;
+
+#if V8_HOST_ARCH_ARM
+ EXPECT_TRUE(cpu.has_fpu());
+#endif
+
+#if V8_HOST_ARCH_IA32
+ EXPECT_TRUE(cpu.has_fpu());
+ EXPECT_TRUE(cpu.has_sahf());
+#endif
+
+#if V8_HOST_ARCH_X64
+ EXPECT_TRUE(cpu.has_fpu());
+ EXPECT_TRUE(cpu.has_cmov());
+ EXPECT_TRUE(cpu.has_mmx());
+ EXPECT_TRUE(cpu.has_sse());
+ EXPECT_TRUE(cpu.has_sse2());
+#endif
+}
+
+} // namespace base
+} // namespace v8
=======================================
--- /dev/null
+++
/branches/bleeding_edge/test/base-unittests/platform/condition-variable-unittest.cc
Wed Aug 6 09:35:21 2014 UTC
@@ -0,0 +1,296 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "src/base/platform/condition-variable.h"
+
+#include "src/base/platform/platform.h"
+#include "src/base/platform/time.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace v8 {
+namespace base {
+
+TEST(ConditionVariable, WaitForAfterNofityOnSameThread) {
+ for (int n = 0; n < 10; ++n) {
+ Mutex mutex;
+ ConditionVariable cv;
+
+ LockGuard<Mutex> lock_guard(&mutex);
+
+ cv.NotifyOne();
+ EXPECT_FALSE(cv.WaitFor(&mutex, TimeDelta::FromMicroseconds(n)));
+
+ cv.NotifyAll();
+ EXPECT_FALSE(cv.WaitFor(&mutex, TimeDelta::FromMicroseconds(n)));
+ }
+}
+
+
+namespace {
+
+class ThreadWithMutexAndConditionVariable V8_FINAL : public Thread {
+ public:
+ ThreadWithMutexAndConditionVariable()
+ : Thread("ThreadWithMutexAndConditionVariable"),
+ running_(false), finished_(false) {}
+ virtual ~ThreadWithMutexAndConditionVariable() {}
+
+ virtual void Run() V8_OVERRIDE {
+ LockGuard<Mutex> lock_guard(&mutex_);
+ running_ = true;
+ cv_.NotifyOne();
+ while (running_) {
+ cv_.Wait(&mutex_);
+ }
+ finished_ = true;
+ cv_.NotifyAll();
+ }
+
+ bool running_;
+ bool finished_;
+ ConditionVariable cv_;
+ Mutex mutex_;
+};
+
+}
+
+
+TEST(ConditionVariable, MultipleThreadsWithSeparateConditionVariables) {
+ static const int kThreadCount = 128;
+ ThreadWithMutexAndConditionVariable threads[kThreadCount];
+
+ for (int n = 0; n < kThreadCount; ++n) {
+ LockGuard<Mutex> lock_guard(&threads[n].mutex_);
+ EXPECT_FALSE(threads[n].running_);
+ EXPECT_FALSE(threads[n].finished_);
+ threads[n].Start();
+ // Wait for nth thread to start.
+ while (!threads[n].running_) {
+ threads[n].cv_.Wait(&threads[n].mutex_);
+ }
+ }
+
+ for (int n = kThreadCount - 1; n >= 0; --n) {
+ LockGuard<Mutex> lock_guard(&threads[n].mutex_);
+ EXPECT_TRUE(threads[n].running_);
+ EXPECT_FALSE(threads[n].finished_);
+ }
+
+ for (int n = 0; n < kThreadCount; ++n) {
+ LockGuard<Mutex> lock_guard(&threads[n].mutex_);
+ EXPECT_TRUE(threads[n].running_);
+ EXPECT_FALSE(threads[n].finished_);
+ // Tell the nth thread to quit.
+ threads[n].running_ = false;
+ threads[n].cv_.NotifyOne();
+ }
+
+ for (int n = kThreadCount - 1; n >= 0; --n) {
+ // Wait for nth thread to quit.
+ LockGuard<Mutex> lock_guard(&threads[n].mutex_);
+ while (!threads[n].finished_) {
+ threads[n].cv_.Wait(&threads[n].mutex_);
+ }
+ EXPECT_FALSE(threads[n].running_);
+ EXPECT_TRUE(threads[n].finished_);
+ }
+
+ for (int n = 0; n < kThreadCount; ++n) {
+ threads[n].Join();
+ LockGuard<Mutex> lock_guard(&threads[n].mutex_);
+ EXPECT_FALSE(threads[n].running_);
+ EXPECT_TRUE(threads[n].finished_);
+ }
+}
+
+
+namespace {
+
+class ThreadWithSharedMutexAndConditionVariable V8_FINAL : public Thread {
+ public:
+ ThreadWithSharedMutexAndConditionVariable()
+ : Thread("ThreadWithSharedMutexAndConditionVariable"),
+ running_(false), finished_(false), cv_(NULL), mutex_(NULL) {}
+ virtual ~ThreadWithSharedMutexAndConditionVariable() {}
+
+ virtual void Run() V8_OVERRIDE {
+ LockGuard<Mutex> lock_guard(mutex_);
+ running_ = true;
+ cv_->NotifyAll();
+ while (running_) {
+ cv_->Wait(mutex_);
+ }
+ finished_ = true;
+ cv_->NotifyAll();
+ }
+
+ bool running_;
+ bool finished_;
+ ConditionVariable* cv_;
+ Mutex* mutex_;
+};
+
+}
+
+
+TEST(ConditionVariable,
MultipleThreadsWithSharedSeparateConditionVariables) {
+ static const int kThreadCount = 128;
+ ThreadWithSharedMutexAndConditionVariable threads[kThreadCount];
+ ConditionVariable cv;
+ Mutex mutex;
+
+ for (int n = 0; n < kThreadCount; ++n) {
+ threads[n].mutex_ = &mutex;
+ threads[n].cv_ = &cv;
+ }
+
+ // Start all threads.
+ {
+ LockGuard<Mutex> lock_guard(&mutex);
+ for (int n = 0; n < kThreadCount; ++n) {
+ EXPECT_FALSE(threads[n].running_);
+ EXPECT_FALSE(threads[n].finished_);
+ threads[n].Start();
+ }
+ }
+
+ // Wait for all threads to start.
+ {
+ LockGuard<Mutex> lock_guard(&mutex);
+ for (int n = kThreadCount - 1; n >= 0; --n) {
+ while (!threads[n].running_) {
+ cv.Wait(&mutex);
+ }
+ }
+ }
+
+ // Make sure that all threads are running.
+ {
+ LockGuard<Mutex> lock_guard(&mutex);
+ for (int n = 0; n < kThreadCount; ++n) {
+ EXPECT_TRUE(threads[n].running_);
+ EXPECT_FALSE(threads[n].finished_);
+ }
+ }
+
+ // Tell all threads to quit.
+ {
+ LockGuard<Mutex> lock_guard(&mutex);
+ for (int n = kThreadCount - 1; n >= 0; --n) {
+ EXPECT_TRUE(threads[n].running_);
+ EXPECT_FALSE(threads[n].finished_);
+ // Tell the nth thread to quit.
+ threads[n].running_ = false;
+ }
+ cv.NotifyAll();
+ }
+
+ // Wait for all threads to quit.
+ {
+ LockGuard<Mutex> lock_guard(&mutex);
+ for (int n = 0; n < kThreadCount; ++n) {
+ while (!threads[n].finished_) {
+ cv.Wait(&mutex);
+ }
+ }
+ }
+
+ // Make sure all threads are finished.
+ {
+ LockGuard<Mutex> lock_guard(&mutex);
+ for (int n = kThreadCount - 1; n >= 0; --n) {
+ EXPECT_FALSE(threads[n].running_);
+ EXPECT_TRUE(threads[n].finished_);
+ }
+ }
+
+ // Join all threads.
+ for (int n = 0; n < kThreadCount; ++n) {
+ threads[n].Join();
+ }
+}
+
+
+namespace {
+
+class LoopIncrementThread V8_FINAL : public Thread {
+ public:
+ LoopIncrementThread(int rem,
+ int* counter,
+ int limit,
+ int thread_count,
+ ConditionVariable* cv,
+ Mutex* mutex)
+ : Thread("LoopIncrementThread"), rem_(rem), counter_(counter),
+ limit_(limit), thread_count_(thread_count), cv_(cv), mutex_(mutex)
{
+ EXPECT_LT(rem, thread_count);
+ EXPECT_EQ(0, limit % thread_count);
+ }
+
+ virtual void Run() V8_OVERRIDE {
+ int last_count = -1;
+ while (true) {
+ LockGuard<Mutex> lock_guard(mutex_);
+ int count = *counter_;
+ while (count % thread_count_ != rem_ && count < limit_) {
+ cv_->Wait(mutex_);
+ count = *counter_;
+ }
+ if (count >= limit_) break;
+ EXPECT_EQ(*counter_, count);
+ if (last_count != -1) {
+ EXPECT_EQ(last_count + (thread_count_ - 1), count);
+ }
+ count++;
+ *counter_ = count;
+ last_count = count;
+ cv_->NotifyAll();
+ }
+ }
+
+ private:
+ const int rem_;
+ int* counter_;
+ const int limit_;
+ const int thread_count_;
+ ConditionVariable* cv_;
+ Mutex* mutex_;
+};
+
+}
+
+
+TEST(ConditionVariable, LoopIncrement) {
+ static const int kMaxThreadCount = 16;
+ Mutex mutex;
+ ConditionVariable cv;
+ for (int thread_count = 1; thread_count < kMaxThreadCount;
++thread_count) {
+ int limit = thread_count * 10;
+ int counter = 0;
+
+ // Setup the threads.
+ Thread** threads = new Thread*[thread_count];
+ for (int n = 0; n < thread_count; ++n) {
+ threads[n] = new LoopIncrementThread(
+ n, &counter, limit, thread_count, &cv, &mutex);
+ }
+
+ // Start all threads.
+ for (int n = thread_count - 1; n >= 0; --n) {
+ threads[n]->Start();
+ }
+
+ // Join and cleanup all threads.
+ for (int n = 0; n < thread_count; ++n) {
+ threads[n]->Join();
+ delete threads[n];
+ }
+ delete[] threads;
+
+ EXPECT_EQ(limit, counter);
+ }
+}
+
+} // namespace base
+} // namespace v8
=======================================
--- /dev/null
+++ /branches/bleeding_edge/test/base-unittests/platform/mutex-unittest.cc
Wed Aug 6 09:35:21 2014 UTC
@@ -0,0 +1,91 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "src/base/platform/mutex.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace v8 {
+namespace base {
+
+TEST(Mutex, LockGuardMutex) {
+ Mutex mutex;
+ { LockGuard<Mutex> lock_guard(&mutex); }
+ { LockGuard<Mutex> lock_guard(&mutex); }
+}
+
+
+TEST(Mutex, LockGuardRecursiveMutex) {
+ RecursiveMutex recursive_mutex;
+ { LockGuard<RecursiveMutex> lock_guard(&recursive_mutex); }
+ {
+ LockGuard<RecursiveMutex> lock_guard1(&recursive_mutex);
+ LockGuard<RecursiveMutex> lock_guard2(&recursive_mutex);
+ }
+}
+
+
+TEST(Mutex, LockGuardLazyMutex) {
+ LazyMutex lazy_mutex = LAZY_MUTEX_INITIALIZER;
+ { LockGuard<Mutex> lock_guard(lazy_mutex.Pointer()); }
+ { LockGuard<Mutex> lock_guard(lazy_mutex.Pointer()); }
+}
+
+
+TEST(Mutex, LockGuardLazyRecursiveMutex) {
+ LazyRecursiveMutex lazy_recursive_mutex =
LAZY_RECURSIVE_MUTEX_INITIALIZER;
+ { LockGuard<RecursiveMutex> lock_guard(lazy_recursive_mutex.Pointer()); }
+ {
+ LockGuard<RecursiveMutex> lock_guard1(lazy_recursive_mutex.Pointer());
+ LockGuard<RecursiveMutex> lock_guard2(lazy_recursive_mutex.Pointer());
+ }
+}
+
+
+TEST(Mutex, MultipleMutexes) {
+ Mutex mutex1;
+ Mutex mutex2;
+ Mutex mutex3;
+ // Order 1
+ mutex1.Lock();
+ mutex2.Lock();
+ mutex3.Lock();
+ mutex1.Unlock();
+ mutex2.Unlock();
+ mutex3.Unlock();
+ // Order 2
+ mutex1.Lock();
+ mutex2.Lock();
+ mutex3.Lock();
+ mutex3.Unlock();
+ mutex2.Unlock();
+ mutex1.Unlock();
+}
+
+
+TEST(Mutex, MultipleRecursiveMutexes) {
+ RecursiveMutex recursive_mutex1;
+ RecursiveMutex recursive_mutex2;
+ // Order 1
+ recursive_mutex1.Lock();
+ recursive_mutex2.Lock();
+ EXPECT_TRUE(recursive_mutex1.TryLock());
+ EXPECT_TRUE(recursive_mutex2.TryLock());
+ recursive_mutex1.Unlock();
+ recursive_mutex1.Unlock();
+ recursive_mutex2.Unlock();
+ recursive_mutex2.Unlock();
+ // Order 2
+ recursive_mutex1.Lock();
+ EXPECT_TRUE(recursive_mutex1.TryLock());
+ recursive_mutex2.Lock();
+ EXPECT_TRUE(recursive_mutex2.TryLock());
+ recursive_mutex2.Unlock();
+ recursive_mutex1.Unlock();
+ recursive_mutex2.Unlock();
+ recursive_mutex1.Unlock();
+}
+
+} // namespace base
+} // namespace v8
=======================================
--- /dev/null
+++
/branches/bleeding_edge/test/base-unittests/platform/platform-unittest.cc
Wed Aug 6 09:35:21 2014 UTC
@@ -0,0 +1,115 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "src/base/platform/platform.h"
+
+#if V8_OS_POSIX
+#include <unistd.h> // NOLINT
+#endif
+
+#if V8_OS_WIN
+#include "src/base/win32-headers.h"
+#endif
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace v8 {
+namespace base {
+
+TEST(OS, GetCurrentProcessId) {
+#if V8_OS_POSIX
+ EXPECT_EQ(static_cast<int>(getpid()), OS::GetCurrentProcessId());
+#endif
+
+#if V8_OS_WIN
+ EXPECT_EQ(static_cast<int>(::GetCurrentProcessId()),
+ OS::GetCurrentProcessId());
+#endif
+}
+
+
+TEST(OS, NumberOfProcessorsOnline) {
+ EXPECT_GT(OS::NumberOfProcessorsOnline(), 0);
+}
+
+
+namespace {
+
+class SelfJoinThread V8_FINAL : public Thread {
+ public:
+ SelfJoinThread() : Thread("SelfJoinThread") {}
+ virtual void Run() V8_OVERRIDE { Join(); }
+};
+
+}
+
+
+TEST(Thread, SelfJoin) {
+ SelfJoinThread thread;
+ thread.Start();
+ thread.Join();
+}
+
+
+namespace {
+
+class ThreadLocalStorageTest : public Thread, public ::testing::Test {
+ public:
+ ThreadLocalStorageTest() : Thread("ThreadLocalStorageTest") {
+ for (size_t i = 0; i < ARRAY_SIZE(keys_); ++i) {
+ keys_[i] = Thread::CreateThreadLocalKey();
+ }
+ }
+ ~ThreadLocalStorageTest() {
+ for (size_t i = 0; i < ARRAY_SIZE(keys_); ++i) {
+ Thread::DeleteThreadLocalKey(keys_[i]);
+ }
+ }
+
+ virtual void Run() V8_FINAL V8_OVERRIDE {
+ for (size_t i = 0; i < ARRAY_SIZE(keys_); i++) {
+ CHECK(!Thread::HasThreadLocal(keys_[i]));
+ }
+ for (size_t i = 0; i < ARRAY_SIZE(keys_); i++) {
+ Thread::SetThreadLocal(keys_[i], GetValue(i));
+ }
+ for (size_t i = 0; i < ARRAY_SIZE(keys_); i++) {
+ CHECK(Thread::HasThreadLocal(keys_[i]));
+ }
+ for (size_t i = 0; i < ARRAY_SIZE(keys_); i++) {
+ CHECK_EQ(GetValue(i), Thread::GetThreadLocal(keys_[i]));
+ CHECK_EQ(GetValue(i), Thread::GetExistingThreadLocal(keys_[i]));
+ }
+ for (size_t i = 0; i < ARRAY_SIZE(keys_); i++) {
+ Thread::SetThreadLocal(keys_[i], GetValue(ARRAY_SIZE(keys_) - i -
1));
+ }
+ for (size_t i = 0; i < ARRAY_SIZE(keys_); i++) {
+ CHECK(Thread::HasThreadLocal(keys_[i]));
+ }
+ for (size_t i = 0; i < ARRAY_SIZE(keys_); i++) {
+ CHECK_EQ(GetValue(ARRAY_SIZE(keys_) - i - 1),
+ Thread::GetThreadLocal(keys_[i]));
+ CHECK_EQ(GetValue(ARRAY_SIZE(keys_) - i - 1),
+ Thread::GetExistingThreadLocal(keys_[i]));
+ }
+ }
+
+ private:
+ static void* GetValue(size_t x) {
+ return reinterpret_cast<void*>(static_cast<uintptr_t>(x + 1));
+ }
+
+ Thread::LocalStorageKey keys_[256];
+};
+
+}
+
+
+TEST_F(ThreadLocalStorageTest, DoTest) {
+ Run();
+ Start();
+ Join();
+}
+
+} // namespace base
+} // namespace v8
=======================================
--- /dev/null
+++ /branches/bleeding_edge/test/base-unittests/platform/time-unittest.cc
Wed Aug 6 09:35:21 2014 UTC
@@ -0,0 +1,183 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "src/base/platform/time.h"
+
+#if V8_OS_POSIX
+#include <sys/time.h>
+#endif
+
+#if V8_OS_WIN
+#include "src/base/win32-headers.h"
+#endif
+
+#include "src/base/platform/elapsed-timer.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace v8 {
+namespace base {
+
+TEST(TimeDelta, FromAndIn) {
+ EXPECT_EQ(TimeDelta::FromDays(2), TimeDelta::FromHours(48));
+ EXPECT_EQ(TimeDelta::FromHours(3), TimeDelta::FromMinutes(180));
+ EXPECT_EQ(TimeDelta::FromMinutes(2), TimeDelta::FromSeconds(120));
+ EXPECT_EQ(TimeDelta::FromSeconds(2), TimeDelta::FromMilliseconds(2000));
+ EXPECT_EQ(TimeDelta::FromMilliseconds(2),
TimeDelta::FromMicroseconds(2000));
+ EXPECT_EQ(static_cast<int>(13), TimeDelta::FromDays(13).InDays());
+ EXPECT_EQ(static_cast<int>(13), TimeDelta::FromHours(13).InHours());
+ EXPECT_EQ(static_cast<int>(13), TimeDelta::FromMinutes(13).InMinutes());
+ EXPECT_EQ(static_cast<int64_t>(13),
TimeDelta::FromSeconds(13).InSeconds());
+ EXPECT_EQ(13.0, TimeDelta::FromSeconds(13).InSecondsF());
+ EXPECT_EQ(static_cast<int64_t>(13),
+ TimeDelta::FromMilliseconds(13).InMilliseconds());
+ EXPECT_EQ(13.0, TimeDelta::FromMilliseconds(13).InMillisecondsF());
+ EXPECT_EQ(static_cast<int64_t>(13),
+ TimeDelta::FromMicroseconds(13).InMicroseconds());
+}
+
+
+#if V8_OS_MACOSX
+TEST(TimeDelta, MachTimespec) {
+ TimeDelta null = TimeDelta();
+ EXPECT_EQ(null, TimeDelta::FromMachTimespec(null.ToMachTimespec()));
+ TimeDelta delta1 = TimeDelta::FromMilliseconds(42);
+ EXPECT_EQ(delta1, TimeDelta::FromMachTimespec(delta1.ToMachTimespec()));
+ TimeDelta delta2 = TimeDelta::FromDays(42);
+ EXPECT_EQ(delta2, TimeDelta::FromMachTimespec(delta2.ToMachTimespec()));
+}
+#endif
+
+
+TEST(Time, JsTime) {
+ Time t = Time::FromJsTime(700000.3);
+ EXPECT_EQ(700000.3, t.ToJsTime());
+}
+
+
+#if V8_OS_POSIX
+TEST(Time, Timespec) {
+ Time null;
+ EXPECT_TRUE(null.IsNull());
+ EXPECT_EQ(null, Time::FromTimespec(null.ToTimespec()));
+ Time now = Time::Now();
+ EXPECT_EQ(now, Time::FromTimespec(now.ToTimespec()));
+ Time now_sys = Time::NowFromSystemTime();
+ EXPECT_EQ(now_sys, Time::FromTimespec(now_sys.ToTimespec()));
+ Time unix_epoch = Time::UnixEpoch();
+ EXPECT_EQ(unix_epoch, Time::FromTimespec(unix_epoch.ToTimespec()));
+ Time max = Time::Max();
+ EXPECT_TRUE(max.IsMax());
+ EXPECT_EQ(max, Time::FromTimespec(max.ToTimespec()));
+}
+
+
+TEST(Time, Timeval) {
+ Time null;
+ EXPECT_TRUE(null.IsNull());
+ EXPECT_EQ(null, Time::FromTimeval(null.ToTimeval()));
+ Time now = Time::Now();
+ EXPECT_EQ(now, Time::FromTimeval(now.ToTimeval()));
+ Time now_sys = Time::NowFromSystemTime();
+ EXPECT_EQ(now_sys, Time::FromTimeval(now_sys.ToTimeval()));
+ Time unix_epoch = Time::UnixEpoch();
+ EXPECT_EQ(unix_epoch, Time::FromTimeval(unix_epoch.ToTimeval()));
+ Time max = Time::Max();
+ EXPECT_TRUE(max.IsMax());
+ EXPECT_EQ(max, Time::FromTimeval(max.ToTimeval()));
+}
+#endif
+
+
+#if V8_OS_WIN
+TEST(Time, Filetime) {
+ Time null;
+ EXPECT_TRUE(null.IsNull());
+ EXPECT_EQ(null, Time::FromFiletime(null.ToFiletime()));
+ Time now = Time::Now();
+ EXPECT_EQ(now, Time::FromFiletime(now.ToFiletime()));
+ Time now_sys = Time::NowFromSystemTime();
+ EXPECT_EQ(now_sys, Time::FromFiletime(now_sys.ToFiletime()));
+ Time unix_epoch = Time::UnixEpoch();
+ EXPECT_EQ(unix_epoch, Time::FromFiletime(unix_epoch.ToFiletime()));
+ Time max = Time::Max();
+ EXPECT_TRUE(max.IsMax());
+ EXPECT_EQ(max, Time::FromFiletime(max.ToFiletime()));
+}
+#endif
+
+
+namespace {
+
+template <typename T>
+static void ResolutionTest(T (*Now)(), TimeDelta target_granularity) {
+ // We're trying to measure that intervals increment in a VERY small
amount
+ // of time -- according to the specified target granularity.
Unfortunately,
+ // if we happen to have a context switch in the middle of our test, the
+ // context switch could easily exceed our limit. So, we iterate on this
+ // several times. As long as we're able to detect the fine-granularity
+ // timers at least once, then the test has succeeded.
+ static const TimeDelta kExpirationTimeout = TimeDelta::FromSeconds(1);
+ ElapsedTimer timer;
+ timer.Start();
+ TimeDelta delta;
+ do {
+ T start = Now();
+ T now = start;
+ // Loop until we can detect that the clock has changed. Non-HighRes
timers
+ // will increment in chunks, i.e. 15ms. By spinning until we see a
clock
+ // change, we detect the minimum time between measurements.
+ do {
+ now = Now();
+ delta = now - start;
+ } while (now <= start);
+ EXPECT_NE(static_cast<int64_t>(0), delta.InMicroseconds());
+ } while (delta > target_granularity
&& !timer.HasExpired(kExpirationTimeout));
+ EXPECT_LE(delta, target_granularity);
+}
+
+}
+
+
+TEST(Time, NowResolution) {
+ // We assume that Time::Now() has at least 16ms resolution.
+ static const TimeDelta kTargetGranularity =
TimeDelta::FromMilliseconds(16);
+ ResolutionTest<Time>(&Time::Now, kTargetGranularity);
+}
+
+
+TEST(TimeTicks, NowResolution) {
+ // We assume that TimeTicks::Now() has at least 16ms resolution.
+ static const TimeDelta kTargetGranularity =
TimeDelta::FromMilliseconds(16);
+ ResolutionTest<TimeTicks>(&TimeTicks::Now, kTargetGranularity);
+}
+
+
+TEST(TimeTicks, HighResolutionNowResolution) {
+ if (!TimeTicks::IsHighResolutionClockWorking()) return;
+
+ // We assume that TimeTicks::HighResolutionNow() has sub-ms resolution.
+ static const TimeDelta kTargetGranularity =
TimeDelta::FromMilliseconds(1);
+ ResolutionTest<TimeTicks>(&TimeTicks::HighResolutionNow,
kTargetGranularity);
+}
+
+
+TEST(TimeTicks, IsMonotonic) {
+ TimeTicks previous_normal_ticks;
+ TimeTicks previous_highres_ticks;
+ ElapsedTimer timer;
+ timer.Start();
+ while (!timer.HasExpired(TimeDelta::FromMilliseconds(100))) {
+ TimeTicks normal_ticks = TimeTicks::Now();
+ TimeTicks highres_ticks = TimeTicks::HighResolutionNow();
+ EXPECT_GE(normal_ticks, previous_normal_ticks);
+ EXPECT_GE((normal_ticks - previous_normal_ticks).InMicroseconds(), 0);
+ EXPECT_GE(highres_ticks, previous_highres_ticks);
+ EXPECT_GE((highres_ticks - previous_highres_ticks).InMicroseconds(),
0);
+ previous_normal_ticks = normal_ticks;
+ previous_highres_ticks = highres_ticks;
+ }
+}
+
+} // namespace base
+} // namespace v8
=======================================
--- /dev/null
+++ /branches/bleeding_edge/test/base-unittests/testcfg.py Wed Aug 6
09:35:21 2014 UTC
@@ -0,0 +1,51 @@
+# Copyright 2014 the V8 project authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import os
+import shutil
+
+from testrunner.local import commands
+from testrunner.local import testsuite
+from testrunner.local import utils
+from testrunner.objects import testcase
+
+
+class BaseUnitTestsSuite(testsuite.TestSuite):
+ def __init__(self, name, root):
+ super(BaseUnitTestsSuite, self).__init__(name, root)
+
+ def ListTests(self, context):
+ shell = os.path.abspath(os.path.join(context.shell_dir, self.shell()))
+ if utils.IsWindows():
+ shell += ".exe"
+ output = commands.Execute(context.command_prefix +
+ [shell, "--gtest_list_tests"] +
+ context.extra_flags)
+ if output.exit_code != 0:
+ print output.stdout
+ print output.stderr
+ return []
+ tests = []
+ test_case = ''
+ for test_desc in output.stdout.strip().split():
+ if test_desc.endswith('.'):
+ test_case = test_desc
+ else:
+ test = testcase.TestCase(self, test_case + test_desc,
dependency=None)
+ tests.append(test)
+ tests.sort()
+ return tests
+
+ def GetFlagsForTestCase(self, testcase, context):
+ return (testcase.flags + ["--gtest_filter=" + testcase.path] +
+ ["--gtest_random_seed=%s" % context.random_seed] +
+ ["--gtest_print_time=0"] +
+ context.mode_flags)
+
+ def shell(self):
+ return "base-unittests"
+
+
+def GetSuite(name, root):
+ return BaseUnitTestsSuite(name, root)
=======================================
--- /dev/null
+++
/branches/bleeding_edge/test/base-unittests/utils/random-number-generator-unittest.cc
Wed Aug 6 09:35:21 2014 UTC
@@ -0,0 +1,53 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <climits>
+
+#include "src/base/utils/random-number-generator.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace v8 {
+namespace base {
+
+class RandomNumberGeneratorTest : public ::testing::TestWithParam<int> {};
+
+
+static const int kMaxRuns = 12345;
+
+
+TEST_P(RandomNumberGeneratorTest, NextIntWithMaxValue) {
+ RandomNumberGenerator rng(GetParam());
+ for (int max = 1; max <= kMaxRuns; ++max) {
+ int n = rng.NextInt(max);
+ EXPECT_LE(0, n);
+ EXPECT_LT(n, max);
+ }
+}
+
+
+TEST_P(RandomNumberGeneratorTest, NextBooleanReturnsFalseOrTrue) {
+ RandomNumberGenerator rng(GetParam());
+ for (int k = 0; k < kMaxRuns; ++k) {
+ bool b = rng.NextBool();
+ EXPECT_TRUE(b == false || b == true);
+ }
+}
+
+
+TEST_P(RandomNumberGeneratorTest, NextDoubleReturnsValueBetween0And1) {
+ RandomNumberGenerator rng(GetParam());
+ for (int k = 0; k < kMaxRuns; ++k) {
+ double d = rng.NextDouble();
+ EXPECT_LE(0.0, d);
+ EXPECT_LT(d, 1.0);
+ }
+}
+
+
+INSTANTIATE_TEST_CASE_P(RandomSeeds, RandomNumberGeneratorTest,
+ ::testing::Values(INT_MIN, -1, 0, 1, 42, 100,
+ 1234567890, 987654321, INT_MAX));
+
+} // namespace base
+} // namespace v8
=======================================
--- /branches/bleeding_edge/test/cctest/test-condition-variable.cc Mon Jun
30 13:25:46 2014 UTC
+++ /dev/null
@@ -1,307 +0,0 @@
-// 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:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following
-// disclaimer in the documentation and/or other materials provided
-// with the distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived
-// from this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// 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.
-
-#include "src/v8.h"
-
-#include "src/base/platform/condition-variable.h"
-#include "src/base/platform/time.h"
-#include "test/cctest/cctest.h"
-
-using namespace ::v8::internal;
-
-
-TEST(WaitForAfterNofityOnSameThread) {
- for (int n = 0; n < 10; ++n) {
- v8::base::Mutex mutex;
- v8::base::ConditionVariable cv;
-
- v8::base::LockGuard<v8::base::Mutex> lock_guard(&mutex);
-
- cv.NotifyOne();
- CHECK_EQ(false,
- cv.WaitFor(&mutex, v8::base::TimeDelta::FromMicroseconds(n)));
-
- cv.NotifyAll();
- CHECK_EQ(false,
- cv.WaitFor(&mutex, v8::base::TimeDelta::FromMicroseconds(n)));
- }
-}
-
-
-class ThreadWithMutexAndConditionVariable V8_FINAL : public
v8::base::Thread {
- public:
- ThreadWithMutexAndConditionVariable()
- : Thread("ThreadWithMutexAndConditionVariable"),
- running_(false), finished_(false) {}
- virtual ~ThreadWithMutexAndConditionVariable() {}
-
- virtual void Run() V8_OVERRIDE {
- v8::base::LockGuard<v8::base::Mutex> lock_guard(&mutex_);
- running_ = true;
- cv_.NotifyOne();
- while (running_) {
- cv_.Wait(&mutex_);
- }
- finished_ = true;
- cv_.NotifyAll();
- }
-
- bool running_;
- bool finished_;
- v8::base::ConditionVariable cv_;
- v8::base::Mutex mutex_;
-};
-
-
-TEST(MultipleThreadsWithSeparateConditionVariables) {
- static const int kThreadCount = 128;
- ThreadWithMutexAndConditionVariable threads[kThreadCount];
-
- for (int n = 0; n < kThreadCount; ++n) {
- v8::base::LockGuard<v8::base::Mutex> lock_guard(&threads[n].mutex_);
- CHECK(!threads[n].running_);
- CHECK(!threads[n].finished_);
- threads[n].Start();
- // Wait for nth thread to start.
- while (!threads[n].running_) {
- threads[n].cv_.Wait(&threads[n].mutex_);
- }
- }
-
- for (int n = kThreadCount - 1; n >= 0; --n) {
- v8::base::LockGuard<v8::base::Mutex> lock_guard(&threads[n].mutex_);
- CHECK(threads[n].running_);
- CHECK(!threads[n].finished_);
- }
-
- for (int n = 0; n < kThreadCount; ++n) {
- v8::base::LockGuard<v8::base::Mutex> lock_guard(&threads[n].mutex_);
- CHECK(threads[n].running_);
- CHECK(!threads[n].finished_);
- // Tell the nth thread to quit.
- threads[n].running_ = false;
- threads[n].cv_.NotifyOne();
- }
-
- for (int n = kThreadCount - 1; n >= 0; --n) {
- // Wait for nth thread to quit.
- v8::base::LockGuard<v8::base::Mutex> lock_guard(&threads[n].mutex_);
- while (!threads[n].finished_) {
- threads[n].cv_.Wait(&threads[n].mutex_);
- }
- CHECK(!threads[n].running_);
- CHECK(threads[n].finished_);
- }
-
- for (int n = 0; n < kThreadCount; ++n) {
- threads[n].Join();
- v8::base::LockGuard<v8::base::Mutex> lock_guard(&threads[n].mutex_);
- CHECK(!threads[n].running_);
- CHECK(threads[n].finished_);
- }
-}
-
-
-class ThreadWithSharedMutexAndConditionVariable V8_FINAL
- : public v8::base::Thread {
- public:
- ThreadWithSharedMutexAndConditionVariable()
- : Thread("ThreadWithSharedMutexAndConditionVariable"),
- running_(false), finished_(false), cv_(NULL), mutex_(NULL) {}
- virtual ~ThreadWithSharedMutexAndConditionVariable() {}
-
- virtual void Run() V8_OVERRIDE {
- v8::base::LockGuard<v8::base::Mutex> lock_guard(mutex_);
- running_ = true;
- cv_->NotifyAll();
- while (running_) {
- cv_->Wait(mutex_);
- }
- finished_ = true;
- cv_->NotifyAll();
- }
-
- bool running_;
- bool finished_;
- v8::base::ConditionVariable* cv_;
- v8::base::Mutex* mutex_;
-};
-
-
-TEST(MultipleThreadsWithSharedSeparateConditionVariables) {
- static const int kThreadCount = 128;
- ThreadWithSharedMutexAndConditionVariable threads[kThreadCount];
- v8::base::ConditionVariable cv;
- v8::base::Mutex mutex;
-
- for (int n = 0; n < kThreadCount; ++n) {
- threads[n].mutex_ = &mutex;
- threads[n].cv_ = &cv;
- }
-
- // Start all threads.
- {
- v8::base::LockGuard<v8::base::Mutex> lock_guard(&mutex);
- for (int n = 0; n < kThreadCount; ++n) {
- CHECK(!threads[n].running_);
- CHECK(!threads[n].finished_);
- threads[n].Start();
- }
- }
-
- // Wait for all threads to start.
- {
- v8::base::LockGuard<v8::base::Mutex> lock_guard(&mutex);
- for (int n = kThreadCount - 1; n >= 0; --n) {
- while (!threads[n].running_) {
- cv.Wait(&mutex);
- }
- }
- }
-
- // Make sure that all threads are running.
- {
- v8::base::LockGuard<v8::base::Mutex> lock_guard(&mutex);
- for (int n = 0; n < kThreadCount; ++n) {
- CHECK(threads[n].running_);
- CHECK(!threads[n].finished_);
- }
- }
-
- // Tell all threads to quit.
- {
- v8::base::LockGuard<v8::base::Mutex> lock_guard(&mutex);
- for (int n = kThreadCount - 1; n >= 0; --n) {
- CHECK(threads[n].running_);
- CHECK(!threads[n].finished_);
- // Tell the nth thread to quit.
- threads[n].running_ = false;
- }
- cv.NotifyAll();
- }
-
- // Wait for all threads to quit.
- {
- v8::base::LockGuard<v8::base::Mutex> lock_guard(&mutex);
- for (int n = 0; n < kThreadCount; ++n) {
- while (!threads[n].finished_) {
- cv.Wait(&mutex);
- }
- }
- }
-
- // Make sure all threads are finished.
- {
- v8::base::LockGuard<v8::base::Mutex> lock_guard(&mutex);
- for (int n = kThreadCount - 1; n >= 0; --n) {
- CHECK(!threads[n].running_);
- CHECK(threads[n].finished_);
- }
- }
-
- // Join all threads.
- for (int n = 0; n < kThreadCount; ++n) {
- threads[n].Join();
- }
-}
-
-
-class LoopIncrementThread V8_FINAL : public v8::base::Thread {
- public:
- LoopIncrementThread(int rem,
- int* counter,
- int limit,
- int thread_count,
- v8::base::ConditionVariable* cv,
- v8::base::Mutex* mutex)
- : Thread("LoopIncrementThread"), rem_(rem), counter_(counter),
- limit_(limit), thread_count_(thread_count), cv_(cv), mutex_(mutex)
{
- CHECK_LT(rem, thread_count);
- CHECK_EQ(0, limit % thread_count);
- }
-
- virtual void Run() V8_OVERRIDE {
- int last_count = -1;
- while (true) {
- v8::base::LockGuard<v8::base::Mutex> lock_guard(mutex_);
- int count = *counter_;
- while (count % thread_count_ != rem_ && count < limit_) {
- cv_->Wait(mutex_);
- count = *counter_;
- }
- if (count >= limit_) break;
- CHECK_EQ(*counter_, count);
- if (last_count != -1) {
- CHECK_EQ(last_count + (thread_count_ - 1), count);
- }
- count++;
- *counter_ = count;
- last_count = count;
- cv_->NotifyAll();
- }
- }
-
- private:
- const int rem_;
- int* counter_;
- const int limit_;
- const int thread_count_;
- v8::base::ConditionVariable* cv_;
- v8::base::Mutex* mutex_;
-};
-
-
-TEST(LoopIncrement) {
- static const int kMaxThreadCount = 16;
- v8::base::Mutex mutex;
- v8::base::ConditionVariable cv;
- for (int thread_count = 1; thread_count < kMaxThreadCount;
++thread_count) {
- int limit = thread_count * 100;
- int counter = 0;
-
- // Setup the threads.
- v8::base::Thread** threads = new v8::base::Thread*[thread_count];
- for (int n = 0; n < thread_count; ++n) {
- threads[n] = new LoopIncrementThread(
- n, &counter, limit, thread_count, &cv, &mutex);
- }
-
- // Start all threads.
- for (int n = thread_count - 1; n >= 0; --n) {
- threads[n]->Start();
- }
-
- // Join and cleanup all threads.
- for (int n = 0; n < thread_count; ++n) {
- threads[n]->Join();
- delete threads[n];
- }
- delete[] threads;
-
- CHECK_EQ(limit, counter);
- }
-}
=======================================
--- /branches/bleeding_edge/test/cctest/test-cpu-ia32.cc Mon Jun 30
13:25:46 2014 UTC
+++ /dev/null
@@ -1,40 +0,0 @@
-// 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:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following
-// disclaimer in the documentation and/or other materials provided
-// with the distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived
-// from this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// 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.
-
-#include "src/v8.h"
-
-#include "src/base/cpu.h"
-#include "test/cctest/cctest.h"
-
-using namespace v8::internal;
-
-
-TEST(RequiredFeaturesX64) {
- // Test for the features required by every x86 CPU in compat/legacy mode.
- v8::base::CPU cpu;
- CHECK(cpu.has_sahf());
-}
=======================================
--- /branches/bleeding_edge/test/cctest/test-cpu-x64.cc Mon Jun 30 13:25:46
2014 UTC
+++ /dev/null
@@ -1,44 +0,0 @@
-// 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:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following
-// disclaimer in the documentation and/or other materials provided
-// with the distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived
-// from this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// 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.
-
-#include "src/v8.h"
-
-#include "src/base/cpu.h"
-#include "test/cctest/cctest.h"
-
-using namespace v8::internal;
-
-
-TEST(RequiredFeaturesX64) {
- // Test for the features required by every x64 CPU.
- v8::base::CPU cpu;
- CHECK(cpu.has_fpu());
- CHECK(cpu.has_cmov());
- CHECK(cpu.has_mmx());
- CHECK(cpu.has_sse());
- CHECK(cpu.has_sse2());
-}
=======================================
--- /branches/bleeding_edge/test/cctest/test-cpu-x87.cc Mon Jun 30 13:25:46
2014 UTC
+++ /dev/null
@@ -1,40 +0,0 @@
-// 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:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following
-// disclaimer in the documentation and/or other materials provided
-// with the distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived
-// from this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// 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.
-
-#include "src/v8.h"
-
-#include "src/base/cpu.h"
-#include "test/cctest/cctest.h"
-
-using namespace v8::internal;
-
-
-TEST(RequiredFeaturesX64) {
- // Test for the features required by every x86 CPU in compat/legacy mode.
- v8::base::CPU cpu;
- CHECK(cpu.has_sahf());
-}
=======================================
--- /branches/bleeding_edge/test/cctest/test-cpu.cc Mon Jun 30 13:25:46
2014 UTC
+++ /dev/null
@@ -1,55 +0,0 @@
-// 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:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following
-// disclaimer in the documentation and/or other materials provided
-// with the distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived
-// from this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// 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.
-
-#include "src/v8.h"
-
-#include "src/base/cpu.h"
-#include "test/cctest/cctest.h"
-
-using namespace v8::internal;
-
-
-TEST(FeatureImplications) {
- // Test for features implied by other features.
- v8::base::CPU cpu;
-
- // ia32 and x64 features
- CHECK(!cpu.has_sse() || cpu.has_mmx());
- CHECK(!cpu.has_sse2() || cpu.has_sse());
- CHECK(!cpu.has_sse3() || cpu.has_sse2());
- CHECK(!cpu.has_ssse3() || cpu.has_sse3());
- CHECK(!cpu.has_sse41() || cpu.has_sse3());
- CHECK(!cpu.has_sse42() || cpu.has_sse41());
-
- // arm features
- CHECK(!cpu.has_vfp3_d32() || cpu.has_vfp3());
-}
-
-
-TEST(NumberOfProcessorsOnline) {
- CHECK_GT(v8::base::OS::NumberOfProcessorsOnline(), 0);
-}
=======================================
--- /branches/bleeding_edge/test/cctest/test-mutex.cc Mon Jun 30 13:25:46
2014 UTC
+++ /dev/null
@@ -1,124 +0,0 @@
-// 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:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following
-// disclaimer in the documentation and/or other materials provided
-// with the distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived
-// from this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// 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.
-
-#include <cstdlib>
-
-#include "src/v8.h"
-
-#include "src/base/platform/mutex.h"
-#include "test/cctest/cctest.h"
-
-using namespace ::v8::internal;
-
-
-TEST(LockGuardMutex) {
- v8::base::Mutex mutex;
- { v8::base::LockGuard<v8::base::Mutex> lock_guard(&mutex);
- }
- { v8::base::LockGuard<v8::base::Mutex> lock_guard(&mutex);
- }
-}
-
-
-TEST(LockGuardRecursiveMutex) {
- v8::base::RecursiveMutex recursive_mutex;
- { v8::base::LockGuard<v8::base::RecursiveMutex>
lock_guard(&recursive_mutex);
- }
- { v8::base::LockGuard<v8::base::RecursiveMutex>
lock_guard1(&recursive_mutex);
- v8::base::LockGuard<v8::base::RecursiveMutex>
lock_guard2(&recursive_mutex);
- }
-}
-
-
-TEST(LockGuardLazyMutex) {
- v8::base::LazyMutex lazy_mutex = LAZY_MUTEX_INITIALIZER;
- { v8::base::LockGuard<v8::base::Mutex> lock_guard(lazy_mutex.Pointer());
- }
- { v8::base::LockGuard<v8::base::Mutex> lock_guard(lazy_mutex.Pointer());
- }
-}
-
-
-TEST(LockGuardLazyRecursiveMutex) {
- v8::base::LazyRecursiveMutex lazy_recursive_mutex =
- LAZY_RECURSIVE_MUTEX_INITIALIZER;
- {
- v8::base::LockGuard<v8::base::RecursiveMutex> lock_guard(
- lazy_recursive_mutex.Pointer());
- }
- {
- v8::base::LockGuard<v8::base::RecursiveMutex> lock_guard1(
- lazy_recursive_mutex.Pointer());
- v8::base::LockGuard<v8::base::RecursiveMutex> lock_guard2(
- lazy_recursive_mutex.Pointer());
- }
-}
-
-
-TEST(MultipleMutexes) {
- v8::base::Mutex mutex1;
- v8::base::Mutex mutex2;
- v8::base::Mutex mutex3;
- // Order 1
- mutex1.Lock();
- mutex2.Lock();
- mutex3.Lock();
- mutex1.Unlock();
- mutex2.Unlock();
- mutex3.Unlock();
- // Order 2
- mutex1.Lock();
- mutex2.Lock();
- mutex3.Lock();
- mutex3.Unlock();
- mutex2.Unlock();
- mutex1.Unlock();
-}
-
-
-TEST(MultipleRecursiveMutexes) {
- v8::base::RecursiveMutex recursive_mutex1;
- v8::base::RecursiveMutex recursive_mutex2;
- // Order 1
- recursive_mutex1.Lock();
- recursive_mutex2.Lock();
- CHECK(recursive_mutex1.TryLock());
- CHECK(recursive_mutex2.TryLock());
- recursive_mutex1.Unlock();
- recursive_mutex1.Unlock();
- recursive_mutex2.Unlock();
- recursive_mutex2.Unlock();
- // Order 2
- recursive_mutex1.Lock();
- CHECK(recursive_mutex1.TryLock());
- recursive_mutex2.Lock();
- CHECK(recursive_mutex2.TryLock());
- recursive_mutex2.Unlock();
- recursive_mutex1.Unlock();
- recursive_mutex2.Unlock();
- recursive_mutex1.Unlock();
-}
=======================================
--- /branches/bleeding_edge/test/cctest/test-platform-macos.cc Tue Jun 3
08:12:43 2014 UTC
+++ /dev/null
@@ -1,35 +0,0 @@
-// Copyright 2006-2008 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:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following
-// disclaimer in the documentation and/or other materials provided
-// with the distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived
-// from this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// 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 "src/v8.h"
-#include "test/cctest/cctest.h"
-
-using namespace ::v8::internal;
=======================================
--- /branches/bleeding_edge/test/cctest/test-platform-tls.cc Mon Jun 30
13:25:46 2014 UTC
+++ /dev/null
@@ -1,93 +0,0 @@
-// Copyright 2011 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:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following
-// disclaimer in the documentation and/or other materials provided
-// with the distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived
-// from this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// 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 fast TLS support.
-
-#include "src/v8.h"
-
-#include "src/base/logging.h"
-#include "src/base/platform/platform.h"
-#include "test/cctest/cctest.h"
-
-using v8::base::Thread;
-
-static const int kValueCount = 128;
-
-static Thread::LocalStorageKey keys[kValueCount];
-
-static void* GetValue(int num) {
- return reinterpret_cast<void*>(static_cast<intptr_t>(num + 1));
-}
-
-
-static void DoTest() {
- for (int i = 0; i < kValueCount; i++) {
- CHECK(!Thread::HasThreadLocal(keys[i]));
- }
- for (int i = 0; i < kValueCount; i++) {
- Thread::SetThreadLocal(keys[i], GetValue(i));
- }
- for (int i = 0; i < kValueCount; i++) {
- CHECK(Thread::HasThreadLocal(keys[i]));
- }
- for (int i = 0; i < kValueCount; i++) {
- CHECK_EQ(GetValue(i), Thread::GetThreadLocal(keys[i]));
- CHECK_EQ(GetValue(i), Thread::GetExistingThreadLocal(keys[i]));
- }
- for (int i = 0; i < kValueCount; i++) {
- Thread::SetThreadLocal(keys[i], GetValue(kValueCount - i - 1));
- }
- for (int i = 0; i < kValueCount; i++) {
- CHECK(Thread::HasThreadLocal(keys[i]));
- }
- for (int i = 0; i < kValueCount; i++) {
- CHECK_EQ(GetValue(kValueCount - i - 1),
- Thread::GetThreadLocal(keys[i]));
- CHECK_EQ(GetValue(kValueCount - i - 1),
- Thread::GetExistingThreadLocal(keys[i]));
- }
-}
-
-class TestThread : public Thread {
- public:
- TestThread() : Thread("TestThread") {}
-
- virtual void Run() {
- DoTest();
- }
-};
-
-
-TEST(FastTLS) {
- for (int i = 0; i < kValueCount; i++) {
- keys[i] = Thread::CreateThreadLocalKey();
- }
- DoTest();
- TestThread thread;
- thread.Start();
- thread.Join();
-}
=======================================
--- /branches/bleeding_edge/test/cctest/test-time.cc Mon Jun 30 13:25:46
2014 UTC
+++ /dev/null
@@ -1,198 +0,0 @@
-// 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:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following
-// disclaimer in the documentation and/or other materials provided
-// with the distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived
-// from this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// 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.
-
-#include "src/v8.h"
-#include "test/cctest/cctest.h"
-
-#if V8_OS_POSIX
-#include <sys/time.h> // NOLINT
-#endif
-
-#if V8_OS_WIN
-#include "src/base/win32-headers.h"
-#endif
-
-using namespace v8::base;
-using namespace v8::internal;
-
-
-TEST(TimeDeltaFromAndIn) {
- CHECK(TimeDelta::FromDays(2) == TimeDelta::FromHours(48));
- CHECK(TimeDelta::FromHours(3) == TimeDelta::FromMinutes(180));
- CHECK(TimeDelta::FromMinutes(2) == TimeDelta::FromSeconds(120));
- CHECK(TimeDelta::FromSeconds(2) == TimeDelta::FromMilliseconds(2000));
- CHECK(TimeDelta::FromMilliseconds(2) ==
TimeDelta::FromMicroseconds(2000));
- CHECK_EQ(static_cast<int>(13), TimeDelta::FromDays(13).InDays());
- CHECK_EQ(static_cast<int>(13), TimeDelta::FromHours(13).InHours());
- CHECK_EQ(static_cast<int>(13), TimeDelta::FromMinutes(13).InMinutes());
- CHECK_EQ(static_cast<int64_t>(13),
TimeDelta::FromSeconds(13).InSeconds());
- CHECK_EQ(13.0, TimeDelta::FromSeconds(13).InSecondsF());
- CHECK_EQ(static_cast<int64_t>(13),
- TimeDelta::FromMilliseconds(13).InMilliseconds());
- CHECK_EQ(13.0, TimeDelta::FromMilliseconds(13).InMillisecondsF());
- CHECK_EQ(static_cast<int64_t>(13),
- TimeDelta::FromMicroseconds(13).InMicroseconds());
-}
-
-
-#if V8_OS_MACOSX
-TEST(TimeDeltaFromMachTimespec) {
- TimeDelta null = TimeDelta();
- CHECK(null == TimeDelta::FromMachTimespec(null.ToMachTimespec()));
- TimeDelta delta1 = TimeDelta::FromMilliseconds(42);
- CHECK(delta1 == TimeDelta::FromMachTimespec(delta1.ToMachTimespec()));
- TimeDelta delta2 = TimeDelta::FromDays(42);
- CHECK(delta2 == TimeDelta::FromMachTimespec(delta2.ToMachTimespec()));
-}
-#endif
-
-
-TEST(TimeJsTime) {
- Time t = Time::FromJsTime(700000.3);
- CHECK_EQ(700000.3, t.ToJsTime());
-}
-
-
-#if V8_OS_POSIX
-TEST(TimeFromTimespec) {
- Time null;
- CHECK(null.IsNull());
- CHECK(null == Time::FromTimespec(null.ToTimespec()));
- Time now = Time::Now();
- CHECK(now == Time::FromTimespec(now.ToTimespec()));
- Time now_sys = Time::NowFromSystemTime();
- CHECK(now_sys == Time::FromTimespec(now_sys.ToTimespec()));
- Time unix_epoch = Time::UnixEpoch();
- CHECK(unix_epoch == Time::FromTimespec(unix_epoch.ToTimespec()));
- Time max = Time::Max();
- CHECK(max.IsMax());
- CHECK(max == Time::FromTimespec(max.ToTimespec()));
-}
-
-
-TEST(TimeFromTimeval) {
- Time null;
- CHECK(null.IsNull());
- CHECK(null == Time::FromTimeval(null.ToTimeval()));
- Time now = Time::Now();
- CHECK(now == Time::FromTimeval(now.ToTimeval()));
- Time now_sys = Time::NowFromSystemTime();
- CHECK(now_sys == Time::FromTimeval(now_sys.ToTimeval()));
- Time unix_epoch = Time::UnixEpoch();
- CHECK(unix_epoch == Time::FromTimeval(unix_epoch.ToTimeval()));
- Time max = Time::Max();
- CHECK(max.IsMax());
- CHECK(max == Time::FromTimeval(max.ToTimeval()));
-}
-#endif
-
-
-#if V8_OS_WIN
-TEST(TimeFromFiletime) {
- Time null;
- CHECK(null.IsNull());
- CHECK(null == Time::FromFiletime(null.ToFiletime()));
- Time now = Time::Now();
- CHECK(now == Time::FromFiletime(now.ToFiletime()));
- Time now_sys = Time::NowFromSystemTime();
- CHECK(now_sys == Time::FromFiletime(now_sys.ToFiletime()));
- Time unix_epoch = Time::UnixEpoch();
- CHECK(unix_epoch == Time::FromFiletime(unix_epoch.ToFiletime()));
- Time max = Time::Max();
- CHECK(max.IsMax());
- CHECK(max == Time::FromFiletime(max.ToFiletime()));
-}
-#endif
-
-
-TEST(TimeTicksIsMonotonic) {
- TimeTicks previous_normal_ticks;
- TimeTicks previous_highres_ticks;
- ElapsedTimer timer;
- timer.Start();
- while (!timer.HasExpired(TimeDelta::FromMilliseconds(100))) {
- TimeTicks normal_ticks = TimeTicks::Now();
- TimeTicks highres_ticks = TimeTicks::HighResolutionNow();
- CHECK_GE(normal_ticks, previous_normal_ticks);
- CHECK_GE((normal_ticks - previous_normal_ticks).InMicroseconds(), 0);
- CHECK_GE(highres_ticks, previous_highres_ticks);
- CHECK_GE((highres_ticks - previous_highres_ticks).InMicroseconds(), 0);
- previous_normal_ticks = normal_ticks;
- previous_highres_ticks = highres_ticks;
- }
-}
-
-
-template <typename T>
-static void ResolutionTest(T (*Now)(), TimeDelta target_granularity) {
- // We're trying to measure that intervals increment in a VERY small
amount
- // of time -- according to the specified target granularity.
Unfortunately,
- // if we happen to have a context switch in the middle of our test, the
- // context switch could easily exceed our limit. So, we iterate on this
- // several times. As long as we're able to detect the fine-granularity
- // timers at least once, then the test has succeeded.
- static const TimeDelta kExpirationTimeout = TimeDelta::FromSeconds(1);
- ElapsedTimer timer;
- timer.Start();
- TimeDelta delta;
- do {
- T start = Now();
- T now = start;
- // Loop until we can detect that the clock has changed. Non-HighRes
timers
- // will increment in chunks, i.e. 15ms. By spinning until we see a
clock
- // change, we detect the minimum time between measurements.
- do {
- now = Now();
- delta = now - start;
- } while (now <= start);
- CHECK_NE(static_cast<int64_t>(0), delta.InMicroseconds());
- } while (delta > target_granularity
&& !timer.HasExpired(kExpirationTimeout));
- CHECK_LE(delta, target_granularity);
-}
-
-
-TEST(TimeNowResolution) {
- // We assume that Time::Now() has at least 16ms resolution.
- static const TimeDelta kTargetGranularity =
TimeDelta::FromMilliseconds(16);
- ResolutionTest<Time>(&Time::Now, kTargetGranularity);
-}
-
-
-TEST(TimeTicksNowResolution) {
- // We assume that TimeTicks::Now() has at least 16ms resolution.
- static const TimeDelta kTargetGranularity =
TimeDelta::FromMilliseconds(16);
- ResolutionTest<TimeTicks>(&TimeTicks::Now, kTargetGranularity);
-}
-
-
-TEST(TimeTicksHighResolutionNowResolution) {
- if (!TimeTicks::IsHighResolutionClockWorking()) return;
-
- // We assume that TimeTicks::HighResolutionNow() has sub-ms resolution.
- static const TimeDelta kTargetGranularity =
TimeDelta::FromMilliseconds(1);
- ResolutionTest<TimeTicks>(&TimeTicks::HighResolutionNow,
kTargetGranularity);
-}
=======================================
--- /branches/bleeding_edge/build/all.gyp Tue Aug 5 10:16:47 2014 UTC
+++ /branches/bleeding_edge/build/all.gyp Wed Aug 6 09:35:21 2014 UTC
@@ -10,6 +10,7 @@
'dependencies': [
'../samples/samples.gyp:*',
'../src/d8.gyp:d8',
+ '../test/base-unittests/base-unittests.gyp:*',
'../test/cctest/cctest.gyp:*',
],
'conditions': [
=======================================
--- /branches/bleeding_edge/test/cctest/cctest.gyp Tue Aug 5 13:26:55 2014
UTC
+++ /branches/bleeding_edge/test/cctest/cctest.gyp Wed Aug 6 09:35:21 2014
UTC
@@ -100,10 +100,8 @@
'test-checks.cc',
'test-circular-queue.cc',
'test-compiler.cc',
- 'test-condition-variable.cc',
'test-constantpool.cc',
'test-conversions.cc',
- 'test-cpu.cc',
'test-cpu-profiler.cc',
'test-dataflow.cc',
'test-date.cc',
@@ -137,13 +135,11 @@
'test-microtask-delivery.cc',
'test-mark-compact.cc',
'test-mementos.cc',
- 'test-mutex.cc',
'test-object-observe.cc',
'test-ordered-hash-table.cc',
'test-ostreams.cc',
'test-parsing.cc',
'test-platform.cc',
- 'test-platform-tls.cc',
'test-profile-generator.cc',
'test-random-number-generator.cc',
'test-regexp.cc',
@@ -157,7 +153,6 @@
'test-strtod.cc',
'test-thread-termination.cc',
'test-threads.cc',
- 'test-time.cc',
'test-types.cc',
'test-unbound-queue.cc',
'test-unique.cc',
@@ -175,7 +170,6 @@
'test-assembler-ia32.cc',
'test-code-stubs.cc',
'test-code-stubs-ia32.cc',
- 'test-cpu-ia32.cc',
'test-disasm-ia32.cc',
'test-macro-assembler-ia32.cc',
'test-log-stack-tracer.cc'
@@ -186,7 +180,6 @@
'test-assembler-x64.cc',
'test-code-stubs.cc',
'test-code-stubs-x64.cc',
- 'test-cpu-x64.cc',
'test-disasm-x64.cc',
'test-macro-assembler-x64.cc',
'test-log-stack-tracer.cc'
@@ -237,7 +230,6 @@
'test-assembler-x87.cc',
'test-code-stubs.cc',
'test-code-stubs-x87.cc',
- 'test-cpu-x87.cc',
'test-disasm-x87.cc',
'test-macro-assembler-x87.cc',
'test-log-stack-tracer.cc'
@@ -248,11 +240,6 @@
'test-platform-linux.cc',
],
}],
- [ 'OS=="mac"', {
- 'sources': [
- 'test-platform-macos.cc',
- ],
- }],
[ 'OS=="win"', {
'sources': [
'test-platform-win32.cc',
=======================================
--- /branches/bleeding_edge/test/cctest/test-platform-linux.cc Mon Jun 30
13:25:46 2014 UTC
+++ /branches/bleeding_edge/test/cctest/test-platform-linux.cc Wed Aug 6
09:35:21 2014 UTC
@@ -51,8 +51,3 @@
CHECK(vm->Uncommit(block_addr, block_size));
delete vm;
}
-
-
-TEST(GetCurrentProcessId) {
- CHECK_EQ(static_cast<int>(getpid()),
v8::base::OS::GetCurrentProcessId());
-}
=======================================
--- /branches/bleeding_edge/test/cctest/test-platform-win32.cc Mon Jun 30
13:25:46 2014 UTC
+++ /branches/bleeding_edge/test/cctest/test-platform-win32.cc Wed Aug 6
09:35:21 2014 UTC
@@ -50,9 +50,3 @@
CHECK(vm->Uncommit(block_addr, block_size));
delete vm;
}
-
-
-TEST(GetCurrentProcessId) {
- CHECK_EQ(static_cast<int>(::GetCurrentProcessId()),
- v8::base::OS::GetCurrentProcessId());
-}
=======================================
--- /branches/bleeding_edge/test/cctest/test-random-number-generator.cc Mon
Jun 30 13:25:46 2014 UTC
+++ /branches/bleeding_edge/test/cctest/test-random-number-generator.cc Wed
Aug 6 09:35:21 2014 UTC
@@ -40,41 +40,6 @@
};
-TEST(NextIntWithMaxValue) {
- for (unsigned n = 0; n < ARRAY_SIZE(kRandomSeeds); ++n) {
- v8::base::RandomNumberGenerator rng(kRandomSeeds[n]);
- for (int max = 1; max <= kMaxRuns; ++max) {
- int n = rng.NextInt(max);
- CHECK_LE(0, n);
- CHECK_LT(n, max);
- }
- }
-}
-
-
-TEST(NextBoolReturnsBooleanValue) {
- for (unsigned n = 0; n < ARRAY_SIZE(kRandomSeeds); ++n) {
- v8::base::RandomNumberGenerator rng(kRandomSeeds[n]);
- for (int k = 0; k < kMaxRuns; ++k) {
- bool b = rng.NextBool();
- CHECK(b == false || b == true);
- }
- }
-}
-
-
-TEST(NextDoubleRange) {
- for (unsigned n = 0; n < ARRAY_SIZE(kRandomSeeds); ++n) {
- v8::base::RandomNumberGenerator rng(kRandomSeeds[n]);
- for (int k = 0; k < kMaxRuns; ++k) {
- double d = rng.NextDouble();
- CHECK_LE(0.0, d);
- CHECK_LT(d, 1.0);
- }
- }
-}
-
-
TEST(RandomSeedFlagIsUsed) {
for (unsigned n = 0; n < ARRAY_SIZE(kRandomSeeds); ++n) {
FLAG_random_seed = kRandomSeeds[n];
=======================================
--- /branches/bleeding_edge/test/cctest/test-threads.cc Mon Jun 30 13:25:46
2014 UTC
+++ /branches/bleeding_edge/test/cctest/test-threads.cc Wed Aug 6 09:35:21
2014 UTC
@@ -175,19 +175,3 @@
delete threads[i];
}
}
-
-
-class ThreadC : public v8::base::Thread {
- public:
- ThreadC() : Thread("ThreadC") { }
- void Run() {
- Join();
- }
-};
-
-
-TEST(ThreadJoinSelf) {
- ThreadC thread;
- thread.Start();
- thread.Join();
-}
=======================================
--- /branches/bleeding_edge/tools/presubmit.py Wed Aug 6 07:20:14 2014 UTC
+++ /branches/bleeding_edge/tools/presubmit.py Wed Aug 6 09:35:21 2014 UTC
@@ -235,7 +235,9 @@
or (name in CppLintProcessor.IGNORE_LINT))
def GetPathsToSearch(self):
- return ['src', 'include', 'samples', join('test', 'cctest')]
+ return ['src', 'include', 'samples',
+ join('test', 'base-unittests'),
+ join('test', 'cctest')]
def GetCpplintScript(self, prio_path):
for path in [prio_path] + os.environ["PATH"].split(os.pathsep):
=======================================
--- /branches/bleeding_edge/tools/run-tests.py Tue Aug 5 10:16:47 2014 UTC
+++ /branches/bleeding_edge/tools/run-tests.py Wed Aug 6 09:35:21 2014 UTC
@@ -50,7 +50,8 @@
ARCH_GUESS = utils.DefaultArch()
-DEFAULT_TESTS =
["mjsunit", "fuzz-natives", "cctest", "message", "preparser"]
+DEFAULT_TESTS = ["mjsunit", "fuzz-natives", "base-unittests",
+ "cctest", "message", "preparser"]
TIMEOUT_DEFAULT = 60
TIMEOUT_SCALEFACTOR = {"debug" : 4,
"release" : 1 }
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.