diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-09 15:25:53 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-09 15:25:53 +0000 |
commit | 19d536f25ffa4e876c7af79b201c7330841b31ea (patch) | |
tree | 2f64619a8812920692bd3c7e69103727021e9d53 /base/test/multiprocess_test.h | |
parent | 6c4e6631acb0893ba00f035792e80942e2b00bd3 (diff) | |
download | chromium_src-19d536f25ffa4e876c7af79b201c7330841b31ea.zip chromium_src-19d536f25ffa4e876c7af79b201c7330841b31ea.tar.gz chromium_src-19d536f25ffa4e876c7af79b201c7330841b31ea.tar.bz2 |
Cleanup in base. This moves the implementation (and a bunch of header file
dependencies) from the multiprocess test and the test_suite headers to .cc
files. Moves multiprocess_test to the test directory, and all of this stuff to
the existing base_test_support project. I also used the base namespace.
Previously other projects included this functionality just by #include because
it was all inline, so I had to add dependencies on base_test_support in a few
places.
Moves and renames the command line switch this was using to base_switches. Move
the base switch for process type to chrome switches.
TEST=none
BUG=none
Review URL: http://codereview.chromium.org/3026055
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@55400 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/test/multiprocess_test.h')
-rw-r--r-- | base/test/multiprocess_test.h | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/base/test/multiprocess_test.h b/base/test/multiprocess_test.h new file mode 100644 index 0000000..5126abe --- /dev/null +++ b/base/test/multiprocess_test.h @@ -0,0 +1,86 @@ +// Copyright (c) 2010 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 BASE_TEST_MULTIPROCESS_TEST_H_ +#define BASE_TEST_MULTIPROCESS_TEST_H_ +#pragma once + +#include <string> + +#include "base/basictypes.h" +#include "base/process.h" +#include "base/process_util.h" +#include "build/build_config.h" +#include "testing/platform_test.h" + +class CommandLine; + +namespace base { + +// A MultiProcessTest is a test class which makes it easier to +// write a test which requires code running out of process. +// +// To create a multiprocess test simply follow these steps: +// +// 1) Derive your test from MultiProcessTest. Example: +// +// class MyTest : public MultiProcessTest { +// }; +// +// TEST_F(MyTest, TestCaseName) { +// ... +// } +// +// 2) Create a mainline function for the child processes and include +// testing/multiprocess_func_list.h. +// See the declaration of the MULTIPROCESS_TEST_MAIN macro +// in that file for an example. +// 3) Call SpawnChild("foo"), where "foo" is the name of +// the function you wish to run in the child processes. +// That's it! +class MultiProcessTest : public PlatformTest { + public: + MultiProcessTest(); + + protected: + // Run a child process. + // 'procname' is the name of a function which the child will + // execute. It must be exported from this library in order to + // run. + // + // Example signature: + // extern "C" int __declspec(dllexport) FooBar() { + // // do client work here + // } + // + // Returns the handle to the child, or NULL on failure + ProcessHandle SpawnChild(const std::string& procname, bool debug_on_start); + +#if defined(OS_POSIX) + ProcessHandle SpawnChild(const std::string& procname, + const file_handle_mapping_vector& fds_to_map, + bool debug_on_start); +#endif + + CommandLine MakeCmdLine(const std::string& procname, bool debug_on_start); + + private: +#if defined(OS_WIN) + ProcessHandle SpawnChildImpl(const std::string& procname, + bool debug_on_start); + +#elif defined(OS_POSIX) + // TODO(port): with the CommandLine refactoring, this code is very similar + // to the Windows code. Investigate whether this can be made shorter. + ProcessHandle SpawnChildImpl(const std::string& procname, + const file_handle_mapping_vector& fds_to_map, + bool debug_on_start); +#endif + + DISALLOW_COPY_AND_ASSIGN(MultiProcessTest); +}; + +} // namespace base + +#endif // BASE_TEST_MULTIPROCESS_TEST_H_ |