1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
//
// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
// file was obtained (LICENSE.txt). A copy of the license may also be
// found online at https://opensource.org/licenses/MIT.
//
#include <nuts.h>
#define SECONDS(x) ((x) *1000)
void
test_stats_socket(void)
{
#ifdef NNG_ENABLE_STATS
nng_socket s1;
nng_socket s2;
const nng_stat *st1;
const nng_stat *st2;
const nng_stat *item;
nng_stat *stats;
NUTS_OPEN(s1);
NUTS_OPEN(s2);
NUTS_MARRY(s1, s2);
NUTS_SEND(s1, "ping");
NUTS_RECV(s2, "ping");
nng_stats_get(&stats);
NUTS_ASSERT(stats != NULL);
st1 = nng_stat_find_socket(stats, s1);
st2 = nng_stat_find_socket(stats, s2);
NUTS_ASSERT(st1 != NULL);
NUTS_ASSERT(st2 != NULL);
NUTS_ASSERT(st1 != st2);
item = nng_stat_find(st1, "tx_msgs");
NUTS_ASSERT(item != NULL);
NUTS_ASSERT(nng_stat_value(item) == 1);
NUTS_ASSERT(nng_stat_unit(item) == NNG_UNIT_MESSAGES);
item = nng_stat_find(st2, "rx_msgs");
NUTS_ASSERT(item != NULL);
NUTS_ASSERT(nng_stat_value(item) == 1);
NUTS_ASSERT(nng_stat_unit(item) == NNG_UNIT_MESSAGES);
NUTS_CLOSE(s1);
NUTS_CLOSE(s2);
nng_stats_free(stats);
#endif
}
void
test_stats_dump(void)
{
#ifdef NNG_ENABLE_STATS
nng_socket s1;
nng_socket s2;
const nng_stat *st1;
const nng_stat *st2;
nng_stat *stats;
NUTS_OPEN(s1);
NUTS_OPEN(s2);
NUTS_MARRY(s1, s2);
NUTS_SEND(s1, "ping");
NUTS_RECV(s2, "ping");
nng_stats_get(&stats);
NUTS_ASSERT(stats != NULL);
st1 = nng_stat_find_socket(stats, s1);
st2 = nng_stat_find_socket(stats, s2);
NUTS_ASSERT(st1 != NULL);
NUTS_ASSERT(st2 != NULL);
NUTS_ASSERT(st1 != st2);
nng_stats_dump(stats);
nng_stats_free(stats);
NUTS_CLOSE(s1);
NUTS_CLOSE(s2);
#endif
}
NUTS_TESTS = {
{ "socket stats", test_stats_socket },
{ "dump stats", test_stats_dump },
{ NULL, NULL },
};
|