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

Side by Side Diff: sandbox/mac/sandbox_mac_compiler_unittest.mm

Issue 2733323002: Changing multiprocess test SpawnChild to return a struct. (Closed)
Patch Set: Fixed bots. Created 3 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #include <fcntl.h> 5 #include <fcntl.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 #include <sys/stat.h> 7 #include <sys/stat.h>
8 #include <unistd.h> 8 #include <unistd.h>
9 9
10 #include "base/process/kill.h" 10 #include "base/process/kill.h"
(...skipping 14 matching lines...) Expand all
25 25
26 SandboxCompiler compiler(profile); 26 SandboxCompiler compiler(profile);
27 27
28 std::string error; 28 std::string error;
29 CHECK(compiler.CompileAndApplyProfile(&error)); 29 CHECK(compiler.CompileAndApplyProfile(&error));
30 30
31 return 0; 31 return 0;
32 } 32 }
33 33
34 TEST_F(SandboxMacCompilerTest, BasicProfileTest) { 34 TEST_F(SandboxMacCompilerTest, BasicProfileTest) {
35 base::Process process = SpawnChild("BasicProfileProcess"); 35 base::SpawnChildResult spawn_result = SpawnChild("BasicProfileProcess");
36 base::Process process = std::move(spawn_result.process);
36 ASSERT_TRUE(process.IsValid()); 37 ASSERT_TRUE(process.IsValid());
37 int exit_code = 42; 38 int exit_code = 42;
38 EXPECT_TRUE(process.WaitForExitWithTimeout(TestTimeouts::action_max_timeout(), 39 EXPECT_TRUE(process.WaitForExitWithTimeout(TestTimeouts::action_max_timeout(),
39 &exit_code)); 40 &exit_code));
40 EXPECT_EQ(exit_code, 0); 41 EXPECT_EQ(exit_code, 0);
41 } 42 }
42 43
43 MULTIPROCESS_TEST_MAIN(BasicProfileWithParamProcess) { 44 MULTIPROCESS_TEST_MAIN(BasicProfileWithParamProcess) {
44 std::string profile = 45 std::string profile =
45 "(version 1)" 46 "(version 1)"
46 "(allow file-read* file-write* (literal (param \"DIR\")))"; 47 "(allow file-read* file-write* (literal (param \"DIR\")))";
47 48
48 SandboxCompiler compiler(profile); 49 SandboxCompiler compiler(profile);
49 CHECK(compiler.InsertStringParam("DIR", "/")); 50 CHECK(compiler.InsertStringParam("DIR", "/"));
50 51
51 std::string error; 52 std::string error;
52 CHECK(compiler.CompileAndApplyProfile(&error)); 53 CHECK(compiler.CompileAndApplyProfile(&error));
53 54
54 return 0; 55 return 0;
55 } 56 }
56 57
57 TEST_F(SandboxMacCompilerTest, BasicProfileTestWithParam) { 58 TEST_F(SandboxMacCompilerTest, BasicProfileTestWithParam) {
58 base::Process process = SpawnChild("BasicProfileWithParamProcess"); 59 base::SpawnChildResult spawn_result =
60 SpawnChild("BasicProfileWithParamProcess");
61 base::Process process = std::move(spawn_result.process);
59 ASSERT_TRUE(process.IsValid()); 62 ASSERT_TRUE(process.IsValid());
60 int exit_code = 42; 63 int exit_code = 42;
61 EXPECT_TRUE(process.WaitForExitWithTimeout(TestTimeouts::action_max_timeout(), 64 EXPECT_TRUE(process.WaitForExitWithTimeout(TestTimeouts::action_max_timeout(),
62 &exit_code)); 65 &exit_code));
63 EXPECT_EQ(exit_code, 0); 66 EXPECT_EQ(exit_code, 0);
64 } 67 }
65 68
66 MULTIPROCESS_TEST_MAIN(ProfileFunctionalProcess) { 69 MULTIPROCESS_TEST_MAIN(ProfileFunctionalProcess) {
67 std::string profile = 70 std::string profile =
68 "(version 1)" 71 "(version 1)"
(...skipping 10 matching lines...) Expand all
79 uint8_t byte; 82 uint8_t byte;
80 int fd = open("/dev/urandom", O_RDONLY); 83 int fd = open("/dev/urandom", O_RDONLY);
81 CHECK_NE(fd, -1); 84 CHECK_NE(fd, -1);
82 85
83 EXPECT_TRUE(read(fd, &byte, sizeof(byte)) == sizeof(byte)); 86 EXPECT_TRUE(read(fd, &byte, sizeof(byte)) == sizeof(byte));
84 87
85 return 0; 88 return 0;
86 } 89 }
87 90
88 TEST_F(SandboxMacCompilerTest, ProfileFunctionalityTest) { 91 TEST_F(SandboxMacCompilerTest, ProfileFunctionalityTest) {
89 base::Process process = SpawnChild("ProfileFunctionalProcess"); 92 base::SpawnChildResult spawn_result = SpawnChild("ProfileFunctionalProcess");
93 base::Process process = std::move(spawn_result.process);
90 ASSERT_TRUE(process.IsValid()); 94 ASSERT_TRUE(process.IsValid());
91 int exit_code = 42; 95 int exit_code = 42;
92 EXPECT_TRUE(process.WaitForExitWithTimeout(TestTimeouts::action_max_timeout(), 96 EXPECT_TRUE(process.WaitForExitWithTimeout(TestTimeouts::action_max_timeout(),
93 &exit_code)); 97 &exit_code));
94 EXPECT_EQ(exit_code, 0); 98 EXPECT_EQ(exit_code, 0);
95 } 99 }
96 100
97 MULTIPROCESS_TEST_MAIN(ProfileFunctionalTestWithParamsProcess) { 101 MULTIPROCESS_TEST_MAIN(ProfileFunctionalTestWithParamsProcess) {
98 std::string profile = 102 std::string profile =
99 "(version 1)" 103 "(version 1)"
(...skipping 19 matching lines...) Expand all
119 EXPECT_TRUE(read(fd, &byte, sizeof(byte)) == sizeof(byte)); 123 EXPECT_TRUE(read(fd, &byte, sizeof(byte)) == sizeof(byte));
120 124
121 // Make sure the sandbox isn't overly permissive. 125 // Make sure the sandbox isn't overly permissive.
122 struct stat st; 126 struct stat st;
123 EXPECT_EQ(stat("/", &st), -1); 127 EXPECT_EQ(stat("/", &st), -1);
124 128
125 return 0; 129 return 0;
126 } 130 }
127 131
128 TEST_F(SandboxMacCompilerTest, ProfileFunctionalityTestWithParams) { 132 TEST_F(SandboxMacCompilerTest, ProfileFunctionalityTestWithParams) {
129 base::Process process = SpawnChild("ProfileFunctionalTestWithParamsProcess"); 133 base::SpawnChildResult spawn_result =
134 SpawnChild("ProfileFunctionalTestWithParamsProcess");
135 base::Process process = std::move(spawn_result.process);
130 ASSERT_TRUE(process.IsValid()); 136 ASSERT_TRUE(process.IsValid());
131 int exit_code = 42; 137 int exit_code = 42;
132 EXPECT_TRUE(process.WaitForExitWithTimeout(TestTimeouts::action_max_timeout(), 138 EXPECT_TRUE(process.WaitForExitWithTimeout(TestTimeouts::action_max_timeout(),
133 &exit_code)); 139 &exit_code));
134 EXPECT_EQ(exit_code, 0); 140 EXPECT_EQ(exit_code, 0);
135 } 141 }
136 142
137 MULTIPROCESS_TEST_MAIN(ProfileFunctionalityTestErrorProcess) { 143 MULTIPROCESS_TEST_MAIN(ProfileFunctionalityTestErrorProcess) {
138 std::string profile = "(+ 5 a)"; 144 std::string profile = "(+ 5 a)";
139 145
140 SandboxCompiler compiler(profile); 146 SandboxCompiler compiler(profile);
141 147
142 // Make sure that this invalid profile results in an error returned. 148 // Make sure that this invalid profile results in an error returned.
143 std::string error; 149 std::string error;
144 CHECK_EQ(error, ""); 150 CHECK_EQ(error, "");
145 CHECK(!compiler.CompileAndApplyProfile(&error)); 151 CHECK(!compiler.CompileAndApplyProfile(&error));
146 CHECK_NE(error, ""); 152 CHECK_NE(error, "");
147 153
148 return 0; 154 return 0;
149 } 155 }
150 156
151 TEST_F(SandboxMacCompilerTest, ProfileFunctionalityTestError) { 157 TEST_F(SandboxMacCompilerTest, ProfileFunctionalityTestError) {
152 base::Process process = SpawnChild("ProfileFunctionalityTestErrorProcess"); 158 base::SpawnChildResult spawn_result =
159 SpawnChild("ProfileFunctionalityTestErrorProcess");
160 base::Process process = std::move(spawn_result.process);
153 ASSERT_TRUE(process.IsValid()); 161 ASSERT_TRUE(process.IsValid());
154 int exit_code = 42; 162 int exit_code = 42;
155 EXPECT_TRUE(process.WaitForExitWithTimeout(TestTimeouts::action_max_timeout(), 163 EXPECT_TRUE(process.WaitForExitWithTimeout(TestTimeouts::action_max_timeout(),
156 &exit_code)); 164 &exit_code));
157 EXPECT_EQ(exit_code, 0); 165 EXPECT_EQ(exit_code, 0);
158 } 166 }
159 167
160 } // namespace sandbox 168 } // namespace sandbox
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698