Skip to content

Commit

Permalink
tests: Initial import of congure_quic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
miri64 committed Feb 26, 2021
1 parent 31ee9fe commit 485b887
Show file tree
Hide file tree
Showing 7 changed files with 1,244 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/congure_quic/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
include ../Makefile.tests_common

USEMODULE += congure_quic
USEMODULE += congure_test
USEMODULE += fmt
USEMODULE += shell
USEMODULE += shell_commands
USEMODULE += ztimer_msec ztimer_usec

INCLUDES += -I$(CURDIR)

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_quic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Tests for the CongURE QUIC implementation
=========================================

This test tests the `congure_quic` 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_quic/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
82 changes: 82 additions & 0 deletions tests/congure_quic/congure_impl.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* 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 <m.lenders@fu-berlin.de>
*/

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

#include "congure_impl.h"

static unsigned _event_cb_calls;
static void *_event_cb_arg;

static void _event_cb(void *);

static const congure_quic_snd_consts_t _consts[] = {
{
.cong_event_cb = NULL,
.init_wnd = 12000,
.min_wnd = 2400,
.init_rtt = 333,
.max_msg_size = 1200,
.pc_thresh = 3000,
.granularity = 1,
.loss_reduction_numerator = 1,
.loss_reduction_denominator = 2,
.inter_msg_interval_numerator = 5,
.inter_msg_interval_denominator = 4,
},
{
.cong_event_cb = _event_cb,
.init_wnd = 12000,
.min_wnd = 2400,
.init_rtt = 333,
.max_msg_size = 1200,
.pc_thresh = 3000,
.granularity = 1,
.loss_reduction_numerator = 1,
.loss_reduction_denominator = 2,
.inter_msg_interval_numerator = 5,
.inter_msg_interval_denominator = 4,
},
};

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

unsigned congure_quic_test_get_event_cb_calls(void)
{
return _event_cb_calls;
}

void *congure_quic_test_get_event_cb_arg(void)
{
return _event_cb_arg;
}

static void _event_cb(void *ctx)
{
_event_cb_calls++;
_event_cb_arg = ctx;
}

/** @} */
36 changes: 36 additions & 0 deletions tests/congure_quic/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 <m.lenders@fu-berlin.de>
*/
#ifndef CONGURE_IMPL_H
#define CONGURE_IMPL_H

#include "congure/quic.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef congure_quic_snd_t congure_test_snd_t;

int congure_test_snd_setup(congure_test_snd_t *c, unsigned id);
unsigned congure_quic_test_get_event_cb_calls(void);
void *congure_quic_test_get_event_cb_arg(void);

#ifdef __cplusplus
}
#endif

#endif /* CONGURE_IMPL_H */
/** @} */
218 changes: 218 additions & 0 deletions tests/congure_quic/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
/*
* 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 <m.lenders@fu-berlin.de>
*/

#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"

static int _json_statham(int argc, char **argv);
static int _set_cwnd(int argc, char **argv);
static int _set_ssthresh(int argc, char **argv);
static int _set_limited(int argc, char **argv);
static int _set_max_ack_delay(int argc, char **argv);
static int _set_recovery_start(int argc, char **argv);
static int _get_event_cb(int argc, char **argv);

static congure_quic_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_ssthresh", "Set ssthresh member for CongURE state object",
_set_ssthresh },
{ "set_limited", "Set limited member for CongURE state object",
_set_limited },
{ "set_max_ack_delay", "Set max_ack_delay member for CongURE state object",
_set_max_ack_delay },
{ "set_recovery_start", "Set recovery_start member for CongURE state object",
_set_recovery_start },
{ "get_event_cb",
"Get state of cong_event_cb mock of CongURE state object",
_get_event_cb },
{ NULL, NULL, NULL }
};

int main(void)
{
char line_buf[SHELL_DEFAULT_BUFSIZE];
shell_run(shell_commands, line_buf, SHELL_DEFAULT_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(",")

#define PRINT_FIELD_BOOL(obj, field) \
print_str("\"" #field "\":"); \
print_str(((obj).field) ? "true" : "false"); \
print_str(",")

static void _print_congure_quic_consts(const congure_quic_snd_consts_t *consts)
{
print_str("\"consts\":");

if (consts) {
print_str("{");
PRINT_FIELD_PTR(*consts, cong_event_cb);
PRINT_FIELD_UINT(*consts, init_wnd);
PRINT_FIELD_UINT(*consts, min_wnd);
PRINT_FIELD_UINT(*consts, init_rtt);
PRINT_FIELD_UINT(*consts, max_msg_size);
PRINT_FIELD_UINT(*consts, pc_thresh);
PRINT_FIELD_UINT(*consts, granularity);
PRINT_FIELD_UINT(*consts, loss_reduction_numerator);
PRINT_FIELD_UINT(*consts, loss_reduction_denominator);
PRINT_FIELD_UINT(*consts, inter_msg_interval_numerator);
PRINT_FIELD_UINT(*consts, inter_msg_interval_denominator);
print_str("},");
}
else {
print_str("null,");
}
}

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

PRINT_FIELD_PTR(_congure_state.super, ctx);
PRINT_FIELD_UINT(_congure_state.super, cwnd);
_print_congure_quic_consts(_congure_state.consts);
PRINT_FIELD_UINT(_congure_state, first_rtt_sample);
PRINT_FIELD_UINT(_congure_state, in_flight_size);
PRINT_FIELD_UINT(_congure_state, recovery_start);
PRINT_FIELD_UINT(_congure_state, ssthresh);
PRINT_FIELD_UINT(_congure_state, smoothed_rtt);
PRINT_FIELD_UINT(_congure_state, rtt_var);
PRINT_FIELD_UINT(_congure_state, min_rtt);
PRINT_FIELD_BOOL(_congure_state, limited);
PRINT_FIELD_UINT(_congure_state, max_ack_delay);

print_str("}\n");
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\":\"`ssthresh` 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 _set_limited(int argc, char **argv)
{
uint32_t tmp;

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

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

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

static int _set_recovery_start(int argc, char **argv)
{
if (argc < 2) {
print_str("{\"error\":\"`recovery_start` argument expected\"}");
return 1;
}
_congure_state.recovery_start = scn_u32_dec(argv[1], strlen(argv[1]));
return 0;
}

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

print_str("{\"event_cb\":");
print_str("{\"calls\":");
print_u32_dec(congure_quic_test_get_event_cb_calls());
print_str(",");
print_str("\"last_args\":{\"ctx\":\"0x");
print_u32_hex((intptr_t)congure_quic_test_get_event_cb_arg());
print_str("\"}");
print_str("}");
print_str("}\n");
return 0;
}

/** @} */
Loading

0 comments on commit 485b887

Please sign in to comment.