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
14
15#include <array>
16#include <thread>
17#include <vector>
18
19#include <catch2/catch_amalgamated.hpp>
20#include <harness.h>
21
22TEST_CASE("pm::throttleDownTest", "[yarp::pm]")
23{
24 YARP_REQUIRE_PLUGIN("throttleDown", "portmonitor")
25
27
30
31 struct TestCase {
32 std::string carrier;
33 int value_to_send;
34 int period_ms;
35 double send_rate; // messages per second
36 double expected_receive_rate; // expected messages per second at receiver
37 double tolerance; // tolerance for rate comparison
38 };
39
40 auto tc = GENERATE(
41 // Without throttle - should receive all messages
42 TestCase {"fast_tcp", 42, 0, 10.0, 10.0, 2.0},
43 // With throttle - 500ms period = max 2 messages/second
44 TestCase {"fast_tcp+send.portmonitor+type.dll+file.throttleDown+period_ms.500", 42, 500, 10.0, 2.0, 1.0},
45 // With throttle - 200ms period = max 5 messages/second
46 TestCase {"fast_tcp+send.portmonitor+type.dll+file.throttleDown+period_ms.200", 42, 200, 10.0, 5.0, 2.0}
47 );
48
49 SECTION("Test throttling behavior - sending at " + std::to_string(tc.send_rate) + " Hz, expecting ~" + std::to_string(tc.expected_receive_rate) + " Hz")
50 {
51 yarp::os::Port sender;
52 yarp::os::Port receiver;
53
54 sender.open("/send");
55 receiver.open("/recv");
56
57 bool b = yarp::os::Network::connect("/send", "/recv", tc.carrier);
58 REQUIRE(b);
59
60 // Allow connection to establish
62
63 sender.write(yarp::os::Value(tc.value_to_send));
64
66
67 yarp::os::Value rval;
68 receiver.read(rval);
69 CHECK(rval.asInt64()==tc.value_to_send);
70
71 receiver.close();
72 sender.close();
73 }
74
76}
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 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
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:216
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]")