Commit b68b558b authored by Kevin Marshall's avatar Kevin Marshall Committed by Commit Bot

[fuchsia] Add webrunner unit tests, browsertests to Fuchsia bots.

* Fixed webrunner_unittests (tests were not being exercised, so the
  test code drifted from the impl)
* Added webrunner_unittests, webrunner_browsertests to Fuchsia test
  bot list.


Bug: 871594
Change-Id: I3f86f2f1d76534c51236a3dea43dc898d996b121
Reviewed-on: https://chromium-review.googlesource.com/1174868
Commit-Queue: Kevin Marshall <kmarshall@chromium.org>
Reviewed-by: default avatarWez <wez@chromium.org>
Reviewed-by: default avatarDirk Pranke <dpranke@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584669}
parent ac8b5ef7
......@@ -3129,6 +3129,18 @@
"can_use_on_swarming_builders": true
},
"test": "ui_base_unittests"
},
{
"swarming": {
"can_use_on_swarming_builders": true
},
"test": "webrunner_browsertests"
},
{
"swarming": {
"can_use_on_swarming_builders": true
},
"test": "webrunner_unittests"
}
]
},
......@@ -3280,6 +3292,28 @@
]
},
"test": "ui_base_unittests"
},
{
"swarming": {
"can_use_on_swarming_builders": true,
"dimension_sets": [
{
"kvm": "1"
}
]
},
"test": "webrunner_browsertests"
},
{
"swarming": {
"can_use_on_swarming_builders": true,
"dimension_sets": [
{
"kvm": "1"
}
]
},
"test": "webrunner_unittests"
}
]
},
......@@ -3446,6 +3480,28 @@
]
},
"test": "ui_base_unittests"
},
{
"swarming": {
"can_use_on_swarming_builders": true,
"dimension_sets": [
{
"kvm": "1"
}
]
},
"test": "webrunner_browsertests"
},
{
"swarming": {
"can_use_on_swarming_builders": true,
"dimension_sets": [
{
"kvm": "1"
}
]
},
"test": "webrunner_unittests"
}
]
},
......
......@@ -786,6 +786,28 @@
]
},
"test": "ui_base_unittests"
},
{
"swarming": {
"can_use_on_swarming_builders": true,
"dimension_sets": [
{
"kvm": "1"
}
]
},
"test": "webrunner_browsertests"
},
{
"swarming": {
"can_use_on_swarming_builders": true,
"dimension_sets": [
{
"kvm": "1"
}
]
},
"test": "webrunner_unittests"
}
]
},
......
......@@ -1351,6 +1351,14 @@
"../../third_party/blink/tools/run_blinkpy_tests.py"
]
},
"webrunner_browsertests": {
"label": "//webrunner:webrunner_browsertests",
"type": "console_test_launcher",
},
"webrunner_unittests": {
"label": "//webrunner:webrunner_unittests",
"type": "console_test_launcher",
},
"webkit_unit_tests": {
"label": "//third_party/blink/renderer/controller:webkit_unit_tests",
"type": "console_test_launcher",
......
......@@ -981,6 +981,8 @@
'--test-launcher-filter-file=../../testing/buildbot/filters/fuchsia.ui_base_unittests.filter',
],
},
'webrunner_browsertests': {},
'webrunner_unittests': {},
},
'goma_gtests': {
......
......@@ -190,8 +190,7 @@ test("webrunner_browsertests") {
test("webrunner_unittests") {
sources = [
# TODO(kmarshall): Uncomment this when the tests are fixed.
# "service/context_provider_impl_unittest.cc",
"service/context_provider_impl_unittest.cc",
]
deps = [
":fidl",
......
......@@ -5,6 +5,7 @@
#include "webrunner/service/context_provider_impl.h"
#include <fuchsia/sys/cpp/fidl.h>
#include <lib/async/default.h>
#include <lib/zx/job.h>
#include <stdio.h>
#include <zircon/processargs.h>
......@@ -26,20 +27,36 @@ namespace webrunner {
namespace {
// Relaunches the current executable as a Context process.
base::Process LaunchContextProcess(base::CommandLine launch_command,
base::Process LaunchContextProcess(const base::CommandLine& launch_command,
const base::LaunchOptions& launch_options) {
base::CommandLine launch_command_modified = launch_command;
// TODO(crbug.com/867052): Remove this flag when GPU process works on Fuchsia.
launch_command.AppendSwitch(switches::kDisableGpu);
return base::LaunchProcess(launch_command, launch_options);
launch_command_modified.AppendSwitch(switches::kDisableGpu);
return base::LaunchProcess(launch_command_modified, launch_options);
}
} // namespace
ContextProviderImpl::ContextProviderImpl()
: launch_(base::BindRepeating(&LaunchContextProcess)) {}
ContextProviderImpl::ContextProviderImpl() : ContextProviderImpl(false) {}
ContextProviderImpl::ContextProviderImpl(bool use_shared_tmp)
: launch_(base::BindRepeating(&LaunchContextProcess)),
use_shared_tmp_(use_shared_tmp) {}
ContextProviderImpl::~ContextProviderImpl() = default;
// static
std::unique_ptr<ContextProviderImpl> ContextProviderImpl::CreateForTest() {
// Bind the unique_ptr in a two step process.
// std::make_unique<> doesn't work well with private constructors,
// and the unique_ptr(raw_ptr*) constructor format isn't permitted as per
// PRESUBMIT.py policy.
std::unique_ptr<ContextProviderImpl> provider;
provider.reset(new ContextProviderImpl(true));
return provider;
}
void ContextProviderImpl::SetLaunchCallbackForTests(
const LaunchContextProcessCallback& launch) {
launch_ = launch;
......@@ -57,9 +74,11 @@ void ContextProviderImpl::Create(
// Clone job because the context needs to be able to spawn child processes.
launch_options.spawn_flags = FDIO_SPAWN_CLONE_JOB;
// Clone stderr to get logs in system debug log.
// Clone stdout/stderr to get logs in system debug log.
launch_options.fds_to_remap.push_back(
std::make_pair(STDERR_FILENO, STDERR_FILENO));
launch_options.fds_to_remap.push_back(
std::make_pair(STDOUT_FILENO, STDOUT_FILENO));
// Context and child processes need access to the read-only package files.
launch_options.paths_to_clone.push_back(base::FilePath("/pkg"));
......@@ -67,6 +86,9 @@ void ContextProviderImpl::Create(
// Context needs access to the read-only SSL root certificates list.
launch_options.paths_to_clone.push_back(base::FilePath("/config/ssl"));
if (use_shared_tmp_)
launch_options.paths_to_clone.push_back(base::FilePath("/tmp"));
// Transfer the ContextRequest handle to a well-known location in the child
// process' handle table.
zx::channel context_handle(context_request.TakeChannel());
......@@ -91,8 +113,10 @@ void ContextProviderImpl::Create(
zx::job job;
zx_status_t status = zx::job::create(*base::GetDefaultJob(), 0, &job);
ZX_CHECK(status == ZX_OK, status) << "zx_job_create";
launch_options.job_handle = job.get();
ignore_result(launch_.Run(std::move(launch_command), launch_options));
ignore_result(context_handle.release());
ignore_result(job.release());
}
......
......@@ -6,6 +6,7 @@
#define WEBRUNNER_SERVICE_CONTEXT_PROVIDER_IMPL_H_
#include <lib/fidl/cpp/binding_set.h>
#include <memory>
#include "base/callback.h"
#include "base/macros.h"
......@@ -26,6 +27,11 @@ class WEBRUNNER_EXPORT ContextProviderImpl
ContextProviderImpl();
~ContextProviderImpl() override;
// Creates a ContextProviderImpl that shares its /tmp directory with its child
// processes. This is useful for GTest processes, which depend on a shared
// tmpdir for storing startup flags and retrieving test result files.
static std::unique_ptr<ContextProviderImpl> CreateForTest();
// Binds |this| object instance to |request|.
// The service will persist and continue to serve other channels in the event
// that a bound channel is dropped.
......@@ -38,11 +44,13 @@ class WEBRUNNER_EXPORT ContextProviderImpl
private:
using LaunchContextProcessCallback = base::RepeatingCallback<base::Process(
base::CommandLine command,
const base::CommandLine& command,
const base::LaunchOptions& options)>;
friend class ContextProviderImplTest;
explicit ContextProviderImpl(bool use_shared_tmp);
// Overrides the default child process launching logic to call |launch|
// instead.
void SetLaunchCallbackForTests(const LaunchContextProcessCallback& launch);
......@@ -50,6 +58,9 @@ class WEBRUNNER_EXPORT ContextProviderImpl
// Spawns a Context child process.
LaunchContextProcessCallback launch_;
// If set, then the ContextProvider will share /tmp with its child processes.
bool use_shared_tmp_ = true;
fidl::BindingSet<chromium::web::ContextProvider> bindings_;
DISALLOW_COPY_AND_ASSIGN(ContextProviderImpl);
......
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