HelenOS sources
This source file includes following definitions.
- test_seg_received
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
#include <adt/prodcons.h>
#include <inet/endpoint.h>
#include <io/log.h>
#include <pcut/pcut.h>
#include "../rqueue.h"
#include "../segment.h"
PCUT_INIT;
PCUT_TEST_SUITE(rqueue);
enum {
test_seg_max = 10
};
static void test_seg_received(inet_ep2_t *, tcp_segment_t *);
static tcp_rqueue_cb_t rcb = {
.seg_received = test_seg_received
};
static int seg_cnt;
static tcp_segment_t *recv_seg[test_seg_max];
static void test_seg_received(inet_ep2_t *epp, tcp_segment_t *seg)
{
recv_seg[seg_cnt++] = seg;
}
PCUT_TEST_BEFORE
{
errno_t rc;
rc = log_init("test-tcp");
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
}
PCUT_TEST(init_fini)
{
tcp_rqueue_init(&rcb);
tcp_rqueue_fibril_start();
tcp_rqueue_fini();
}
PCUT_TEST(one_segment)
{
tcp_segment_t *seg;
inet_ep2_t epp;
tcp_rqueue_init(&rcb);
seg_cnt = 0;
seg = tcp_segment_make_ctrl(CTL_SYN);
PCUT_ASSERT_NOT_NULL(seg);
inet_ep2_init(&epp);
tcp_rqueue_insert_seg(&epp, seg);
tcp_rqueue_fibril_start();
tcp_rqueue_fini();
PCUT_ASSERT_INT_EQUALS(1, seg_cnt);
PCUT_ASSERT_EQUALS(seg, recv_seg[0]);
tcp_segment_delete(seg);
}
PCUT_TEST(multiple_segments)
{
tcp_segment_t *seg[test_seg_max];
inet_ep2_t epp;
int i;
tcp_rqueue_init(&rcb);
seg_cnt = 0;
inet_ep2_init(&epp);
tcp_rqueue_fibril_start();
for (i = 0; i < test_seg_max; i++) {
seg[i] = tcp_segment_make_ctrl(CTL_ACK);
PCUT_ASSERT_NOT_NULL(seg[i]);
tcp_rqueue_insert_seg(&epp, seg[i]);
}
tcp_rqueue_fini();
PCUT_ASSERT_INT_EQUALS(test_seg_max, seg_cnt);
for (i = 0; i < test_seg_max; i++) {
PCUT_ASSERT_EQUALS(seg[i], recv_seg[i]);
tcp_segment_delete(seg[i]);
}
}
PCUT_EXPORT(rqueue);
HelenOS homepage, sources at GitHub