Skip to content

Commit d77bc81

Browse files
committed
Add tests
1 parent 75df2fc commit d77bc81

3 files changed

Lines changed: 70 additions & 87 deletions

File tree

source/network/connection/mplb/rdma/dcqcn.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void DCQCN::on_cnp() {
3434

3535
TimeNs now = Scheduler::get_instance().get_current_time();
3636
m_last_cnp = now;
37-
m_bytes_from_last_byte_reset = SizeByte(0);
37+
m_bytes_from_last_byte_reset = SizeByte(0ul);
3838
m_time_counter = 0;
3939
}
4040

@@ -76,7 +76,7 @@ void DCQCN::on_rate_reduce_monitor_period() {
7676
std::max(m_params.rpg_min_dec_fac,
7777
(1 - m_alpha / static_cast<double>(1 << m_params.rpg_gd)));
7878
m_current_rate = std::max(m_current_rate, m_params.rpg_min_rate);
79-
m_bytes_from_last_byte_reset = SizeByte(0);
79+
m_bytes_from_last_byte_reset = SizeByte(0ul);
8080
m_byte_counter = 0;
8181
m_time_counter = 0;
8282
}

source/network/connection/mplb/rdma/dcqcn.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct ParamsDQCCN {
1717
TimeUs rpg_time_reset = TimeUs(300);
1818

1919
// The sent bytes counter between rate increase events.
20-
SizeByte rpg_byte_reset = SizeByte(64 * 32767);
20+
SizeByte rpg_byte_reset = SizeByte(64 * 32767ul);
2121

2222
// The threshold of rate increase events for moving to next rate increase
2323
// phase.
@@ -97,7 +97,7 @@ class DCQCN {
9797
bool m_dec_target_rate = false;
9898

9999
// Size & time counters (T & BC on Increment scheme part of NVIDIA docs)
100-
SizeByte m_bytes_from_last_byte_reset = SizeByte(0);
100+
SizeByte m_bytes_from_last_byte_reset = SizeByte(0ul);
101101
std::uint32_t m_time_counter = 0;
102102
std::uint32_t m_byte_counter = 0;
103103

test/connection/rdma/dcqcn_test.cpp

Lines changed: 66 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <gtest/gtest.h>
44

55
#include "scheduler/scheduler.hpp"
6+
#include "utils/defer.hpp"
67

78
namespace sim {
89
namespace test2 {
@@ -11,7 +12,7 @@ struct Fixture : public ::testing::Test {
1112
Fixture() : params() {
1213
// задать удобные параметры для детерминированного тестирования
1314
params.rpg_time_reset = TimeUs(100);
14-
params.rpg_byte_reset = SizeByte(1000);
15+
params.rpg_byte_reset = SizeByte(1000ul);
1516
params.rpg_threshold = 1;
1617
params.rpg_ai_rate = SpeedMbps(10);
1718
params.rpg_hai_rate = SpeedMbps(100);
@@ -32,97 +33,79 @@ struct Fixture : public ::testing::Test {
3233
// Helper: устанавливаем начальный момент времени
3334
TimeNs now_ns(int us) { return TimeNs(us * 1000); }
3435

35-
// 1) start() ставит таймеры (проверим, что события запланированы и первый
36-
// alpha обновится)
37-
TEST_F(Fixture, RateIncrease) {
38-
Scheduler& sched = Scheduler::get_instance();
36+
TEST_F(Fixture, AdditiveIncreaseByTimer) {
3937
DCQCN cc(params);
4038
cc.start();
39+
utils::Defer defer([&cc]() { cc.stop(); });
4140

42-
SpeedMbps initial_rate = cc.get_rate();
41+
SpeedMbps before = cc.get_rate();
4342

4443
// one additive increase should be triggered
45-
sched.tick_to(
46-
params.rpg_time_reset); // dce_tcp_rtt = 10us => первый alpha через
47-
// 10us; убедимся, что до 5us не выполнено
44+
Scheduler::get_instance().tick_to(params.rpg_time_reset);
4845

4946
SpeedMbps new_rate = cc.get_rate();
50-
EXPECT_GT(new_rate, initial_rate);
47+
EXPECT_GT(new_rate, before);
5148
}
5249

53-
// // 2) on_data_delivery: после накопления rpg_byte_reset должно вызвать
54-
// // on_rate_increase_event
55-
// TEST_F(Fixture, RateIncreaseByBytes) {
56-
// DCQCN cc(params);
57-
// cc.start();
58-
59-
// // начальная скорость — rpg_min_rate
60-
// auto before = cc.get_rate();
61-
62-
// // доставляем ровно rpg_byte_reset -> должно инкрементнуть целевую и
63-
// // обновить текущую
64-
// cc.on_data_delivery(params.rpg_byte_reset);
65-
// auto after = cc.get_rate();
66-
// EXPECT_GT(after, before);
67-
// }
68-
69-
// // 3) on_rate_increase_event: проверка фаз (AI vs HAI)
70-
// // Нужна имитация нескольких итераций: увеличиваем time_counter и
71-
// byte_counter
72-
// // вручную через deliveries/time advance
73-
// TEST_F(Fixture, AdditiveAndHyperIncreasePhases) {
74-
// DCQCN cc(params);
75-
// cc.start();
76-
77-
// // Сценарий: сначала одно событие -> additive increase
78-
// cc.on_data_delivery(params.rpg_byte_reset);
79-
// auto rate1 = cc.get_rate();
80-
81-
// // имитируем много событий, чтобы перейти в HAI
82-
// for (int i = 0; i < 5; ++i)
83-
// cc.on_data_delivery(params.rpg_byte_reset); auto rate2 =
84-
// cc.get_rate();
85-
86-
// EXPECT_GT(rate2, rate1);
87-
// }
88-
89-
// // 4) on_cnp + rate reduction: при получении CNP и срабатывании monitor
90-
// period
91-
// // текущая скорость должна уменьшиться
92-
// TEST_F(Fixture, RateDecreaseOnCnp) {
93-
// DCQCN cc(params);
94-
// cc.start();
95-
96-
// // предварительно поднимем скорость
97-
// cc.on_data_delivery(params.rpg_byte_reset);
98-
// cc.on_data_delivery(params.rpg_byte_reset);
99-
// auto up = cc.get_rate();
100-
101-
// // получаем CNP
102-
// cc.on_cnp();
103-
104-
// // продвигаем время вперёд чтобы сработал rate_reduce_monitor_period
105-
// sched.tick_to(now_ns(25)); // period = 20us
106-
// sched.run_pending_tasks(); // выполнит on_rate_reduce_monitor_period
107-
// auto down = cc.get_rate();
108-
109-
// EXPECT_LT(down, up);
110-
// }
111-
112-
// // 5) stop() — дальнейшие события игнорируются
113-
// TEST_F(Fixture, StopPreventsFurtherChanges) {
114-
// DCQCN cc(params);
115-
// cc.start();
116-
117-
// cc.stop();
118-
// cc.on_data_delivery(params.rpg_byte_reset * 10);
119-
// auto rate_after = cc.get_rate();
120-
121-
// // скорость не должна измениться после stop (равна минимальной
122-
// установленной
123-
// // при ctor)
124-
// EXPECT_EQ(rate_after, params.rpg_min_rate);
125-
// }
50+
TEST_F(Fixture, AdditiveIncreaseByBytes) {
51+
DCQCN cc(params);
52+
cc.start();
53+
utils::Defer defer([&cc]() { cc.stop(); });
54+
55+
SpeedMbps before = cc.get_rate();
56+
57+
cc.on_data_delivery(params.rpg_byte_reset);
58+
SpeedMbps after = cc.get_rate();
59+
EXPECT_GT(after, before);
60+
}
61+
62+
TEST_F(Fixture, AdditiveAndHyperIncrease) {
63+
DCQCN cc(params);
64+
cc.start();
65+
utils::Defer defer([&cc]() { cc.stop(); });
66+
67+
SpeedMbps rate_start = cc.get_rate();
68+
69+
// one additive increase
70+
cc.on_data_delivery(params.rpg_byte_reset);
71+
72+
SpeedGbps rate_ai = cc.get_rate();
73+
EXPECT_GT(rate_ai, rate_start);
74+
75+
// two more additive increase
76+
Scheduler::get_instance().tick_to(params.rpg_time_reset * 2);
77+
78+
SpeedMbps rate_before_hai = cc.get_rate();
79+
80+
// one hyper increase
81+
cc.on_data_delivery(params.rpg_byte_reset);
82+
83+
SpeedMbps rate_hai = cc.get_rate();
84+
85+
EXPECT_GT(rate_hai, rate_before_hai);
86+
87+
static constexpr double thresh = 2.0;
88+
89+
EXPECT_GT(rate_hai - rate_before_hai, thresh * (rate_ai - rate_start));
90+
}
91+
92+
TEST_F(Fixture, RateDecreaseOnCnp) {
93+
DCQCN cc(params);
94+
cc.start();
95+
utils::Defer defer([&cc]() { cc.stop(); });
96+
97+
// increase speed
98+
cc.on_data_delivery(params.rpg_byte_reset);
99+
cc.on_data_delivery(params.rpg_byte_reset);
100+
SpeedMbps up = cc.get_rate();
101+
102+
cc.on_cnp();
103+
104+
Scheduler::get_instance().tick_to(params.rate_reduce_monitor_period);
105+
SpeedMbps down = cc.get_rate();
106+
107+
EXPECT_LT(down, up);
108+
}
126109

127110
} // namespace test2
128111
} // namespace sim

0 commit comments

Comments
 (0)