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

Side by Side Diff: native_client_sdk/src/tests/nacl_io_test/syscalls_test.cc

Issue 23005005: [NaCl SDK] nacl_io: Add initial implementations of kill and signal (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nits Created 7 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « native_client_sdk/src/tests/nacl_io_test/signal_test.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
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <errno.h>
6 #include <fcntl.h>
7 #include <sys/types.h>
8 #include <sys/socket.h>
9
10 #include "gmock/gmock.h"
11 #include "gtest/gtest.h"
12
13 #include "nacl_io/kernel_intercept.h"
14 #include "nacl_io/kernel_proxy.h"
15
16 using namespace nacl_io;
17 using namespace sdk_util;
18
19 namespace {
20 class TestsWithKI : public ::testing::Test {
21 public:
22 TestsWithKI() {}
23
24 void SetUp() {
25 ki_init(&kp_);
26 }
27
28 void TearDown() {
29 ki_uninit();
30 }
31
32 protected:
33 KernelProxy kp_;
34 };
35
36 class SyscallsKill : public TestsWithKI {
37 };
38
39 class SyscallsSignal : public TestsWithKI {
40 };
41
42 TEST_F(SyscallsKill, KillSignals) {
43 // SIGSEGV can't be sent via kill(2)
44 ASSERT_EQ(-1, kill(0, SIGSEGV)) << "kill(SEGV) failed to return an error";
45 ASSERT_EQ(EINVAL, errno) << "kill(SEGV) failedd to set errno to EINVAL";
46
47 // Our implemenation should understand SIGWINCH
48 ASSERT_EQ(0, kill(0, SIGWINCH)) << "kill(SIGWINCH) failed: " << errno;
49
50 // And USR1/USR2
51 ASSERT_EQ(0, kill(0, SIGUSR1)) << "kill(SIGUSR1) failed: " << errno;
52 ASSERT_EQ(0, kill(0, SIGUSR2)) << "kill(SIGUSR2) failed: " << errno;
53 }
54
55 TEST_F(SyscallsKill, KillPIDValues) {
56 // Any PID other than 0, -1 and getpid() should yield ESRCH
57 // since there is only one valid process under NaCl
58 int mypid = getpid();
59 ASSERT_EQ(0, kill(0, SIGWINCH));
60 ASSERT_EQ(0, kill(-1, SIGWINCH));
61 ASSERT_EQ(0, kill(mypid, SIGWINCH));
62
63 // Don't use mypid + 1 since getpid() actually returns -1
64 // when the IRT interface is missing (e.g. within chrome),
65 // and 0 is always a valid PID when calling kill().
66 int invalid_pid = mypid + 10;
67 ASSERT_EQ(-1, kill(invalid_pid, SIGWINCH));
68 ASSERT_EQ(ESRCH, errno);
69 }
70
71 static bool g_handler_called = false;
72 void sighandler(int) {
73 g_handler_called = true;
74 }
75
76 TEST_F(SyscallsSignal, SignalValues) {
77 ASSERT_EQ(signal(SIGSEGV, sighandler), SIG_ERR)
78 << "registering SEGV handler didn't fail";
79 ASSERT_EQ(errno, EINVAL) << "signal(SEGV) failed to set errno to EINVAL";
80
81 ASSERT_EQ(signal(-1, sighandler), SIG_ERR)
82 << "registering handler for invalid signal didn't fail";
83 ASSERT_EQ(errno, EINVAL) << "signal(-1) failed to set errno to EINVAL";
84 }
85
86 TEST_F(SyscallsSignal, HandlerValues) {
87 // Unsupported signal.
88 ASSERT_NE(SIG_ERR, signal(SIGSEGV, SIG_DFL));
89 ASSERT_EQ(SIG_ERR, signal(SIGSEGV, SIG_IGN));
90 ASSERT_EQ(SIG_ERR, signal(SIGSEGV, sighandler));
91
92 // Supported signal.
93 ASSERT_NE(SIG_ERR, signal(SIGWINCH, SIG_DFL));
94 ASSERT_NE(SIG_ERR, signal(SIGWINCH, SIG_IGN));
95 ASSERT_NE(SIG_ERR, signal(SIGWINCH, sighandler));
96 }
97
98 TEST_F(SyscallsSignal, Sigwinch) {
99 g_handler_called = false;
100
101 // Register WINCH handler
102 sighandler_t newsig = sighandler;
103 sighandler_t oldsig = signal(SIGWINCH, newsig);
104 ASSERT_NE(oldsig, SIG_ERR);
105
106 // Send signal.
107 kill(0, SIGWINCH);
108
109 // Verify that handler was called
110 EXPECT_TRUE(g_handler_called);
111
112 // Restore existing handler
113 oldsig = signal(SIGWINCH, oldsig);
114
115 // Verify the our newsig was returned as previous handler
116 ASSERT_EQ(oldsig, newsig);
117 }
118
119 } // namespace
OLDNEW
« no previous file with comments | « native_client_sdk/src/tests/nacl_io_test/signal_test.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698