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

Unified Diff: ports/glibc-compat/src/test.cc

Issue 1260083004: Add needed functions to glibc-compat for pkg (Closed) Base URL: https://chromium.googlesource.com/external/naclports.git@master
Patch Set: fix wrong c++ lib Created 5 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ports/glibc-compat/src/openat.c ('k') | ports/glibc-compat/src/timegm.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..61a82b9e95891563ccdbac80e7686cd728027e77 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,68 @@ 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 = sizeof(first);
+ read_iov[1].iov_base = second;
+ read_iov[1].iov_len = sizeof(second);
+ read_iov[2].iov_base = third;
+ read_iov[2].iov_len = sizeof(third);
+ int i = 0;
+ ssize_t ret = 0;
+ const char* str1 = "abcdefghijklmnopqrstuvwxyz\n";
+ const char* str2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ\n";
+ const char* str3 = "0123456789\n";
+ write_iov[0].iov_base = (void*)str1;
+ write_iov[0].iov_len = strlen(str1) + 1;
+ write_iov[1].iov_base = (void*)str2;
+ write_iov[1].iov_len = strlen(str2) + 1;
+ write_iov[2].iov_base = (void*)str3;
+ write_iov[2].iov_len = strlen(str3) + 1;
+ 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(str1, (const char*)read_iov[0].iov_base);
+ ASSERT_EQ(28, read_iov[0].iov_len);
+ ASSERT_STREQ(str2, (const char*)read_iov[1].iov_base);
+ ASSERT_EQ(28, read_iov[1].iov_len);
+ ASSERT_STREQ(str3, (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 +169,33 @@ 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);
+}
+
+/* Calling err will cause the test program exit with failure code if errno
+ * is set. No tests for err.
+ */
+
+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);
« no previous file with comments | « ports/glibc-compat/src/openat.c ('k') | ports/glibc-compat/src/timegm.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698