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

Side by Side Diff: sandbox/linux/seccomp-bpf/syscall_unittest.cc

Issue 11434088: Linux Sandbox: add test for one argument system calls. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | 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 <asm/unistd.h> 5 #include <asm/unistd.h>
6 #include <fcntl.h> 6 #include <fcntl.h>
7 #include <sys/mman.h> 7 #include <sys/mman.h>
8 #include <unistd.h> 8 #include <unistd.h>
9 9
10 #include "base/posix/eintr_wrapper.h" 10 #include "base/posix/eintr_wrapper.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 #else 47 #else
48 #warning Incomplete test case; need port for target platform 48 #warning Incomplete test case; need port for target platform
49 #endif 49 #endif
50 } 50 }
51 51
52 TEST(Syscall, TrivialSyscallNoArgs) { 52 TEST(Syscall, TrivialSyscallNoArgs) {
53 // Test that we can do basic system calls 53 // Test that we can do basic system calls
54 EXPECT_EQ(SandboxSyscall(__NR_getpid), syscall(__NR_getpid)); 54 EXPECT_EQ(SandboxSyscall(__NR_getpid), syscall(__NR_getpid));
55 } 55 }
56 56
57 TEST(Syscall, TrivialSyscallOneArg) {
58 int new_fd;
59 // Duplicate standard error and close it.
60 ASSERT_GE(new_fd = SandboxSyscall(__NR_dup, 2), 0);
61 int close_return_value = HANDLE_EINTR(SandboxSyscall(__NR_close, new_fd));
62 ASSERT_EQ(close_return_value, 0);
63 }
64
57 TEST(Syscall, ComplexSyscallSixArgs) { 65 TEST(Syscall, ComplexSyscallSixArgs) {
58 int fd; 66 int fd;
59 ASSERT_LE(0, fd = SandboxSyscall(__NR_open, "/dev/null", O_RDWR, 0L)); 67 ASSERT_LE(0, fd = SandboxSyscall(__NR_open, "/dev/null", O_RDWR, 0L));
60 68
61 // Use mmap() to allocate some read-only memory 69 // Use mmap() to allocate some read-only memory
62 char *addr0; 70 char *addr0;
63 ASSERT_NE((char *)NULL, 71 ASSERT_NE((char *)NULL,
64 addr0 = reinterpret_cast<char *>( 72 addr0 = reinterpret_cast<char *>(
65 SandboxSyscall(kMMapNr, (void *)NULL, 4096, PROT_READ, 73 SandboxSyscall(kMMapNr, (void *)NULL, 4096, PROT_READ,
66 MAP_PRIVATE|MAP_ANONYMOUS, fd, 0L))); 74 MAP_PRIVATE|MAP_ANONYMOUS, fd, 0L)));
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 EXPECT_EQ(8192, SandboxSyscall(__NR_read, fd, buf, 8192L)); 112 EXPECT_EQ(8192, SandboxSyscall(__NR_read, fd, buf, 8192L));
105 EXPECT_EQ(0, memcmp(addr2, buf, 8192)); 113 EXPECT_EQ(0, memcmp(addr2, buf, 8192));
106 114
107 // Clean up 115 // Clean up
108 EXPECT_EQ(0, SandboxSyscall(__NR_munmap, addr2, 8192L)); 116 EXPECT_EQ(0, SandboxSyscall(__NR_munmap, addr2, 8192L));
109 EXPECT_EQ(0, SandboxSyscall(__NR_munmap, addr3, 4096L)); 117 EXPECT_EQ(0, SandboxSyscall(__NR_munmap, addr3, 4096L));
110 EXPECT_EQ(0, HANDLE_EINTR(SandboxSyscall(__NR_close, fd))); 118 EXPECT_EQ(0, HANDLE_EINTR(SandboxSyscall(__NR_close, fd)));
111 } 119 }
112 120
113 } // namespace 121 } // namespace
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698