Skip to content

Commit

Permalink
Provide android specific implementation for MultiProcessTest::SpawnCh…
Browse files Browse the repository at this point in the history
…ildImpl

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
  • Loading branch information
nileshagrawal@chromium.org committed May 29, 2012
1 parent 7298a33 commit 04de380
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions base/base.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 2 additions & 0 deletions base/test/multiprocess_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -50,5 +51,6 @@ ProcessHandle MultiProcessTest::SpawnChildImpl(
base::LaunchProcess(MakeCmdLine(procname, debug_on_start), options, &handle);
return handle;
}
#endif // !defined(OS_ANDROID)

} // namespace base
38 changes: 38 additions & 0 deletions base/test/multiprocess_test_android.cc
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 04de380

Please sign in to comment.