YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
stats_monitorTest.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2026-2026 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
7#include <yarp/os/Network.h>
8#include <yarp/os/LogStream.h>
9#include <yarp/os/Time.h>
10#include <yarp/os/Port.h>
11
13
14#include <array>
15#include <thread>
16
17#include <catch2/catch_amalgamated.hpp>
18#include <harness.h>
19
20TEST_CASE("pm::stats_monitorTest", "[yarp::pm]")
21{
22 YARP_REQUIRE_PLUGIN("stats_monitor", "portmonitor")
23 YARP_REQUIRE_PLUGIN("throttleDown", "portmonitor")
24
26
29 bool b;
30 std::string s1 = "/stats_monitor/send/recv/stats:o";
31 std::string s2 = "/stats_monitor/recv/send/stats:o";
32
33 SECTION("Test that normally the portmonitor is not used")
34 {
35 yarp::os::Port sender;
36 yarp::os::Port receiver;
37
38 sender.open("/send");
39 receiver.open("/recv");
40
41 yarp::os::Network::connect("/send", "/recv");
42
45 REQUIRE(!b);
47 REQUIRE(!b);
48
49 receiver.close();
50 sender.close();
51
54 REQUIRE(!b);
56 REQUIRE(!b);
57 }
58
59 SECTION("Test standard usage of stats_monitor")
60 {
61 yarp::os::Port sender;
62 yarp::os::Port receiver;
63
64 sender.open("/send");
65 receiver.open("/recv");
66
67 yarp::os::Network::connect("/send", "/recv","tcp+send.portmonitor+file.stats_monitor+type.dll");
68
71 REQUIRE(b);
73 REQUIRE(b);
74
75 receiver.close();
76 sender.close();
77
80 REQUIRE(!b);
82 REQUIRE(!b);
83 }
84
85 SECTION("Test usage of environment variable YARP_CONNECTIONS_STATS_ENABLE")
86 {
87 yarp::os::Port sender;
88 yarp::os::Port receiver;
89
90 yarp::conf::environment::set_bool("YARP_CONNECTIONS_STATS_ENABLE", true );
91
92 sender.open("/send");
93 receiver.open("/recv");
94
95 yarp::os::Network::connect("/send", "/recv");
96
99 REQUIRE(b);
101 REQUIRE(b);
102
103 receiver.close();
104 sender.close();
105
108 REQUIRE(!b);
110 REQUIRE(!b);
111
112 yarp::conf::environment::unset("YARP_CONNECTIONS_STATS_ENABLE");
113 }
114
115 SECTION("Test multiple monitors concatenation using environment variable")
116 {
117 yarp::os::Port sender;
118 yarp::os::Port receiver;
119
120 yarp::conf::environment::set_bool("YARP_CONNECTIONS_STATS_ENABLE", true );
121
122 sender.open("/send");
123 receiver.open("/recv");
124
125 yarp::os::Network::connect("/send", "/recv", "tcp+send.portmonitor+type.dll+file.throttleDown+period_ms.500");
126
129 REQUIRE(b);
131 REQUIRE(b);
132
133 receiver.close();
134 sender.close();
135
138 REQUIRE(!b);
140 REQUIRE(!b);
141
142 yarp::conf::environment::unset("YARP_CONNECTIONS_STATS_ENABLE");
143 }
144
145 SECTION("Test multiple monitors concatenation (send version)")
146 {
147 yarp::os::Port sender;
148 yarp::os::Port receiver;
149
150 sender.open("/send");
151 receiver.open("/recv");
152
153 yarp::os::Network::connect("/send", "/recv", "tcp+send.portmonitor+type.dll+file.throttleDown+period_ms.500+file1.stats_monitor+type1.dll");
154
157 REQUIRE(b);
159 REQUIRE(b);
160
161 receiver.close();
162 sender.close();
163
166 REQUIRE(!b);
168 REQUIRE(!b);
169 }
170
171/*
172 //This is not implemented yet, because the portmonitor is not yet implemented for the receiver side
173 SECTION("Test multiple monitors concatenation (recv version)")
174 {
175 yarp::os::Port sender;
176 yarp::os::Port receiver;
177
178 sender.open("/send");
179 receiver.open("/recv");
180
181 yarp::os::Network::connect("/send", "/recv", "tcp+recv.portmonitor+type.dll+file.throttleDown+period_ms.500+file1.stats_monitor+type1.dll");
182
183 yarp::os::Time::delay(1.0);
184 b = yarp::os::Network::exists(s1);
185 REQUIRE(b);
186 b = yarp::os::Network::exists(s2);
187 REQUIRE(b);
188
189 receiver.close();
190 sender.close();
191
192 yarp::os::Time::delay(1.0);
193 b = yarp::os::Network::exists(s1);
194 REQUIRE(!b);
195 b = yarp::os::Network::exists(s2);
196 REQUIRE(!b);
197 }
198*/
199
201}
static bool connect(const std::string &src, const std::string &dest, const std::string &carrier="", bool quiet=true)
Request that an output port connect to an input port.
Definition Network.cpp:751
static bool exists(const std::string &port, bool quiet=true, bool checkVer=true)
Check for a port to be ready and responsive.
Definition Network.cpp:815
static bool setLocalMode(bool flag)
Chooses whether communication is process-local.
Definition Network.cpp:1118
Utilities for manipulating the YARP network, including initialization and shutdown.
Definition Network.h:718
A mini-server for network communication.
Definition Port.h:46
void close() override
Stop port activity.
Definition Port.cpp:330
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
Definition Port.cpp:79
bool set_bool(const std::string &key, bool value)
Set a bool to an environment variable (as 1 or 0).
bool unset(const std::string &key)
Remove an environment variable.
void delay(double seconds)
Wait for a certain number of seconds.
Definition Time.cpp:111
@ YARP_CLOCK_SYSTEM
Definition Time.h:28
The main, catch-all namespace for YARP.
Definition dirs.h:16
TEST_CASE("pm::stats_monitorTest", "[yarp::pm]")