skip to content
==> tests/net_counters.c <==
1/* net.rs's counters_fill_the_block, one for one. */
2#include "mesh/abi/host_net.h"
3#include "mesh/abi/peer_frames.h"
4#include "mesh/abi/snapshot.h"
5#include "mesh/check.h"
6#include "mesh/net_counters.h"
7
8#include <stdlib.h>
9
10static uint64_t u(const uint8_t *b, size_t o) {
11    uint64_t v = 0;
12    for (int i = 7; i >= 0; i--) v = v << 8 | b[o + (size_t)i];
13    return v;
14}
15
16int main(void) {
17    static mesh_net_counters c;
18    mesh_net_counters_init(&c);
19    uint8_t round[4] = {MESH_F_ROUND, 0, 0, 0}, beat[1] = {MESH_F_BEAT};
20    mesh_net_counters_tx(&c, 2, round, 4);
21    mesh_net_counters_tx(&c, 2, beat, 1);
22    mesh_net_counters_rx(&c, 2, MESH_F_FRAME, 100);
23    mesh_net_counters_rx(&c, 1, MESH_F_STATE, 7);
24    mesh_net_counters_ctl(&c, 5, 1000);
25    mesh_net_counters_http(&c, 30, 400);
26    uint8_t *b = calloc(1, MESH_SNAP_HOST);
27    mesh_net_counters_fill(&c, b);
28    CHECK_U(u(b, mesh_link(2) + MESH_L_TX_BYTES), 5);
29    CHECK_U(u(b, mesh_link(2) + MESH_L_RX_BYTES), 100);
30    CHECK_U(u(b, mesh_link(1) + MESH_L_RX_BYTES), 7);
31    CHECK_U(u(b, mesh_link(2) + MESH_L_TX_FRAMES + 8 * MESH_KIND_ROUND), 1);
32    CHECK_U(u(b, mesh_link(2) + MESH_L_TX_FRAMES + 8 * MESH_KIND_CTL), 1);
33    CHECK_U(u(b, mesh_link(2) + MESH_L_RX_FRAMES + 8 * MESH_KIND_PLACE), 1);
34    CHECK_U(u(b, mesh_link(1) + MESH_L_RX_FRAMES + 8 * MESH_KIND_LOAD), 1);
35    CHECK_U(u(b, MESH_S_CTL_RX), 5);
36    CHECK_U(u(b, MESH_S_CTL_TX), 1000);
37    CHECK_U(u(b, MESH_S_CTL_REQS), 1);
38    CHECK_U(u(b, MESH_S_HTTP_RX), 30);
39    CHECK_U(u(b, MESH_S_HTTP_TX), 400);
40    CHECK_U(u(b, MESH_S_HTTP_CONNS), 1);
41    free(b);
42    return mesh_check_done();
43}