aboutsummaryrefslogtreecommitdiff
path: root/REORG.TODO/math/test-fenv-tls.c
diff options
context:
space:
mode:
authorZack Weinberg <zackw@panix.com>2017-06-08 15:39:03 -0400
committerZack Weinberg <zackw@panix.com>2017-06-08 15:39:03 -0400
commit5046dbb4a7eba5eccfd258f92f4735c9ffc8d069 (patch)
tree4470480d904b65cf14ca524f96f79eca818c3eaf /REORG.TODO/math/test-fenv-tls.c
parent199fc19d3aaaf57944ef036e15904febe877fc93 (diff)
downloadglibc-5046dbb4a7eba5eccfd258f92f4735c9ffc8d069.tar
glibc-5046dbb4a7eba5eccfd258f92f4735c9ffc8d069.tar.gz
glibc-5046dbb4a7eba5eccfd258f92f4735c9ffc8d069.tar.bz2
glibc-5046dbb4a7eba5eccfd258f92f4735c9ffc8d069.zip
Prepare for radical source tree reorganization.zack/build-layout-experiment
All top-level files and directories are moved into a temporary storage directory, REORG.TODO, except for files that will certainly still exist in their current form at top level when we're done (COPYING, COPYING.LIB, LICENSES, NEWS, README), all old ChangeLog files (which are moved to the new directory OldChangeLogs, instead), and the generated file INSTALL (which is just deleted; in the new order, there will be no generated files checked into version control).
Diffstat (limited to 'REORG.TODO/math/test-fenv-tls.c')
-rw-r--r--REORG.TODO/math/test-fenv-tls.c208
1 files changed, 208 insertions, 0 deletions
diff --git a/REORG.TODO/math/test-fenv-tls.c b/REORG.TODO/math/test-fenv-tls.c
new file mode 100644
index 0000000000..24f3fadbef
--- /dev/null
+++ b/REORG.TODO/math/test-fenv-tls.c
@@ -0,0 +1,208 @@
+/* Test floating-point environment is thread-local.
+ Copyright (C) 2013-2017 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <fenv.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdint.h>
+
+#define TEST_ONE_RM(RM) \
+ do \
+ { \
+ if (fesetround (RM) == 0) \
+ { \
+ rm = fegetround (); \
+ if (rm != RM) \
+ { \
+ printf ("expected " #RM ", got %d\n", rm); \
+ ret = 1; \
+ } \
+ } \
+ } \
+ while (0)
+
+static void *
+test_round (void *arg)
+{
+ intptr_t ret = 0;
+ for (int i = 0; i < 10000; i++)
+ {
+ int rm;
+#ifdef FE_DOWNWARD
+ TEST_ONE_RM (FE_DOWNWARD);
+#endif
+#ifdef FE_TONEAREST
+ TEST_ONE_RM (FE_TONEAREST);
+#endif
+#ifdef FE_TOWARDZERO
+ TEST_ONE_RM (FE_TOWARDZERO);
+#endif
+#ifdef FE_UPWARD
+ TEST_ONE_RM (FE_UPWARD);
+#endif
+ }
+ return (void *) ret;
+}
+
+#define TEST_ONE_RAISE(EX) \
+ do \
+ { \
+ if (feraiseexcept (EX) == 0) \
+ if (fetestexcept (EX) != EX) \
+ { \
+ printf (#EX " not raised\n"); \
+ ret = 1; \
+ } \
+ if (feclearexcept (FE_ALL_EXCEPT) == 0) \
+ if (fetestexcept (FE_ALL_EXCEPT) != 0) \
+ { \
+ printf ("exceptions not all cleared\n"); \
+ ret = 1; \
+ } \
+ } \
+ while (0)
+
+static void *
+test_raise (void *arg)
+{
+ intptr_t ret = 0;
+ for (int i = 0; i < 10000; i++)
+ {
+#ifdef FE_DIVBYZERO
+ TEST_ONE_RAISE (FE_DIVBYZERO);
+#endif
+#ifdef FE_INEXACT
+ TEST_ONE_RAISE (FE_INEXACT);
+#endif
+#ifdef FE_INVALID
+ TEST_ONE_RAISE (FE_INVALID);
+#endif
+#ifdef FE_OVERFLOW
+ TEST_ONE_RAISE (FE_OVERFLOW);
+#endif
+#ifdef UNDERFLOW
+ TEST_ONE_RAISE (FE_UNDERFLOW);
+#endif
+ }
+ return (void *) ret;
+}
+
+#define TEST_ONE_ENABLE(EX) \
+ do \
+ { \
+ if (feenableexcept (EX) != -1) \
+ if (fegetexcept () != EX) \
+ { \
+ printf (#EX " not enabled\n"); \
+ ret = 1; \
+ } \
+ if (fedisableexcept (EX) != -1) \
+ if (fegetexcept () != 0) \
+ { \
+ printf ("exceptions not all disabled\n"); \
+ ret = 1; \
+ } \
+ } \
+ while (0)
+
+static void *
+test_enable (void *arg)
+{
+ intptr_t ret = 0;
+ for (int i = 0; i < 10000; i++)
+ {
+#ifdef FE_DIVBYZERO
+ TEST_ONE_ENABLE (FE_DIVBYZERO);
+#endif
+#ifdef FE_INEXACT
+ TEST_ONE_ENABLE (FE_INEXACT);
+#endif
+#ifdef FE_INVALID
+ TEST_ONE_ENABLE (FE_INVALID);
+#endif
+#ifdef FE_OVERFLOW
+ TEST_ONE_ENABLE (FE_OVERFLOW);
+#endif
+#ifdef UNDERFLOW
+ TEST_ONE_ENABLE (FE_UNDERFLOW);
+#endif
+ }
+ return (void *) ret;
+}
+
+static int
+do_test (void)
+{
+ int ret = 0;
+ void *vret;
+ pthread_t thread_id;
+ int pret;
+
+ pret = pthread_create (&thread_id, NULL, test_round, NULL);
+ if (pret != 0)
+ {
+ printf ("pthread_create failed: %d\n", pret);
+ return 1;
+ }
+ vret = test_round (NULL);
+ ret |= (intptr_t) vret;
+ pret = pthread_join (thread_id, &vret);
+ if (pret != 0)
+ {
+ printf ("pthread_join failed: %d\n", pret);
+ return 1;
+ }
+ ret |= (intptr_t) vret;
+
+ pret = pthread_create (&thread_id, NULL, test_raise, NULL);
+ if (pret != 0)
+ {
+ printf ("pthread_create failed: %d\n", pret);
+ return 1;
+ }
+ vret = test_raise (NULL);
+ ret |= (intptr_t) vret;
+ pret = pthread_join (thread_id, &vret);
+ if (pret != 0)
+ {
+ printf ("pthread_join failed: %d\n", pret);
+ return 1;
+ }
+ ret |= (intptr_t) vret;
+
+ pret = pthread_create (&thread_id, NULL, test_enable, NULL);
+ if (pret != 0)
+ {
+ printf ("pthread_create failed: %d\n", pret);
+ return 1;
+ }
+ vret = test_enable (NULL);
+ ret |= (intptr_t) vret;
+ pret = pthread_join (thread_id, &vret);
+ if (pret != 0)
+ {
+ printf ("pthread_join failed: %d\n", pret);
+ return 1;
+ }
+ ret |= (intptr_t) vret;
+
+ return ret;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"