YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
throttleDownTest.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/Bottle.h>
12#include <yarp/os/Carriers.h>
13
15
16#include <array>
17#include <thread>
18#include <vector>
19
20#include <catch2/catch_amalgamated.hpp>
21#include <harness.h>
22
23TEST_CASE("pm::throttleDownTest", "[yarp::pm]")
24{
25 YARP_REQUIRE_PLUGIN("throttleDown", "portmonitor")
26
28
30
31 REQUIRE(yarp::os::Carriers::getCarrierTemplate("portmonitor") != nullptr);
32
34
35 struct TestCase {
36 std::string carrier;
37 int value_to_send;
38 int period_ms;
39 double send_rate; // messages per second
40 double expected_receive_rate; // expected messages per second at receiver
41 double tolerance; // tolerance for rate comparison
42 };
43
44 auto tc = GENERATE(
45 // Without throttle - should receive all messages
46 TestCase {"fast_tcp", 42, 0, 10.0, 10.0, 2.0},
47 // With throttle - 500ms period = max 2 messages/second
48 TestCase {"fast_tcp+send.portmonitor+type.dll+file.throttleDown+period_ms.500", 42, 500, 10.0, 2.0, 1.0},
49 // With throttle - 200ms period = max 5 messages/second
50 TestCase {"fast_tcp+send.portmonitor+type.dll+file.throttleDown+period_ms.200", 42, 200, 10.0, 5.0, 2.0}
51 );
52
53 SECTION("Test throttling behavior - sending at " + std::to_string(tc.send_rate) + " Hz, expecting ~" + std::to_string(tc.expected_receive_rate) + " Hz")
54 {
55 yarp::os::Port sender;
56 yarp::os::Port receiver;
57
58 sender.open("/send");
59 receiver.open("/recv");
60
61 bool b = yarp::os::Network::connect("/send", "/recv", tc.carrier);
62 REQUIRE(b);
63
64 // Allow connection to establish
66
67 sender.write(yarp::os::Value(tc.value_to_send));
68
70
71 yarp::os::Value rval;
72 receiver.read(rval);
73 CHECK(rval.asInt64()==tc.value_to_send);
74
75 receiver.close();
76 sender.close();
77 }
78
80}
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 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
bool write(const PortWriter &writer, const PortWriter *callback=nullptr) const override
Write an object to the port.
Definition Port.cpp:395
bool read(PortReader &reader, bool willReply=false) override
Read an object from the port.
Definition Port.cpp:440
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
A single value (typically within a Bottle).
Definition Value.h:44
virtual std::int64_t asInt64() const
Get 64-bit integer value.
Definition Value.cpp:210
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::throttleDownTest", "[yarp::pm]")