Mojo: Make a public test_support shared library.

The test runner can then inject dependencies into it (just as we do for
system and gles2).

This removes public/tests's base dependency.

R=sky@chromium.org

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@251115 0039d316-1c4b-4281-b951-d872f2087c98
parent e3eac422
...@@ -3,10 +3,12 @@ ...@@ -3,10 +3,12 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "base/test/perf_test_suite.h" #include "base/test/perf_test_suite.h"
#include "mojo/common/test/test_support_impl.h"
#include "mojo/public/tests/test_support_private.h"
#include "mojo/system/embedder/embedder.h" #include "mojo/system/embedder/embedder.h"
int main(int argc, char** argv) { int main(int argc, char** argv) {
mojo::embedder::Init(); mojo::embedder::Init();
mojo::test::TestSupport::Init(new mojo::test::TestSupportImpl());
return base::PerfTestSuite(argc, argv).Run(); return base::PerfTestSuite(argc, argv).Run();
} }
...@@ -5,12 +5,15 @@ ...@@ -5,12 +5,15 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/test/launcher/unit_test_launcher.h" #include "base/test/launcher/unit_test_launcher.h"
#include "base/test/test_suite.h" #include "base/test/test_suite.h"
#include "mojo/common/test/test_support_impl.h"
#include "mojo/public/tests/test_support_private.h"
#include "mojo/system/embedder/embedder.h" #include "mojo/system/embedder/embedder.h"
int main(int argc, char** argv) { int main(int argc, char** argv) {
base::TestSuite test_suite(argc, argv); base::TestSuite test_suite(argc, argv);
mojo::embedder::Init(); mojo::embedder::Init();
mojo::test::TestSupport::Init(new mojo::test::TestSupportImpl());
return base::LaunchUnitTests( return base::LaunchUnitTests(
argc, argv, base::Bind(&base::TestSuite::Run, argc, argv, base::Bind(&base::TestSuite::Run,
......
// Copyright 2014 The Chromium 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 "mojo/common/test/test_support_impl.h"
#include "base/test/perf_log.h"
namespace mojo {
namespace test {
TestSupportImpl::TestSupportImpl() {
}
TestSupportImpl::~TestSupportImpl() {
}
void TestSupportImpl::LogPerfResult(const char* test_name,
double value,
const char* units) {
base::LogPerfResult(test_name, value, units);
}
} // namespace test
} // namespace mojo
// Copyright 2014 The Chromium 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 MOJO_COMMON_TEST_TEST_SUPPORT_IMPL_H_
#define MOJO_COMMON_TEST_TEST_SUPPORT_IMPL_H_
#include "base/macros.h"
#include "mojo/public/tests/test_support_private.h"
namespace mojo {
namespace test {
class TestSupportImpl : public TestSupport {
public:
TestSupportImpl();
virtual ~TestSupportImpl();
virtual void LogPerfResult(const char* test_name,
double value,
const char* units) OVERRIDE;
private:
DISALLOW_COPY_AND_ASSIGN(TestSupportImpl);
};
} // namespace test
} // namespace mojo
#endif // MOJO_COMMON_TEST_TEST_SUPPORT_IMPL_H_
...@@ -68,6 +68,8 @@ ...@@ -68,6 +68,8 @@
'../testing/gtest.gyp:gtest', '../testing/gtest.gyp:gtest',
'mojo_system', 'mojo_system',
'mojo_system_impl', 'mojo_system_impl',
'mojo_test_support',
'mojo_test_support_impl',
], ],
'sources': [ 'sources': [
'common/test/run_all_unittests.cc', 'common/test/run_all_unittests.cc',
...@@ -80,6 +82,8 @@ ...@@ -80,6 +82,8 @@
'../base/base.gyp:test_support_base', '../base/base.gyp:test_support_base',
'mojo_system', 'mojo_system',
'mojo_system_impl', 'mojo_system_impl',
'mojo_test_support',
'mojo_test_support_impl',
], ],
'sources': [ 'sources': [
'common/test/run_all_perftests.cc', 'common/test/run_all_perftests.cc',
...@@ -210,6 +214,17 @@ ...@@ -210,6 +214,17 @@
'gles2/gles2_context.h', 'gles2/gles2_context.h',
], ],
}, },
{
'target_name': 'mojo_test_support_impl',
'type': 'static_library',
'dependencies': [
'../base/base.gyp:base',
],
'sources': [
'common/test/test_support_impl.cc',
'common/test/test_support_impl.h',
],
},
{ {
'target_name': 'mojo_common_lib', 'target_name': 'mojo_common_lib',
'type': '<(component)', 'type': '<(component)',
......
...@@ -47,9 +47,30 @@ ...@@ -47,9 +47,30 @@
}, },
'sources': [ 'sources': [
'public/gles2/gles2.h', 'public/gles2/gles2.h',
'public/gles2/gles2_export.h',
'public/gles2/gles2_private.cc', 'public/gles2/gles2_private.cc',
'public/gles2/gles2_private.h', 'public/gles2/gles2_private.h',
'public/gles2/gles2_export.h', ],
},
{
'target_name': 'mojo_test_support',
'type': 'shared_library',
'defines': [
'MOJO_TEST_SUPPORT_IMPLEMENTATION',
],
'include_dirs': [
'..',
],
'direct_dependent_settings': {
'include_dirs': [
'..',
],
},
'sources': [
'public/tests/test_support.h',
'public/tests/test_support_private.cc',
'public/tests/test_support_private.h',
'public/tests/test_support_export.h',
], ],
}, },
{ {
...@@ -59,6 +80,7 @@ ...@@ -59,6 +80,7 @@
'../base/base.gyp:base', '../base/base.gyp:base',
'../testing/gtest.gyp:gtest', '../testing/gtest.gyp:gtest',
'mojo_system', 'mojo_system',
'mojo_test_support',
], ],
'sources': [ 'sources': [
'public/tests/test_utils.cc', 'public/tests/test_utils.cc',
......
# TODO(darin): Eliminate the base dependency!
include_rules = [ include_rules = [
"+base",
"+mojo", "+mojo",
] ]
// Copyright 2014 The Chromium 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 MOJO_PUBLIC_TESTS_TEST_SUPPORT_H_
#define MOJO_PUBLIC_TESTS_TEST_SUPPORT_H_
// Note: This header should be compilable as C.
#include "mojo/public/tests/test_support_export.h"
#ifdef __cplusplus
extern "C" {
#endif
MOJO_TEST_SUPPORT_EXPORT void MojoTestSupportLogPerfResult(
const char* test_name,
double value,
const char* units);
#ifdef __cplusplus
} // extern "C"
#endif
#endif // MOJO_PUBLIC_TESTS_TEST_SUPPORT_H_
// Copyright 2014 The Chromium 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 MOJO_PUBLIC_TESTS_TEST_SUPPORT_EXPORT_H_
#define MOJO_PUBLIC_TESTS_TEST_SUPPORT_EXPORT_H_
#if defined(WIN32)
#if defined(MOJO_TEST_SUPPORT_IMPLEMENTATION)
#define MOJO_TEST_SUPPORT_EXPORT __declspec(dllexport)
#else
#define MOJO_TEST_SUPPORT_EXPORT __declspec(dllimport)
#endif
#else // !defined(WIN32)
#if defined(MOJO_TEST_SUPPORT_IMPLEMENTATION)
#define MOJO_TEST_SUPPORT_EXPORT __attribute__((visibility("default")))
#else
#define MOJO_TEST_SUPPORT_EXPORT
#endif
#endif // defined(WIN32)
#endif // MOJO_PUBLIC_TESTS_TEST_SUPPORT_EXPORT_H_
// Copyright 2014 The Chromium 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 "mojo/public/tests/test_support_private.h"
#include <assert.h>
#include <stddef.h>
#include <stdio.h>
static mojo::test::TestSupport* g_test_support = NULL;
extern "C" {
void MojoTestSupportLogPerfResult(const char* test_name,
double value,
const char* units) {
if (g_test_support)
g_test_support->LogPerfResult(test_name, value, units);
else
printf("[no test runner]\t%s\t%g\t%s\n", test_name, value, units);
}
} // extern "C"
namespace mojo {
namespace test {
TestSupport::~TestSupport() {
}
// static
void TestSupport::Init(TestSupport* test_support) {
assert(!g_test_support);
g_test_support = test_support;
}
// static
TestSupport* TestSupport::Get() {
return g_test_support;
}
// static
void TestSupport::Reset() {
g_test_support = NULL;
}
} // namespace test
} // namespace mojo
// Copyright 2014 The Chromium 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 MOJO_PUBLIC_TESTS_TEST_SUPPORT_PRIVATE_H_
#define MOJO_PUBLIC_TESTS_TEST_SUPPORT_PRIVATE_H_
#include "mojo/public/tests/test_support.h"
namespace mojo {
namespace test {
// Implementors of the test support APIs can use this interface to install their
// implementation into the mojo_test_support dynamic library.
class MOJO_TEST_SUPPORT_EXPORT TestSupport {
public:
virtual ~TestSupport();
static void Init(TestSupport* test_support);
static TestSupport* Get();
static void Reset();
virtual void LogPerfResult(const char* test_name,
double value,
const char* units) = 0;
};
} // namespace test
} // namespace mojo
#endif // MOJO_PUBLIC_TESTS_TEST_SUPPORT_PRIVATE_H_
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
#include "mojo/public/tests/test_utils.h" #include "mojo/public/tests/test_utils.h"
#include "base/test/perf_log.h"
#include "mojo/public/system/core_cpp.h" #include "mojo/public/system/core_cpp.h"
#include "mojo/public/tests/test_support.h"
namespace mojo { namespace mojo {
namespace test { namespace test {
...@@ -82,9 +82,9 @@ void IterateAndReportPerf(const char* test_name, ...@@ -82,9 +82,9 @@ void IterateAndReportPerf(const char* test_name,
end_time = GetTimeTicksNow(); end_time = GetTimeTicksNow();
} while (end_time - start_time < kPerftestTimeMicroseconds); } while (end_time - start_time < kPerftestTimeMicroseconds);
base::LogPerfResult(test_name, MojoTestSupportLogPerfResult(test_name,
1000000.0 * iterations / (end_time - start_time), 1000000.0 * iterations / (end_time - start_time),
"iterations/second"); "iterations/second");
} }
} // namespace test } // namespace test
......
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