Commit ef17fe76 authored by bmeurer@chromium.org's avatar bmeurer@chromium.org

Refactor unit tests for the base library to use GTest.

TEST=base-unittests
BUG=v8:3489
LOG=y
R=jochen@chromium.org, svenpanne@chromium.org

Review URL: https://codereview.chromium.org/448603002

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22911 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 6f4aea95
......@@ -10,6 +10,7 @@
'dependencies': [
'../samples/samples.gyp:*',
'../src/d8.gyp:d8',
'../test/base-unittests/base-unittests.gyp:*',
'../test/cctest/cctest.gyp:*',
],
'conditions': [
......
include_rules = [
"-include",
"+include/v8config.h",
"+include/v8stdint.h",
"-src",
"+src/base",
"+testing",
]
# 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',
],
},
],
}
# 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.
[
]
// 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
// 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"
// 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/time.h"
#include "test/cctest/cctest.h"
using namespace ::v8::internal;
#include "src/base/platform/platform.h"
#include "src/base/platform/time.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace v8 {
namespace base {
TEST(WaitForAfterNofityOnSameThread) {
TEST(ConditionVariable, WaitForAfterNofityOnSameThread) {
for (int n = 0; n < 10; ++n) {
v8::base::Mutex mutex;
v8::base::ConditionVariable cv;
Mutex mutex;
ConditionVariable cv;
v8::base::LockGuard<v8::base::Mutex> lock_guard(&mutex);
LockGuard<Mutex> lock_guard(&mutex);
cv.NotifyOne();
CHECK_EQ(false,
cv.WaitFor(&mutex, v8::base::TimeDelta::FromMicroseconds(n)));
EXPECT_FALSE(cv.WaitFor(&mutex, TimeDelta::FromMicroseconds(n)));
cv.NotifyAll();
CHECK_EQ(false,
cv.WaitFor(&mutex, v8::base::TimeDelta::FromMicroseconds(n)));
EXPECT_FALSE(cv.WaitFor(&mutex, TimeDelta::FromMicroseconds(n)));
}
}
class ThreadWithMutexAndConditionVariable V8_FINAL : public v8::base::Thread {
namespace {
class ThreadWithMutexAndConditionVariable V8_FINAL : public Thread {
public:
ThreadWithMutexAndConditionVariable()
: Thread("ThreadWithMutexAndConditionVariable"),
......@@ -60,7 +37,7 @@ class ThreadWithMutexAndConditionVariable V8_FINAL : public v8::base::Thread {
virtual ~ThreadWithMutexAndConditionVariable() {}
virtual void Run() V8_OVERRIDE {
v8::base::LockGuard<v8::base::Mutex> lock_guard(&mutex_);
LockGuard<Mutex> lock_guard(&mutex_);
running_ = true;
cv_.NotifyOne();
while (running_) {
......@@ -72,19 +49,21 @@ class ThreadWithMutexAndConditionVariable V8_FINAL : public v8::base::Thread {
bool running_;
bool finished_;
v8::base::ConditionVariable cv_;
v8::base::Mutex mutex_;
ConditionVariable cv_;
Mutex mutex_;
};
}
TEST(MultipleThreadsWithSeparateConditionVariables) {
TEST(ConditionVariable, 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_);
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_) {
......@@ -93,15 +72,15 @@ TEST(MultipleThreadsWithSeparateConditionVariables) {
}
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_);
LockGuard<Mutex> lock_guard(&threads[n].mutex_);
EXPECT_TRUE(threads[n].running_);
EXPECT_FALSE(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_);
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();
......@@ -109,25 +88,26 @@ TEST(MultipleThreadsWithSeparateConditionVariables) {
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_);
LockGuard<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_);
EXPECT_FALSE(threads[n].running_);
EXPECT_TRUE(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_);
LockGuard<Mutex> lock_guard(&threads[n].mutex_);
EXPECT_FALSE(threads[n].running_);
EXPECT_TRUE(threads[n].finished_);
}
}
class ThreadWithSharedMutexAndConditionVariable V8_FINAL
: public v8::base::Thread {
namespace {
class ThreadWithSharedMutexAndConditionVariable V8_FINAL : public Thread {
public:
ThreadWithSharedMutexAndConditionVariable()
: Thread("ThreadWithSharedMutexAndConditionVariable"),
......@@ -135,7 +115,7 @@ class ThreadWithSharedMutexAndConditionVariable V8_FINAL
virtual ~ThreadWithSharedMutexAndConditionVariable() {}
virtual void Run() V8_OVERRIDE {
v8::base::LockGuard<v8::base::Mutex> lock_guard(mutex_);
LockGuard<Mutex> lock_guard(mutex_);
running_ = true;
cv_->NotifyAll();
while (running_) {
......@@ -147,16 +127,18 @@ class ThreadWithSharedMutexAndConditionVariable V8_FINAL
bool running_;
bool finished_;
v8::base::ConditionVariable* cv_;
v8::base::Mutex* mutex_;
ConditionVariable* cv_;
Mutex* mutex_;
};
}
TEST(MultipleThreadsWithSharedSeparateConditionVariables) {
TEST(ConditionVariable, MultipleThreadsWithSharedSeparateConditionVariables) {
static const int kThreadCount = 128;
ThreadWithSharedMutexAndConditionVariable threads[kThreadCount];
v8::base::ConditionVariable cv;
v8::base::Mutex mutex;
ConditionVariable cv;
Mutex mutex;
for (int n = 0; n < kThreadCount; ++n) {
threads[n].mutex_ = &mutex;
......@@ -165,17 +147,17 @@ TEST(MultipleThreadsWithSharedSeparateConditionVariables) {
// Start all threads.
{
v8::base::LockGuard<v8::base::Mutex> lock_guard(&mutex);
LockGuard<Mutex> lock_guard(&mutex);
for (int n = 0; n < kThreadCount; ++n) {
CHECK(!threads[n].running_);
CHECK(!threads[n].finished_);
EXPECT_FALSE(threads[n].running_);
EXPECT_FALSE(threads[n].finished_);
threads[n].Start();
}
}
// Wait for all threads to start.
{
v8::base::LockGuard<v8::base::Mutex> lock_guard(&mutex);
LockGuard<Mutex> lock_guard(&mutex);
for (int n = kThreadCount - 1; n >= 0; --n) {
while (!threads[n].running_) {
cv.Wait(&mutex);
......@@ -185,19 +167,19 @@ TEST(MultipleThreadsWithSharedSeparateConditionVariables) {
// Make sure that all threads are running.
{
v8::base::LockGuard<v8::base::Mutex> lock_guard(&mutex);
LockGuard<Mutex> lock_guard(&mutex);
for (int n = 0; n < kThreadCount; ++n) {
CHECK(threads[n].running_);
CHECK(!threads[n].finished_);
EXPECT_TRUE(threads[n].running_);
EXPECT_FALSE(threads[n].finished_);
}
}
// Tell all threads to quit.
{
v8::base::LockGuard<v8::base::Mutex> lock_guard(&mutex);
LockGuard<Mutex> lock_guard(&mutex);
for (int n = kThreadCount - 1; n >= 0; --n) {
CHECK(threads[n].running_);
CHECK(!threads[n].finished_);
EXPECT_TRUE(threads[n].running_);
EXPECT_FALSE(threads[n].finished_);
// Tell the nth thread to quit.
threads[n].running_ = false;
}
......@@ -206,7 +188,7 @@ TEST(MultipleThreadsWithSharedSeparateConditionVariables) {
// Wait for all threads to quit.
{
v8::base::LockGuard<v8::base::Mutex> lock_guard(&mutex);
LockGuard<Mutex> lock_guard(&mutex);
for (int n = 0; n < kThreadCount; ++n) {
while (!threads[n].finished_) {
cv.Wait(&mutex);
......@@ -216,10 +198,10 @@ TEST(MultipleThreadsWithSharedSeparateConditionVariables) {
// Make sure all threads are finished.
{
v8::base::LockGuard<v8::base::Mutex> lock_guard(&mutex);
LockGuard<Mutex> lock_guard(&mutex);
for (int n = kThreadCount - 1; n >= 0; --n) {
CHECK(!threads[n].running_);
CHECK(threads[n].finished_);
EXPECT_FALSE(threads[n].running_);
EXPECT_TRUE(threads[n].finished_);
}
}
......@@ -230,33 +212,35 @@ TEST(MultipleThreadsWithSharedSeparateConditionVariables) {
}
class LoopIncrementThread V8_FINAL : public v8::base::Thread {
namespace {
class LoopIncrementThread V8_FINAL : public Thread {
public:
LoopIncrementThread(int rem,
int* counter,
int limit,
int thread_count,
v8::base::ConditionVariable* cv,
v8::base::Mutex* mutex)
ConditionVariable* cv,
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);
EXPECT_LT(rem, thread_count);
EXPECT_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_);
LockGuard<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);
EXPECT_EQ(*counter_, count);
if (last_count != -1) {
CHECK_EQ(last_count + (thread_count_ - 1), count);
EXPECT_EQ(last_count + (thread_count_ - 1), count);
}
count++;
*counter_ = count;
......@@ -270,21 +254,23 @@ class LoopIncrementThread V8_FINAL : public v8::base::Thread {
int* counter_;
const int limit_;
const int thread_count_;
v8::base::ConditionVariable* cv_;
v8::base::Mutex* mutex_;
ConditionVariable* cv_;
Mutex* mutex_;
};
}
TEST(LoopIncrement) {
TEST(ConditionVariable, LoopIncrement) {
static const int kMaxThreadCount = 16;
v8::base::Mutex mutex;
v8::base::ConditionVariable cv;
Mutex mutex;
ConditionVariable cv;
for (int thread_count = 1; thread_count < kMaxThreadCount; ++thread_count) {
int limit = thread_count * 100;
int limit = thread_count * 10;
int counter = 0;
// Setup the threads.
v8::base::Thread** threads = new v8::base::Thread*[thread_count];
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);
......@@ -302,6 +288,9 @@ TEST(LoopIncrement) {
}
delete[] threads;
CHECK_EQ(limit, counter);
EXPECT_EQ(limit, counter);
}
}
} // namespace base
} // namespace v8
// 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
// 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
// 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"
// 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> // NOLINT
#include <sys/time.h>
#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());
#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(TimeDeltaFromMachTimespec) {
TEST(TimeDelta, MachTimespec) {
TimeDelta null = TimeDelta();
CHECK(null == TimeDelta::FromMachTimespec(null.ToMachTimespec()));
EXPECT_EQ(null, TimeDelta::FromMachTimespec(null.ToMachTimespec()));
TimeDelta delta1 = TimeDelta::FromMilliseconds(42);
CHECK(delta1 == TimeDelta::FromMachTimespec(delta1.ToMachTimespec()));
EXPECT_EQ(delta1, TimeDelta::FromMachTimespec(delta1.ToMachTimespec()));
TimeDelta delta2 = TimeDelta::FromDays(42);
CHECK(delta2 == TimeDelta::FromMachTimespec(delta2.ToMachTimespec()));
EXPECT_EQ(delta2, TimeDelta::FromMachTimespec(delta2.ToMachTimespec()));
}
#endif
TEST(TimeJsTime) {
TEST(Time, JsTime) {
Time t = Time::FromJsTime(700000.3);
CHECK_EQ(700000.3, t.ToJsTime());
EXPECT_EQ(700000.3, t.ToJsTime());
}
#if V8_OS_POSIX
TEST(TimeFromTimespec) {
TEST(Time, Timespec) {
Time null;
CHECK(null.IsNull());
CHECK(null == Time::FromTimespec(null.ToTimespec()));
EXPECT_TRUE(null.IsNull());
EXPECT_EQ(null, Time::FromTimespec(null.ToTimespec()));
Time now = Time::Now();
CHECK(now == Time::FromTimespec(now.ToTimespec()));
EXPECT_EQ(now, Time::FromTimespec(now.ToTimespec()));
Time now_sys = Time::NowFromSystemTime();
CHECK(now_sys == Time::FromTimespec(now_sys.ToTimespec()));
EXPECT_EQ(now_sys, Time::FromTimespec(now_sys.ToTimespec()));
Time unix_epoch = Time::UnixEpoch();
CHECK(unix_epoch == Time::FromTimespec(unix_epoch.ToTimespec()));
EXPECT_EQ(unix_epoch, Time::FromTimespec(unix_epoch.ToTimespec()));
Time max = Time::Max();
CHECK(max.IsMax());
CHECK(max == Time::FromTimespec(max.ToTimespec()));
EXPECT_TRUE(max.IsMax());
EXPECT_EQ(max, Time::FromTimespec(max.ToTimespec()));
}
TEST(TimeFromTimeval) {
TEST(Time, Timeval) {
Time null;
CHECK(null.IsNull());
CHECK(null == Time::FromTimeval(null.ToTimeval()));
EXPECT_TRUE(null.IsNull());
EXPECT_EQ(null, Time::FromTimeval(null.ToTimeval()));
Time now = Time::Now();
CHECK(now == Time::FromTimeval(now.ToTimeval()));
EXPECT_EQ(now, Time::FromTimeval(now.ToTimeval()));
Time now_sys = Time::NowFromSystemTime();
CHECK(now_sys == Time::FromTimeval(now_sys.ToTimeval()));
EXPECT_EQ(now_sys, Time::FromTimeval(now_sys.ToTimeval()));
Time unix_epoch = Time::UnixEpoch();
CHECK(unix_epoch == Time::FromTimeval(unix_epoch.ToTimeval()));
EXPECT_EQ(unix_epoch, Time::FromTimeval(unix_epoch.ToTimeval()));
Time max = Time::Max();
CHECK(max.IsMax());
CHECK(max == Time::FromTimeval(max.ToTimeval()));
EXPECT_TRUE(max.IsMax());
EXPECT_EQ(max, Time::FromTimeval(max.ToTimeval()));
}
#endif
#if V8_OS_WIN
TEST(TimeFromFiletime) {
TEST(Time, Filetime) {
Time null;
CHECK(null.IsNull());
CHECK(null == Time::FromFiletime(null.ToFiletime()));
EXPECT_TRUE(null.IsNull());
EXPECT_EQ(null, Time::FromFiletime(null.ToFiletime()));
Time now = Time::Now();
CHECK(now == Time::FromFiletime(now.ToFiletime()));
EXPECT_EQ(now, Time::FromFiletime(now.ToFiletime()));
Time now_sys = Time::NowFromSystemTime();
CHECK(now_sys == Time::FromFiletime(now_sys.ToFiletime()));
EXPECT_EQ(now_sys, Time::FromFiletime(now_sys.ToFiletime()));
Time unix_epoch = Time::UnixEpoch();
CHECK(unix_epoch == Time::FromFiletime(unix_epoch.ToFiletime()));
EXPECT_EQ(unix_epoch, Time::FromFiletime(unix_epoch.ToFiletime()));
Time max = Time::Max();
CHECK(max.IsMax());
CHECK(max == Time::FromFiletime(max.ToFiletime()));
EXPECT_TRUE(max.IsMax());
EXPECT_EQ(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;
}
}
namespace {
template <typename T>
static void ResolutionTest(T (*Now)(), TimeDelta target_granularity) {
......@@ -169,30 +131,53 @@ static void ResolutionTest(T (*Now)(), TimeDelta target_granularity) {
now = Now();
delta = now - start;
} while (now <= start);
CHECK_NE(static_cast<int64_t>(0), delta.InMicroseconds());
EXPECT_NE(static_cast<int64_t>(0), delta.InMicroseconds());
} while (delta > target_granularity && !timer.HasExpired(kExpirationTimeout));
CHECK_LE(delta, target_granularity);
EXPECT_LE(delta, target_granularity);
}
}
TEST(TimeNowResolution) {
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(TimeTicksNowResolution) {
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(TimeTicksHighResolutionNowResolution) {
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
# 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)
// 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
......@@ -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',
......
// 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());
}
// 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());
}
// 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());
}
// 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);
}
// 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();
}
......@@ -51,8 +51,3 @@ TEST(VirtualMemory) {
CHECK(vm->Uncommit(block_addr, block_size));
delete vm;
}
TEST(GetCurrentProcessId) {
CHECK_EQ(static_cast<int>(getpid()), v8::base::OS::GetCurrentProcessId());
}
// 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;
// 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();
}
......@@ -50,9 +50,3 @@ TEST(VirtualMemory) {
CHECK(vm->Uncommit(block_addr, block_size));
delete vm;
}
TEST(GetCurrentProcessId) {
CHECK_EQ(static_cast<int>(::GetCurrentProcessId()),
v8::base::OS::GetCurrentProcessId());
}
......@@ -40,41 +40,6 @@ static const int kRandomSeeds[] = {
};
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];
......
......@@ -175,19 +175,3 @@ TEST(ThreadIdValidation) {
delete threads[i];
}
}
class ThreadC : public v8::base::Thread {
public:
ThreadC() : Thread("ThreadC") { }
void Run() {
Join();
}
};
TEST(ThreadJoinSelf) {
ThreadC thread;
thread.Start();
thread.Join();
}
......@@ -235,7 +235,9 @@ class CppLintProcessor(SourceFileProcessor):
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):
......
......@@ -50,7 +50,8 @@ from testrunner.objects import context
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 }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment