Sun Sep 3 13:29:55 2017 UTC ()
Use a global double to stop GCC from optimizing the test away
Better diagnostic messages
More familiar test for 'even number'


(maya)
diff -r1.7 -r1.8 src/tests/lib/libm/t_round.c

cvs diff -r1.7 -r1.8 src/tests/lib/libm/t_round.c (expand / switch to unified diff)

--- src/tests/lib/libm/t_round.c 2017/08/30 22:55:41 1.7
+++ src/tests/lib/libm/t_round.c 2017/09/03 13:29:55 1.8
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: t_round.c,v 1.7 2017/08/30 22:55:41 maya Exp $ */ 1/* $NetBSD: t_round.c,v 1.8 2017/09/03 13:29:55 maya Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2011 The NetBSD Foundation, Inc. 4 * Copyright (c) 2011 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -93,43 +93,45 @@ ATF_TC_BODY(rounding_alpha, tc) @@ -93,43 +93,45 @@ ATF_TC_BODY(rounding_alpha, tc)
93{ 93{
94 double d; 94 double d;
95 gimpy_limb_t u; 95 gimpy_limb_t u;
96 int i; 96 int i;
97 97
98 d = 1.0; 98 d = 1.0;
99 for (i = 0; i < GIMPY_NUMB_BITS - 1; i++) 99 for (i = 0; i < GIMPY_NUMB_BITS - 1; i++)
100 d = d + d; 100 d = d + d;
101 101
102 printf("d = %g\n", d); 102 printf("d = %g\n", d);
103 u = (gimpy_limb_t) d; 103 u = (gimpy_limb_t) d;
104 104
105 for (; i > 0; i--) { 105 for (; i > 0; i--) {
106 printf("i=%d, u: %"PRIu64"\n", i, u); 106 ATF_CHECK_MSG((u % 2 == 0),
107 ATF_CHECK(!(u & 1)); 107 "%"PRIu64" is not an even number! (iteration %d)", u , i);
108 u = u >> 1; 108 u = u >> 1;
109 } 109 }
110} 110}
111 111
112ATF_TC(rounding_alpha_simple); 112ATF_TC(rounding_alpha_simple);
113ATF_TC_HEAD(rounding_alpha_simple, tc) 113ATF_TC_HEAD(rounding_alpha_simple, tc)
114{ 114{
115 atf_tc_set_md_var(tc, "descr","Checking double to uint64_t edge case"); 115 atf_tc_set_md_var(tc, "descr","Checking double to uint64_t edge case");
116} 116}
117 117
 118
 119double rounding_alpha_simple_even = 9223372036854775808.000000; /* 2^63 */
 120
118ATF_TC_BODY(rounding_alpha_simple, tc) 121ATF_TC_BODY(rounding_alpha_simple, tc)
119{ 122{
120 double even = 9223372036854775808.000000; /* 2^63 */ 123 uint64_t unsigned_even = rounding_alpha_simple_even;
121 uint64_t unsigned_even = even; 
122 124
123 ATF_CHECK_MSG(unsigned_even % 2 == 0, 125 ATF_CHECK_MSG(unsigned_even % 2 == 0,
124 "2^63 casted to uint64_t is odd"); 126 "2^63 casted to uint64_t is odd (got %"PRIu64")", unsigned_even);
125 127
126} 128}
127ATF_TP_ADD_TCS(tp) 129ATF_TP_ADD_TCS(tp)
128{ 130{
129 131
130 ATF_TP_ADD_TC(tp, round_dir); 132 ATF_TP_ADD_TC(tp, round_dir);
131 ATF_TP_ADD_TC(tp, rounding_alpha); 133 ATF_TP_ADD_TC(tp, rounding_alpha);
132 ATF_TP_ADD_TC(tp, rounding_alpha_simple); 134 ATF_TP_ADD_TC(tp, rounding_alpha_simple);
133 135
134 return atf_no_error(); 136 return atf_no_error();
135} 137}