Updates for glibc 2.17.
Bug: http://b/111358231
Test: builds
Change-Id: I542b2a9acc74261ad12b78e4add0f3ae77c3656c
diff --git a/tests/getauxval_test.cpp b/tests/getauxval_test.cpp
index 63bc963..aa21817 100644
--- a/tests/getauxval_test.cpp
+++ b/tests/getauxval_test.cpp
@@ -14,29 +14,14 @@
* limitations under the License.
*/
+#include <sys/auxv.h>
+
#include <errno.h>
#include <sys/cdefs.h>
#include <sys/utsname.h>
#include <gtest/gtest.h>
-// getauxval() was only added as of glibc version 2.16.
-// See: http://lwn.net/Articles/519085/
-// Don't try to compile this code on older glibc versions.
-
-#if defined(__BIONIC__)
- #define GETAUXVAL_CAN_COMPILE 1
-#elif defined(__GLIBC_PREREQ)
- #if __GLIBC_PREREQ(2, 16)
- #define GETAUXVAL_CAN_COMPILE 1
- #endif
-#endif
-
-#if defined(GETAUXVAL_CAN_COMPILE)
-#include <sys/auxv.h>
-#endif
-
TEST(getauxval, expected_values) {
-#if defined(GETAUXVAL_CAN_COMPILE)
ASSERT_EQ(0UL, getauxval(AT_SECURE));
ASSERT_EQ(getuid(), getauxval(AT_UID));
ASSERT_EQ(geteuid(), getauxval(AT_EUID));
@@ -48,19 +33,12 @@
ASSERT_NE(0UL, getauxval(AT_PHNUM));
ASSERT_NE(0UL, getauxval(AT_ENTRY));
ASSERT_NE(0UL, getauxval(AT_PAGESZ));
-#else
- GTEST_LOG_(INFO) << "This test requires a C library with getauxval.\n";
-#endif
}
TEST(getauxval, unexpected_values) {
-#if defined(GETAUXVAL_CAN_COMPILE)
errno = 0;
ASSERT_EQ(0UL, getauxval(0xdeadbeef));
ASSERT_EQ(ENOENT, errno);
-#else
- GTEST_LOG_(INFO) << "This test requires a C library with getauxval.\n";
-#endif
}
TEST(getauxval, arm_has_AT_HWCAP2) {
diff --git a/tests/stdlib_test.cpp b/tests/stdlib_test.cpp
index a249b75..408a9c7 100644
--- a/tests/stdlib_test.cpp
+++ b/tests/stdlib_test.cpp
@@ -36,14 +36,6 @@
#include "math_data_test.h"
#include "utils.h"
-#if defined(__BIONIC__)
- #define ALIGNED_ALLOC_AVAILABLE 1
-#elif defined(__GLIBC_PREREQ)
- #if __GLIBC_PREREQ(2, 16)
- #define ALIGNED_ALLOC_AVAILABLE 1
- #endif
-#endif
-
template <typename T = int (*)(char*)>
class GenericTemporaryFile {
public:
@@ -274,7 +266,6 @@
TEST(stdlib, aligned_alloc_sweep) {
SKIP_WITH_HWASAN;
-#if defined(ALIGNED_ALLOC_AVAILABLE)
// Verify powers of 2 up to 2048 allocate, and verify that all other
// alignment values between the powers of 2 fail.
size_t last_align = 1;
@@ -292,31 +283,20 @@
free(ptr);
last_align = align;
}
-#else
- GTEST_LOG_(INFO) << "This test requires a C library that has aligned_alloc.\n";
-#endif
}
TEST(stdlib, aligned_alloc_overflow) {
SKIP_WITH_HWASAN;
-#if defined(ALIGNED_ALLOC_AVAILABLE)
ASSERT_TRUE(aligned_alloc(16, SIZE_MAX) == nullptr);
-#else
- GTEST_LOG_(INFO) << "This test requires a C library that has aligned_alloc.\n";
-#endif
}
TEST(stdlib, aligned_alloc_size_not_multiple_of_alignment) {
SKIP_WITH_HWASAN;
-#if defined(ALIGNED_ALLOC_AVAILABLE)
for (size_t size = 1; size <= 2048; size++) {
void* ptr = aligned_alloc(2048, size);
ASSERT_TRUE(ptr != nullptr) << "Failed at size " << std::to_string(size);
free(ptr);
}
-#else
- GTEST_LOG_(INFO) << "This test requires a C library that has aligned_alloc.\n";
-#endif
}
TEST(stdlib, realpath__NULL_filename) {
diff --git a/tests/uchar_test.cpp b/tests/uchar_test.cpp
index 522d5ac..48c500d 100644
--- a/tests/uchar_test.cpp
+++ b/tests/uchar_test.cpp
@@ -15,12 +15,7 @@
*/
-#include <sys/cdefs.h>
-#if defined(__BIONIC__)
-#define HAVE_UCHAR 1
-#elif defined(__GLIBC__)
-#define HAVE_UCHAR __GLIBC_PREREQ(2, 16)
-#endif
+#include <uchar.h>
#include <gtest/gtest.h>
@@ -29,21 +24,12 @@
#include <locale.h>
#include <stdint.h>
-#if HAVE_UCHAR
-#include <uchar.h>
-#endif
-
TEST(uchar, sizeof_uchar_t) {
-#if HAVE_UCHAR
EXPECT_EQ(2U, sizeof(char16_t));
EXPECT_EQ(4U, sizeof(char32_t));
-#else
- GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
-#endif
}
TEST(uchar, start_state) {
-#if HAVE_UCHAR
char out[MB_LEN_MAX];
mbstate_t ps;
@@ -64,31 +50,19 @@
EXPECT_EQ(static_cast<size_t>(-2), mbrtoc32(nullptr, "\xf0\xa4", 1, &ps));
EXPECT_EQ(1U, c32rtomb(out, L'\0', &ps));
EXPECT_TRUE(mbsinit(&ps));
-#else
- GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
-#endif
}
TEST(uchar, c16rtomb_null_out) {
-#if HAVE_UCHAR
EXPECT_EQ(1U, c16rtomb(nullptr, L'\0', nullptr));
EXPECT_EQ(1U, c16rtomb(nullptr, L'h', nullptr));
-#else
- GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
-#endif
}
TEST(uchar, c16rtomb_null_char) {
-#if HAVE_UCHAR
char bytes[MB_LEN_MAX];
EXPECT_EQ(1U, c16rtomb(bytes, L'\0', nullptr));
-#else
- GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
-#endif
}
TEST(uchar, c16rtomb) {
-#if HAVE_UCHAR
char bytes[MB_LEN_MAX];
memset(bytes, 0, sizeof(bytes));
@@ -113,13 +87,9 @@
EXPECT_EQ('\xe2', bytes[0]);
EXPECT_EQ('\x82', bytes[1]);
EXPECT_EQ('\xac', bytes[2]);
-#else
- GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
-#endif
}
TEST(uchar, c16rtomb_surrogate) {
-#if HAVE_UCHAR
char bytes[MB_LEN_MAX];
memset(bytes, 0, sizeof(bytes));
@@ -129,13 +99,9 @@
EXPECT_EQ('\x8a', bytes[1]);
EXPECT_EQ('\xaf', bytes[2]);
EXPECT_EQ('\x8d', bytes[3]);
-#else
- GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
-#endif
}
TEST(uchar, c16rtomb_invalid) {
-#if HAVE_UCHAR
char bytes[MB_LEN_MAX];
memset(bytes, 0, sizeof(bytes));
@@ -143,21 +109,13 @@
EXPECT_EQ(0U, c16rtomb(bytes, 0xdbea, nullptr));
EXPECT_EQ(static_cast<size_t>(-1), c16rtomb(bytes, 0xdbea, nullptr));
-#else
- GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
-#endif
}
TEST(uchar, mbrtoc16_null) {
-#if HAVE_UCHAR
ASSERT_EQ(0U, mbrtoc16(nullptr, nullptr, 0, nullptr));
-#else
- GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
-#endif
}
TEST(uchar, mbrtoc16_zero_len) {
-#if HAVE_UCHAR
char16_t out;
out = L'x';
@@ -168,13 +126,9 @@
ASSERT_EQ(0U, mbrtoc16(&out, "", 0, nullptr));
ASSERT_EQ(1U, mbrtoc16(&out, "hello", 1, nullptr));
ASSERT_EQ(L'h', out);
-#else
- GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
-#endif
}
TEST(uchar, mbrtoc16) {
-#if HAVE_UCHAR
char16_t out;
ASSERT_STREQ("C.UTF-8", setlocale(LC_CTYPE, "C.UTF-8"));
@@ -189,13 +143,9 @@
// 3-byte UTF-8.
ASSERT_EQ(3U, mbrtoc16(&out, "\xe2\x82\xac" "def", 6, nullptr));
ASSERT_EQ(static_cast<char16_t>(0x20ac), out);
-#else
- GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
-#endif
}
TEST(uchar, mbrtoc16_surrogate) {
-#if HAVE_UCHAR
char16_t out;
ASSERT_EQ(static_cast<size_t>(-3),
@@ -203,32 +153,20 @@
ASSERT_EQ(static_cast<char16_t>(0xdbea), out);
ASSERT_EQ(4U, mbrtoc16(&out, "\xf4\x8a\xaf\x8d" "ef", 6, nullptr));
ASSERT_EQ(static_cast<char16_t>(0xdfcd), out);
-#else
- GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
-#endif
}
TEST(uchar, mbrtoc16_reserved_range) {
-#if HAVE_UCHAR
char16_t out;
ASSERT_EQ(static_cast<size_t>(-1),
mbrtoc16(&out, "\xf0\x80\xbf\xbf", 6, nullptr));
-#else
- GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
-#endif
}
TEST(uchar, mbrtoc16_beyond_range) {
-#if HAVE_UCHAR
char16_t out;
ASSERT_EQ(static_cast<size_t>(-1),
mbrtoc16(&out, "\xf5\x80\x80\x80", 6, nullptr));
-#else
- GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
-#endif
}
-#if HAVE_UCHAR
void test_mbrtoc16_incomplete(mbstate_t* ps) {
ASSERT_STREQ("C.UTF-8", setlocale(LC_CTYPE, "C.UTF-8"));
uselocale(LC_GLOBAL_LOCALE);
@@ -259,22 +197,16 @@
ASSERT_EQ(static_cast<size_t>(-1), mbrtoc16(&out, "\x20" "cdef", 5, ps));
ASSERT_EQ(EILSEQ, errno);
}
-#endif
TEST(uchar, mbrtoc16_incomplete) {
-#if HAVE_UCHAR
mbstate_t ps;
memset(&ps, 0, sizeof(ps));
test_mbrtoc16_incomplete(&ps);
test_mbrtoc16_incomplete(nullptr);
-#else
- GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
-#endif
}
TEST(uchar, c32rtomb) {
-#if HAVE_UCHAR
EXPECT_EQ(1U, c32rtomb(nullptr, L'\0', nullptr));
EXPECT_EQ(1U, c32rtomb(nullptr, L'h', nullptr));
@@ -317,13 +249,9 @@
// Invalid code point.
EXPECT_EQ(static_cast<size_t>(-1), c32rtomb(bytes, 0xffffffff, nullptr));
EXPECT_EQ(EILSEQ, errno);
-#else
- GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
-#endif
}
TEST(uchar, mbrtoc32_valid_non_characters) {
-#if HAVE_UCHAR
ASSERT_STREQ("C.UTF-8", setlocale(LC_CTYPE, "C.UTF-8"));
uselocale(LC_GLOBAL_LOCALE);
@@ -332,13 +260,9 @@
ASSERT_EQ(0xfffeU, out[0]);
ASSERT_EQ(3U, mbrtoc32(out, "\xef\xbf\xbf", 3, nullptr));
ASSERT_EQ(0xffffU, out[0]);
-#else
- GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
-#endif
}
TEST(uchar, mbrtoc32_out_of_range) {
-#if HAVE_UCHAR
ASSERT_STREQ("C.UTF-8", setlocale(LC_CTYPE, "C.UTF-8"));
uselocale(LC_GLOBAL_LOCALE);
@@ -346,13 +270,9 @@
errno = 0;
ASSERT_EQ(static_cast<size_t>(-1), mbrtoc32(out, "\xf5\x80\x80\x80", 4, nullptr));
ASSERT_EQ(EILSEQ, errno);
-#else
- GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
-#endif
}
TEST(uchar, mbrtoc32) {
-#if HAVE_UCHAR
char32_t out[8];
out[0] = L'x';
@@ -393,12 +313,8 @@
// Illegal over-long sequence.
ASSERT_EQ(static_cast<size_t>(-1), mbrtoc32(out, "\xf0\x82\x82\xac" "ef", 6, nullptr));
ASSERT_EQ(EILSEQ, errno);
-#else
- GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
-#endif
}
-#if HAVE_UCHAR
void test_mbrtoc32_incomplete(mbstate_t* ps) {
ASSERT_STREQ("C.UTF-8", setlocale(LC_CTYPE, "C.UTF-8"));
uselocale(LC_GLOBAL_LOCALE);
@@ -427,16 +343,11 @@
ASSERT_EQ(static_cast<size_t>(-1), mbrtoc32(&out, "\x20" "cdef", 5, ps));
ASSERT_EQ(EILSEQ, errno);
}
-#endif
TEST(uchar, mbrtoc32_incomplete) {
-#if HAVE_UCHAR
mbstate_t ps;
memset(&ps, 0, sizeof(ps));
test_mbrtoc32_incomplete(&ps);
test_mbrtoc32_incomplete(nullptr);
-#else
- GTEST_LOG_(INFO) << "uchar.h is unavailable.\n";
-#endif
}