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/process_util.h" | 10 #include "base/process_util.h" |
10 #include "base/string_util.h" | 11 #include "base/string_util.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
12 | 13 |
13 #if defined(OS_POSIX) | 14 #if defined(OS_POSIX) |
14 #include <sys/types.h> | 15 #include <sys/types.h> |
15 #include <unistd.h> | 16 #include <unistd.h> |
16 #endif | 17 #endif |
17 | 18 |
18 // Command line switch to invoke a child process rather than | 19 // Command line switch to invoke a child process rather than |
19 // to run the normal test suite. | 20 // to run the normal test suite. |
20 static const wchar_t kRunClientProcess[] = L"client"; | 21 static const wchar_t kRunClientProcess[] = L"client"; |
21 | 22 |
22 // A MultiProcessTest is a test class which makes it easier to | 23 // A MultiProcessTest is a test class which makes it easier to |
23 // write a test which requires code running out of process. | 24 // write a test which requires code running out of process. |
24 // | 25 // |
25 // To create a multiprocess test simply follow these steps: | 26 // To create a multiprocess test simply follow these steps: |
26 // | 27 // |
27 // 1) Derive your test from MultiProcessTest. | 28 // 1) Derive your test from MultiProcessTest. |
28 // 2) Modify your mainline so that if it sees the | 29 // 2) Modify your mainline so that if it sees the |
29 // kRunClientProcess switch, it will deal with it. | 30 // kRunClientProcess switch, it will deal with it. |
30 // 3) Create a mainline function for the child processes | 31 // 3) Create a mainline function for the child processes |
31 // 4) Call SpawnChild("foo"), where "foo" is the name of | 32 // 4) Call SpawnChild("foo"), where "foo" is the name of |
32 // the function you wish to run in the child processes. | 33 // the function you wish to run in the child processes. |
33 // 5) On posix, add the function's name to the list in the file | 34 // 5) On Linux, add the function's name to the list in the file |
34 // base_unittests_exported_symbols.version | 35 // base_unittests_exported_symbols.version |
35 // That's it! | 36 // That's it! |
36 // | 37 // |
37 class MultiProcessTest : public testing::Test { | 38 class MultiProcessTest : public PlatformTest { |
38 public: | 39 public: |
39 // Prototype function for a client function. Multi-process | 40 // Prototype function for a client function. Multi-process |
40 // clients must provide a callback with this signature to run. | 41 // clients must provide a callback with this signature to run. |
41 typedef int (*ChildFunctionPtr)(); | 42 typedef int (*ChildFunctionPtr)(); |
42 | 43 |
43 protected: | 44 protected: |
44 // Run a child process. | 45 // Run a child process. |
45 // 'procname' is the name of a function which the child will | 46 // 'procname' is the name of a function which the child will |
46 // execute. It must be exported from this library in order to | 47 // execute. It must be exported from this library in order to |
47 // run. | 48 // run. |
(...skipping 24 matching lines...) Expand all Loading... |
72 clvec.push_back(switchstr.c_str()); | 73 clvec.push_back(switchstr.c_str()); |
73 process_util::LaunchApp(clvec, false, &handle); | 74 process_util::LaunchApp(clvec, false, &handle); |
74 #endif | 75 #endif |
75 | 76 |
76 return handle; | 77 return handle; |
77 } | 78 } |
78 }; | 79 }; |
79 | 80 |
80 #endif // BASE_MULTIPROCESS_TEST_H__ | 81 #endif // BASE_MULTIPROCESS_TEST_H__ |
81 | 82 |
OLD | NEW |