Skip to content

Commit

Permalink
tests: Initial import of congure_reno tests
Browse files Browse the repository at this point in the history
  • Loading branch information
miri64 committed Apr 8, 2022
1 parent 0f16743 commit 56cf940
Show file tree
Hide file tree
Showing 7 changed files with 1,218 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/congure_reno/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
include ../Makefile.tests_common

USEMODULE += congure_reno
USEMODULE += congure_test
USEMODULE += fmt
USEMODULE += shell
USEMODULE += shell_commands

INCLUDES += -I$(CURDIR)

# Use a terminal that does not introduce extra characters into the stream.
RIOT_TERMINAL ?= socat

CFLAGS += -DSTDIO_UART_RX_BUFSIZE=512 # Adapt to SHELL_BUFSIZE in app

include $(RIOTBASE)/Makefile.include

ifndef CONFIG_SHELL_NO_ECHO
CFLAGS += -DCONFIG_SHELL_NO_ECHO=1
endif

ifndef CONFIG_CONGURE_TEST_LOST_MSG_POOL_SIZE
CFLAGS += -DCONFIG_CONGURE_TEST_LOST_MSG_POOL_SIZE=6
endif
30 changes: 30 additions & 0 deletions tests/congure_reno/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Tests for the CongURE TCP Reno implementation
=============================================

This test tests the `congure_reno` implementation.

Usage
-----

The test requires an up-to-date version of `riotctrl` with `rapidjson` support:

```console
$ pip install --upgrade riotctrl[rapidjson]
```

Then simply run the application using:

```console
$ BOARD="<board>" make flash test
```

It can also executed with pytest:

```console
$ pytest tests/01-run.py
```

Expected result
---------------

