Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(189)

Side by Side Diff: mojo/common/test/multiprocess_test_helper.h

Issue 194593007: Mojo: MultiprocessTestHelper: Allow {ASSERT,EXPECT}_...() to be used in child. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comment fix Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | mojo/common/test/multiprocess_test_helper.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 MOJO_COMMON_TEST_MULTIPROCESS_TEST_HELPER_H_ 5 #ifndef MOJO_COMMON_TEST_MULTIPROCESS_TEST_HELPER_H_
6 #define MOJO_COMMON_TEST_MULTIPROCESS_TEST_HELPER_H_ 6 #define MOJO_COMMON_TEST_MULTIPROCESS_TEST_HELPER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 11 matching lines...) Expand all
22 } 22 }
23 23
24 namespace test { 24 namespace test {
25 25
26 class MultiprocessTestHelper { 26 class MultiprocessTestHelper {
27 public: 27 public:
28 MultiprocessTestHelper(); 28 MultiprocessTestHelper();
29 ~MultiprocessTestHelper(); 29 ~MultiprocessTestHelper();
30 30
31 // Start a child process and run the "main" function "named" |test_child_name| 31 // Start a child process and run the "main" function "named" |test_child_name|
32 // declared using |MOJO_MULTIPROCESS_TEST_CHILD_MAIN()| (below). 32 // declared using |MOJO_MULTIPROCESS_TEST_CHILD_MAIN()| or
33 // |MOJO_MULTIPROCESS_TEST_CHILD_TEST()| (below).
33 void StartChild(const std::string& test_child_name); 34 void StartChild(const std::string& test_child_name);
34 // Wait for the child process to terminate. 35 // Wait for the child process to terminate.
35 // Returns the exit code of the child process. Note that, though it's declared 36 // Returns the exit code of the child process. Note that, though it's declared
36 // to be an |int|, the exit code is subject to mangling by the OS. E.g., we 37 // to be an |int|, the exit code is subject to mangling by the OS. E.g., we
37 // usually return -1 on error in the child (e.g., if |test_child_name| was not 38 // usually return -1 on error in the child (e.g., if |test_child_name| was not
38 // found), but this is mangled to 255 on Linux. You should only rely on codes 39 // found), but this is mangled to 255 on Linux. You should only rely on codes
39 // 0-127 being preserved, and -1 being outside the range 0-127. 40 // 0-127 being preserved, and -1 being outside the range 0-127.
40 int WaitForChildShutdown(); 41 int WaitForChildShutdown();
41 42
43 // Like |WaitForChildShutdown()|, but returns true on success (exit code of 0)
44 // and false otherwise. You probably want to do something like
45 // |EXPECT_TRUE(WaitForChildTestShutdown());|. Mainly for use with
46 // |MOJO_MULTIPROCESS_TEST_CHILD_TEST()|.
47 bool WaitForChildTestShutdown();
48
42 // For use by |MOJO_MULTIPROCESS_TEST_CHILD_MAIN()| only: 49 // For use by |MOJO_MULTIPROCESS_TEST_CHILD_MAIN()| only:
43 static void ChildSetup(); 50 static void ChildSetup();
44 51
45 // For use in the main process: 52 // For use in the main process:
46 embedder::ScopedPlatformHandle server_platform_handle; 53 embedder::ScopedPlatformHandle server_platform_handle;
47 54
48 // For use (and only valid) in the child process: 55 // For use (and only valid) in the child process:
49 static embedder::ScopedPlatformHandle client_platform_handle; 56 static embedder::ScopedPlatformHandle client_platform_handle;
50 57
51 private: 58 private:
52 scoped_ptr<embedder::PlatformChannelPair> platform_channel_pair_; 59 scoped_ptr<embedder::PlatformChannelPair> platform_channel_pair_;
53 60
54 // Valid after |StartChild()| and before |WaitForChildShutdown()|. 61 // Valid after |StartChild()| and before |WaitForChildShutdown()|.
55 base::ProcessHandle test_child_handle_; 62 base::ProcessHandle test_child_handle_;
56 63
57 DISALLOW_COPY_AND_ASSIGN(MultiprocessTestHelper); 64 DISALLOW_COPY_AND_ASSIGN(MultiprocessTestHelper);
58 }; 65 };
59 66
60 // Use this to declare the child process's "main()" function for tests using 67 // Use this to declare the child process's "main()" function for tests using
61 // |MultiprocessTestHelper|. It returns an |int|, which will be the process's 68 // |MultiprocessTestHelper|. It returns an |int|, which will be the process's
62 // exit code (but see the comment about |WaitForChildShutdown()|). 69 // exit code (but see the comment about |WaitForChildShutdown()|).
63 #define MOJO_MULTIPROCESS_TEST_CHILD_MAIN(test_child_name) \ 70 #define MOJO_MULTIPROCESS_TEST_CHILD_MAIN(test_child_name) \
64 MULTIPROCESS_TEST_MAIN_WITH_SETUP( \ 71 MULTIPROCESS_TEST_MAIN_WITH_SETUP( \
65 test_child_name ## TestChildMain, \ 72 test_child_name ## TestChildMain, \
66 ::mojo::test::MultiprocessTestHelper::ChildSetup) 73 ::mojo::test::MultiprocessTestHelper::ChildSetup)
67 74
75 // Use this (and |WaitForChildTestShutdown()|) for the child process's "main()",
76 // if you want to use |EXPECT_...()| or |ASSERT_...()|; it has a |void| return
77 // type. (Note that while an |ASSERT_...()| failure will abort the test in the
78 // child, it will not abort the test in the parent.)
79 #define MOJO_MULTIPROCESS_TEST_CHILD_TEST(test_child_name) \
80 void test_child_name ## TestChildTest(); \
81 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(test_child_name) { \
82 test_child_name ## TestChildTest(); \
83 return (::testing::Test::HasFatalFailure() || \
84 ::testing::Test::HasNonfatalFailure()) ? 1 : 0; \
85 } \
86 void test_child_name ## TestChildTest()
87
68 } // namespace test 88 } // namespace test
69 } // namespace mojo 89 } // namespace mojo
70 90
71 #endif // MOJO_COMMON_TEST_MULTIPROCESS_TEST_HELPER_H_ 91 #endif // MOJO_COMMON_TEST_MULTIPROCESS_TEST_HELPER_H_
OLDNEW
« no previous file with comments | « no previous file | mojo/common/test/multiprocess_test_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698