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

Side by Side Diff: util/test/multiprocess.h

Issue 553153002: Add Multiprocess::SetExpectedChildTermination() (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 6 years, 3 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
« no previous file with comments | « no previous file | util/test/multiprocess.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 2014 The Crashpad Authors. All rights reserved. 1 // Copyright 2014 The Crashpad Authors. All rights reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
(...skipping 17 matching lines...) Expand all
28 28
29 //! \brief Manages a multiprocess test. 29 //! \brief Manages a multiprocess test.
30 //! 30 //!
31 //! These tests are `fork()`-based. The parent and child processes are able to 31 //! These tests are `fork()`-based. The parent and child processes are able to
32 //! communicate via a pair of POSIX pipes. 32 //! communicate via a pair of POSIX pipes.
33 //! 33 //!
34 //! Subclasses are expected to implement the parent and child by overriding the 34 //! Subclasses are expected to implement the parent and child by overriding the
35 //! appropriate methods. 35 //! appropriate methods.
36 class Multiprocess { 36 class Multiprocess {
37 public: 37 public:
38 //! \brief The termination type for a child process.
39 enum TerminationReason : bool {
40 //! \brief The child terminated normally.
41 //!
42 //! A normal return happens when a test returns from RunChild(), or for
43 //! tests that `exec()`, returns from `main()`. This also happens for tests
44 //! that call `exit()` or `_exit()`.
45 kTerminationNormal = false,
46
47 //! \brief The child terminated by signal.
48 //!
49 //! Signal termination happens as a result of a crash, a call to `abort()`,
50 //! assertion failure (including gtest assertions), etc.
51 kTerminationSignal,
52 };
53
38 Multiprocess(); 54 Multiprocess();
39 55
40 //! \brief Runs the test. 56 //! \brief Runs the test.
41 //! 57 //!
42 //! This method establishes the proper testing environment by calling 58 //! This method establishes the proper testing environment by calling
43 //! PreFork(), then calls `fork()`. In the parent process, it calls 59 //! PreFork(), then calls `fork()`. In the parent process, it calls
44 //! RunParent(), and in the child process, it calls RunChild(). 60 //! RunParent(), and in the child process, it calls RunChild().
45 //! 61 //!
46 //! This method uses gtest assertions to validate the testing environment. If 62 //! This method uses gtest assertions to validate the testing environment. If
47 //! the testing environment cannot be set up properly, it is possible that 63 //! the testing environment cannot be set up properly, it is possible that
48 //! MultiprocessParent() or MultiprocessChild() will not be called. In the 64 //! MultiprocessParent() or MultiprocessChild() will not be called. In the
49 //! parent process, this method also waits for the child process to exit after 65 //! parent process, this method also waits for the child process to exit after
50 //! MultiprocessParent() returns, and verifies that it exited cleanly without 66 //! MultiprocessParent() returns, and verifies that it exited in accordance
51 //! raising any gtest assertions. 67 //! with the expectations set by SetExpectedChildTermination().
52 void Run(); 68 void Run();
53 69
70 //! \brief Sets the expected termination reason and code.
71 //!
72 //! The default expected termination reasaon is
73 //! TerminationReason::kTerminationNormal, and the default expected
74 //! termination code is `EXIT_SUCCESS` (`0`).
75 //!
76 //! \param[in] reason Whether to expect the child to terminate normally or
77 //! as a result of a signal.
78 //! \param[in] code If \a reason is TerminationReason::kTerminationNormal,
79 //! this is the expected exit status of the child. If \a reason is
80 //! TerminationReason::kTerminationSignal, this is the signal that is
81 //! expected to kill the child.
82 void SetExpectedChildTermination(TerminationReason reason, int code);
83
54 protected: 84 protected:
55 ~Multiprocess(); 85 ~Multiprocess();
56 86
57 //! \brief Establishes the proper testing environment prior to forking. 87 //! \brief Establishes the proper testing environment prior to forking.
58 //! 88 //!
59 //! Subclasses that solely implement a test should not need to override this 89 //! Subclasses that solely implement a test should not need to override this
60 //! method. Subclasses that do not implement tests but instead implement 90 //! method. Subclasses that do not implement tests but instead implement
61 //! additional testing features on top of this class may override this method 91 //! additional testing features on top of this class may override this method
62 //! provided that they call the superclass’ implementation first as follows: 92 //! provided that they call the superclass’ implementation first as follows:
63 //! 93 //!
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 153
124 //! \brief The subclass-provided child routine. 154 //! \brief The subclass-provided child routine.
125 //! 155 //!
126 //! Test failures should be reported via gtest: `EXPECT_*()`, `ASSERT_*()`, 156 //! Test failures should be reported via gtest: `EXPECT_*()`, `ASSERT_*()`,
127 //! `FAIL()`, etc. 157 //! `FAIL()`, etc.
128 //! 158 //!
129 //! Subclasses must implement this method to define how the child operates. 159 //! Subclasses must implement this method to define how the child operates.
130 virtual void MultiprocessChild() = 0; 160 virtual void MultiprocessChild() = 0;
131 161
132 internal::MultiprocessInfo* info_; 162 internal::MultiprocessInfo* info_;
163 int code_;
Robert Sesek 2014/09/09 20:42:44 Flip the order of these two members to match the p
Mark Mentovai 2014/09/09 20:49:33 rsesek wrote:
Robert Sesek 2014/09/09 20:50:24 No, but that's a pretty irrelevant argument for a
164 TerminationReason reason_;
133 165
134 DISALLOW_COPY_AND_ASSIGN(Multiprocess); 166 DISALLOW_COPY_AND_ASSIGN(Multiprocess);
135 }; 167 };
136 168
137 } // namespace test 169 } // namespace test
138 } // namespace crashpad 170 } // namespace crashpad
139 171
140 #endif // CRASHPAD_UTIL_TEST_MULTIPROCESS_H_ 172 #endif // CRASHPAD_UTIL_TEST_MULTIPROCESS_H_
OLDNEW
« no previous file with comments | « no previous file | util/test/multiprocess.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698