Commit 31718c55 authored by bmeurer@chromium.org's avatar bmeurer@chromium.org

Refactor common unit test code.

TEST=compiler-unittests
BUG=v8:3489
LOG=n
R=svenpanne@chromium.org

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

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@23673 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 33e56ef8
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "src/compiler/change-lowering.h" #include "src/compiler/change-lowering.h"
#include "src/compiler/compiler-test-utils.h"
#include "src/compiler/graph-unittest.h" #include "src/compiler/graph-unittest.h"
#include "src/compiler/js-graph.h" #include "src/compiler/js-graph.h"
#include "src/compiler/node-properties-inl.h" #include "src/compiler/node-properties-inl.h"
......
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "src/compiler/common-operator.h" #include "src/compiler/common-operator.h"
#include "src/compiler/compiler-unittests.h"
#include "src/compiler/operator-properties-inl.h" #include "src/compiler/operator-properties-inl.h"
#include "src/test/test-utils.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
...@@ -12,7 +12,7 @@ namespace compiler { ...@@ -12,7 +12,7 @@ namespace compiler {
namespace { namespace {
class CommonOperatorTest : public CompilerTest { class CommonOperatorTest : public TestWithZone {
public: public:
CommonOperatorTest() : common_(zone()) {} CommonOperatorTest() : common_(zone()) {}
virtual ~CommonOperatorTest() {} virtual ~CommonOperatorTest() {}
......
...@@ -2,20 +2,13 @@ ...@@ -2,20 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef V8_COMPILER_UNITTESTS_COMPILER_UNITTESTS_H_ #ifndef V8_COMPILER_COMPILER_TEST_UTILS_H_
#define V8_COMPILER_UNITTESTS_COMPILER_UNITTESTS_H_ #define V8_COMPILER_COMPILER_TEST_UTILS_H_
#include "include/v8.h" #include "testing/gtest/include/gtest/gtest.h"
#include "src/zone.h"
#include "testing/gtest-support.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
// Forward declarations.
class Factory;
namespace compiler { namespace compiler {
// The TARGET_TEST(Case, Name) macro works just like // The TARGET_TEST(Case, Name) macro works just like
...@@ -57,34 +50,8 @@ namespace compiler { ...@@ -57,34 +50,8 @@ namespace compiler {
#define TARGET_TYPED_TEST(Case, Name) TYPED_TEST(Case, DISABLED_##Name) #define TARGET_TYPED_TEST(Case, Name) TYPED_TEST(Case, DISABLED_##Name)
#endif #endif
class CompilerTest : public ::testing::Test {
public:
CompilerTest();
virtual ~CompilerTest();
Factory* factory() const;
Isolate* isolate() const { return reinterpret_cast<Isolate*>(isolate_); }
Zone* zone() { return &zone_; }
static void SetUpTestCase();
static void TearDownTestCase();
private:
static v8::Isolate* isolate_;
v8::Isolate::Scope isolate_scope_;
v8::HandleScope handle_scope_;
v8::Context::Scope context_scope_;
Zone zone_;
};
template <typename T>
class CompilerTestWithParam : public CompilerTest,
public ::testing::WithParamInterface<T> {};
} // namespace compiler } // namespace compiler
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
#endif // V8_COMPILER_UNITTESTS_COMPILER_UNITTESTS_H_ #endif // V8_COMPILER_COMPILER_TEST_UTILS_H_
...@@ -12,9 +12,7 @@ ...@@ -12,9 +12,7 @@
'target_name': 'compiler-unittests', 'target_name': 'compiler-unittests',
'type': 'executable', 'type': 'executable',
'dependencies': [ 'dependencies': [
'../../testing/gmock.gyp:gmock', '../test/test.gyp:run-all-unittests',
'../../testing/gtest.gyp:gtest',
'../../tools/gyp/v8.gyp:v8_libplatform',
], ],
'include_dirs': [ 'include_dirs': [
'../..', '../..',
...@@ -22,8 +20,7 @@ ...@@ -22,8 +20,7 @@
'sources': [ ### gcmole(all) ### 'sources': [ ### gcmole(all) ###
'change-lowering-unittest.cc', 'change-lowering-unittest.cc',
'common-operator-unittest.cc', 'common-operator-unittest.cc',
'compiler-unittests.cc', 'compiler-test-utils.h',
'compiler-unittests.h',
'graph-unittest.cc', 'graph-unittest.cc',
'graph-unittest.h', 'graph-unittest.h',
'instruction-selector-unittest.cc', 'instruction-selector-unittest.cc',
...@@ -53,29 +50,6 @@ ...@@ -53,29 +50,6 @@
'x64/instruction-selector-x64-unittest.cc', 'x64/instruction-selector-x64-unittest.cc',
], ],
}], }],
['component=="shared_library"', {
# compiler-unittests can't be built against a shared library, so we
# need to depend on the underlying static target in that case.
'conditions': [
['v8_use_snapshot=="true"', {
'dependencies': ['../../tools/gyp/v8.gyp:v8_snapshot'],
},
{
'dependencies': [
'../../tools/gyp/v8.gyp:v8_nosnapshot',
],
}],
],
}, {
'dependencies': ['../../tools/gyp/v8.gyp:v8'],
}],
['os_posix == 1', {
# TODO(svenpanne): This is a temporary work-around to fix the warnings
# that show up because we use -std=gnu++0x instead of -std=c++11.
'cflags!': [
'-pedantic',
],
}],
], ],
}, },
], ],
......
...@@ -6,9 +6,9 @@ ...@@ -6,9 +6,9 @@
#define V8_COMPILER_GRAPH_UNITTEST_H_ #define V8_COMPILER_GRAPH_UNITTEST_H_
#include "src/compiler/common-operator.h" #include "src/compiler/common-operator.h"
#include "src/compiler/compiler-unittests.h"
#include "src/compiler/graph.h" #include "src/compiler/graph.h"
#include "src/compiler/machine-operator.h" #include "src/compiler/machine-operator.h"
#include "src/test/test-utils.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
namespace v8 { namespace v8 {
...@@ -24,7 +24,7 @@ namespace compiler { ...@@ -24,7 +24,7 @@ namespace compiler {
using ::testing::Matcher; using ::testing::Matcher;
class GraphTest : public CompilerTest { class GraphTest : public TestWithContext, public TestWithZone {
public: public:
explicit GraphTest(int parameters = 1); explicit GraphTest(int parameters = 1);
virtual ~GraphTest(); virtual ~GraphTest();
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "src/compiler/instruction-selector-unittest.h" #include "src/compiler/instruction-selector-unittest.h"
#include "src/compiler/compiler-test-utils.h"
#include "src/flags.h" #include "src/flags.h"
namespace v8 { namespace v8 {
...@@ -20,6 +21,9 @@ typedef RawMachineAssembler::Label MLabel; ...@@ -20,6 +21,9 @@ typedef RawMachineAssembler::Label MLabel;
InstructionSelectorTest::InstructionSelectorTest() : rng_(FLAG_random_seed) {} InstructionSelectorTest::InstructionSelectorTest() : rng_(FLAG_random_seed) {}
InstructionSelectorTest::~InstructionSelectorTest() {}
InstructionSelectorTest::Stream InstructionSelectorTest::StreamBuilder::Build( InstructionSelectorTest::Stream InstructionSelectorTest::StreamBuilder::Build(
InstructionSelector::Features features, InstructionSelector::Features features,
InstructionSelectorTest::StreamBuilderMode mode) { InstructionSelectorTest::StreamBuilderMode mode) {
......
...@@ -9,18 +9,18 @@ ...@@ -9,18 +9,18 @@
#include <set> #include <set>
#include "src/base/utils/random-number-generator.h" #include "src/base/utils/random-number-generator.h"
#include "src/compiler/compiler-unittests.h"
#include "src/compiler/instruction-selector.h" #include "src/compiler/instruction-selector.h"
#include "src/compiler/raw-machine-assembler.h" #include "src/compiler/raw-machine-assembler.h"
#include "src/test/test-utils.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
namespace compiler { namespace compiler {
class InstructionSelectorTest : public CompilerTest { class InstructionSelectorTest : public TestWithContext, public TestWithZone {
public: public:
InstructionSelectorTest(); InstructionSelectorTest();
virtual ~InstructionSelectorTest() {} virtual ~InstructionSelectorTest();
base::RandomNumberGenerator* rng() { return &rng_; } base::RandomNumberGenerator* rng() { return &rng_; }
......
...@@ -16,7 +16,6 @@ class MachineOperatorReducerTest : public GraphTest { ...@@ -16,7 +16,6 @@ class MachineOperatorReducerTest : public GraphTest {
public: public:
explicit MachineOperatorReducerTest(int num_parameters = 2) explicit MachineOperatorReducerTest(int num_parameters = 2)
: GraphTest(num_parameters), machine_(zone()) {} : GraphTest(num_parameters), machine_(zone()) {}
virtual ~MachineOperatorReducerTest() {}
protected: protected:
Reduction Reduce(Node* node) { Reduction Reduce(Node* node) {
......
...@@ -2,31 +2,32 @@ ...@@ -2,31 +2,32 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "src/compiler/compiler-unittests.h"
#include "src/compiler/machine-operator.h" #include "src/compiler/machine-operator.h"
#include "src/compiler/operator-properties-inl.h" #include "src/compiler/operator-properties-inl.h"
#include "testing/gmock/include/gmock/gmock.h" #include "src/test/test-utils.h"
using testing::IsNull;
namespace v8 { namespace v8 {
namespace internal { namespace internal {
namespace compiler { namespace compiler {
class MachineOperatorCommonTest : public CompilerTestWithParam<MachineType> { class MachineOperatorCommonTest
: public TestWithZone,
public ::testing::WithParamInterface<MachineType> {
public: public:
MachineOperatorCommonTest() : machine_(NULL) {} MachineOperatorCommonTest() : machine_(NULL) {}
virtual ~MachineOperatorCommonTest() { EXPECT_THAT(machine_, IsNull()); } virtual ~MachineOperatorCommonTest() { EXPECT_EQ(NULL, machine_); }
virtual void SetUp() OVERRIDE { virtual void SetUp() OVERRIDE {
CompilerTestWithParam<MachineType>::SetUp(); TestWithZone::SetUp();
EXPECT_EQ(NULL, machine_);
machine_ = new MachineOperatorBuilder(zone(), GetParam()); machine_ = new MachineOperatorBuilder(zone(), GetParam());
} }
virtual void TearDown() OVERRIDE { virtual void TearDown() OVERRIDE {
ASSERT_TRUE(machine_ != NULL);
delete machine_; delete machine_;
machine_ = NULL; machine_ = NULL;
CompilerTestWithParam<MachineType>::TearDown(); TestWithZone::TearDown();
} }
protected: protected:
......
# TODO(bmeurer): Temporary work-around, will be fixed soonish.
include_rules = [ include_rules = [
"+include/libplatform/libplatform.h" "+include/libplatform/libplatform.h"
] ]
...@@ -3,72 +3,27 @@ ...@@ -3,72 +3,27 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "include/libplatform/libplatform.h" #include "include/libplatform/libplatform.h"
#include "src/compiler/compiler-unittests.h" #include "include/v8.h"
#include "src/isolate-inl.h" #include "src/base/compiler-specific.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
using testing::IsNull;
using testing::NotNull;
namespace v8 {
namespace internal {
namespace compiler {
// static
v8::Isolate* CompilerTest::isolate_ = NULL;
CompilerTest::CompilerTest()
: isolate_scope_(isolate_),
handle_scope_(isolate_),
context_scope_(v8::Context::New(isolate_)),
zone_(isolate()) {}
CompilerTest::~CompilerTest() {}
Factory* CompilerTest::factory() const { return isolate()->factory(); }
// static
void CompilerTest::SetUpTestCase() {
Test::SetUpTestCase();
EXPECT_THAT(isolate_, IsNull());
isolate_ = v8::Isolate::New();
ASSERT_THAT(isolate_, NotNull());
}
// static
void CompilerTest::TearDownTestCase() {
ASSERT_THAT(isolate_, NotNull());
isolate_->Dispose();
isolate_ = NULL;
Test::TearDownTestCase();
}
} // namespace compiler
} // namespace internal
} // namespace v8
namespace { namespace {
class CompilerTestEnvironment FINAL : public ::testing::Environment { class DefaultPlatformEnvironment FINAL : public ::testing::Environment {
public: public:
CompilerTestEnvironment() : platform_(NULL) {} DefaultPlatformEnvironment() : platform_(NULL) {}
~CompilerTestEnvironment() {} ~DefaultPlatformEnvironment() {}
virtual void SetUp() OVERRIDE { virtual void SetUp() OVERRIDE {
EXPECT_THAT(platform_, IsNull()); EXPECT_EQ(NULL, platform_);
platform_ = v8::platform::CreateDefaultPlatform(); platform_ = v8::platform::CreateDefaultPlatform();
ASSERT_TRUE(platform_ != NULL);
v8::V8::InitializePlatform(platform_); v8::V8::InitializePlatform(platform_);
ASSERT_TRUE(v8::V8::Initialize()); ASSERT_TRUE(v8::V8::Initialize());
} }
virtual void TearDown() OVERRIDE { virtual void TearDown() OVERRIDE {
ASSERT_THAT(platform_, NotNull()); ASSERT_TRUE(platform_ != NULL);
v8::V8::Dispose(); v8::V8::Dispose();
v8::V8::ShutdownPlatform(); v8::V8::ShutdownPlatform();
delete platform_; delete platform_;
...@@ -84,7 +39,7 @@ class CompilerTestEnvironment FINAL : public ::testing::Environment { ...@@ -84,7 +39,7 @@ class CompilerTestEnvironment FINAL : public ::testing::Environment {
int main(int argc, char** argv) { int main(int argc, char** argv) {
testing::InitGoogleMock(&argc, argv); testing::InitGoogleMock(&argc, argv);
testing::AddGlobalTestEnvironment(new CompilerTestEnvironment); testing::AddGlobalTestEnvironment(new DefaultPlatformEnvironment);
v8::V8::SetFlagsFromCommandLine(&argc, argv, true); v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
return RUN_ALL_TESTS(); return RUN_ALL_TESTS();
} }
// 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/test/test-utils.h"
#include "src/isolate-inl.h"
namespace v8 {
// static
Isolate* TestWithIsolate::isolate_ = NULL;
TestWithIsolate::TestWithIsolate()
: isolate_scope_(isolate()), handle_scope_(isolate()) {}
TestWithIsolate::~TestWithIsolate() {}
// static
void TestWithIsolate::SetUpTestCase() {
Test::SetUpTestCase();
EXPECT_EQ(NULL, isolate_);
isolate_ = v8::Isolate::New();
EXPECT_TRUE(isolate_ != NULL);
}
// static
void TestWithIsolate::TearDownTestCase() {
ASSERT_TRUE(isolate_ != NULL);
isolate_->Dispose();
isolate_ = NULL;
Test::TearDownTestCase();
}
TestWithContext::TestWithContext()
: context_(Context::New(isolate())), context_scope_(context_) {}
TestWithContext::~TestWithContext() {}
namespace internal {
TestWithIsolate::~TestWithIsolate() {}
Factory* TestWithIsolate::factory() const { return isolate()->factory(); }
TestWithZone::~TestWithZone() {}
} // namespace internal
} // 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.
#ifndef V8_TEST_TEST_UTILS_H_
#define V8_TEST_TEST_UTILS_H_
#include "include/v8.h"
#include "src/base/macros.h"
#include "src/zone.h"
#include "testing/gtest-support.h"
namespace v8 {
class TestWithIsolate : public ::testing::Test {
public:
TestWithIsolate();
virtual ~TestWithIsolate();
Isolate* isolate() const { return isolate_; }
static void SetUpTestCase();
static void TearDownTestCase();
private:
static Isolate* isolate_;
Isolate::Scope isolate_scope_;
HandleScope handle_scope_;
DISALLOW_COPY_AND_ASSIGN(TestWithIsolate);
};
class TestWithContext : public virtual TestWithIsolate {
public:
TestWithContext();
virtual ~TestWithContext();
const Local<Context>& context() const { return context_; }
private:
Local<Context> context_;
Context::Scope context_scope_;
DISALLOW_COPY_AND_ASSIGN(TestWithContext);
};
namespace internal {
// Forward declarations.
class Factory;
class TestWithIsolate : public virtual ::v8::TestWithIsolate {
public:
TestWithIsolate() {}
virtual ~TestWithIsolate();
Factory* factory() const;
Isolate* isolate() const {
return reinterpret_cast<Isolate*>(::v8::TestWithIsolate::isolate());
}
private:
DISALLOW_COPY_AND_ASSIGN(TestWithIsolate);
};
class TestWithZone : public TestWithIsolate {
public:
TestWithZone() : zone_(isolate()) {}
virtual ~TestWithZone();
Zone* zone() { return &zone_; }
private:
Zone zone_;
DISALLOW_COPY_AND_ASSIGN(TestWithZone);
};
} // namespace internal
} // namespace v8
#endif // V8_TEST_TEST_UTILS_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.
{
'variables': {
'v8_code': 1,
},
'includes': ['../../build/toolchain.gypi', '../../build/features.gypi'],
'targets': [
{
'target_name': 'run-all-unittests',
'type': 'static_library',
'variables': {
'optimize': 'max',
},
'dependencies': [
'../../testing/gmock.gyp:gmock',
'../../testing/gtest.gyp:gtest',
'../../tools/gyp/v8.gyp:v8_libplatform',
],
'include_dirs': [
'../..',
],
'sources': [ ### gcmole(all) ###
'run-all-unittests.cc',
'test-utils.h',
'test-utils.cc',
],
'export_dependent_settings': [
'../../testing/gmock.gyp:gmock',
'../../testing/gtest.gyp:gtest',
],
'conditions': [
['component=="shared_library"', {
# compiler-unittests can't be built against a shared library, so we
# need to depend on the underlying static target in that case.
'conditions': [
['v8_use_snapshot=="true"', {
'dependencies': ['../../tools/gyp/v8.gyp:v8_snapshot'],
},
{
'dependencies': [
'../../tools/gyp/v8.gyp:v8_nosnapshot',
],
}],
],
}, {
'dependencies': ['../../tools/gyp/v8.gyp:v8'],
}],
['os_posix == 1', {
# TODO(svenpanne): This is a temporary work-around to fix the warnings
# that show up because we use -std=gnu++0x instead of -std=c++11.
'cflags!': [
'-pedantic',
],
'direct_dependent_settings': {
'cflags!': [
'-pedantic',
],
},
}],
['want_separate_host_toolset==1', {
'toolsets': ['host', 'target'],
}, {
'toolsets': ['target'],
}],
],
},
],
}
...@@ -47,6 +47,13 @@ ...@@ -47,6 +47,13 @@
'export_dependent_settings': [ 'export_dependent_settings': [
'gtest.gyp:gtest', 'gtest.gyp:gtest',
], ],
'conditions': [
['want_separate_host_toolset==1', {
'toolsets': ['host', 'target'],
}, {
'toolsets': ['target'],
}],
],
}, },
{ {
'target_name': 'gmock_main', 'target_name': 'gmock_main',
......
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