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

Side by Side Diff: util/test/multiprocess_test.cc

Issue 506143002: Refactor MachMultiprocess (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 | « util/test/multiprocess.cc ('k') | util/util.gyp » ('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,
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 "util/test/mac/mach_multiprocess.h" 15 #include "util/test/multiprocess.h"
16 16
17 #include <unistd.h> 17 #include <unistd.h>
18 18
19 #include "base/basictypes.h" 19 #include "base/basictypes.h"
20 #include "gtest/gtest.h" 20 #include "gtest/gtest.h"
21 #include "util/file/fd_io.h" 21 #include "util/file/fd_io.h"
22 #include "util/test/errors.h" 22 #include "util/test/errors.h"
23 23
24 namespace { 24 namespace {
25 25
26 using namespace crashpad; 26 using namespace crashpad;
27 using namespace crashpad::test; 27 using namespace crashpad::test;
28 28
29 class TestMachMultiprocess final : public MachMultiprocess { 29 class TestMultiprocess final : public Multiprocess {
30 public: 30 public:
31 TestMachMultiprocess() : MachMultiprocess() {} 31 TestMultiprocess() : Multiprocess() {}
32 32
33 ~TestMachMultiprocess() {} 33 ~TestMultiprocess() {}
34 34
35 protected: 35 private:
36 // The base class will have already exercised the Mach ports for IPC and the 36 virtual void MultiprocessParent() override {
37 // child task port. Just make sure that the pipe is set up correctly and that
38 // ChildPID() works as expected.
39 virtual void Parent() override {
40 int read_fd = ReadPipeFD(); 37 int read_fd = ReadPipeFD();
41 char c; 38 char c;
42 ssize_t rv = ReadFD(read_fd, &c, 1); 39 ssize_t rv = ReadFD(read_fd, &c, 1);
43 ASSERT_EQ(1, rv) << ErrnoMessage("read"); 40 ASSERT_EQ(1, rv) << ErrnoMessage("read");
44 EXPECT_EQ('M', c); 41 EXPECT_EQ('M', c);
45 42
46 pid_t pid; 43 pid_t pid;
47 rv = ReadFD(read_fd, &pid, sizeof(pid)); 44 rv = ReadFD(read_fd, &pid, sizeof(pid));
48 ASSERT_EQ(static_cast<ssize_t>(sizeof(pid)), rv) << ErrnoMessage("read"); 45 ASSERT_EQ(static_cast<ssize_t>(sizeof(pid)), rv) << ErrnoMessage("read");
49 EXPECT_EQ(pid, ChildPID()); 46 EXPECT_EQ(pid, ChildPID());
50 47
51 int write_fd = WritePipeFD(); 48 int write_fd = WritePipeFD();
52 c = 'm'; 49 c = 'm';
53 rv = WriteFD(write_fd, &c, 1); 50 rv = WriteFD(write_fd, &c, 1);
54 ASSERT_EQ(1, rv) << ErrnoMessage("write"); 51 ASSERT_EQ(1, rv) << ErrnoMessage("write");
55 52
56 // The child will close its end of the pipe and exit. Make sure that the 53 // The child will close its end of the pipe and exit. Make sure that the
57 // parent sees EOF. 54 // parent sees EOF.
58 rv = ReadFD(read_fd, &c, 1); 55 rv = ReadFD(read_fd, &c, 1);
59 ASSERT_EQ(0, rv) << ErrnoMessage("read"); 56 ASSERT_EQ(0, rv) << ErrnoMessage("read");
60 } 57 }
61 58
62 virtual void Child() override { 59 virtual void MultiprocessChild() override {
63 int write_fd = WritePipeFD(); 60 int write_fd = WritePipeFD();
64 61
65 char c = 'M'; 62 char c = 'M';
66 ssize_t rv = WriteFD(write_fd, &c, 1); 63 ssize_t rv = WriteFD(write_fd, &c, 1);
67 ASSERT_EQ(1, rv) << ErrnoMessage("write"); 64 ASSERT_EQ(1, rv) << ErrnoMessage("write");
68 65
69 pid_t pid = getpid(); 66 pid_t pid = getpid();
70 rv = WriteFD(write_fd, &pid, sizeof(pid)); 67 rv = WriteFD(write_fd, &pid, sizeof(pid));
71 ASSERT_EQ(static_cast<ssize_t>(sizeof(pid)), rv) << ErrnoMessage("write"); 68 ASSERT_EQ(static_cast<ssize_t>(sizeof(pid)), rv) << ErrnoMessage("write");
72 69
73 int read_fd = ReadPipeFD(); 70 int read_fd = ReadPipeFD();
74 rv = ReadFD(read_fd, &c, 1); 71 rv = ReadFD(read_fd, &c, 1);
75 ASSERT_EQ(1, rv) << ErrnoMessage("read"); 72 ASSERT_EQ(1, rv) << ErrnoMessage("read");
76 EXPECT_EQ('m', c); 73 EXPECT_EQ('m', c);
77 } 74 }
78 75
79 private: 76 DISALLOW_COPY_AND_ASSIGN(TestMultiprocess);
80 DISALLOW_COPY_AND_ASSIGN(TestMachMultiprocess);
81 }; 77 };
82 78
83 TEST(MachMultiprocess, MachMultiprocess) { 79 TEST(Multiprocess, Multiprocess) {
84 TestMachMultiprocess mach_multiprocess; 80 TestMultiprocess multiprocess;
85 mach_multiprocess.Run(); 81 multiprocess.Run();
86 } 82 }
87 83
88 } // namespace 84 } // namespace
OLDNEW
« no previous file with comments | « util/test/multiprocess.cc ('k') | util/util.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698