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

Side by Side Diff: util/mach/scoped_task_suspend_test.cc

Issue 649693002: Add ScopedTaskSuspend and its test (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Update documentation Created 6 years, 2 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/mach/scoped_task_suspend.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
(Empty)
1 // Copyright 2014 The Crashpad Authors. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "util/mach/scoped_task_suspend.h"
16
17 #include <mach/mach.h>
18
19 #include "gtest/gtest.h"
20 #include "util/file/fd_io.h"
21 #include "util/test/mac/mach_errors.h"
22 #include "util/test/mac/mach_multiprocess.h"
23
24 namespace crashpad {
25 namespace test {
26 namespace {
27
28 int SuspendCount(task_t task) {
29 // As of the 10.8 SDK, the preferred routine is MACH_TASK_BASIC_INFO.
30 // TASK_BASIC_INFO_64 is equivalent and works on earlier systems.
31 task_basic_info_64 task_basic_info;
32 mach_msg_type_number_t task_basic_info_count = TASK_BASIC_INFO_64_COUNT;
33 kern_return_t kr = task_info(task,
34 TASK_BASIC_INFO_64,
35 reinterpret_cast<task_info_t>(&task_basic_info),
36 &task_basic_info_count);
37 if (kr != KERN_SUCCESS) {
38 ADD_FAILURE() << MachErrorMessage(kr, "task_info");
39 return -1;
40 }
41
42 return task_basic_info.suspend_count;
43 }
44
45 class ScopedTaskSuspendTest final : public MachMultiprocess {
46 public:
47 ScopedTaskSuspendTest() : MachMultiprocess() {}
48 ~ScopedTaskSuspendTest() {}
49
50 private:
51 // MachMultiprocess:
52
53 virtual void MachMultiprocessParent() override {
54 task_t child_task = ChildTask();
55
56 EXPECT_EQ(0, SuspendCount(child_task));
57
58 {
59 ScopedTaskSuspend suspend(child_task);
60 EXPECT_EQ(1, SuspendCount(child_task));
61
62 {
63 ScopedTaskSuspend suspend_again(child_task);
64 EXPECT_EQ(2, SuspendCount(child_task));
65 }
66
67 EXPECT_EQ(1, SuspendCount(child_task));
68 }
69
70 EXPECT_EQ(0, SuspendCount(child_task));
71 }
72
73 virtual void MachMultiprocessChild() override {
74 CheckedReadFDAtEOF(ReadPipeFD());
75 }
76
77 DISALLOW_COPY_AND_ASSIGN(ScopedTaskSuspendTest);
78 };
79
80 TEST(ScopedTaskSuspend, ScopedTaskSuspend) {
81 ScopedTaskSuspendTest scoped_task_suspend_test;
82 scoped_task_suspend_test.Run();
83 }
84
85 } // namespace
86 } // namespace test
87 } // namespace crashpad
OLDNEW
« no previous file with comments | « util/mach/scoped_task_suspend.cc ('k') | util/util.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698