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

Side by Side Diff: test/win/win_multiprocess_test.cc

Issue 1164453003: Refactor multiprocess test code to allow multiple child processes to be launched. (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@multiprocess_test
Patch Set: Review comment. Created 5 years, 5 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 | « test/win/win_multiprocess.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Crashpad Authors. All rights reserved. 1 // Copyright 2015 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,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 #include "test/win/win_multiprocess.h" 15 #include "test/win/win_multiprocess.h"
16 16
17 #include "base/basictypes.h" 17 #include "base/basictypes.h"
18 #include "gtest/gtest.h" 18 #include "gtest/gtest.h"
19 19
20 namespace crashpad { 20 namespace crashpad {
21 namespace test { 21 namespace test {
22 namespace { 22 namespace {
23 23
24 template <int ExitCode>
24 class TestWinMultiprocess final : public WinMultiprocess { 25 class TestWinMultiprocess final : public WinMultiprocess {
25 public: 26 public:
26 explicit TestWinMultiprocess(unsigned int exit_code) 27 TestWinMultiprocess() {}
27 : WinMultiprocess(), exit_code_(exit_code) {}
28
29 ~TestWinMultiprocess() {}
30 28
31 private: 29 private:
32 // WinMultiprocess will have already exercised the pipes. 30 // WinMultiprocess will have already exercised the pipes.
33 void WinMultiprocessParent() override {} 31 void WinMultiprocessParent() override { SetExpectedChildExitCode(ExitCode); }
34 32
35 void WinMultiprocessChild() override { 33 void WinMultiprocessChild() override {
36 exit(exit_code_); 34 exit(ExitCode);
37 } 35 }
38 36
39 unsigned int exit_code_;
40
41 DISALLOW_COPY_AND_ASSIGN(TestWinMultiprocess); 37 DISALLOW_COPY_AND_ASSIGN(TestWinMultiprocess);
42 }; 38 };
43 39
44 enum class FailureType { 40 class TestWinMultiprocessChildAsserts final : public WinMultiprocess {
45 kExpect, 41 public:
46 kAssert, 42 TestWinMultiprocessChildAsserts() {}
43
44 private:
45 void WinMultiprocessParent() override { SetExpectedChildExitCode(255); }
46 void WinMultiprocessChild() override {
47 ASSERT_FALSE(true);
48 }
49
50 DISALLOW_COPY_AND_ASSIGN(TestWinMultiprocessChildAsserts);
47 }; 51 };
48 52
49 class TestWinMultiprocessChildFails final : public WinMultiprocess { 53 class TestWinMultiprocessChildExpects final : public WinMultiprocess {
50 public: 54 public:
51 explicit TestWinMultiprocessChildFails(FailureType failure_type) 55 TestWinMultiprocessChildExpects() {}
52 : WinMultiprocess(), failure_type_(failure_type) {}
53 ~TestWinMultiprocessChildFails() {}
54 56
55 private: 57 private:
56 void WinMultiprocessParent() override {} 58 void WinMultiprocessParent() override { SetExpectedChildExitCode(255); }
57 void WinMultiprocessChild() override { 59 void WinMultiprocessChild() override {
58 switch (failure_type_) { 60 EXPECT_FALSE(true);
59 case FailureType::kExpect:
60 EXPECT_FALSE(true);
61 break;
62 case FailureType::kAssert:
63 ASSERT_FALSE(true);
64 break;
65 }
66 } 61 }
67 62
68 FailureType failure_type_; 63 DISALLOW_COPY_AND_ASSIGN(TestWinMultiprocessChildExpects);
69
70 DISALLOW_COPY_AND_ASSIGN(TestWinMultiprocessChildFails);
71 }; 64 };
72 65
73
74 TEST(WinMultiprocess, WinMultiprocess) { 66 TEST(WinMultiprocess, WinMultiprocess) {
75 TestWinMultiprocess win_multiprocess(0); 67 WinMultiprocess::Run<TestWinMultiprocess<0>>();
76 win_multiprocess.Run();
77 } 68 }
78 69
79 TEST(WinMultiprocess, WinMultiprocessNonSuccessExitCode) { 70 TEST(WinMultiprocess, WinMultiprocessNonSuccessExitCode) {
80 TestWinMultiprocess win_multiprocess(100); 71 WinMultiprocess::Run<TestWinMultiprocess<100>>();
81 win_multiprocess.SetExpectedChildExitCode(100);
82 win_multiprocess.Run();
83 } 72 }
84 73
85 TEST(WinMultiprocessChildFails, ChildExpectFailure) { 74 TEST(WinMultiprocessChildFails, ChildExpectFailure) {
86 TestWinMultiprocessChildFails multiprocess_failing_child( 75 WinMultiprocess::Run<TestWinMultiprocessChildExpects>();
87 FailureType::kExpect);
88 multiprocess_failing_child.SetExpectedChildExitCode(255);
89 multiprocess_failing_child.Run();
90 } 76 }
91 77
92 TEST(WinMultiprocessChildFails, ChildAssertFailure) { 78 TEST(WinMultiprocessChildFails, ChildAssertFailure) {
93 TestWinMultiprocessChildFails multiprocess_failing_child( 79 WinMultiprocess::Run<TestWinMultiprocessChildAsserts>();
94 FailureType::kAssert);
95 multiprocess_failing_child.SetExpectedChildExitCode(255);
96 multiprocess_failing_child.Run();
97 } 80 }
98 81
99 } // namespace 82 } // namespace
100 } // namespace test 83 } // namespace test
101 } // namespace crashpad 84 } // namespace crashpad
OLDNEW
« no previous file with comments | « test/win/win_multiprocess.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698