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

Side by Side Diff: sandbox/linux/tests/unit_tests.cc

Issue 1147463003: Linux sandbox: support build configuration without base test framework (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 | « sandbox/linux/tests/main.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <poll.h> 6 #include <poll.h>
7 #include <signal.h> 7 #include <signal.h>
8 #include <stdio.h> 8 #include <stdio.h>
9 #include <sys/resource.h> 9 #include <sys/resource.h>
10 #include <sys/time.h> 10 #include <sys/time.h>
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 62
63 // TODO(jln): figure out why base/.../dynamic_annotations.h's 63 // TODO(jln): figure out why base/.../dynamic_annotations.h's
64 // RunningOnValgrind() cannot link. 64 // RunningOnValgrind() cannot link.
65 bool IsRunningOnValgrind() { return RUNNING_ON_VALGRIND; } 65 bool IsRunningOnValgrind() { return RUNNING_ON_VALGRIND; }
66 66
67 static const int kExpectedValue = 42; 67 static const int kExpectedValue = 42;
68 static const int kIgnoreThisTest = 43; 68 static const int kIgnoreThisTest = 43;
69 static const int kExitWithAssertionFailure = 1; 69 static const int kExitWithAssertionFailure = 1;
70 static const int kExitForTimeout = 2; 70 static const int kExitForTimeout = 2;
71 71
72 #if !defined(OS_ANDROID) 72 #if defined(SANDBOX_USES_BASE_TEST_SUITE)
73 // This is due to StackDumpSignalHandler() performing _exit(1). 73 // This is due to StackDumpSignalHandler() performing _exit(1).
74 // TODO(jln): get rid of the collision with kExitWithAssertionFailure. 74 // TODO(jln): get rid of the collision with kExitWithAssertionFailure.
75 const int kExitAfterSIGSEGV = 1; 75 const int kExitAfterSIGSEGV = 1;
76 #endif 76 #endif
77 77
78 static void SigAlrmHandler(int) { 78 static void SigAlrmHandler(int) {
79 const char failure_message[] = "Timeout reached!\n"; 79 const char failure_message[] = "Timeout reached!\n";
80 // Make sure that we never block here. 80 // Make sure that we never block here.
81 if (!fcntl(2, F_SETFL, O_NONBLOCK)) { 81 if (!fcntl(2, F_SETFL, O_NONBLOCK)) {
82 ignore_result(write(2, failure_message, sizeof(failure_message) - 1)); 82 ignore_result(write(2, failure_message, sizeof(failure_message) - 1));
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 #endif 275 #endif
276 EXPECT_FALSE(subprocess_exited_without_matching_message) << details; 276 EXPECT_FALSE(subprocess_exited_without_matching_message) << details;
277 } 277 }
278 278
279 void UnitTests::DeathSEGVMessage(int status, 279 void UnitTests::DeathSEGVMessage(int status,
280 const std::string& msg, 280 const std::string& msg,
281 const void* aux) { 281 const void* aux) {
282 std::string details(TestFailedMessage(msg)); 282 std::string details(TestFailedMessage(msg));
283 const char* expected_msg = static_cast<const char*>(aux); 283 const char* expected_msg = static_cast<const char*>(aux);
284 284
285 #if defined(OS_ANDROID) 285 #if !defined(SANDBOX_USES_BASE_TEST_SUITE)
286 const bool subprocess_got_sigsegv = 286 const bool subprocess_got_sigsegv =
287 WIFSIGNALED(status) && (SIGSEGV == WTERMSIG(status)); 287 WIFSIGNALED(status) && (SIGSEGV == WTERMSIG(status));
288 #else 288 #else
289 // This hack is required when a signaal handler is installed
mdempsky 2015/05/15 02:33:23 nit: s/signaal/signal/
290 // for SEGV that will _exit(1).
289 const bool subprocess_got_sigsegv = 291 const bool subprocess_got_sigsegv =
290 WIFEXITED(status) && (kExitAfterSIGSEGV == WEXITSTATUS(status)); 292 WIFEXITED(status) && (kExitAfterSIGSEGV == WEXITSTATUS(status));
291 #endif 293 #endif
292 294
293 ASSERT_TRUE(subprocess_got_sigsegv) << "Exit status: " << status 295 ASSERT_TRUE(subprocess_got_sigsegv) << "Exit status: " << status
294 << " " << details; 296 << " " << details;
295 297
296 bool subprocess_exited_without_matching_message = 298 bool subprocess_exited_without_matching_message =
297 msg.find(expected_msg) == std::string::npos; 299 msg.find(expected_msg) == std::string::npos;
298 EXPECT_FALSE(subprocess_exited_without_matching_message) << details; 300 EXPECT_FALSE(subprocess_exited_without_matching_message) << details;
(...skipping 28 matching lines...) Expand all
327 fflush(stderr); 329 fflush(stderr);
328 _exit(kExitWithAssertionFailure); 330 _exit(kExitWithAssertionFailure);
329 } 331 }
330 332
331 void UnitTests::IgnoreThisTest() { 333 void UnitTests::IgnoreThisTest() {
332 fflush(stderr); 334 fflush(stderr);
333 _exit(kIgnoreThisTest); 335 _exit(kIgnoreThisTest);
334 } 336 }
335 337
336 } // namespace 338 } // namespace
OLDNEW
« no previous file with comments | « sandbox/linux/tests/main.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698