aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2017-08-29 15:28:33 -0700
committerElliott Hughes <enh@google.com>2017-08-29 15:32:18 -0700
commit45da3263249f55cd7a0d927128a285ac20720367 (patch)
tree8224951e0b8b70b032a3f5b577c62d37e0bf2e64
parent0d5d0746e8b88dab66038d6150cb92b62467aac1 (diff)
downloadbionic-45da3263249f55cd7a0d927128a285ac20720367.tar.gz
Add tests for all C11 headers.
Well, all except <threads.h> which we have no current plans to implement. The only thing this turned up is that clang's <float.h> doesn't define FLT_HAS_SUBNORM/DBL_HAS_SUBNORM/LDBL_HAS_SUBNORM, so for now we assert that those are missing so that when we get a fixed clang, we notice. Also the <tgmath.h> is utterly perfunctory, but seems like an appropriate amount of effort to put in. Bug: N/A Test: ran tests Change-Id: I7f7a7040b3271ceda625bee8a40a9d8cef52ee44
-rw-r--r--tests/Android.bp8
-rw-r--r--tests/float_test.cpp127
-rw-r--r--tests/iso646_test.c51
-rw-r--r--tests/limits_test.cpp79
-rw-r--r--tests/stdalign_test.cpp31
-rw-r--r--tests/stdarg_test.cpp35
-rw-r--r--tests/stdbool_test.c23
-rw-r--r--tests/stdnoreturn_test.cpp25
-rw-r--r--tests/tgmath_test.c22
9 files changed, 401 insertions, 0 deletions
diff --git a/tests/Android.bp b/tests/Android.bp
index b5f8dc8d8..6b96e24d1 100644
--- a/tests/Android.bp
+++ b/tests/Android.bp
@@ -66,6 +66,7 @@ cc_test_library {
"eventfd_test.cpp",
"fcntl_test.cpp",
"fenv_test.cpp",
+ "float_test.cpp",
"ftw_test.cpp",
"getauxval_test.cpp",
"getcwd_test.cpp",
@@ -73,10 +74,12 @@ cc_test_library {
"iconv_test.cpp",
"ifaddrs_test.cpp",
"inttypes_test.cpp",
+ "iso646_test.c",
"langinfo_test.cpp",
"leak_test.cpp",
"libgen_basename_test.cpp",
"libgen_test.cpp",
+ "limits_test.cpp",
"linux_swab_test.cpp",
"locale_test.cpp",
"malloc_test.cpp",
@@ -102,12 +105,16 @@ cc_test_library {
"stack_protector_test.cpp",
"stack_protector_test_helper.cpp",
"stack_unwinding_test.cpp",
+ "stdalign_test.cpp",
+ "stdarg_test.cpp",
"stdatomic_test.cpp",
+ "stdbool_test.c",
"stdint_test.cpp",
"stdio_nofortify_test.cpp",
"stdio_test.cpp",
"stdio_ext_test.cpp",
"stdlib_test.cpp",
+ "stdnoreturn_test.cpp",
"string_nofortify_test.cpp",
"string_test.cpp",
"string_posix_strerror_r_test.cpp",
@@ -142,6 +149,7 @@ cc_test_library {
"sys_xattr_test.cpp",
"system_properties_test.cpp",
"system_properties_test2.cpp",
+ "tgmath_test.c",
"time_test.cpp",
"uchar_test.cpp",
"unistd_nofortify_test.cpp",
diff --git a/tests/float_test.cpp b/tests/float_test.cpp
new file mode 100644
index 000000000..a75214e20
--- /dev/null
+++ b/tests/float_test.cpp
@@ -0,0 +1,127 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+
+#include <float.h>
+
+TEST(float_h, macros) {
+#if !defined(FLT_RADIX)
+#error FLT_RADIX
+#endif
+#if !defined(DECIMAL_DIG)
+#error DECIMAL_DIG
+#endif
+#if !defined(FLT_DECIMAL_DIG)
+#error FLT_DECIMAL_DIG
+#endif
+#if !defined(DBL_DECIMAL_DIG)
+#error DBL_DECIMAL_DIG
+#endif
+#if !defined(LDBL_DECIMAL_DIG)
+#error LDBL_DECIMAL_DIG
+#endif
+#if !defined(FLT_MIN)
+#error FLT_MIN
+#endif
+#if !defined(DBL_MIN)
+#error DBL_MIN
+#endif
+#if !defined(LDBL_MIN)
+#error LDBL_MIN
+#endif
+#if !defined(FLT_EPSILON)
+#error FLT_EPSILON
+#endif
+#if !defined(DBL_EPSILON)
+#error DBL_EPSILON
+#endif
+#if !defined(LDBL_EPSILON)
+#error LDBL_EPSILON
+#endif
+#if !defined(FLT_DIG)
+#error FLT_DIG
+#endif
+#if !defined(DBL_DIG)
+#error DBL_DIG
+#endif
+#if !defined(LDBL_DIG)
+#error LDBL_DIG
+#endif
+#if !defined(FLT_MANT_DIG)
+#error FLT_MANT_DIG
+#endif
+#if !defined(DBL_MANT_DIG)
+#error DBL_MANT_DIG
+#endif
+#if !defined(LDBL_MANT_DIG)
+#error LDBL_MANT_DIG
+#endif
+#if !defined(FLT_MIN_EXP)
+#error FLT_MIN_EXP
+#endif
+#if !defined(DBL_MIN_EXP)
+#error DBL_MIN_EXP
+#endif
+#if !defined(LDBL_MIN_EXP)
+#error LDBL_MIN_EXP
+#endif
+#if !defined(FLT_MIN_10_EXP)
+#error FLT_MIN_10_EXP
+#endif
+#if !defined(DBL_MIN_10_EXP)
+#error DBL_MIN_10_EXP
+#endif
+#if !defined(LDBL_MIN_10_EXP)
+#error LDBL_MIN_10_EXP
+#endif
+#if !defined(FLT_MAX_EXP)
+#error FLT_MAX_EXP
+#endif
+#if !defined(DBL_MAX_EXP)
+#error DBL_MAX_EXP
+#endif
+#if !defined(LDBL_MAX_EXP)
+#error LDBL_MAX_EXP
+#endif
+#if !defined(FLT_MAX_10_EXP)
+#error FLT_MAX_10_EXP
+#endif
+#if !defined(DBL_MAX_10_EXP)
+#error DBL_MAX_10_EXP
+#endif
+#if !defined(LDBL_MAX_10_EXP)
+#error LDBL_MAX_10_EXP
+#endif
+#if !defined(FLT_ROUNDS)
+#error FLT_ROUNDS
+#endif
+#if !defined(FLT_EVAL_METHOD)
+#error FLT_EVAL_METHOD
+#endif
+// TODO: FLT_HAS_SUBNORM currently missing from clang. Negate this test when fixed.
+#if defined(FLT_HAS_SUBNORM)
+#error FLT_HAS_SUBNORM
+#endif
+// TODO: DBL_HAS_SUBNORM currently missing from clang. Negate this test when fixed.
+#if defined(DBL_HAS_SUBNORM)
+#error DBL_HAS_SUBNORM
+#endif
+// TODO: LDBL_HAS_SUBNORM currently missing from clang. Negate this test when fixed.
+#if defined(LDBL_HAS_SUBNORM)
+#error LDBL_HAS_SUBNORM
+#endif
+}
diff --git a/tests/iso646_test.c b/tests/iso646_test.c
new file mode 100644
index 000000000..618f0275b
--- /dev/null
+++ b/tests/iso646_test.c
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <iso646.h>
+
+#if !defined(and)
+#error and
+#endif
+#if !defined(and_eq)
+#error and_eq
+#endif
+#if !defined(bitand)
+#error bitand
+#endif
+#if !defined(bitor)
+#error bitor
+#endif
+#if !defined(compl)
+#error compl
+#endif
+#if !defined(not)
+#error not
+#endif
+#if !defined(not_eq)
+#error not_eq
+#endif
+#if !defined(or)
+#error or
+#endif
+#if !defined(or_eq)
+#error or_eq
+#endif
+#if !defined(xor)
+#error xor
+#endif
+#if !defined(xor_eq)
+#error xor_eq
+#endif
diff --git a/tests/limits_test.cpp b/tests/limits_test.cpp
new file mode 100644
index 000000000..1d48ffe46
--- /dev/null
+++ b/tests/limits_test.cpp
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+
+#include <limits.h>
+
+TEST(limits, macros) {
+#if CHAR_BIT != 8
+#error Insane CHAR_BIT
+#endif
+#if !defined(MB_LEN_MAX)
+#error MB_LEN_MAX
+#endif
+#if !defined(CHAR_MIN)
+#error CHAR_MIN
+#endif
+#if !defined(CHAR_MAX)
+#error CHAR_MAX
+#endif
+#if !defined(SCHAR_MIN)
+#error SCHAR_MIN
+#endif
+#if !defined(SCHAR_MAX)
+#error SCHAR_MAX
+#endif
+#if !defined(SHRT_MIN)
+#error SHRT_MIN
+#endif
+#if !defined(SHRT_MAX)
+#error SHRT_MAX
+#endif
+#if !defined(INT_MIN)
+#error INT_MIN
+#endif
+#if !defined(INT_MAX)
+#error INT_MAX
+#endif
+#if !defined(LONG_MIN)
+#error LONG_MIN
+#endif
+#if !defined(LONG_MAX)
+#error LONG_MAX
+#endif
+#if !defined(LLONG_MIN)
+#error LLONG_MIN
+#endif
+#if !defined(LLONG_MAX)
+#error LLONG_MAX
+#endif
+#if !defined(UCHAR_MAX)
+#error UCHAR_MAX
+#endif
+#if !defined(USHRT_MAX)
+#error USHRT_MAX
+#endif
+#if !defined(UINT_MAX)
+#error UINT_MAX
+#endif
+#if !defined(ULONG_MAX)
+#error ULONG_MAX
+#endif
+#if !defined(ULLONG_MAX)
+#error ULLONG_MAX
+#endif
+}
diff --git a/tests/stdalign_test.cpp b/tests/stdalign_test.cpp
new file mode 100644
index 000000000..fd6b81e34
--- /dev/null
+++ b/tests/stdalign_test.cpp
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+
+#include <stdalign.h>
+
+TEST(stdalign, smoke) {
+#if !defined(__alignas_is_defined) || __alignas_is_defined != 1
+#error __alignas_is_defined
+#endif
+#if !defined(__alignof_is_defined) || __alignof_is_defined != 1
+#error __alignof_is_defined
+#endif
+ ASSERT_EQ(1U, alignof(char));
+ struct alignas(128) S128 {};
+ ASSERT_EQ(128U, alignof(S128));
+}
diff --git a/tests/stdarg_test.cpp b/tests/stdarg_test.cpp
new file mode 100644
index 000000000..3f33dc2de
--- /dev/null
+++ b/tests/stdarg_test.cpp
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+
+#include <stdarg.h>
+
+TEST(stdarg, smoke) {
+#if !defined(va_start)
+#error va_start
+#endif
+#if !defined(va_arg)
+#error va_arg
+#endif
+#if !defined(va_copy)
+#error va_copy
+#endif
+#if !defined(va_end)
+#error va_end
+#endif
+ va_list l __attribute__((__unused__));
+}
diff --git a/tests/stdbool_test.c b/tests/stdbool_test.c
new file mode 100644
index 000000000..cc23f2939
--- /dev/null
+++ b/tests/stdbool_test.c
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdbool.h>
+
+#if !defined(__bool_true_false_are_defined)
+#error __bool_true_false_are_defined
+#endif
+bool stdbool_true = true;
+bool stdbool_false = false;
diff --git a/tests/stdnoreturn_test.cpp b/tests/stdnoreturn_test.cpp
new file mode 100644
index 000000000..8d6f62f8c
--- /dev/null
+++ b/tests/stdnoreturn_test.cpp
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdnoreturn.h>
+
+#if !defined(__noreturn_is_defined)
+#error __noreturn_is_defined
+#endif
+
+noreturn void stdnoreturn_h_test_function() {
+ for (;;) ;
+}
diff --git a/tests/tgmath_test.c b/tests/tgmath_test.c
new file mode 100644
index 000000000..f9773066d
--- /dev/null
+++ b/tests/tgmath_test.c
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <tgmath.h>
+
+float complex tgmath_h_test_function() {
+ float complex z = 1 + 0.5*I;
+ return sqrt(z);
+}