Consistently use #if defined(__BIONIC__) in tests.
I've also switched some tests to be positive rather than negative,
because !defined is slightly harder to reason about and there are
only two cases: bionic and glibc.
Change-Id: I8d3ac40420ca5aead3e88c69cf293f267273c8ef
diff --git a/tests/dlfcn_test.cpp b/tests/dlfcn_test.cpp
index 1fdecdb..b31d7e4 100644
--- a/tests/dlfcn_test.cpp
+++ b/tests/dlfcn_test.cpp
@@ -53,7 +53,7 @@
TEST(dlfcn, dlopen_failure) {
void* self = dlopen("/does/not/exist", RTLD_NOW);
ASSERT_TRUE(self == NULL);
-#if __BIONIC__
+#if defined(__BIONIC__)
ASSERT_STREQ("dlopen failed: library \"/does/not/exist\" not found", dlerror());
#else
ASSERT_STREQ("/does/not/exist: cannot open shared object file: No such file or directory", dlerror());
@@ -92,14 +92,14 @@
// NULL handle.
sym = dlsym(NULL, "test");
ASSERT_TRUE(sym == NULL);
-#if __BIONIC__
+#if defined(__BIONIC__)
ASSERT_SUBSTR("dlsym library handle is null", dlerror());
#else
ASSERT_SUBSTR("undefined symbol: test", dlerror()); // glibc isn't specific about the failure.
#endif
// NULL symbol name.
-#if __BIONIC__
+#if defined(__BIONIC__)
// glibc marks this parameter non-null and SEGVs if you cheat.
sym = dlsym(self, NULL);
ASSERT_TRUE(sym == NULL);
@@ -206,7 +206,7 @@
dlerror(); // Clear any pending errors.
void* handle;
-#ifdef __GLIBC__
+#if defined(__GLIBC__)
// glibc was smart enough not to define RTLD_NOW as 0, so it can detect missing flags.
handle = dlopen(NULL, 0);
ASSERT_TRUE(handle == NULL);
diff --git a/tests/fcntl_test.cpp b/tests/fcntl_test.cpp
index 725ac4a..fb6b07e 100644
--- a/tests/fcntl_test.cpp
+++ b/tests/fcntl_test.cpp
@@ -73,7 +73,7 @@
TEST(fcntl, fallocate_EINVAL) {
TemporaryFile tf;
-#if !defined(__GLIBC__)
+#if defined(__BIONIC__)
errno = 0;
ASSERT_EQ(-1, fallocate(tf.fd, 0, 0, -1));
ASSERT_EQ(EINVAL, errno);
@@ -98,7 +98,7 @@
ASSERT_EQ(0, fstat(tf.fd, &sb));
ASSERT_EQ(0, sb.st_size);
-#if !defined(__GLIBC__)
+#if defined(__BIONIC__)
ASSERT_EQ(0, fallocate(tf.fd, 0, 0, 1));
ASSERT_EQ(0, fstat(tf.fd, &sb));
ASSERT_EQ(1, sb.st_size);
diff --git a/tests/fortify_test.cpp b/tests/fortify_test.cpp
index e0d055e..873c71e 100644
--- a/tests/fortify_test.cpp
+++ b/tests/fortify_test.cpp
@@ -668,7 +668,7 @@
}
TEST(DEATHTEST, FD_ISSET_fortified) {
-#ifdef __BIONIC__ // glibc catches this at compile-time.
+#if defined(__BIONIC__) // glibc catches this at compile-time.
::testing::FLAGS_gtest_death_test_style = "threadsafe";
fd_set set;
memset(&set, 0, sizeof(set));
diff --git a/tests/locale_test.cpp b/tests/locale_test.cpp
index 347b5b1..7d063f9 100644
--- a/tests/locale_test.cpp
+++ b/tests/locale_test.cpp
@@ -58,7 +58,7 @@
EXPECT_EQ(NULL, setlocale(13, NULL));
EXPECT_EQ(EINVAL, errno);
-#if __BIONIC__
+#if defined(__BIONIC__)
// The "" locale is implementation-defined. For bionic, it's the C locale.
// glibc will give us something like "en_US.UTF-8", depending on the user's configuration.
EXPECT_STREQ("C", setlocale(LC_ALL, ""));
diff --git a/tests/regex_test.cpp b/tests/regex_test.cpp
index 659d1db..d026221 100644
--- a/tests/regex_test.cpp
+++ b/tests/regex_test.cpp
@@ -28,7 +28,7 @@
char buf[80];
regerror(REG_NOMATCH, &re, buf, sizeof(buf));
-#if __BIONIC__
+#if defined(__BIONIC__)
ASSERT_STREQ("regexec() failed to match", buf);
#else
ASSERT_STREQ("No match", buf);
diff --git a/tests/sched_test.cpp b/tests/sched_test.cpp
index 7c19962..caf4c65 100644
--- a/tests/sched_test.cpp
+++ b/tests/sched_test.cpp
@@ -21,7 +21,7 @@
#include <sys/types.h>
#include <sys/wait.h>
-#ifdef __BIONIC__
+#if defined(__BIONIC__)
static int child_fn(void* i_ptr) {
*reinterpret_cast<int*>(i_ptr) = 42;
return 123;
diff --git a/tests/stdio_test.cpp b/tests/stdio_test.cpp
index 4725350..655ad3f 100644
--- a/tests/stdio_test.cpp
+++ b/tests/stdio_test.cpp
@@ -219,7 +219,7 @@
}
TEST(stdio, snprintf_n) {
-#if !defined(__GLIBC__)
+#if defined(__BIONIC__)
// http://b/14492135
char buf[32];
int i = 1234;
@@ -460,7 +460,7 @@
errno = 0;
EXPECT_EQ(EOF, fwprintf(fp, L"hello"));
-#if !defined(__GLIBC__)
+#if defined(__BIONIC__)
EXPECT_EQ(EBADF, errno);
#endif
@@ -478,7 +478,7 @@
errno = 0;
EXPECT_EQ(WEOF, fputwc(L'x', fp));
-#if !defined(__GLIBC__)
+#if defined(__BIONIC__)
EXPECT_EQ(EBADF, errno);
#endif
}
@@ -521,7 +521,7 @@
ASSERT_EQ(mb_four_bytes, static_cast<wchar_t>(fgetwc(fp)));
EXPECT_EQ(0, fgetpos(fp, &pos5));
-#ifdef __BIONIC__
+#if defined(__BIONIC__)
// Bionic's fpos_t is just an alias for off_t. This is inherited from OpenBSD
// upstream. Glibc differs by storing the mbstate_t inside its fpos_t. In
// Bionic (and upstream OpenBSD) the mbstate_t is stored inside the FILE
@@ -586,9 +586,9 @@
// Store the "inside multi byte" position.
fpos_t pos_inside_mb;
ASSERT_EQ(0, fgetpos(fp, &pos_inside_mb));
- #ifdef __BIONIC__
- ASSERT_EQ(offset_inside_mb, static_cast<off_t>(pos_inside_mb));
- #endif
+#if defined(__BIONIC__)
+ ASSERT_EQ(offset_inside_mb, static_cast<off_t>(pos_inside_mb));
+#endif
// Reading from within a byte should produce an error.
ASSERT_EQ(WEOF, fgetwc(fp));
diff --git a/tests/stdlib_test.cpp b/tests/stdlib_test.cpp
index fc0f0e1..978a60f 100644
--- a/tests/stdlib_test.cpp
+++ b/tests/stdlib_test.cpp
@@ -42,7 +42,7 @@
EXPECT_EQ(902267124, lrand48());
EXPECT_EQ(132366131, lrand48());
-#if __BIONIC__
+#if defined(__BIONIC__)
// On bionic, random(3) is equivalent to lrand48...
srandom(0x01020304);
EXPECT_EQ(1409163720, random());
diff --git a/tests/sys_resource_test.cpp b/tests/sys_resource_test.cpp
index bd974cb..d6d99a0 100644
--- a/tests/sys_resource_test.cpp
+++ b/tests/sys_resource_test.cpp
@@ -18,7 +18,7 @@
#include <sys/resource.h>
-#if __GLIBC__
+#if defined(__GLIBC__)
/* The host glibc we're currently building with doesn't have prlimit64 yet. */
static int prlimit64(pid_t, int resource, const struct rlimit64* new_limit, struct rlimit64* old_limit) {
if (new_limit != NULL) {
@@ -30,7 +30,7 @@
#endif
TEST(sys_resource, smoke) {
-#if __LP64__ || __GLIBC__
+#if defined(__LP64__) || defined(__GLIBC__)
ASSERT_EQ(sizeof(rlimit), sizeof(rlimit64));
ASSERT_EQ(8U, sizeof(rlim_t));
#else
diff --git a/tests/unistd_test.cpp b/tests/unistd_test.cpp
index 2b51aad..ff05039 100644
--- a/tests/unistd_test.cpp
+++ b/tests/unistd_test.cpp
@@ -67,7 +67,7 @@
ASSERT_EQ(reinterpret_cast<void*>(-1), sbrk(-(current_brk + 1)));
ASSERT_EQ(ENOMEM, errno);
-#if !defined(__GLIBC__)
+#if defined(__BIONIC__)
// The maximum negative value is an interesting special case that glibc gets wrong.
ASSERT_EQ(reinterpret_cast<void*>(-1), sbrk(PTRDIFF_MIN));
ASSERT_EQ(ENOMEM, errno);
diff --git a/tests/wchar_test.cpp b/tests/wchar_test.cpp
index 30d7bff..c8aec2d 100644
--- a/tests/wchar_test.cpp
+++ b/tests/wchar_test.cpp
@@ -288,7 +288,7 @@
// 4-byte UTF-8.
ASSERT_EQ(4U, mbrtowc(out, "\xf0\xa4\xad\xa2" "ef", 6, NULL));
ASSERT_EQ(static_cast<wchar_t>(0x24b62), out[0]);
-#if __BIONIC__ // glibc allows this.
+#if defined(__BIONIC__) // glibc allows this.
// Illegal 5-byte UTF-8.
ASSERT_EQ(static_cast<size_t>(-1), mbrtowc(out, "\xf8\xa1\xa2\xa3\xa4" "f", 6, NULL));
ASSERT_EQ(EILSEQ, errno);