From 063525c61d24776094d76971f33920e2a2079530 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Tue, 13 May 2014 11:19:57 -0700 Subject: [PATCH] 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 --- tests/dlfcn_test.cpp | 8 ++++---- tests/fcntl_test.cpp | 4 ++-- tests/fortify_test.cpp | 2 +- tests/locale_test.cpp | 2 +- tests/regex_test.cpp | 2 +- tests/sched_test.cpp | 2 +- tests/stdio_test.cpp | 14 +++++++------- tests/stdlib_test.cpp | 2 +- tests/sys_resource_test.cpp | 4 ++-- tests/unistd_test.cpp | 2 +- tests/wchar_test.cpp | 2 +- 11 files changed, 22 insertions(+), 22 deletions(-) diff --git a/tests/dlfcn_test.cpp b/tests/dlfcn_test.cpp index 1fdecdbeb..b31d7e452 100644 --- a/tests/dlfcn_test.cpp +++ b/tests/dlfcn_test.cpp @@ -53,7 +53,7 @@ TEST(dlfcn, dlsym_in_self) { 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 @@ TEST(dlfcn, dlsym_failures) { // 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 @@ TEST(dlfcn, dlopen_bad_flags) { 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 725ac4a4c..fb6b07ee3 100644 --- a/tests/fcntl_test.cpp +++ b/tests/fcntl_test.cpp @@ -73,7 +73,7 @@ TEST(fcntl, creat_creat64) { 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 @@ TEST(fcntl, fallocate) { 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 e0d055eda..873c71eb1 100644 --- a/tests/fortify_test.cpp +++ b/tests/fortify_test.cpp @@ -668,7 +668,7 @@ TEST(DEATHTEST, recv_fortified) { } 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 347b5b19d..7d063f9dd 100644 --- a/tests/locale_test.cpp +++ b/tests/locale_test.cpp @@ -58,7 +58,7 @@ TEST(locale, setlocale) { 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 659d1db43..d02622190 100644 --- a/tests/regex_test.cpp +++ b/tests/regex_test.cpp @@ -28,7 +28,7 @@ TEST(regex, smoke) { 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 7c1996257..caf4c6599 100644 --- a/tests/sched_test.cpp +++ b/tests/sched_test.cpp @@ -21,7 +21,7 @@ #include #include -#ifdef __BIONIC__ +#if defined(__BIONIC__) static int child_fn(void* i_ptr) { *reinterpret_cast(i_ptr) = 42; return 123; diff --git a/tests/stdio_test.cpp b/tests/stdio_test.cpp index 4725350fa..655ad3f87 100644 --- a/tests/stdio_test.cpp +++ b/tests/stdio_test.cpp @@ -219,7 +219,7 @@ TEST(stdio, snprintf_ls) { } TEST(stdio, snprintf_n) { -#if !defined(__GLIBC__) +#if defined(__BIONIC__) // http://b/14492135 char buf[32]; int i = 1234; @@ -460,7 +460,7 @@ TEST(stdio, cantwrite_EBADF) { errno = 0; EXPECT_EQ(EOF, fwprintf(fp, L"hello")); -#if !defined(__GLIBC__) +#if defined(__BIONIC__) EXPECT_EQ(EBADF, errno); #endif @@ -478,7 +478,7 @@ TEST(stdio, cantwrite_EBADF) { errno = 0; EXPECT_EQ(WEOF, fputwc(L'x', fp)); -#if !defined(__GLIBC__) +#if defined(__BIONIC__) EXPECT_EQ(EBADF, errno); #endif } @@ -521,7 +521,7 @@ TEST(stdio, consistent_fpos_t) { ASSERT_EQ(mb_four_bytes, static_cast(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 @@ TEST(stdio, fpos_t_and_seek) { // 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(pos_inside_mb)); - #endif +#if defined(__BIONIC__) + ASSERT_EQ(offset_inside_mb, static_cast(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 fc0f0e1a2..978a60fa8 100644 --- a/tests/stdlib_test.cpp +++ b/tests/stdlib_test.cpp @@ -42,7 +42,7 @@ TEST(stdlib, lrand48_random_rand) { 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 bd974cb94..d6d99a095 100644 --- a/tests/sys_resource_test.cpp +++ b/tests/sys_resource_test.cpp @@ -18,7 +18,7 @@ #include -#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 @@ static int prlimit64(pid_t, int resource, const struct rlimit64* new_limit, stru #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 2b51aad59..ff05039fe 100644 --- a/tests/unistd_test.cpp +++ b/tests/unistd_test.cpp @@ -67,7 +67,7 @@ TEST(unistd, sbrk_ENOMEM) { ASSERT_EQ(reinterpret_cast(-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(-1), sbrk(PTRDIFF_MIN)); ASSERT_EQ(ENOMEM, errno); diff --git a/tests/wchar_test.cpp b/tests/wchar_test.cpp index 30d7bff4f..c8aec2d8c 100644 --- a/tests/wchar_test.cpp +++ b/tests/wchar_test.cpp @@ -288,7 +288,7 @@ TEST(wchar, mbrtowc) { // 4-byte UTF-8. ASSERT_EQ(4U, mbrtowc(out, "\xf0\xa4\xad\xa2" "ef", 6, NULL)); ASSERT_EQ(static_cast(0x24b62), out[0]); -#if __BIONIC__ // glibc allows this. +#if defined(__BIONIC__) // glibc allows this. // Illegal 5-byte UTF-8. ASSERT_EQ(static_cast(-1), mbrtowc(out, "\xf8\xa1\xa2\xa3\xa4" "f", 6, NULL)); ASSERT_EQ(EILSEQ, errno);