]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Add test for socktoa(), sockporttoa() with scoped address.
authorDave Hart <hart@ntp.org>
Sun, 12 Dec 2010 08:30:28 +0000 (08:30 +0000)
committerDave Hart <hart@ntp.org>
Sun, 12 Dec 2010 08:30:28 +0000 (08:30 +0000)
Correct unit tests for sntp offset_calculation() arg change.

bk: 4d048824jcvkNGaNeqf0qvlEPvBKDw

ntpd/ntp_control.c
ntpd/ntpsim.c
sntp/tests/packetHandling.cpp
sntp/tests/utilities.cpp
tests/libntp/socktoa.cpp

index f032809c49d577f1695c66ac8b58d481be580424..9b3394e8fb3a359cedb8104e1ad66a47871fd45d 100644 (file)
@@ -579,8 +579,6 @@ ctl_error(
         * send packet and bump counters
         */
        if (res_authenticate && sys_authenticate) {
-               int maclen;
-
                maclen = authencrypt(res_keyid, (u_int32 *)&rpkt,
                                     CTL_HEADER_LEN);
                sendpkt(rmt_addr, lcl_inter, -2, (void *)&rpkt,
index d15b2f75659bcc8768d44ad5d05341a95a38b9fe..9ef3bf69b48fac3fae4e777b6b63891c01d8ad5c 100644 (file)
@@ -70,24 +70,26 @@ determine_recv_buf_ordering(
 /* Define a function to create the server associations */
 void create_server_associations(void)
 {
-    int i;
-    for (i = 0;i < simulation.num_of_servers;++i) {
-       printf("%s\n", stoa(simulation.servers[i].addr));
-       if (peer_config(simulation.servers[i].addr,
-                       NULL,
-                       ANY_INTERFACE_CHOOSE(simulation.servers[i].addr),
-                       MODE_CLIENT,
-                       NTP_VERSION,
-                       NTP_MINDPOLL,
-                       NTP_MAXDPOLL,
-                       0, /* peerflags */
-                       0, /* ttl */
-                       0, /* peerkey */
-                       (u_char *)"*" /* peerkeystr */) == 0) {
-           fprintf(stderr, "ERROR!! Could not create association for: %s",
-                   stoa(simulation.servers[i].addr));
+       int i;
+
+       for (i = 0; i < simulation.num_of_servers; ++i) {
+               printf("%s\n", stoa(simulation.servers[i].addr));
+               if (peer_config(simulation.servers[i].addr,
+                               NULL,
+                               ANY_INTERFACE_CHOOSE(simulation.servers[i].addr),
+                               MODE_CLIENT,
+                               NTP_VERSION,
+                               NTP_MINDPOLL,
+                               NTP_MAXDPOLL,
+                               0, /* peerflags */
+                               0, /* ttl */
+                               0, /* peerkey */
+                               NULL /* group ident */) == 0) {
+                       fprintf(stderr,
+                               "ERROR!! Could not create association for: %s",
+                               stoa(simulation.servers[i].addr));
+               }
        }
-    }
 }
 
 
index c24f624232841dc52f76b78d9b792884945a97c1..74b861da7f56f812f049c1659685c7c38b75f703 100644 (file)
@@ -111,11 +111,12 @@ TEST_F(mainTest, OffsetCalculationPositiveOffset) {
        tmp.l_uf = 0UL;
        HTONL_FP(&tmp, &rpkt.xmt);
 
-       // T4 - Destination timestamp
+       // T4 - Destination timestamp as standard timeval
        tmp.l_ui = 1000000001UL;
        tmp.l_uf = 0UL;
        timeval dst;
        TSTOTV(&tmp, &dst);
+       dst.tv_sec -= JAN_1970;
 
        double offset, precision, root_disp;
        offset_calculation(&rpkt, LEN_PKT_NOMAC, &dst, &offset, &precision, &root_disp);
@@ -152,11 +153,12 @@ TEST_F(mainTest, OffsetCalculationNegativeOffset) {
        tmp.l_uf = 2147483648UL;
        HTONL_FP(&tmp, &rpkt.xmt);
 
-       // T4 - Destination timestamp
+       // T4 - Destination timestamp as standard timeval
        tmp.l_ui = 1000000003UL;
        tmp.l_uf = 0UL;
        timeval dst;
        TSTOTV(&tmp, &dst);
+       dst.tv_sec -= JAN_1970;
 
        double offset, precision, root_disp;
        offset_calculation(&rpkt, LEN_PKT_NOMAC, &dst, &offset, &precision, &root_disp);
index 1142971e7cb3c40fec2e785848acb745004a22c6..bd4c58b20407ecb2a8a73acb4bd8ff1c31e2a8ff 100644 (file)
@@ -85,6 +85,7 @@ TEST_F(utilitiesTest, IPv6Address) {
        sockaddr_u      input;
        addrinfo        inputA;
 
+       memset(&input, 0, sizeof(input));
        input.sa6.sin6_family = AF_INET6;
        input.sa6.sin6_addr = address;
        EXPECT_STREQ(expected, ss_to_str(&input));
@@ -96,8 +97,8 @@ TEST_F(utilitiesTest, IPv6Address) {
 TEST_F(utilitiesTest, SetLiVnMode1) {
        pkt expected;
        expected.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOWARNING,
-                                                                                NTP_VERSION,
-                                                                                MODE_SERVER);
+                                            NTP_VERSION,
+                                            MODE_SERVER);
 
        pkt actual;
        set_li_vn_mode(&actual, LEAP_NOWARNING, NTP_VERSION,
index 2b6827e80d209586012c27cf427619c3386009d3..6c70b6d8ddc1ad32ca16de84bbcfcf4b2feee85d 100644 (file)
@@ -13,9 +13,9 @@ TEST_F(socktoaTest, IPv4AddressWithPort) {
 TEST_F(socktoaTest, IPv6AddressWithPort) {
        const struct in6_addr address = {
                0x20, 0x01, 0x0d, 0xb8,
-        0x85, 0xa3, 0x08, 0xd3, 
-        0x13, 0x19, 0x8a, 0x2e,
-        0x03, 0x70, 0x73, 0x34
+               0x85, 0xa3, 0x08, 0xd3, 
+               0x13, 0x19, 0x8a, 0x2e,
+               0x03, 0x70, 0x73, 0x34
        };
 
        const char* expected =
@@ -24,13 +24,40 @@ TEST_F(socktoaTest, IPv6AddressWithPort) {
                "[2001:db8:85a3:8d3:1319:8a2e:370:7334]:123";
 
        sockaddr_u input;
-       input.sa6.sin6_family = AF_INET6;
-       input.sa6.sin6_addr = address;
+       memset(&input, 0, sizeof(input));
+       AF(&input) = AF_INET6;
+       SET_ADDR6N(&input, address);
+       SET_PORT(&input, 123);
+
+       EXPECT_STREQ(expected, socktoa(&input));
+       EXPECT_STREQ(expected_port, sockporttoa(&input));
+}
+
+#ifdef ISC_PLATFORM_HAVESCOPEID
+TEST_F(socktoaTest, ScopedIPv6AddressWithPort) {
+       const struct in6_addr address = {
+               0xfe, 0x80, 0x00, 0x00,
+               0x00, 0x00, 0x00, 0x00,
+               0x02, 0x12, 0x3f, 0xff, 
+               0xfe, 0x29, 0xff, 0xfa
+       };
+
+       const char* expected =
+               "fe80::212:3fff:fe29:fffa%5";
+       const char* expected_port = 
+               "[fe80::212:3fff:fe29:fffa%5]:123";
+
+       sockaddr_u input;
+       memset(&input, 0, sizeof(input));
+       AF(&input) = AF_INET6;
+       SET_ADDR6N(&input, address);
        SET_PORT(&input, 123);
+       SCOPE_VAR(&input) = 5;
 
        EXPECT_STREQ(expected, socktoa(&input));
        EXPECT_STREQ(expected_port, sockporttoa(&input));
 }
+#endif /* ISC_PLATFORM_HAVESCOPEID */
 
 TEST_F(socktoaTest, HashEqual) {
        sockaddr_u input1 = CreateSockaddr4("192.00.2.2", 123);