[Git][NTPsec/ntpsec][filt-fix] 8 commits: tests/decodenetnum: test for /etc/services and port names.
Ian Bruene
gitlab at mg.gitlab.com
Thu Apr 13 21:23:03 UTC 2017
Ian Bruene pushed to branch filt-fix at NTPsec / ntpsec
Commits:
25a240c2 by Gary E. Miller at 2017-04-13T12:45:28-07:00
tests/decodenetnum: test for /etc/services and port names.
Some overly lean jails fail to supply /etc/services.
- - - - -
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.
- - - - -
ba0d0dba by Ian Bruene at 2017-04-13T21:22:39+00:00
Belated filtcooker/stringfiltcooker swap
- - - - -
6 changed files:
- ntpclients/ntpmon
- tests/libntp/decodenetnum.c
- tests/libntp/lfpfunc.c
- tests/libntp/lfptest.h
- tests/libntp/macencrypt.c
- tests/libntp/recvbuff.c
Changes:
=====================================
ntpclients/ntpmon
=====================================
--- a/ntpclients/ntpmon
+++ b/ntpclients/ntpmon
@@ -118,9 +118,9 @@ def peer_detail(variables, showunits=False):
ntp.util.UNIT_S,
strip=True,
width=None)
- vcopy['filtdelay'] = ntp.util.filtcooker(vcopyraw['filtdelay'])
- vcopy['filtoffset'] = ntp.util.filtcooker(vcopyraw['filtoffset'])
- vcopy['filtdisp'] = ntp.util.filtcooker(vcopyraw['filtdisp'])
+ vcopy['filtdelay'] = ntp.util.stringfiltcooker(vcopyraw['filtdelay'])
+ vcopy['filtoffset'] = ntp.util.stringfiltcooker(vcopyraw['filtoffset'])
+ vcopy['filtdisp'] = ntp.util.stringfiltcooker(vcopyraw['filtdisp'])
else:
vcopy['filtdelay'] = vcopy['filtdelay'].replace(' ', '\t')
vcopy['filtoffset'] = vcopy['filtoffset'].replace(' ', '\t')
=====================================
tests/libntp/decodenetnum.c
=====================================
--- a/tests/libntp/decodenetnum.c
+++ b/tests/libntp/decodenetnum.c
@@ -1,3 +1,8 @@
+#include <unistd.h> /* for close() */
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
#include "config.h"
#include "ntp_stdlib.h"
@@ -13,6 +18,18 @@ TEST_TEAR_DOWN(decodenetnum) {}
#include "sockaddrtest.h"
+TEST(decodenetnum, Services) {
+ const char *str = "/etc/services";
+ int ret;
+
+ /* try to open /etc/services for read */
+ ret = open(str, O_RDONLY);
+ TEST_ASSERT_NOT_EQUAL(-1, ret);
+ if ( -1 != ret) {
+ close(ret);
+ }
+}
+
TEST(decodenetnum, IPv4AddressOnly) {
const char *str = "192.0.2.1";
int ret;
@@ -28,6 +45,7 @@ TEST(decodenetnum, IPv4AddressOnly) {
TEST_ASSERT_TRUE(IsEqualS(&expected, &actual));
}
+/* test with numeric port */
TEST(decodenetnum, IPv4AddressWithPort) {
const char *str = "192.0.2.2:2000";
sockaddr_u actual;
@@ -43,6 +61,22 @@ TEST(decodenetnum, IPv4AddressWithPort) {
TEST_ASSERT_TRUE(IsEqualS(&expected, &actual));
}
+/* test for named port */
+TEST(decodenetnum, IPv4AddressWithPort2) {
+ const char *str = "192.168.2.2:ntp";
+ sockaddr_u actual;
+ int ret;
+
+ sockaddr_u expected;
+ SET_AF(&expected, AF_INET);
+ PSOCK_ADDR4(&expected)->s_addr = inet_addr("192.168.2.2");
+ SET_PORT(&expected, 123);
+
+ ret = decodenetnum(str, &actual);
+ TEST_ASSERT_EQUAL_INT(0, ret);
+ TEST_ASSERT_TRUE(IsEqualS(&expected, &actual));
+}
+
TEST(decodenetnum, IPv6AddressOnly) {
int ret;
const struct in6_addr address = {{{
@@ -115,8 +149,10 @@ TEST(decodenetnum, IllegalCharInPort) {
}
TEST_GROUP_RUNNER(decodenetnum) {
+ RUN_TEST_CASE(decodenetnum, Services);
RUN_TEST_CASE(decodenetnum, IPv4AddressOnly);
RUN_TEST_CASE(decodenetnum, IPv4AddressWithPort);
+ RUN_TEST_CASE(decodenetnum, IPv4AddressWithPort2);
RUN_TEST_CASE(decodenetnum, IPv6AddressOnly);
RUN_TEST_CASE(decodenetnum, IPv6AddressWithPort);
RUN_TEST_CASE(decodenetnum, IllegalAddress);
=====================================
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/7593fdbe2d07a0972e98c5bebd2786bdb1c83d7d...ba0d0dba2f2d8549e9c17c928c8323b9400c321c
---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/7593fdbe2d07a0972e98c5bebd2786bdb1c83d7d...ba0d0dba2f2d8549e9c17c928c8323b9400c321c
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/92b90387/attachment.html>
More information about the vc
mailing list