Chromium Code Reviews| Index: ports/glibc-compat/src/test.cc |
| diff --git a/ports/glibc-compat/src/test.cc b/ports/glibc-compat/src/test.cc |
| index cbe5e13c71e65e96a43af45f6dcb9a9d31847432..cecd1f607c2ad3f7d75ba9f189e816d2bc6e1f0a 100644 |
| --- a/ports/glibc-compat/src/test.cc |
| +++ b/ports/glibc-compat/src/test.cc |
| @@ -9,6 +9,12 @@ |
| #include <stdlib.h> |
| #include <sys/stat.h> |
| #include <sys/types.h> |
| +#include <sys/uio.h> |
| +#include <fcntl.h> |
| +#include <dirent.h> |
| +#include <sys/file.h> |
| +#include <err.h> |
| +#include <time.h> |
| #ifndef __GLIBC__ |
| #include <sys/endian.h> |
| @@ -29,7 +35,6 @@ TEST(TestMktemp, mkdtemp_errors) { |
| ASSERT_EQ(EINVAL, errno); |
| ASSERT_EQ((char*)NULL, mkdtemp(not_XXXXXX_suffix)); |
| ASSERT_EQ(EINVAL, errno); |
| - |
| } |
| TEST(TestMktemp, mkdtemp) { |
| @@ -92,6 +97,70 @@ TEST(TestEndian, byte_swap) { |
| } |
| #endif |
| +// readv is not implemented in glibc. |
| +#ifndef __GLIBC__ |
| +TEST(TestReadv, readv_writev) { |
| + struct iovec write_iov[3]; |
| + struct iovec read_iov[3]; |
| + char first[28], second[28], third[12]; |
| + read_iov[0].iov_base = first; |
| + read_iov[0].iov_len = 28; |
|
Sam Clegg
2015/07/28 00:14:13
sizeof(first)?
zhitingzhu
2015/07/28 02:05:41
Done.
|
| + read_iov[1].iov_base = second; |
| + read_iov[1].iov_len = 28; |
| + read_iov[2].iov_base = third; |
| + read_iov[2].iov_len = 12; |
| + int i = 0; |
| + ssize_t ret = 0; |
| + char str1[] = "abcdefghijklmnopqrstuvwxyz\n"; |
|
Sam Clegg
2015/07/28 00:14:13
Why not 'const char*'?
zhitingzhu
2015/07/28 02:05:41
Done.
|
| + char str2[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"; |
| + char str3[] = "0123456789\n"; |
| + write_iov[0].iov_base = str1; |
| + write_iov[0].iov_len = 28; |
|
Sam Clegg
2015/07/28 00:14:13
sizeof?
zhitingzhu
2015/07/28 02:05:41
Done.
|
| + write_iov[1].iov_base = str2; |
| + write_iov[1].iov_len = 28; |
| + write_iov[2].iov_base = str3; |
| + write_iov[2].iov_len = 12; |
| + int fd = open("test.txt", O_CREAT | O_WRONLY, S_IRUSR|S_IWUSR); |
| + ASSERT_NE(fd, -1); |
| + ret = writev(fd, write_iov, 3); |
| + ASSERT_NE(ret, -1); |
| + ASSERT_NE(close(fd), -1); |
| + fd = open("test.txt", O_RDONLY); |
| + ASSERT_NE(fd, -1); |
| + ret = readv(fd, read_iov, 3); |
| + ASSERT_NE(ret, -1); |
| + ASSERT_STREQ("abcdefghijklmnopqrstuvwxyz\n", |
|
Sam Clegg
2015/07/28 00:14:13
Use str1 here?
zhitingzhu
2015/07/28 02:05:41
Done.
|
| + (const char*)read_iov[0].iov_base); |
| + ASSERT_EQ(28, read_iov[0].iov_len); |
| + ASSERT_STREQ("ABCDEFGHIJKLMNOPQRSTUVWXYZ\n", |
| + (const char*)read_iov[1].iov_base); |
| + ASSERT_EQ(28, read_iov[1].iov_len); |
| + ASSERT_STREQ("0123456789\n", (const char*)read_iov[2].iov_base); |
| + ASSERT_EQ(12, read_iov[2].iov_len); |
| + ASSERT_NE(close(fd), -1); |
| + ASSERT_NE(-1, unlink("test.txt")); |
| +} |
| +#endif |
| + |
| +// No tests for funtions ended with at, e.g. openat, fts_* |
| +// fchdir is not implemented in sel_ldr |
| +#if 0 |
| +TEST(TestOpenat, openat) { |
| + ASSERT_NE(-1, mkdir("t1", S_IRWXU | S_IRWXG | S_IXGRP)); |
| + DIR* dir = opendir("t1"); |
| + ASSERT_NE((DIR*)NULL, dir); |
| + int fd_t1 = dirfd(dir); |
| + ASSERT_NE(-1, fd_t1); |
| + int fd_t2 = openat(fd_t1, "test.txt", O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR); |
| + ASSERT_NE(-1, fd_t2); |
| + ASSERT_EQ(4, write(fd_t2, "test", 4)); |
| + ASSERT_NE(-1, close(fd_t2)); |
| + ASSERT_NE(-1, close(fd_t1)); |
| + ASSERT_NE(-1, unlink("t1/test.txt")); |
| + ASSERT_NE(-1, rmdir("t1")); |
| +} |
| +#endif |
| + |
| TEST(TestLockf, lockf) { |
| // The fcntl() method underlying lockf() is not implemented in NaCl. |
| ASSERT_EQ(-1, lockf(1, F_LOCK, 1)); |
| @@ -102,6 +171,31 @@ TEST(TestLockf, lockf) { |
| ASSERT_EQ(ENOSYS, errno); |
| } |
| +TEST(TestFlock, flock) { |
| + // The fcntl() method underlying flock() is not implemented in NaCl. |
| + ASSERT_EQ(-1, flock(1, LOCK_SH)); |
| + ASSERT_EQ(ENOSYS, errno); |
| + ASSERT_EQ(-1, flock(1, LOCK_EX)); |
| + ASSERT_EQ(ENOSYS, errno); |
| + ASSERT_EQ(-1, flock(1, LOCK_UN)); |
| + ASSERT_EQ(ENOSYS, errno); |
| +} |
| + |
| +// Can't tested err as it will let the test program fail. |
|
Sam Clegg
2015/07/28 00:14:13
Can you elaborate or re-phrase this comment? Its
zhitingzhu
2015/07/28 02:05:41
Done.
|
| + |
| +TEST(TestTimegm, timegm) { |
| + struct tm tmp; |
| + tmp.tm_sec = 1; |
| + tmp.tm_min = 0; |
| + tmp.tm_hour = 0; |
| + tmp.tm_mday = 3; |
| + tmp.tm_mon = 4 - 1; |
| + tmp.tm_year = 2015 - 1900; |
| + tmp.tm_isdst = -1; |
| + time_t tt = timegm(&tmp); |
| + ASSERT_EQ(1428019201, tt); |
| +} |
| + |
| int main(int argc, char** argv) { |
| setenv("TERM", "xterm-256color", 0); |
| ::testing::InitGoogleTest(&argc, argv); |