From patchwork Fri Feb 6 21:00:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roland McGrath X-Patchwork-Id: 437461 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 5C8A814017D for ; Sat, 7 Feb 2015 08:00:48 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:mime-version:content-type :content-transfer-encoding:from:to:subject:message-id:date; q= dns; s=default; b=qZzQt9dkaIVnK3RM+W+JnneX51QDPxOnlbXgWINMlNyzyv /bZ2CNqM5ZqhSv3ub0H/ZjRSOETk+DcxrZrvBw3kHh1c2lJTmtMHl1FxmgqP3uOW WdOHHBZJwXU1jBIcW3f/RyAhFd0JzVp9bzexaJynfKZi7fd4q0MBxMPKS8Ep0= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:mime-version:content-type :content-transfer-encoding:from:to:subject:message-id:date; s= default; bh=CPf+PN6iWhQqnRi9FWGXoB4pzAk=; b=VbaFjp1q2w06luRBdN4p GPWlR9OrPq9QvgwliSFyAq24m7l1/TTLaC9M0OGy0rI/W9SDQuRadW8ddeZNXp3S sWfFOJ7iY0wsPXlGG/HEE9QlX4isiQWL+kiuu9edy3GCKNZIx1e3I+NUJJGow3TP D7ZFIxL3K2E5WmPAoaHQHm0= Received: (qmail 17046 invoked by alias); 6 Feb 2015 21:00:16 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 17033 invoked by uid 89); 6 Feb 2015 21:00:16 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL, BAYES_00 autolearn=ham version=3.3.2 X-HELO: topped-with-meat.com MIME-Version: 1.0 From: Roland McGrath To: "GNU C. Library" Subject: [PATCH roland/test-snan] Clean up math/test-snan. Message-Id: <20150206210012.080072C3A9B@topped-with-meat.com> Date: Fri, 6 Feb 2015 13:00:11 -0800 (PST) X-CMAE-Score: 0 X-CMAE-Analysis: v=2.1 cv=SvUDtp+0 c=1 sm=1 tr=0 a=WkljmVdYkabdwxfqvArNOQ==:117 a=14OXPxybAAAA:8 a=kj9zAlcOel0A:10 a=hOe2yjtxAAAA:8 a=1DiC6VYUXjQujAIIofYA:9 a=dNv69WYsrwLj1d8e:21 a=sZgOHAAQaqXdXOR7:21 a=CjuIK1q_8ugA:10 This is a general cleanup of test-snan.c, intended not to change at all what it actually does. My real motivation for touching this test was to make it stop gratuitously using SA_SIGINFO (which it doesn't actually need). But when I saw the cruft and duplication rampant in this file, I had to act. Tested x86_64-linux-gnu. OK? Thanks, Roland 2015-02-06 Roland McGrath * math/test-snan.c: Drop unnecessary #include's of , , , and . (dest_offset, dest_address, value, zero): Remove unused variables. (ldouble): Remove typedef. (myFPsighandler): Use simple handler signature, not SA_SIGINFO signature. Pass 1 to siglongjmp rather than 0 (which is converted to 1). Fix code style. (set_sigaction_FP, remove_sigaction_FP): Functions removed. (check): Function removed. (CHECK): New macro. (TEST_FUNC): Fix code style. Use CHECK macro rather than repeating boilerplate feclearexcept + feenableexcept + sigsetjmp code. Don't call set_sigaction_FP and remove_sigaction_FP here. (ldouble_test): Just use 'long double' as macro argument, no need for the 'ldouble' typedef. (do_test): Set up SIGFPE handler at start, using plain signal rather than sigaction. Fix code style. --- a/math/test-snan.c +++ b/math/test-snan.c @@ -19,73 +19,40 @@ #define _GNU_SOURCE 1 #include -#include -#include -#include #include #include #include #include #include -#include #include -int dest_offset; -char *dest_address; -double value = 123.456; -double zero = 0.0; - static sigjmp_buf sigfpe_buf; -typedef long double ldouble; - - -void -myFPsighandler(int signal, - siginfo_t *info, - void *context) -{ - siglongjmp(sigfpe_buf, 0); -} - -int -set_sigaction_FP(void) +static void +myFPsighandler (int signal) { - struct sigaction sa; - /* register RT signal handler via sigaction */ - sa.sa_flags = SA_SIGINFO; - sa.sa_sigaction = &myFPsighandler; - sigemptyset(&sa.sa_mask); - sigaction(SIGFPE, &sa, NULL); - - return 0; -} - -int -remove_sigaction_FP(void) -{ - struct sigaction sa; - /* restore default RT signal handler via sigaction */ - sa.sa_flags = SA_SIGINFO; - sa.sa_handler = SIG_DFL; - sigemptyset(&sa.sa_mask); - sigaction(SIGFPE, &sa, NULL); - - return 0; + siglongjmp (sigfpe_buf, 1); } static int errors = 0; -static void -check (const char *testname, int result) -{ - if (!result) { - printf ("Failure: %s\n", testname); - errors++; - } -} +#define CHECK(testname, expr) \ + do { \ + feclearexcept (FE_ALL_EXCEPT); \ + feenableexcept (FE_ALL_EXCEPT); \ + if (sigsetjmp (sigfpe_buf, 0)) \ + { \ + printf ("%s raised SIGFPE\n", testname); \ + ++errors; \ + } \ + else if (!(expr)) \ + { \ + printf ("Failure: %s\n", testname); \ + ++errors; \ + } \ + } while (0) #define TEST_FUNC(NAME, FLOAT, SUFFIX) \ static void \ @@ -112,278 +79,63 @@ NAME (void) \ (void) &minus_sNaN_var; \ (void) &Inf_var; \ \ - set_sigaction_FP (); \ - fegetenv(&saved_fenv); \ - \ - feclearexcept(FE_ALL_EXCEPT); \ - feenableexcept (FE_ALL_EXCEPT); \ - if (sigsetjmp(sigfpe_buf, 0)) \ - { \ - printf (#FLOAT " issignaling (qNaN) raised SIGFPE\n"); \ - errors++; \ - } else { \ - check (#FLOAT " issignaling (qNaN)", !issignaling (qNaN_var)); \ - } \ - \ - feclearexcept(FE_ALL_EXCEPT); \ - feenableexcept (FE_ALL_EXCEPT); \ - if (sigsetjmp(sigfpe_buf, 0)) \ - { \ - printf (#FLOAT " issignaling (-qNaN) raised SIGFPE\n"); \ - errors++; \ - } else { \ - check (#FLOAT " issignaling (-qNaN)", !issignaling (-qNaN_var)); \ - } \ - \ - feclearexcept(FE_ALL_EXCEPT); \ - feenableexcept (FE_ALL_EXCEPT); \ - if (sigsetjmp(sigfpe_buf, 0)) \ - { \ - printf (#FLOAT " issignaling (sNaN) raised SIGFPE\n"); \ - errors++; \ - } else { \ - check (#FLOAT " issignaling (sNaN)", \ - SNAN_TESTS (FLOAT) ? issignaling (sNaN_var) : 1); \ - } \ - \ - feclearexcept(FE_ALL_EXCEPT); \ - feenableexcept (FE_ALL_EXCEPT); \ - if (sigsetjmp(sigfpe_buf, 0)) \ - { \ - printf (#FLOAT " issignaling (-sNaN) raised SIGFPE\n"); \ - errors++; \ - } else { \ - check (#FLOAT " issignaling (-sNaN)", \ - SNAN_TESTS (FLOAT) ? issignaling (minus_sNaN_var) : 1); \ - } \ - \ - feclearexcept(FE_ALL_EXCEPT); \ - feenableexcept (FE_ALL_EXCEPT); \ - if (sigsetjmp(sigfpe_buf, 0)) \ - { \ - printf (#FLOAT " isnan (qNaN) raised SIGFPE\n"); \ - errors++; \ - } else { \ - check (#FLOAT " isnan (qNaN)", isnan (qNaN_var)); \ - } \ - \ - feclearexcept(FE_ALL_EXCEPT); \ - feenableexcept (FE_ALL_EXCEPT); \ - if (sigsetjmp(sigfpe_buf, 0)) \ - { \ - printf (#FLOAT " isnan (-qNaN) raised SIGFPE\n"); \ - errors++; \ - } else { \ - check (#FLOAT " isnan (-qNaN)", isnan (-qNaN_var)); \ - } \ - \ - feclearexcept(FE_ALL_EXCEPT); \ - feenableexcept (FE_ALL_EXCEPT); \ - if (sigsetjmp(sigfpe_buf, 0)) \ - { \ - printf (#FLOAT " isnan (sNaN) raised SIGFPE\n"); \ - errors++; \ - } else { \ - check (#FLOAT " isnan (sNaN)", \ - SNAN_TESTS (FLOAT) ? isnan (sNaN_var) : 1); \ - } \ - \ - feclearexcept(FE_ALL_EXCEPT); \ - feenableexcept (FE_ALL_EXCEPT); \ - if (sigsetjmp(sigfpe_buf, 0)) \ - { \ - printf (#FLOAT " isnan (-sNaN) raised SIGFPE\n"); \ - errors++; \ - } else { \ - check (#FLOAT " isnan (-sNaN)", \ - SNAN_TESTS (FLOAT) ? isnan (minus_sNaN_var) : 1); \ - } \ - \ - feclearexcept(FE_ALL_EXCEPT); \ - feenableexcept (FE_ALL_EXCEPT); \ - if (sigsetjmp(sigfpe_buf, 0)) \ - { \ - printf (#FLOAT " isinf (qNaN) raised SIGFPE\n"); \ - errors++; \ - } else { \ - check (#FLOAT " isinf (qNaN)", !isinf (qNaN_var)); \ - } \ - \ - feclearexcept(FE_ALL_EXCEPT); \ - feenableexcept (FE_ALL_EXCEPT); \ - if (sigsetjmp(sigfpe_buf, 0)) \ - { \ - printf (#FLOAT " isinf (-qNaN) raised SIGFPE\n"); \ - errors++; \ - } else { \ - check (#FLOAT " isinf (-qNaN)", !isinf (-qNaN_var)); \ - } \ - \ - feclearexcept(FE_ALL_EXCEPT); \ - feenableexcept (FE_ALL_EXCEPT); \ - if (sigsetjmp(sigfpe_buf, 0)) \ - { \ - printf (#FLOAT " isinf (sNaN) raised SIGFPE\n"); \ - errors++; \ - } else { \ - check (#FLOAT " isinf (sNaN)", \ - SNAN_TESTS (FLOAT) ? !isinf (sNaN_var) : 1); \ - } \ - \ - feclearexcept(FE_ALL_EXCEPT); \ - feenableexcept (FE_ALL_EXCEPT); \ - if (sigsetjmp(sigfpe_buf, 0)) \ - { \ - printf (#FLOAT " isinf (-sNaN) raised SIGFPE\n"); \ - errors++; \ - } else { \ - check (#FLOAT " isinf (-sNaN)", \ - SNAN_TESTS (FLOAT) ? !isinf (minus_sNaN_var) : 1); \ - } \ - \ - feclearexcept(FE_ALL_EXCEPT); \ - feenableexcept (FE_ALL_EXCEPT); \ - if (sigsetjmp(sigfpe_buf, 0)) \ - { \ - printf (#FLOAT " isfinite (qNaN) raised SIGFPE\n"); \ - errors++; \ - } else { \ - check (#FLOAT " isfinite (qNaN)", !isfinite (qNaN_var)); \ - } \ - \ - feclearexcept(FE_ALL_EXCEPT); \ - feenableexcept (FE_ALL_EXCEPT); \ - if (sigsetjmp(sigfpe_buf, 0)) \ - { \ - printf (#FLOAT " isfinite (-qNaN) raised SIGFPE\n"); \ - errors++; \ - } else { \ - check (#FLOAT " isfinite (-qNaN)", !isfinite (-qNaN_var)); \ - } \ - \ - feclearexcept(FE_ALL_EXCEPT); \ - feenableexcept (FE_ALL_EXCEPT); \ - if (sigsetjmp(sigfpe_buf, 0)) \ - { \ - printf (#FLOAT " isfinite (sNaN) raised SIGFPE\n"); \ - errors++; \ - } else { \ - check (#FLOAT " isfinite (sNaN)", \ - SNAN_TESTS (FLOAT) ? !isfinite (sNaN_var) : 1); \ - } \ - \ - feclearexcept(FE_ALL_EXCEPT); \ - feenableexcept (FE_ALL_EXCEPT); \ - if (sigsetjmp(sigfpe_buf, 0)) \ - { \ - printf (#FLOAT " isfinite (-sNaN) raised SIGFPE\n"); \ - errors++; \ - } else { \ - check (#FLOAT " isfinite (-sNaN)", \ - SNAN_TESTS (FLOAT) ? !isfinite (minus_sNaN_var) : 1); \ - } \ - \ - feclearexcept(FE_ALL_EXCEPT); \ - feenableexcept (FE_ALL_EXCEPT); \ - if (sigsetjmp(sigfpe_buf, 0)) \ - { \ - printf (#FLOAT " isnormal (qNaN) raised SIGFPE\n"); \ - errors++; \ - } else { \ - check (#FLOAT " isnormal (qNaN)", !isnormal (qNaN_var)); \ - } \ - \ - feclearexcept(FE_ALL_EXCEPT); \ - feenableexcept (FE_ALL_EXCEPT); \ - if (sigsetjmp(sigfpe_buf, 0)) \ - { \ - printf (#FLOAT " isnormal (-qNaN) raised SIGFPE\n"); \ - errors++; \ - } else { \ - check (#FLOAT " isnormal (-qNaN)", !isnormal (-qNaN_var)); \ - } \ - \ - feclearexcept(FE_ALL_EXCEPT); \ - feenableexcept (FE_ALL_EXCEPT); \ - if (sigsetjmp(sigfpe_buf, 0)) \ - { \ - printf (#FLOAT " isnormal (sNaN) isnormal SIGFPE\n"); \ - errors++; \ - } else { \ - check (#FLOAT " isnormal (sNaN)", \ - SNAN_TESTS (FLOAT) ? !isnormal (sNaN_var) : 1); \ - } \ - \ - feclearexcept(FE_ALL_EXCEPT); \ - feenableexcept (FE_ALL_EXCEPT); \ - if (sigsetjmp(sigfpe_buf, 0)) \ - { \ - printf (#FLOAT " isnormal (-sNaN) raised SIGFPE\n"); \ - errors++; \ - } else { \ - check (#FLOAT " isnormal (-sNaN)", \ - SNAN_TESTS (FLOAT) ? !isnormal (minus_sNaN_var) : 1); \ - } \ - \ - feclearexcept(FE_ALL_EXCEPT); \ - feenableexcept (FE_ALL_EXCEPT); \ - if (sigsetjmp(sigfpe_buf, 0)) \ - { \ - printf (#FLOAT " fpclassify (qNaN) raised SIGFPE\n"); \ - errors++; \ - } else { \ - check (#FLOAT " fpclassify (qNaN)", (fpclassify (qNaN_var)==FP_NAN)); \ - } \ - \ - feclearexcept(FE_ALL_EXCEPT); \ - feenableexcept (FE_ALL_EXCEPT); \ - if (sigsetjmp(sigfpe_buf, 0)) \ - { \ - printf (#FLOAT " fpclassify (-qNaN) raised SIGFPE\n"); \ - errors++; \ - } else { \ - check (#FLOAT " fpclassify (-qNaN)", (fpclassify (-qNaN_var)==FP_NAN)); \ - } \ - \ - feclearexcept(FE_ALL_EXCEPT); \ - feenableexcept (FE_ALL_EXCEPT); \ - if (sigsetjmp(sigfpe_buf, 0)) \ - { \ - printf (#FLOAT " fpclassify (sNaN) isnormal SIGFPE\n"); \ - errors++; \ - } else { \ - check (#FLOAT " fpclassify (sNaN)", \ - SNAN_TESTS (FLOAT) ? fpclassify (sNaN_var) == FP_NAN : 1); \ - } \ - \ - feclearexcept(FE_ALL_EXCEPT); \ - feenableexcept (FE_ALL_EXCEPT); \ - if (sigsetjmp(sigfpe_buf, 0)) \ - { \ - printf (#FLOAT " fpclassify (-sNaN) raised SIGFPE\n"); \ - errors++; \ - } else { \ - check (#FLOAT " fpclassify (-sNaN)", \ - SNAN_TESTS (FLOAT) ? fpclassify (minus_sNaN_var) == FP_NAN : 1); \ - } \ - \ - fesetenv(&saved_fenv); /* restore saved fenv */ \ - remove_sigaction_FP(); \ -} + fegetenv (&saved_fenv); \ + \ + CHECK (#FLOAT " issignaling (qNaN)", !issignaling (qNaN_var)); \ + CHECK (#FLOAT " issignaling (-qNaN)", !issignaling (-qNaN_var)); \ + CHECK (#FLOAT " issignaling (sNaN)", \ + SNAN_TESTS (FLOAT) ? issignaling (sNaN_var) : 1); \ + CHECK (#FLOAT " issignaling (-sNaN)", \ + SNAN_TESTS (FLOAT) ? issignaling (minus_sNaN_var) : 1); \ + CHECK (#FLOAT " isnan (qNaN)", isnan (qNaN_var)); \ + CHECK (#FLOAT " isnan (-qNaN)", isnan (-qNaN_var)); \ + CHECK (#FLOAT " isnan (sNaN)", \ + SNAN_TESTS (FLOAT) ? isnan (sNaN_var) : 1); \ + CHECK (#FLOAT " isnan (-sNaN)", \ + SNAN_TESTS (FLOAT) ? isnan (minus_sNaN_var) : 1); \ + CHECK (#FLOAT " isinf (qNaN)", !isinf (qNaN_var)); \ + CHECK (#FLOAT " isinf (-qNaN)", !isinf (-qNaN_var)); \ + CHECK (#FLOAT " isinf (sNaN)", \ + SNAN_TESTS (FLOAT) ? !isinf (sNaN_var) : 1); \ + CHECK (#FLOAT " isinf (-sNaN)", \ + SNAN_TESTS (FLOAT) ? !isinf (minus_sNaN_var) : 1); \ + CHECK (#FLOAT " isfinite (qNaN)", !isfinite (qNaN_var)); \ + CHECK (#FLOAT " isfinite (-qNaN)", !isfinite (-qNaN_var)); \ + CHECK (#FLOAT " isfinite (sNaN)", \ + SNAN_TESTS (FLOAT) ? !isfinite (sNaN_var) : 1); \ + CHECK (#FLOAT " isfinite (-sNaN)", \ + SNAN_TESTS (FLOAT) ? !isfinite (minus_sNaN_var) : 1); \ + CHECK (#FLOAT " isnormal (qNaN)", !isnormal (qNaN_var)); \ + CHECK (#FLOAT " isnormal (-qNaN)", !isnormal (-qNaN_var)); \ + CHECK (#FLOAT " isnormal (sNaN)", \ + SNAN_TESTS (FLOAT) ? !isnormal (sNaN_var) : 1); \ + CHECK (#FLOAT " isnormal (-sNaN)", \ + SNAN_TESTS (FLOAT) ? !isnormal (minus_sNaN_var) : 1); \ + CHECK (#FLOAT " fpclassify (qNaN)", (fpclassify (qNaN_var)==FP_NAN)); \ + CHECK (#FLOAT " fpclassify (-qNaN)", (fpclassify (-qNaN_var)==FP_NAN)); \ + CHECK (#FLOAT " fpclassify (sNaN)", \ + SNAN_TESTS (FLOAT) ? fpclassify (sNaN_var) == FP_NAN : 1); \ + CHECK (#FLOAT " fpclassify (-sNaN)", \ + SNAN_TESTS (FLOAT) ? fpclassify (minus_sNaN_var) == FP_NAN : 1); \ + \ + fesetenv (&saved_fenv); /* restore saved fenv */ \ +} \ TEST_FUNC (float_test, float, f) TEST_FUNC (double_test, double, ) #ifndef NO_LONG_DOUBLE -TEST_FUNC (ldouble_test, ldouble, l) +TEST_FUNC (ldouble_test, long double, l) #endif static int do_test (void) { - float_test(); - double_test(); + signal (SIGFPE, &myFPsighandler); + + float_test (); + double_test (); #ifndef NO_LONG_DOUBLE - ldouble_test(); + ldouble_test (); #endif return errors != 0;