[Git][NTPsec/ntpsec][master] 6 commits: tests/lfpfunc: improve error message.

Gary E. Miller gitlab at mg.gitlab.com
Thu Apr 13 20:46:18 UTC 2017


Gary E. Miller pushed to branch master at NTPsec / ntpsec


Commits:
2c6ad54a by Gary E. Miller at 2017-04-13T13:27:16-07:00
tests/lfpfunc: improve error message.

NetBSD keeps failing this one test...

- - - - -
298fd592 by Gary E. Miller at 2017-04-13T13:27:51-07:00
tests/lfptest: fix format signedness.

- - - - -
292816b2 by Gary E. Miller at 2017-04-13T13:29:18-07:00
tests/decodenetnum: add missing header.

- - - - -
3b1751b3 by Gary E. Miller at 2017-04-13T13:32:34-07:00
tests/recvbuf: Fix type conversion warning.

- - - - -
3978b318 by Gary E. Miller at 2017-04-13T13:41:02-07:00
tests/macencrypt: Fix Unity issues with const.

- - - - -
20a8f68f by Gary E. Miller at 2017-04-13T13:45:48-07:00
tests/macencrypt: Fix more Unity const issues.

- - - - -


5 changed files:

- tests/libntp/decodenetnum.c
- tests/libntp/lfpfunc.c
- tests/libntp/lfptest.h
- tests/libntp/macencrypt.c
- tests/libntp/recvbuff.c


Changes:

=====================================
tests/libntp/decodenetnum.c
=====================================
--- a/tests/libntp/decodenetnum.c
+++ b/tests/libntp/decodenetnum.c
@@ -1,3 +1,4 @@
+#include <unistd.h>          /* for close() */
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>


=====================================
tests/libntp/lfpfunc.c
=====================================
--- a/tests/libntp/lfpfunc.c
+++ b/tests/libntp/lfpfunc.c
@@ -263,9 +263,8 @@ TEST(lfpfunc, FDF_RoundTrip) {
 		l_fp temp = op1 - op3;
 		double d = lfptod(temp);
                 /* cast to long unsgiend int for 32 bit binaries */
-                snprintf(msg, sizeof(msg), "%llx not %llx within %f",
-                         (long long unsigned)op1,
-                         (long long unsigned)op2, eps(op2));
+                snprintf(msg, sizeof(msg), "%f diff %f not within %e",
+                         op2, d, eps(op2));
 		TEST_ASSERT_DOUBLE_WITHIN_MESSAGE(eps(op2), 0.0, fabs(d), msg);
 	}
 


=====================================
tests/libntp/lfptest.h
=====================================
--- a/tests/libntp/lfptest.h
+++ b/tests/libntp/lfptest.h
@@ -6,10 +6,12 @@
 static bool IsEqual(const l_fp *expected, const l_fp *actual) {
 	if (*expected == *actual) {
 		return true;
-	} else {
-		printf("Expected: %s (%d.%d) but was: %s (%d.%d)\n", lfptoa(*expected, FRACTION_PREC), lfpuint(*expected), lfpfrac(*expected), lfptoa(*actual, FRACTION_PREC), lfpuint(*actual), lfpfrac(*actual));
-		return false;
 	}
+	printf("Expected: %s (%u.%u) but was: %s (%u.%u)\n",
+		lfptoa(*expected, FRACTION_PREC), lfpuint(*expected),
+		lfpfrac(*expected), lfptoa(*actual, FRACTION_PREC),
+		lfpuint(*actual), lfpfrac(*actual));
+	return false;
 }
 
 static const uint32_t HALF = 2147483648U;           // (1 << 31)


=====================================
tests/libntp/macencrypt.c
=====================================
--- a/tests/libntp/macencrypt.c
+++ b/tests/libntp/macencrypt.c
@@ -18,14 +18,14 @@ TEST_TEAR_DOWN(macencrypt) {}
  * Example packet with MD5 hash calculated manually.
  */
 const int keytype = NID_md5;
-const char *key = "abcdefgh";
+char key[] = "abcdefgh";
 const u_short keyLength = 8;
 const char *packet = "ijklmnopqrstuvwx";
 const int packetLength = 16;
 const int keyIdLength = 4;
 const int digestLength = 16;
 const int totalLength = 36; //error: initializer element is not constant packetLength + keyIdLength + digestLength;
-const char *expectedPacket = "ijklmnopqrstuvwx\0\0\0\0\x0c\x0e\x84\xcf\x0b\xb7\xa8\x68\x8e\x52\x38\xdb\xbc\x1c\x39\x53";
+char expectedPacket[] = "ijklmnopqrstuvwx\0\0\0\0\x0c\x0e\x84\xcf\x0b\xb7\xa8\x68\x8e\x52\x38\xdb\xbc\x1c\x39\x53";
 
 TEST(macencrypt, Encrypt) {
 	char *packetPtr[totalLength];
@@ -47,15 +47,17 @@ TEST(macencrypt, Encrypt) {
 TEST(macencrypt, DecryptValid) {
 	cache_secretsize = keyLength;
 
-	TEST_ASSERT_TRUE(mac_authdecrypt(keytype, (u_char*)key, (uint32_t*)expectedPacket, packetLength, 20));
+	TEST_ASSERT_TRUE(mac_authdecrypt(keytype, (u_char*)key,
+                         (uint32_t*)expectedPacket, packetLength, 20));
 }
 
 TEST(macencrypt, DecryptInvalid) {
 	cache_secretsize = keyLength;
 
-	const char *invalidPacket = "ijklmnopqrstuvwx\0\0\0\0\x0c\x0e\x84\xcf\x0b\xb7\xa8\x68\x8e\x52\x38\xdb\xbc\x1c\x39\x54";
+	char invalidPacket[] = "ijklmnopqrstuvwx\0\0\0\0\x0c\x0e\x84\xcf\x0b\xb7\xa8\x68\x8e\x52\x38\xdb\xbc\x1c\x39\x54";
 
-	TEST_ASSERT_FALSE(mac_authdecrypt(keytype, (u_char*)key, (uint32_t*)invalidPacket, packetLength, 20));
+	TEST_ASSERT_FALSE(mac_authdecrypt(keytype, (u_char*)key,
+                          (uint32_t*)invalidPacket, packetLength, 20));
 }
 
 TEST(macencrypt, IPv4AddressToRefId) {


=====================================
tests/libntp/recvbuff.c
=====================================
--- a/tests/libntp/recvbuff.c
+++ b/tests/libntp/recvbuff.c
@@ -33,11 +33,13 @@ TEST(recvbuff, GetAndFree) {
 
 TEST(recvbuff, GetAndFill) {
 	recvbuf_t* buf = get_free_recv_buffer();
+	recvbuf_t* buf1;
 
 	add_full_recv_buffer(buf);
 	TEST_ASSERT_EQUAL(1, full_recvbuffs());
 	TEST_ASSERT_TRUE(has_full_recv_buffer());
-	TEST_ASSERT_POINTERS_EQUAL(buf, get_full_recv_buffer());
+	buf1 = get_full_recv_buffer();
+	TEST_ASSERT_POINTERS_EQUAL(buf, buf1);
 }
 
 TEST_GROUP_RUNNER(recvbuff) {



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/25a240c2ef230ee4af9f9f9bcd314ca5a1156c62...20a8f68fefc1c5a13792ba37c15aaeba6d5e3c96

---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/25a240c2ef230ee4af9f9f9bcd314ca5a1156c62...20a8f68fefc1c5a13792ba37c15aaeba6d5e3c96
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170413/a62ee4fc/attachment.html>


More information about the vc mailing list