[Git][NTPsec/ntpsec][master] 7 commits: tests: ints are not always the same as pointers.
Gary E. Miller
gitlab at mg.gitlab.com
Tue Apr 11 23:35:48 UTC 2017
Gary E. Miller pushed to branch master at NTPsec / ntpsec
Commits:
63820997 by Gary E. Miller at 2017-04-11T14:57:12-07:00
tests: ints are not always the same as pointers.
Fixes some warnings on 32-bit OS.
- - - - -
f065aef2 by Gary E. Miller at 2017-04-11T15:03:02-07:00
tests: 1L is not long enough for int64_t on 32-bit OS.
- - - - -
d984eb69 by Gary E. Miller at 2017-04-11T15:37:28-07:00
ieee754: long is not long enough with 32-bit OS.
- - - - -
41d89b0f by Gary E. Miller at 2017-04-11T15:38:05-07:00
tests/ieee754io: long is not long enough on 32-bit OS.
- - - - -
5584580e by Gary E. Miller at 2017-04-11T16:26:02-07:00
tests/ieee754: fix bad test. ARM does not barrel roll shift.
Any float that big is bad input anyway.
- - - - -
61f39fd4 by Gary E. Miller at 2017-04-11T16:29:49-07:00
libparse/ieee754io: clean up var sizes, fix IEEE_SINGLE max exponent.
- - - - -
aeee1573 by Gary E. Miller at 2017-04-11T16:34:19-07:00
tests/leapsec: revert one bad change.
- - - - -
4 changed files:
- libparse/ieee754io.c
- tests/libntp/recvbuff.c
- tests/libparse/ieee754io.c
- tests/ntpd/leapsec.c
Changes:
=====================================
libparse/ieee754io.c
=====================================
--- a/libparse/ieee754io.c
+++ b/libparse/ieee754io.c
@@ -21,7 +21,7 @@ static uint64_t get_byte (unsigned char *, offsets_t, int *);
static char *
fmt_blong(
- unsigned long val,
+ uint64_t val,
int cnt
)
{
@@ -48,7 +48,7 @@ static char *
fmt_flt(
bool sign,
uint64_t ml,
- unsigned long ch,
+ uint64_t ch,
int length
)
{
@@ -119,13 +119,13 @@ fetch_ieee754(
{
unsigned char *bufp = *buffpp;
bool sign;
- unsigned int bias; /* bias 127 or 1023 */
- unsigned int maxexp;
+ int bias; /* bias 127 or 1023 */
+ int maxexp;
int mbits; /* length of mantissa, 23 or 52 */
uint64_t mantissa; /* mantissa, 23 or 52 bits used, +1 */
- unsigned long characteristic; /* biased exponent, 0 to 255 or 2047 */
+ int characteristic; /* biased exponent, 0 to 255 or 2047 */
int exponent; /* unbiased exponent */
- unsigned int maxexp_lfp; /* maximum exponent that fits in an l_fp */
+ int maxexp_lfp; /* maximum exponent that fits in an l_fp */
unsigned char val;
int fieldindex = 0; /* index into bufp */
int fudge; /* shift difference of l_fp and IEEE */
@@ -166,7 +166,7 @@ fetch_ieee754(
case IEEE_SINGLE:
fudge = 9;
- maxexp_lfp = 127;
+ maxexp_lfp = 30;
mbits = 23;
bias = 127;
maxexp = 255;
@@ -183,7 +183,8 @@ fetch_ieee754(
return IEEE_BADCALL;
}
- exponent = (int)characteristic - (int)bias;
+ exponent = characteristic - bias;
+ shift = exponent + fudge;
#ifdef DEBUG_PARSELIB
if ( debug > 4) {
@@ -194,7 +195,8 @@ fetch_ieee754(
printf("\nfetchieee754: FP: %s -> %s\n", fmt_hex(*buffpp, length),
fmt_flt(sign, mantissa, characteristic, length));
- printf("fetchieee754: Exp: %d, mbits %d\n", exponent, mbits);
+ printf("fetchieee754: Char: %d, Exp: %d, mbits %d, shift %d\n",
+ characteristic, exponent, mbits, shift);
}
#endif
@@ -212,7 +214,7 @@ fetch_ieee754(
}
/* check for overflows */
- if (exponent > (int)maxexp_lfp) {
+ if (exponent > maxexp_lfp) {
/*
* sorry an l_fp only so long
* overflow only in respect to NTP-FP representation
@@ -230,7 +232,6 @@ fetch_ieee754(
/* add in implied 1 */
mantissa |= 1ULL << mbits;
- shift = exponent + fudge;
if ( 0 == shift ) {
/* no shift */
*lfpp = mantissa;
=====================================
tests/libntp/recvbuff.c
=====================================
--- a/tests/libntp/recvbuff.c
+++ b/tests/libntp/recvbuff.c
@@ -37,7 +37,7 @@ TEST(recvbuff, GetAndFill) {
add_full_recv_buffer(buf);
TEST_ASSERT_EQUAL(1, full_recvbuffs());
TEST_ASSERT_TRUE(has_full_recv_buffer());
- TEST_ASSERT_EQUAL(buf, get_full_recv_buffer());
+ TEST_ASSERT_POINTERS_EQUAL(buf, get_full_recv_buffer());
}
TEST_GROUP_RUNNER(recvbuff) {
=====================================
tests/libparse/ieee754io.c
=====================================
--- a/tests/libparse/ieee754io.c
+++ b/tests/libparse/ieee754io.c
@@ -41,7 +41,7 @@ TEST(ieee754io, test_zero32) {
ret = fetch_ieee754( &bp, IEEE_SINGLE, &fp, native_off);
TEST_ASSERT( IEEE_OK == ret);
- TEST_ASSERT_EQUAL_INT64( 0, (long)fp );
+ TEST_ASSERT_EQUAL_INT64( 0, (int64_t)fp );
}
TEST(ieee754io, test_one32) {
@@ -53,7 +53,7 @@ TEST(ieee754io, test_one32) {
ret = fetch_ieee754( &bp, IEEE_SINGLE, &fp, native_off);
TEST_ASSERT( IEEE_OK == ret);
- TEST_ASSERT_EQUAL_INT64( 1L << 32, (long)fp );
+ TEST_ASSERT_EQUAL_INT64( 1LL << 32, (int64_t)fp );
}
TEST(ieee754io, test_negone32) {
@@ -65,7 +65,7 @@ TEST(ieee754io, test_negone32) {
ret = fetch_ieee754( &bp, IEEE_SINGLE, &fp, native_off);
TEST_ASSERT( IEEE_OK == ret);
- TEST_ASSERT_EQUAL_INT64( -(1L << 32), (long)fp );
+ TEST_ASSERT_EQUAL_INT64( -(1LL << 32), (int64_t)fp );
}
TEST(ieee754io, test_nan32) {
@@ -79,7 +79,7 @@ TEST(ieee754io, test_nan32) {
TEST_ASSERT( IEEE_POSINFINITY == ret);
/* not IEEE754, but check for 0 anyway */
- TEST_ASSERT_EQUAL_INT64( 0, (long)fp );
+ TEST_ASSERT_EQUAL_INT64( 0, (int64_t)fp );
/* -INF */
buf[0] = 0xff;
@@ -88,7 +88,7 @@ TEST(ieee754io, test_nan32) {
TEST_ASSERT( IEEE_NEGINFINITY == ret);
/* not IEEE754, but check for 0 anyway */
- TEST_ASSERT_EQUAL_INT64( 0, (long)fp );
+ TEST_ASSERT_EQUAL_INT64( 0, (int64_t)fp );
/* NAN */
buf[0] = 0x7f;
@@ -98,7 +98,7 @@ TEST(ieee754io, test_nan32) {
TEST_ASSERT( IEEE_NAN == ret);
/* not IEEE754, but check for 0 anyway */
- TEST_ASSERT_EQUAL_INT64( 0, (long)fp );
+ TEST_ASSERT_EQUAL_INT64( 0, (int64_t)fp );
}
TEST(ieee754io, test_max32) {
@@ -113,22 +113,22 @@ TEST(ieee754io, test_max32) {
ret = fetch_ieee754( &bp, IEEE_SINGLE, &fp, native_off);
TEST_ASSERT( IEEE_OK == ret);
- TEST_ASSERT_EQUAL_INT64( 0x7FFFFF8000000000UL, fp );
+ TEST_ASSERT_EQUAL_INT64( 0x7FFFFF8000000000ULL, fp );
/* negative max that fits */
bp = &buf_n[0];
ret = fetch_ieee754( &bp, IEEE_SINGLE, &fp, native_off);
TEST_ASSERT( IEEE_OK == ret);
- TEST_ASSERT_EQUAL_UINT64( 0x8000008000000000UL, fp );
+ TEST_ASSERT_EQUAL_UINT64( 0x8000008000000000ULL, fp );
}
TEST(ieee754io, test_order32) {
int ret;
/* not enough precision in a double to get max l_fp */
- unsigned char buf[4] = { 255, 127, 1, 2};
+ unsigned char buf[4] = { 0x3e, 127, 1, 2};
/* not enough precision in a double to get negative max l_fp */
- unsigned char buf_n[4] = { 127, 255, 2, 1};
+ unsigned char buf_n[4] = { 127, 0x3e, 2, 1};
unsigned char *bp = &buf[0];
l_fp fp;
@@ -136,14 +136,16 @@ TEST(ieee754io, test_order32) {
ret = fetch_ieee754( &bp, IEEE_SINGLE, &fp, native_off);
TEST_ASSERT( IEEE_OK == ret);
- TEST_ASSERT_EQUAL_UINT64( (unsigned long)0xFFFFFFFF00FEFE00UL, fp );
+ TEST_ASSERT_EQUAL_UINT64((uint64_t)0x3FC04080ULL,
+ (uint64_t)fp);
/* meinberg order */
bp = &buf_n[0];
ret = fetch_ieee754( &bp, IEEE_SINGLE, &fp, mbg_double);
TEST_ASSERT( IEEE_OK == ret);
- TEST_ASSERT_EQUAL_UINT64( (unsigned long)0xFFFFFFFF00FEFE00UL, fp );
+ TEST_ASSERT_EQUAL_UINT64((uint64_t)0x3FC04080ULL,
+ (uint64_t)fp);
}
TEST(ieee754io, test_small32) {
@@ -169,7 +171,7 @@ TEST(ieee754io, test_zero64) {
ret = fetch_ieee754( &bp, IEEE_DOUBLE, &fp, native_off);
TEST_ASSERT( IEEE_OK == ret);
- TEST_ASSERT_EQUAL_INT64( 0, (long)fp );
+ TEST_ASSERT_EQUAL_INT64( 0, (int64_t)fp );
}
TEST(ieee754io, test_one64) {
@@ -181,7 +183,7 @@ TEST(ieee754io, test_one64) {
ret = fetch_ieee754( &bp, IEEE_DOUBLE, &fp, native_off);
TEST_ASSERT( IEEE_OK == ret);
- TEST_ASSERT_EQUAL_INT64( 1L << 32, (long)fp );
+ TEST_ASSERT_EQUAL_INT64( 1LL << 32, (int64_t)fp );
}
TEST(ieee754io, test_negone64) {
@@ -193,7 +195,7 @@ TEST(ieee754io, test_negone64) {
ret = fetch_ieee754( &bp, IEEE_DOUBLE, &fp, native_off);
TEST_ASSERT( IEEE_OK == ret);
- TEST_ASSERT_EQUAL_INT64( -(1L << 32), (long)fp );
+ TEST_ASSERT_EQUAL_INT64( -(1LL << 32), (int64_t)fp );
}
TEST(ieee754io, test_nan64) {
@@ -207,7 +209,7 @@ TEST(ieee754io, test_nan64) {
TEST_ASSERT( IEEE_POSINFINITY == ret);
/* not IEEE754, but check for 0 anyway */
- TEST_ASSERT_EQUAL_INT64( 0, (long)fp );
+ TEST_ASSERT_EQUAL_INT64( 0, (int64_t)fp );
/* -INF */
buf[0] = 0xff;
@@ -216,7 +218,7 @@ TEST(ieee754io, test_nan64) {
TEST_ASSERT( IEEE_NEGINFINITY == ret);
/* not IEEE754, but check for 0 anyway */
- TEST_ASSERT_EQUAL_INT64( 0, (long)fp );
+ TEST_ASSERT_EQUAL_INT64( 0, (int64_t)fp );
/* +OVERFLOW */
buf[0] = 0x41;
@@ -226,7 +228,7 @@ TEST(ieee754io, test_nan64) {
TEST_ASSERT( IEEE_POSOVERFLOW == ret);
/* not IEEE754, but check for 0 anyway */
- TEST_ASSERT_EQUAL_INT64( 0, (long)fp );
+ TEST_ASSERT_EQUAL_INT64( 0, (int64_t)fp );
/* -OVERFLOW */
buf[0] = 0xC1;
@@ -236,7 +238,7 @@ TEST(ieee754io, test_nan64) {
TEST_ASSERT( IEEE_NEGOVERFLOW == ret);
/* not IEEE754, but check for 0 anyway */
- TEST_ASSERT_EQUAL_INT64( 0, (long)fp );
+ TEST_ASSERT_EQUAL_INT64( 0, (int64_t)fp );
/* NAN */
buf[0] = 0x7f;
@@ -246,7 +248,7 @@ TEST(ieee754io, test_nan64) {
TEST_ASSERT( IEEE_NAN == ret);
/* not IEEE754, but check for 0 anyway */
- TEST_ASSERT_EQUAL_INT64( 0, (long)fp );
+ TEST_ASSERT_EQUAL_INT64( 0, (int64_t)fp );
}
TEST(ieee754io, test_max64) {
@@ -262,14 +264,14 @@ TEST(ieee754io, test_max64) {
ret = fetch_ieee754( &bp, IEEE_DOUBLE, &fp, native_off);
TEST_ASSERT( IEEE_OK == ret);
- TEST_ASSERT_EQUAL_UINT64( (unsigned long)0xFFFFFFFFFFFFF800UL, fp );
+ TEST_ASSERT_EQUAL_UINT64( (uint64_t)0xFFFFFFFFFFFFF800ULL, fp );
/* negative max that fits */
bp = &buf_n[0];
ret = fetch_ieee754( &bp, IEEE_DOUBLE, &fp, native_off);
TEST_ASSERT( IEEE_OK == ret);
- TEST_ASSERT_EQUAL_UINT64( (unsigned long)0xFFFFFFFFFFFFF000UL, fp );
+ TEST_ASSERT_EQUAL_UINT64( (uint64_t)0xFFFFFFFFFFFFF000ULL, fp );
}
TEST(ieee754io, test_order64) {
@@ -285,14 +287,14 @@ TEST(ieee754io, test_order64) {
ret = fetch_ieee754( &bp, IEEE_DOUBLE, &fp, native_off);
TEST_ASSERT( IEEE_OK == ret);
- TEST_ASSERT_EQUAL_UINT64( (unsigned long)0xF808101820283000UL, fp );
+ TEST_ASSERT_EQUAL_UINT64( (uint64_t)0xF808101820283000ULL, fp );
/* meinberg order */
bp = &buf_n[0];
ret = fetch_ieee754( &bp, IEEE_DOUBLE, &fp, mbg_double);
TEST_ASSERT( IEEE_OK == ret);
- TEST_ASSERT_EQUAL_UINT64( (unsigned long)0xF808101820283000UL, fp );
+ TEST_ASSERT_EQUAL_UINT64( (uint64_t)0xF808101820283000ULL, fp );
}
TEST(ieee754io, test_small64) {
=====================================
tests/ntpd/leapsec.c
=====================================
--- a/tests/ntpd/leapsec.c
+++ b/tests/ntpd/leapsec.c
@@ -354,11 +354,11 @@ TEST(leapsec, tableSelect) {
pt1 = leapsec_get_table(0);
pt2 = leapsec_get_table(0);
- TEST_ASSERT_EQUAL(pt1, pt2);
+ TEST_ASSERT_POINTERS_EQUAL(pt1, pt2);
pt1 = leapsec_get_table(1);
pt2 = leapsec_get_table(1);
- TEST_ASSERT_EQUAL(pt1, pt2);
+ TEST_ASSERT_POINTERS_EQUAL(pt1, pt2);
pt1 = leapsec_get_table(1);
pt2 = leapsec_get_table(0);
@@ -371,14 +371,14 @@ TEST(leapsec, tableSelect) {
leapsec_set_table(pt1);
pt2 = leapsec_get_table(0);
pt3 = leapsec_get_table(1);
- TEST_ASSERT_EQUAL(pt1, pt2);
+ TEST_ASSERT_POINTERS_EQUAL(pt1, pt2);
TEST_ASSERT_NOT_EQUAL(pt2, pt3);
pt1 = pt3;
leapsec_set_table(pt1);
pt2 = leapsec_get_table(0);
pt3 = leapsec_get_table(1);
- TEST_ASSERT_EQUAL(pt1, pt2);
+ TEST_ASSERT_POINTERS_EQUAL(pt1, pt2);
TEST_ASSERT_NOT_EQUAL(pt2, pt3);
}
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/3e72e46fb22f31e059dcd676008bda07e5721136...aeee1573e3c575d2853fc8d540051f29bfd651aa
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170411/504d3ea1/attachment.html>
More information about the vc
mailing list