The application's test script passes without error code.
4 changes: 4 additions & 0 deletions tests/congure_reno/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CONFIG_KCONFIG_USEMODULE_CONGURE_TEST=y
CONFIG_KCONFIG_USEMODULE_SHELL=y
CONFIG_CONGURE_TEST_LOST_MSG_POOL_SIZE=6
CONFIG_SHELL_NO_ECHO=y
102 changes: 102 additions & 0 deletions tests/congure_reno/congure_impl.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* Copyright (C) 2021 Freie Universität Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @{
*
* @file
* @author Martine Lenders <[email protected]>
*/

#include <stdbool.h>
#include "kernel_defines.h"

#include "congure_impl.h"

static unsigned _fr_calls;
static bool _same_wnd_adv_res;

static void _fr(congure_reno_snd_t *c);
static bool _same_wnd_adv(congure_reno_snd_t *c, congure_snd_ack_t *ack);
static void _ss_cwnd_inc(congure_reno_snd_t *c);
static void _ca_cwnd_inc(congure_reno_snd_t *c);
static void _fr_cwnd_dec(congure_reno_snd_t *c);

static const congure_reno_snd_consts_t _consts[] = {
{
.fr = _fr,
.same_wnd_adv = _same_wnd_adv,
.init_mss = 1460,
.cwnd_lower = 1095,
.cwnd_upper = 2190,
.init_ssthresh = CONGURE_WND_SIZE_MAX,
.frthresh = 3,
},
{
.fr = _fr,
.same_wnd_adv = _same_wnd_adv,
.ss_cwnd_inc = _ss_cwnd_inc,
.ca_cwnd_inc = _ca_cwnd_inc,
.fr_cwnd_dec = _fr_cwnd_dec,
.init_mss = 1460,
.cwnd_lower = 1095,
.cwnd_upper = 2190,
.init_ssthresh = CONGURE_WND_SIZE_MAX,
.frthresh = 3,
},
};

int congure_test_snd_setup(congure_test_snd_t *c, unsigned id)
{
if (id >= ARRAY_SIZE(_consts)) {
return -1;
}
_fr_calls = 0;
congure_reno_snd_setup(c, &_consts[id]);
return 0;
}

unsigned congure_reno_test_get_fr_calls(void)
{
return _fr_calls;
}

void congure_reno_test_set_same_wnd_adv_res(bool value)
{
_same_wnd_adv_res = value;
}

static void _fr(congure_reno_snd_t *c)
{
(void)c;
_fr_calls++;
}

static bool _same_wnd_adv(congure_reno_snd_t *c, congure_snd_ack_t *ack)
{
(void)c;
(void)ack;
return _same_wnd_adv_res;
}

static void _ss_cwnd_inc(congure_reno_snd_t *c)
{
c->super.cwnd += 1337;
}

static void _ca_cwnd_inc(congure_reno_snd_t *c)
{
c->super.cwnd += 42;
}

static void _fr_cwnd_dec(congure_reno_snd_t *c)
{
c->super.cwnd /= 8;
}

/** @} */
36 changes: 36 additions & 0 deletions tests/congure_reno/congure_impl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (C) 2021 Freie Universität Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @{
*
* @file
*
* @author Martine Lenders <[email protected]>
*/
#ifndef CONGURE_IMPL_H
#define CONGURE_IMPL_H

#include "congure/reno.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef congure_reno_snd_t congure_test_snd_t;

int congure_test_snd_setup(congure_test_snd_t *c, unsigned id);
unsigned congure_reno_test_get_fr_calls(void);
void congure_reno_test_set_same_wnd_adv_res(bool value);

#ifdef __cplusplus
}
#endif

#endif /* CONGURE_IMPL_H */
/** @} */
187 changes: 187 additions & 0 deletions tests/congure_reno/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
/*
* Copyright (C) 2021 Freie Universität Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @{
*
* @file
* @author Martine S. Lenders <[email protected]>
*/

#include <assert.h>
#include <stdlib.h>
#include <string.h>

#include "clist.h"
#include "congure/test.h"
#include "fmt.h"
#include "shell.h"

#include "congure_impl.h"

#define SHELL_BUFSIZE 512U

static char _line_buf[SHELL_BUFSIZE];

static int _json_statham(int argc, char **argv);
static int _set_mss(int argc, char **argv);
static int _set_cwnd(int argc, char **argv);
static int _set_ssthresh(int argc, char **argv);
static int _get_fr_calls(int argc, char **argv);
static int _set_same_wnd_adv_res(int argc, char **argv);

static congure_reno_snd_t _congure_state;
static const shell_command_t shell_commands[] = {
{ "state", "Prints current CongURE state object as JSON", _json_statham },
{ "set_cwnd", "Set cwnd member for CongURE state object", _set_cwnd },
{ "set_mss", "Set new MSS for CongURE state object", _set_mss },
{ "set_ssthresh", "Set ssthresh member for CongURE state object",
_set_ssthresh },
{ "get_ff_calls",
"Get the number of calls to fast_retransmit callback of CongURE state "
"object", _get_fr_calls },
{ "set_same_wnd_adv",
"Set the result for the same_window_advertised callback of CongURE state "
"object", _set_same_wnd_adv_res },
{ NULL, NULL, NULL }
};

int main(void)
{
shell_run(shell_commands, _line_buf, SHELL_BUFSIZE);
return 0;
}

congure_test_snd_t *congure_test_get_state(void)
{
return &_congure_state;
}

#define PRINT_FIELD_PTR(obj_ptr, field) \
print_str("\"" #field "\":\"0x"); \
print_u32_hex((intptr_t)((obj_ptr)->field)); \
print_str("\",")

#define PRINT_FIELD_UINT(obj, field) \
print_str("\"" #field "\":"); \
print_u32_dec((obj).field); \
print_str(",")

static void _print_congure_reno_consts(const congure_reno_snd_consts_t *consts)
{
print_str("\"consts\":");

if (consts) {
print_str("{");
PRINT_FIELD_PTR(consts, fr);
PRINT_FIELD_PTR(consts, same_wnd_adv);
PRINT_FIELD_PTR(consts, ss_cwnd_inc);
PRINT_FIELD_PTR(consts, ca_cwnd_inc);
PRINT_FIELD_PTR(consts, fr_cwnd_dec);
PRINT_FIELD_UINT(*consts, init_mss);
PRINT_FIELD_UINT(*consts, cwnd_upper);
PRINT_FIELD_UINT(*consts, cwnd_lower);
PRINT_FIELD_UINT(*consts, init_ssthresh);
PRINT_FIELD_UINT(*consts, frthresh);
print_str("},");
}
else {
print_str("null,");
}
}

static int _json_statham(int argc, char **argv)
{
(void)argc;
(void)argv;
print_str("{");

PRINT_FIELD_UINT(_congure_state.super, cwnd);
_print_congure_reno_consts(_congure_state.consts);
PRINT_FIELD_UINT(_congure_state, mss);
PRINT_FIELD_UINT(_congure_state, last_ack);
PRINT_FIELD_UINT(_congure_state, ssthresh);
PRINT_FIELD_UINT(_congure_state, in_flight_size);
PRINT_FIELD_UINT(_congure_state, dup_acks);

print_str("}\n");
return 0;
}

static int _set_mss(int argc, char **argv)
{
uint32_t tmp;

if (argc < 2) {
print_str("{\"error\":\"`mss` argument expected\"}");
return 1;
}
tmp = scn_u32_dec(argv[1], strlen(argv[1]));
if (tmp > CONGURE_WND_SIZE_MAX) {
print_str("{\"error\":\"`mss` not 16 bit wide\"}\n");
}
congure_reno_set_mss(&_congure_state, (congure_wnd_size_t)tmp);
return 0;
}

static int _set_cwnd(int argc, char **argv)
{
uint32_t tmp;

if (argc < 2) {
print_str("{\"error\":\"`cwnd` argument expected\"}");
return 1;
}
tmp = scn_u32_dec(argv[1], strlen(argv[1]));
if (tmp > CONGURE_WND_SIZE_MAX) {
print_str("{\"error\":\"`cwnd` not 16 bit wide\"}\n");
}
_congure_state.super.cwnd = (congure_wnd_size_t)tmp;
return 0;
}

static int _set_ssthresh(int argc, char **argv)
{
uint32_t tmp;

if (argc < 2) {
print_str("{\"error\":\"`ssthresh` argument expected\"}");
return 1;
}
tmp = scn_u32_dec(argv[1], strlen(argv[1]));
if (tmp > CONGURE_WND_SIZE_MAX) {
print_str("{\"error\":\"`ssthresh` not 16 bit wide\"}\n");
}
_congure_state.ssthresh = (congure_wnd_size_t)tmp;
return 0;
}

static int _get_fr_calls(int argc, char **argv)
{
(void)argc;
(void)argv;

print_str("{\"fr_calls\":");
print_u32_dec(congure_reno_test_get_fr_calls());
print_str("}\n");
return 0;
}

static int _set_same_wnd_adv_res(int argc, char **argv)
{
if (argc < 2) {
print_str("{\"error\":\"`value` argument expected\"}");
return 1;
}
congure_reno_test_set_same_wnd_adv_res(
(bool)scn_u32_dec(argv[1], strlen(argv[1]))
);
return 0;
}

/** @} */
Loading

0 comments on commit 56cf940

Please sign in to comment.