test_rtt.c revision 06b2a236
1/* Copyright (c) 2017 - 2021 LiteSpeed Technologies Inc.  See LICENSE. */
2#include <assert.h>
3#include <stdio.h>
4#include <stdlib.h>
5#include <string.h>
6#ifndef WIN32
7#include <sys/time.h>
8#endif
9
10#include "lsquic_int_types.h"
11#include "lsquic_rtt.h"
12
13int
14main (void)
15{
16    struct lsquic_rtt_stats stats;
17    lsquic_time_t sent, received;
18
19#define RESET() memset(&stats, 0, sizeof(stats))
20#define TV(sec, usec) (sec * 1000000 + usec)
21
22    RESET();
23    sent = TV(2, 0), received = TV(3, 0);
24    lsquic_rtt_stats_update(&stats, received - sent, 0);
25    assert(("Initial RTT checks out",
26                            1000000 == lsquic_rtt_stats_get_srtt(&stats)));
27    sent = TV(2, 500000), received = TV(3, 0);
28    lsquic_rtt_stats_update(&stats, received - sent, 0);
29    assert(("Second RTT checks out",
30                            937500 == lsquic_rtt_stats_get_srtt(&stats)));
31
32    return 0;
33}
34