Fix __pthread_clone on ARM to set errno on failure.
MIPS and x86 appear to have been correct already.
(Also fix unit tests that ASSERT_EQ with errno so that the
arguments are in the retarded junit order.)
Bug: 3461078
Change-Id: I2418ea98927b56e15b4ba9cfec97f5e7094c6291
diff --git a/tests/dirent_test.cpp b/tests/dirent_test.cpp
index 8f3c249..48ca819 100644
--- a/tests/dirent_test.cpp
+++ b/tests/dirent_test.cpp
@@ -66,12 +66,12 @@
TEST(dirent, fdopendir_invalid) {
ASSERT_TRUE(fdopendir(-1) == NULL);
- ASSERT_EQ(errno, EBADF);
+ ASSERT_EQ(EBADF, errno);
int fd = open("/dev/null", O_RDONLY);
ASSERT_NE(fd, -1);
ASSERT_TRUE(fdopendir(fd) == NULL);
- ASSERT_EQ(errno, ENOTDIR);
+ ASSERT_EQ(ENOTDIR, errno);
close(fd);
}
@@ -85,15 +85,15 @@
// fdopendir(3) took ownership, so closedir(3) closed our fd.
ASSERT_EQ(close(fd), -1);
- ASSERT_EQ(errno, EBADF);
+ ASSERT_EQ(EBADF, errno);
}
TEST(dirent, opendir_invalid) {
ASSERT_TRUE(opendir("/does/not/exist") == NULL);
- ASSERT_EQ(errno, ENOENT);
+ ASSERT_EQ(ENOENT, errno);
ASSERT_TRUE(opendir("/dev/null") == NULL);
- ASSERT_EQ(errno, ENOTDIR);
+ ASSERT_EQ(ENOTDIR, errno);
}
TEST(dirent, opendir) {
@@ -107,7 +107,7 @@
TEST(dirent, closedir_invalid) {
DIR* d = NULL;
ASSERT_EQ(closedir(d), -1);
- ASSERT_EQ(errno, EINVAL);
+ ASSERT_EQ(EINVAL, errno);
}
TEST(dirent, closedir) {
@@ -127,7 +127,7 @@
}
// Reading to the end of the directory is not an error.
// readdir(3) returns NULL, but leaves errno as 0.
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(0, errno);
ASSERT_EQ(closedir(d), 0);
CheckProcSelf(name_set);
@@ -145,7 +145,7 @@
}
// Reading to the end of the directory is not an error.
// readdir_r(3) returns NULL, but leaves errno as 0.
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(0, errno);
ASSERT_EQ(closedir(d), 0);
CheckProcSelf(name_set);
diff --git a/tests/getcwd_test.cpp b/tests/getcwd_test.cpp
index 45ff395..b3b4136 100644
--- a/tests/getcwd_test.cpp
+++ b/tests/getcwd_test.cpp
@@ -25,7 +25,7 @@
errno = 0;
char* cwd = getcwd(NULL, 0);
ASSERT_TRUE(cwd != NULL);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(0, errno);
ASSERT_GE(strlen(cwd), 1U);
free(cwd);
}
@@ -35,7 +35,7 @@
errno = 0;
char* cwd = getcwd(NULL, PATH_MAX);
ASSERT_TRUE(cwd != NULL);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(0, errno);
ASSERT_GE(strlen(cwd), 1U);
free(cwd);
}
@@ -45,7 +45,7 @@
errno = 0;
char* cwd = getcwd(NULL, 1);
ASSERT_TRUE(cwd == NULL);
- ASSERT_EQ(errno, ERANGE);
+ ASSERT_EQ(ERANGE, errno);
}
TEST(getcwd, auto_too_large) {
@@ -53,7 +53,7 @@
errno = 0;
char* cwd = getcwd(NULL, static_cast<size_t>(-1));
ASSERT_TRUE(cwd == NULL);
- ASSERT_EQ(errno, ENOMEM);
+ ASSERT_EQ(ENOMEM, errno);
}
TEST(getcwd, manual_too_small) {
@@ -62,7 +62,7 @@
errno = 0;
char* cwd = getcwd(tiny_buf, sizeof(tiny_buf));
ASSERT_TRUE(cwd == NULL);
- ASSERT_EQ(errno, ERANGE);
+ ASSERT_EQ(ERANGE, errno);
}
TEST(getcwd, manual_zero) {
@@ -71,7 +71,7 @@
errno = 0;
char* cwd = getcwd(tiny_buf, 0);
ASSERT_TRUE(cwd == NULL);
- ASSERT_EQ(errno, EINVAL);
+ ASSERT_EQ(EINVAL, errno);
}
TEST(getcwd, manual_path_max) {
@@ -79,7 +79,7 @@
errno = 0;
char* cwd = getcwd(buf, PATH_MAX);
ASSERT_TRUE(cwd == buf);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(0, errno);
ASSERT_GE(strlen(cwd), 1U);
delete[] cwd;
}
diff --git a/tests/pthread_test.cpp b/tests/pthread_test.cpp
index 2cf45f3..0ccd948 100644
--- a/tests/pthread_test.cpp
+++ b/tests/pthread_test.cpp
@@ -173,3 +173,13 @@
ASSERT_EQ(SIGUSR1, received_signal);
ASSERT_EQ(0, reinterpret_cast<int>(join_result));
}
+
+#if !defined(__GLIBC__)
+extern "C" int __pthread_clone(int (*fn)(void*), void* child_stack, int flags, void* arg);
+TEST(pthread, __pthread_clone) {
+ uintptr_t fake_child_stack[16];
+ errno = 0;
+ ASSERT_EQ(-1, __pthread_clone(NULL, &fake_child_stack[0], CLONE_THREAD, NULL));
+ ASSERT_EQ(EINVAL, errno);
+}
+#endif
diff --git a/tests/stdio_test.cpp b/tests/stdio_test.cpp
index 39f9b0f..70a71fb 100644
--- a/tests/stdio_test.cpp
+++ b/tests/stdio_test.cpp
@@ -75,7 +75,7 @@
// It should set the end-of-file indicator for the stream, though.
errno = 0;
ASSERT_EQ(getdelim(&word_read, &allocated_length, ' ', fp), -1);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(0, errno);
ASSERT_TRUE(feof(fp));
free(word_read);
@@ -91,18 +91,18 @@
// The first argument can't be NULL.
errno = 0;
ASSERT_EQ(getdelim(NULL, &buffer_length, ' ', fp), -1);
- ASSERT_EQ(errno, EINVAL);
+ ASSERT_EQ(EINVAL, errno);
// The second argument can't be NULL.
errno = 0;
ASSERT_EQ(getdelim(&buffer, NULL, ' ', fp), -1);
- ASSERT_EQ(errno, EINVAL);
+ ASSERT_EQ(EINVAL, errno);
// The stream can't be closed.
fclose(fp);
errno = 0;
ASSERT_EQ(getdelim(&buffer, &buffer_length, ' ', fp), -1);
- ASSERT_EQ(errno, EBADF);
+ ASSERT_EQ(EBADF, errno);
}
TEST(stdio, getline) {
@@ -140,7 +140,7 @@
// It should set the end-of-file indicator for the stream, though.
errno = 0;
ASSERT_EQ(getline(&line_read, &allocated_length, fp), -1);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(0, errno);
ASSERT_TRUE(feof(fp));
free(line_read);
@@ -156,16 +156,16 @@
// The first argument can't be NULL.
errno = 0;
ASSERT_EQ(getline(NULL, &buffer_length, fp), -1);
- ASSERT_EQ(errno, EINVAL);
+ ASSERT_EQ(EINVAL, errno);
// The second argument can't be NULL.
errno = 0;
ASSERT_EQ(getline(&buffer, NULL, fp), -1);
- ASSERT_EQ(errno, EINVAL);
+ ASSERT_EQ(EINVAL, errno);
// The stream can't be closed.
fclose(fp);
errno = 0;
ASSERT_EQ(getline(&buffer, &buffer_length, fp), -1);
- ASSERT_EQ(errno, EBADF);
+ ASSERT_EQ(EBADF, errno);
}
diff --git a/tests/stubs_test.cpp b/tests/stubs_test.cpp
index 9daaa22..2e1acc1 100644
--- a/tests/stubs_test.cpp
+++ b/tests/stubs_test.cpp
@@ -38,7 +38,7 @@
errno = 0;
passwd* pwd = getpwuid(uid);
ASSERT_TRUE(pwd != NULL);
- ASSERT_EQ(errno, 0);
+ ASSERT_EQ(0, errno);
EXPECT_STREQ(username, pwd->pw_name);
EXPECT_EQ(uid, pwd->pw_uid);
EXPECT_EQ(uid, pwd->pw_gid);