| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BASE_MULTIPROCESS_TEST_H__ | 5 #ifndef BASE_MULTIPROCESS_TEST_H__ |
| 6 #define BASE_MULTIPROCESS_TEST_H__ | 6 #define BASE_MULTIPROCESS_TEST_H__ |
| 7 | 7 |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/platform_test.h" | 9 #include "base/platform_test.h" |
| 10 #include "base/process_util.h" | 10 #include "base/process_util.h" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "testing/multiprocess_func_list.h" |
| 13 | 14 |
| 14 #if defined(OS_POSIX) | 15 #if defined(OS_POSIX) |
| 15 #include <sys/types.h> | 16 #include <sys/types.h> |
| 16 #include <unistd.h> | 17 #include <unistd.h> |
| 17 #endif | 18 #endif |
| 18 | 19 |
| 19 // Command line switch to invoke a child process rather than | 20 // Command line switch to invoke a child process rather than |
| 20 // to run the normal test suite. | 21 // to run the normal test suite. |
| 21 static const wchar_t kRunClientProcess[] = L"client"; | 22 static const wchar_t kRunClientProcess[] = L"client"; |
| 22 | 23 |
| 23 // A MultiProcessTest is a test class which makes it easier to | 24 // A MultiProcessTest is a test class which makes it easier to |
| 24 // write a test which requires code running out of process. | 25 // write a test which requires code running out of process. |
| 25 // | 26 // |
| 26 // To create a multiprocess test simply follow these steps: | 27 // To create a multiprocess test simply follow these steps: |
| 27 // | 28 // |
| 28 // 1) Derive your test from MultiProcessTest. | 29 // 1) Derive your test from MultiProcessTest. |
| 29 // 2) Modify your mainline so that if it sees the | 30 // 2) Create a mainline function for the child processes and include |
| 30 // kRunClientProcess switch, it will deal with it. | 31 // testing/multiprocess_func_list.h. |
| 31 // 3) Create a mainline function for the child processes | 32 // See the declaration of the MULTIPROCESS_TEST_MAIN macro |
| 32 // 4) Call SpawnChild("foo"), where "foo" is the name of | 33 // in that file for an example. |
| 34 // 3) Call SpawnChild("foo"), where "foo" is the name of |
| 33 // the function you wish to run in the child processes. | 35 // the function you wish to run in the child processes. |
| 34 // 5) On Linux, add the function's name to the list in the file | |
| 35 // base_unittests_exported_symbols.version | |
| 36 // That's it! | 36 // That's it! |
| 37 // | 37 // |
| 38 class MultiProcessTest : public PlatformTest { | 38 class MultiProcessTest : public PlatformTest { |
| 39 public: | |
| 40 // Prototype function for a client function. Multi-process | |
| 41 // clients must provide a callback with this signature to run. | |
| 42 typedef int (*ChildFunctionPtr)(); | |
| 43 | |
| 44 protected: | 39 protected: |
| 45 // Run a child process. | 40 // Run a child process. |
| 46 // 'procname' is the name of a function which the child will | 41 // 'procname' is the name of a function which the child will |
| 47 // execute. It must be exported from this library in order to | 42 // execute. It must be exported from this library in order to |
| 48 // run. | 43 // run. |
| 49 // | 44 // |
| 50 // Example signature: | 45 // Example signature: |
| 51 // extern "C" int __declspec(dllexport) FooBar() { | 46 // extern "C" int __declspec(dllexport) FooBar() { |
| 52 // // do client work here | 47 // // do client work here |
| 53 // } | 48 // } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 72 std::string switchstr = WideToUTF8(wswitchstr); | 67 std::string switchstr = WideToUTF8(wswitchstr); |
| 73 clvec.push_back(switchstr.c_str()); | 68 clvec.push_back(switchstr.c_str()); |
| 74 process_util::LaunchApp(clvec, false, &handle); | 69 process_util::LaunchApp(clvec, false, &handle); |
| 75 #endif | 70 #endif |
| 76 | 71 |
| 77 return handle; | 72 return handle; |
| 78 } | 73 } |
| 79 }; | 74 }; |
| 80 | 75 |
| 81 #endif // BASE_MULTIPROCESS_TEST_H__ | 76 #endif // BASE_MULTIPROCESS_TEST_H__ |
| 82 | |
| OLD | NEW |