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 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 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