OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 #include "gtest/gtest.h" | 7 #include "gtest/gtest.h" |
8 | 8 |
9 #include <fcntl.h> | 9 #include <fcntl.h> |
10 #include <sys/types.h> | 10 #include <sys/types.h> |
| 11 #ifdef __GLIBC__ |
11 #include <sys/select.h> | 12 #include <sys/select.h> |
| 13 #endif |
12 #include <sys/stat.h> | 14 #include <sys/stat.h> |
13 #include <unistd.h> | 15 #include <unistd.h> |
14 | 16 |
15 #include <algorithm> | 17 #include <algorithm> |
16 | 18 |
17 TEST(DevTest, Simple) { | 19 TEST(DevTest, Simple) { |
18 struct stat buf; | 20 struct stat buf; |
19 EXPECT_EQ(0, stat("/dev/random", &buf)); | 21 EXPECT_EQ(0, stat("/dev/random", &buf)); |
20 int h = open("/dev/random", O_RDONLY); | 22 int h = open("/dev/random", O_RDONLY); |
21 EXPECT_GT(h, 0); | 23 EXPECT_GT(h, 0); |
22 char buff[5]; | 24 char buff[5]; |
23 EXPECT_EQ(5, read(h, reinterpret_cast<void*>(buff), 5)); | 25 EXPECT_EQ(5, read(h, reinterpret_cast<void*>(buff), 5)); |
24 | 26 |
25 EXPECT_EQ(0, stat("/dev/urandom", &buf)); | 27 EXPECT_EQ(0, stat("/dev/urandom", &buf)); |
26 int h2 = open("/dev/urandom", O_RDONLY); | 28 int h2 = open("/dev/urandom", O_RDONLY); |
27 EXPECT_GT(h2, 0); | 29 EXPECT_GT(h2, 0); |
28 EXPECT_EQ(5, read(h2, reinterpret_cast<void*>(buff), 5)); | 30 EXPECT_EQ(5, read(h2, reinterpret_cast<void*>(buff), 5)); |
29 | 31 |
30 int q = open("/dev/null", O_RDWR); | 32 int q = open("/dev/null", O_RDWR); |
31 EXPECT_EQ(5, write(q, reinterpret_cast<void*>(buff), 5)); | 33 EXPECT_EQ(5, write(q, reinterpret_cast<void*>(buff), 5)); |
32 EXPECT_EQ(0, read(q, reinterpret_cast<void*>(buff), 5)); | 34 EXPECT_EQ(0, read(q, reinterpret_cast<void*>(buff), 5)); |
33 } | 35 } |
34 | 36 |
| 37 #ifdef __GLIBC__ |
35 TEST(DevTest, Select) { | 38 TEST(DevTest, Select) { |
36 int random = open("/dev/random", O_RDONLY); | 39 int random = open("/dev/random", O_RDONLY); |
37 EXPECT_GT(random, 0); | 40 EXPECT_GT(random, 0); |
38 int null = open("/dev/null", O_RDWR); | 41 int null = open("/dev/null", O_RDWR); |
39 EXPECT_GT(null, 0); | 42 EXPECT_GT(null, 0); |
40 | 43 |
41 fd_set readfds, writefds, exceptfds; | 44 fd_set readfds, writefds, exceptfds; |
42 FD_ZERO(&readfds); | 45 FD_ZERO(&readfds); |
43 FD_ZERO(&writefds); | 46 FD_ZERO(&writefds); |
44 FD_ZERO(&exceptfds); | 47 FD_ZERO(&exceptfds); |
(...skipping 11 matching lines...) Expand all Loading... |
56 | 59 |
57 EXPECT_TRUE(FD_ISSET(random, &readfds)); | 60 EXPECT_TRUE(FD_ISSET(random, &readfds)); |
58 EXPECT_TRUE(FD_ISSET(null, &readfds)); | 61 EXPECT_TRUE(FD_ISSET(null, &readfds)); |
59 | 62 |
60 EXPECT_FALSE(FD_ISSET(random, &writefds)); | 63 EXPECT_FALSE(FD_ISSET(random, &writefds)); |
61 EXPECT_TRUE(FD_ISSET(null, &writefds)); | 64 EXPECT_TRUE(FD_ISSET(null, &writefds)); |
62 | 65 |
63 EXPECT_FALSE(FD_ISSET(random, &exceptfds)); | 66 EXPECT_FALSE(FD_ISSET(random, &exceptfds)); |
64 EXPECT_FALSE(FD_ISSET(null, &exceptfds)); | 67 EXPECT_FALSE(FD_ISSET(null, &exceptfds)); |
65 } | 68 } |
| 69 #endif // __GLIBC__ |
OLD | NEW |