diff options
author | nileshagrawal@chromium.org <nileshagrawal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-29 19:36:32 +0000 |
---|---|---|
committer | nileshagrawal@chromium.org <nileshagrawal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-29 19:36:32 +0000 |
commit | 04de38058e444d560f11ec4827c7d7e65792c804 (patch) | |
tree | 03120be8fde34253aa9da2d4acb01d02171b75e6 | |
parent | 7298a336fd781b2f7e23d30dbb71cf1321629229 (diff) | |
download | chromium_src-04de38058e444d560f11ec4827c7d7e65792c804.zip chromium_src-04de38058e444d560f11ec4827c7d7e65792c804.tar.gz chromium_src-04de38058e444d560f11ec4827c7d7e65792c804.tar.bz2 |
Provide android specific implementation for MultiProcessTest::SpawnChildImpl
When tests are run in an APK, we do not have an executable to exec.
We resort to forking and executing the test method directly.
BUG=125059
TEST=
Review URL: https://chromiumcodereview.appspot.com/10408081
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@139342 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | base/base.gyp | 1 | ||||
-rw-r--r-- | base/test/multiprocess_test.cc | 2 | ||||
-rw-r--r-- | base/test/multiprocess_test_android.cc | 38 |
3 files changed, 41 insertions, 0 deletions
diff --git a/base/base.gyp b/base/base.gyp index 60fa8ab..31b6765 100644 --- a/base/base.gyp +++ b/base/base.gyp @@ -440,6 +440,7 @@ 'test/mock_time_provider.h', 'test/multiprocess_test.cc', 'test/multiprocess_test.h', + 'test/multiprocess_test_android.cc', 'test/perf_test_suite.cc', 'test/perf_test_suite.h', 'test/scoped_locale.cc', diff --git a/base/test/multiprocess_test.cc b/base/test/multiprocess_test.cc index b0773ae..27f9970 100644 --- a/base/test/multiprocess_test.cc +++ b/base/test/multiprocess_test.cc @@ -36,6 +36,7 @@ CommandLine MultiProcessTest::MakeCmdLine(const std::string& procname, return cl; } +#if !defined(OS_ANDROID) ProcessHandle MultiProcessTest::SpawnChildImpl( const std::string& procname, const FileHandleMappingVector& fds_to_map, @@ -50,5 +51,6 @@ ProcessHandle MultiProcessTest::SpawnChildImpl( base::LaunchProcess(MakeCmdLine(procname, debug_on_start), options, &handle); return handle; } +#endif // !defined(OS_ANDROID) } // namespace base diff --git a/base/test/multiprocess_test_android.cc b/base/test/multiprocess_test_android.cc new file mode 100644 index 0000000..cc45d06 --- /dev/null +++ b/base/test/multiprocess_test_android.cc @@ -0,0 +1,38 @@ +// Copyright (c) 2012 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 "base/test/multiprocess_test.h" + +#include <unistd.h> + +#include "base/logging.h" +#include "base/process.h" +#include "testing/multiprocess_func_list.h" + +namespace base { + +// A very basic implementation for android. On Android tests can run in an APK +// and we don't have an executable to exec*. This implementation does the bare +// minimum to execute the method specified by procname (in the child process). +// - File descriptors are not closed and hence |fds_to_map| is ignored. +// - |debug_on_start| is ignored. +ProcessHandle MultiProcessTest::SpawnChildImpl( + const std::string& procname, + const FileHandleMappingVector& fds_to_map, + bool debug_on_start) { + pid_t pid = fork(); + + if (pid < 0) { + DPLOG(ERROR) << "fork"; + return kNullProcessHandle; + } else if (pid == 0) { + // Child process. + _exit(multi_process_function_list::InvokeChildProcessTest(procname)); + } + + // Parent process. + return pid; +} + +} // namespace base |