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#include <yarp/os/Carriers.h>
12
14
15#include <array>
16#include <thread>
17
18#include <catch2/catch_amalgamated.hpp>
19#include <harness.h>
20
21TEST_CASE("pm::stats_monitorTest", "[yarp::pm]")
22{
23 YARP_REQUIRE_PLUGIN("stats_monitor", "portmonitor")
24 YARP_REQUIRE_PLUGIN("throttleDown", "portmonitor")
25
27
29
30 REQUIRE(yarp::os::Carriers::getCarrierTemplate("portmonitor") != nullptr);
31
33 bool b;
34 std::string s1 = "/stats_monitor/send/recv/stats:o";
35 std::string s2 = "/stats_monitor/recv/send/stats:o";
36
37 SECTION("Test that normally the portmonitor is not used")
38 {
39 yarp::os::Port sender;
40 yarp::os::Port receiver;
41
42 sender.open("/send");
43 receiver.open("/recv");
44
45 yarp::os::Network::connect("/send", "/recv");
46
49 REQUIRE(!b);
51 REQUIRE(!b);
52
53 receiver.close();
54 sender.close();
55
58 REQUIRE(!b);
60 REQUIRE(!b);
61 }
62
63 SECTION("Test standard usage of stats_monitor")
64 {
65 yarp::os::Port sender;
66 yarp::os::Port receiver;
67
68 sender.open("/send");
69 receiver.open("/recv");
70
71 yarp::os::Network::connect("/send", "/recv","tcp+send.portmonitor+file.stats_monitor+type.dll");
72
75 REQUIRE(b);
77 REQUIRE(b);
78
79 receiver.close();
80 sender.close();
81
84 REQUIRE(!b);
86 REQUIRE(!b);
87 }
88
89 SECTION("Test usage of environment variable YARP_CONNECTIONS_STATS_ENABLE")
90 {
91 yarp::os::Port sender;
92 yarp::os::Port receiver;
93
94 yarp::conf::environment::set_bool("YARP_CONNECTIONS_STATS_ENABLE", true );
95
96 sender.open("/send");
97 receiver.open("/recv");
98
99 yarp::os::Network::connect("/send", "/recv");
100
103 REQUIRE(b);
105 REQUIRE(b);
106
107 receiver.close();
108 sender.close();
109
112 REQUIRE(!b);
114 REQUIRE(!b);
115
116 yarp::conf::environment::unset("YARP_CONNECTIONS_STATS_ENABLE");
117 }
118
119 SECTION("Test multiple monitors concatenation using environment variable")
120 {
121 yarp::os::Port sender;
122 yarp::os::Port receiver;
123
124 yarp::conf::environment::set_bool("YARP_CONNECTIONS_STATS_ENABLE", true );
125
126 sender.open("/send");
127 receiver.open("/recv");
128
129 yarp::os::Network::connect("/send", "/recv", "tcp+send.portmonitor+type.dll+file.throttleDown+period_ms.500");
130
133 REQUIRE(b);
135 REQUIRE(b);
136
137 receiver.close();
138 sender.close();
139
142 REQUIRE(!b);
144 REQUIRE(!b);
145
146 yarp::conf::environment::unset("YARP_CONNECTIONS_STATS_ENABLE");
147 }
148
149 SECTION("Test multiple monitors concatenation (send version)")
150 {
151 yarp::os::Port sender;
152 yarp::os::Port receiver;
153
154 sender.open("/send");
155 receiver.open("/recv");
156
157 yarp::os::Network::connect("/send", "/recv", "tcp+send.portmonitor+type.dll+file.throttleDown+period_ms.500+file1.stats_monitor+type1.dll");
158
161 REQUIRE(b);
163 REQUIRE(b);
164
165 receiver.close();
166 sender.close();
167
170 REQUIRE(!b);
172 REQUIRE(!b);
173 }
174
175/*
176 //This is not implemented yet, because the portmonitor is not yet implemented for the receiver side
177 SECTION("Test multiple monitors concatenation (recv version)")
178 {
179 yarp::os::Port sender;
180 yarp::os::Port receiver;
181
182 sender.open("/send");
183 receiver.open("/recv");
184
185 yarp::os::Network::connect("/send", "/recv", "tcp+recv.portmonitor+type.dll+file.throttleDown+period_ms.500+file1.stats_monitor+type1.dll");
186
187 yarp::os::Time::delay(1.0);
188 b = yarp::os::Network::exists(s1);
189 REQUIRE(b);
190 b = yarp::os::Network::exists(s2);
191 REQUIRE(b);
192
193 receiver.close();
194 sender.close();
195
196 yarp::os::Time::delay(1.0);
197 b = yarp::os::Network::exists(s1);
198 REQUIRE(!b);
199 b = yarp::os::Network::exists(s2);
200 REQUIRE(!b);
201 }
202*/
203
205}
static Carrier * getCarrierTemplate(const std::string &name)
Get template for carrier.
Definition Carriers.cpp:238
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:784
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:848
static bool setLocalMode(bool flag)
Chooses whether communication is process-local.
Definition Network.cpp:1137
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]")