Changeset 3e2291a9 in mainline for uspace/srv/net/tcp/test/conn.c


Ignore:
Timestamp:
2017-09-17T23:37:43Z (7 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
797dc79e
Parents:
6969eea3
Message:

TCP tests for ucall module and some more for conn module. Implement tcp_uc_abort(). Fix tcp_uc_open() leaking connection of connecting failed. Fix missing transition Closing → Time-Wait. Fix wrong SEG.ACK in response to FIN.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/tcp/test/conn.c

    r6969eea3 r3e2291a9  
    5757        tcp_rqueue_init(&test_rqueue_cb);
    5858        tcp_rqueue_fibril_start();
     59
     60        /* Enable internal loopback */
     61        tcp_conn_lb = tcp_lb_segment;
    5962}
    6063
     
    118121        int rc;
    119122
    120         tcp_conn_lb = tcp_lb_segment;
    121 
    122123        inet_ep2_init(&epp);
    123124        inet_addr(&epp.local.addr, 127, 0, 0, 1);
     
    146147}
    147148
     149/** Test establishing a connection */
     150PCUT_TEST(conn_establish)
     151{
     152        tcp_conn_t *cconn, *sconn;
     153        inet_ep2_t cepp, sepp;
     154        int rc;
     155
     156        /* Client EPP */
     157        inet_ep2_init(&cepp);
     158        inet_addr(&cepp.local.addr, 127, 0, 0, 1);
     159        inet_addr(&cepp.remote.addr, 127, 0, 0, 1);
     160        cepp.remote.port = inet_port_user_lo;
     161
     162        /* Server EPP */
     163        inet_ep2_init(&sepp);
     164        inet_addr(&sepp.local.addr, 127, 0, 0, 1);
     165        sepp.local.port = inet_port_user_lo;
     166
     167        /* Client side of the connection */
     168        cconn = tcp_conn_new(&cepp);
     169        PCUT_ASSERT_NOT_NULL(cconn);
     170
     171        rc = tcp_conn_add(cconn);
     172        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     173
     174        PCUT_ASSERT_INT_EQUALS(st_listen, cconn->cstate);
     175        PCUT_ASSERT_FALSE(tcp_conn_got_syn(cconn));
     176
     177        /* Server side of the connection */
     178        sconn = tcp_conn_new(&sepp);
     179        PCUT_ASSERT_NOT_NULL(sconn);
     180
     181        rc = tcp_conn_add(sconn);
     182        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     183
     184        PCUT_ASSERT_INT_EQUALS(st_listen, sconn->cstate);
     185        PCUT_ASSERT_FALSE(tcp_conn_got_syn(sconn));
     186
     187        /* Start establishing the connection */
     188
     189        tcp_conn_lock(cconn);
     190        tcp_conn_sync(cconn);
     191        PCUT_ASSERT_INT_EQUALS(st_syn_sent, cconn->cstate);
     192        PCUT_ASSERT_FALSE(tcp_conn_got_syn(cconn));
     193
     194        /* Wait for client-side state to transition */
     195        while (cconn->cstate == st_syn_sent)
     196                fibril_condvar_wait(&cconn->cstate_cv, &cconn->lock);
     197
     198        PCUT_ASSERT_INT_EQUALS(st_established, cconn->cstate);
     199        PCUT_ASSERT_TRUE(tcp_conn_got_syn(cconn));
     200        tcp_conn_unlock(cconn);
     201
     202        /* Wait for server-side state to transition */
     203        tcp_conn_lock(sconn);
     204        while (sconn->cstate == st_listen || sconn->cstate == st_syn_received)
     205                fibril_condvar_wait(&sconn->cstate_cv, &sconn->lock);
     206
     207        PCUT_ASSERT_INT_EQUALS(st_established, sconn->cstate);
     208        PCUT_ASSERT_TRUE(tcp_conn_got_syn(sconn));
     209
     210        /* Verify counters */
     211        PCUT_ASSERT_EQUALS(cconn->iss + 1, cconn->snd_nxt);
     212        PCUT_ASSERT_EQUALS(cconn->iss + 1, cconn->snd_una);
     213        PCUT_ASSERT_EQUALS(sconn->iss + 1, sconn->snd_nxt);
     214        PCUT_ASSERT_EQUALS(sconn->iss + 1, sconn->snd_una);
     215
     216        tcp_conn_unlock(sconn);
     217
     218        tcp_conn_lock(cconn);
     219        tcp_conn_reset(cconn);
     220        tcp_conn_unlock(cconn);
     221        tcp_conn_delete(cconn);
     222
     223        tcp_conn_lock(sconn);
     224        tcp_conn_reset(sconn);
     225        tcp_conn_unlock(sconn);
     226        tcp_conn_delete(sconn);
     227}
     228
     229PCUT_TEST(ep2_flipped)
     230{
     231        inet_ep2_t a, fa;
     232
     233        inet_addr(&a.local.addr, 1, 2, 3, 4);
     234        a.local.port = 1234;
     235        inet_addr(&a.remote.addr, 5, 6, 7, 8);
     236        a.remote.port = 5678;
     237
     238        tcp_ep2_flipped(&a, &fa);
     239
     240        PCUT_ASSERT_INT_EQUALS(a.local.port, fa.remote.port);
     241        PCUT_ASSERT_INT_EQUALS(a.remote.port, fa.local.port);
     242
     243        PCUT_ASSERT_TRUE(inet_addr_compare(&a.local.addr, &fa.remote.addr));
     244        PCUT_ASSERT_TRUE(inet_addr_compare(&a.remote.addr, &fa.local.addr));
     245}
     246
    148247PCUT_EXPORT(conn);
Note: See TracChangeset for help on using the changeset viewer.