Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop a2c715065 -> 715394c2b


mn_socket; add test for v6 UDP multicast.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/715394c2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/715394c2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/715394c2

Branch: refs/heads/develop
Commit: 715394c2ba6ff154c48a89a5dde0add2b2866080
Parents: a2c7150
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Fri Sep 16 11:47:01 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Fri Sep 16 11:47:01 2016 -0700

----------------------------------------------------------------------
 sys/mn_socket/src/test/mn_sock_test.c | 109 +++++++++++++++++++++++++++++
 1 file changed, 109 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/715394c2/sys/mn_socket/src/test/mn_sock_test.c
----------------------------------------------------------------------
diff --git a/sys/mn_socket/src/test/mn_sock_test.c 
b/sys/mn_socket/src/test/mn_sock_test.c
index 1d68f7b..d4276a3 100644
--- a/sys/mn_socket/src/test/mn_sock_test.c
+++ b/sys/mn_socket/src/test/mn_sock_test.c
@@ -735,6 +735,114 @@ sock_udp_mcast_v4(void)
     mn_close(tx_sock);
 }
 
+static void
+sock_udp_mcast_v6(void)
+{
+    int loop_if_idx;
+    struct mn_socket *rx_sock;
+    struct mn_socket *tx_sock;
+    struct mn_sockaddr_in6 msin6;
+    union mn_socket_cb sock_cbs = {
+        .socket.readable = sum4_readable
+    };
+    struct os_mbuf *m;
+    char data[] = "1234567890";
+    int rc;
+    struct mn_mreq mreq;
+    uint8_t mcast_addr[16] = {
+        0xff, 2, 0, 0,
+        0, 0, 0, 0,
+        0, 0, 0, 0,
+        0, 0, 0, 2
+    };
+
+    loop_if_idx = sock_find_loopback_if();
+    TEST_ASSERT(loop_if_idx > 0);
+
+    msin6.msin6_family = MN_AF_INET6;
+    msin6.msin6_len = sizeof(msin6);
+    msin6.msin6_port = htons(44344);
+    memset(&msin6.msin6_addr, 0, sizeof(msin6.msin6_addr));
+
+    rc = mn_socket(&rx_sock, MN_PF_INET6, MN_SOCK_DGRAM, 0);
+    TEST_ASSERT(rc == 0);
+    mn_socket_set_cbs(rx_sock, NULL, &sock_cbs);
+
+    rc = mn_bind(rx_sock, (struct mn_sockaddr *)&msin6);
+    TEST_ASSERT(rc == 0);
+
+    rc = mn_socket(&tx_sock, MN_PF_INET6, MN_SOCK_DGRAM, 0);
+    TEST_ASSERT(rc == 0);
+
+    rc = mn_setsockopt(tx_sock, MN_SO_LEVEL, MN_MCAST_IF, &loop_if_idx);
+    TEST_ASSERT(rc == 0);
+
+    m = os_msys_get(sizeof(data), 0);
+    rc = os_mbuf_copyinto(m, 0, data, sizeof(data));
+    TEST_ASSERT(rc == 0);
+
+    /*
+     * multicast tgt
+     */
+    memcpy(&msin6.msin6_addr, mcast_addr, sizeof(mcast_addr));
+
+    rc = mn_sendto(tx_sock, (struct os_mbuf *)m, (struct mn_sockaddr *)&msin6);
+    TEST_ASSERT(rc == 0);
+
+    /*
+     * RX socket has not joined group yet.
+     */
+    rc = os_sem_pend(&test_sem, OS_TICKS_PER_SEC / 2);
+    TEST_ASSERT(rc == OS_TIMEOUT);
+
+    mreq.mm_idx = loop_if_idx;
+    mreq.mm_family = MN_AF_INET6;
+    memcpy(&mreq.mm_addr.v6.s_addr, msin6.msin6_addr.s_addr,
+      sizeof(msin6.msin6_addr.s_addr));
+
+    /*
+     * Now join it.
+     */
+    rc = mn_setsockopt(rx_sock, MN_SO_LEVEL, MN_MCAST_JOIN_GROUP, &mreq);
+    TEST_ASSERT(rc == 0);
+
+    m = os_msys_get(sizeof(data), 0);
+    rc = os_mbuf_copyinto(m, 0, data, sizeof(data));
+    TEST_ASSERT(rc == 0);
+
+    rc = mn_sendto(tx_sock, (struct os_mbuf *)m, (struct mn_sockaddr *)&msin6);
+    TEST_ASSERT(rc == 0);
+
+    rc = os_sem_pend(&test_sem, OS_TICKS_PER_SEC);
+    TEST_ASSERT(rc == 0);
+
+    rc = mn_recvfrom(rx_sock, &m, NULL);
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(m != NULL);
+    TEST_ASSERT(!memcmp(m->om_data, data, sizeof(data)));
+    os_mbuf_free_chain(m);
+
+    /*
+     * Then leave
+     */
+    rc = mn_setsockopt(rx_sock, MN_SO_LEVEL, MN_MCAST_LEAVE_GROUP, &mreq);
+    TEST_ASSERT(rc == 0);
+
+    m = os_msys_get(sizeof(data), 0);
+    TEST_ASSERT(m);
+    rc = os_mbuf_copyinto(m, 0, data, sizeof(data));
+    TEST_ASSERT(rc == 0);
+
+    rc = mn_sendto(tx_sock, (struct os_mbuf *)m, (struct mn_sockaddr *)&msin6);
+    TEST_ASSERT(rc == 0);
+
+    rc = os_sem_pend(&test_sem, OS_TICKS_PER_SEC);
+    TEST_ASSERT(rc == OS_TIMEOUT);
+
+    mn_close(rx_sock);
+    mn_close(tx_sock);
+}
+
 void
 mn_socket_test_handler(void *arg)
 {
@@ -746,6 +854,7 @@ mn_socket_test_handler(void *arg)
     sock_itf_list();
     sock_udp_ll();
     sock_udp_mcast_v4();
+    sock_udp_mcast_v6();
     os_test_restart();
 }
 

Reply via email to