Skip to content

Commit 50dffd3

Browse files
joaquim-srscodebot
authored andcommitted
phy: optimize lower phy downlink processor test
1 parent e33d154 commit 50dffd3

File tree

4 files changed

+112
-66
lines changed

4 files changed

+112
-66
lines changed

tests/unittests/gateways/baseband/baseband_gateway_buffer_test_doubles.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,13 @@ class baseband_gateway_buffer_read_only : public baseband_gateway_buffer_reader
7777

7878
/// Constructor from a writer interface.
7979
baseband_gateway_buffer_read_only(baseband_gateway_buffer_writer& other) noexcept :
80-
nof_channels(other.get_nof_channels()), nof_samples(other.get_nof_samples()), data(nof_channels * nof_samples)
80+
nof_channels(other.get_nof_channels()), nof_samples(other.get_nof_samples())
8181
{
82+
data.clear();
83+
data.reserve(nof_channels * nof_samples);
8284
for (unsigned channel = 0; channel != nof_channels; ++channel) {
83-
span<cf_t> buffer = span<cf_t>(data).subspan(nof_samples * channel, nof_samples);
84-
srsvec::copy(buffer, other[channel]);
85+
span<const cf_t> source = other[channel];
86+
data.insert(data.end(), source.begin(), source.end());
8587
}
8688
}
8789

tests/unittests/phy/lower/amplitude_control/amplitude_controller_test_doubles.h

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,39 @@ class amplitude_controller_spy : public amplitude_controller
2424
std::vector<cf_t> output;
2525
};
2626

27+
amplitude_controller_spy() : random_data(1009)
28+
{
29+
std::mt19937 rgen;
30+
std::uniform_real_distribution<float> sample_dist(-1, 1);
31+
std::generate(random_data.begin(), random_data.end(), [&sample_dist, &rgen]() {
32+
return cf_t(sample_dist(rgen), sample_dist(rgen));
33+
});
34+
}
35+
2736
amplitude_controller_metrics process(span<cf_t> output, span<const cf_t> input) override
2837
{
2938
entries.emplace_back();
3039
entry_t& entry = entries.back();
3140

32-
entry.input.resize(input.size());
33-
srsvec::copy(entry.input, input);
41+
entry.input = std::vector<cf_t>(input.begin(), input.end());
42+
43+
std::size_t remaining = output.size();
44+
span<cf_t> random_data_view(random_data);
45+
46+
while (remaining > 0) {
47+
// Number of samples to copy for this iteration.
48+
unsigned nof_copied_samples = std::min(random_data.size() - random_data_index, remaining);
49+
span<cf_t> random_samples = random_data_view.subspan(random_data_index, nof_copied_samples);
50+
span<cf_t> out_samples = output.subspan(output.size() - remaining, nof_copied_samples);
51+
52+
srsvec::copy(out_samples, random_samples);
3453

35-
std::generate(output.begin(), output.end(), [this]() { return cf_t(output_dist(rgen), output_dist(rgen)); });
54+
// Update remaining samples and buffer index.
55+
remaining -= nof_copied_samples;
56+
random_data_index = (random_data_index + nof_copied_samples) % random_data.size();
57+
}
3658

37-
entry.output.resize(output.size());
38-
srsvec::copy(entry.output, output);
59+
entry.output = std::vector<cf_t>(output.begin(), output.end());
3960

4061
return amplitude_controller_metrics();
4162
}
@@ -45,7 +66,8 @@ class amplitude_controller_spy : public amplitude_controller
4566
void clear() { entries.clear(); }
4667

4768
private:
48-
std::mt19937 rgen;
69+
unsigned random_data_index = 0;
70+
std::vector<cf_t> random_data;
4971
std::uniform_real_distribution<float> output_dist;
5072
std::vector<entry_t> entries;
5173
};

tests/unittests/phy/lower/processors/downlink/lower_phy_downlink_processor_test.cpp

Lines changed: 49 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ bool operator==(const pdxch_processor_configuration& left, const pdxch_processor
106106

107107
} // namespace srsran
108108

109-
using LowerPhyDownlinkProcessorParams = std::tuple<unsigned, sampling_rate, subcarrier_spacing, cyclic_prefix>;
109+
using LowerPhyDownlinkProcessorParams =
110+
std::tuple<unsigned, sampling_rate, std::tuple<subcarrier_spacing, cyclic_prefix>>;
110111

111112
namespace {
112113

@@ -115,27 +116,27 @@ class LowerPhyDownlinkProcessorFixture : public ::testing::TestWithParam<LowerPh
115116
protected:
116117
static void SetUpTestSuite()
117118
{
118-
if (ul_proc_factory == nullptr) {
119+
if (dl_proc_factory == nullptr) {
119120
pdxch_proc_factory = std::make_shared<pdxch_processor_factory_spy>();
120121
ASSERT_NE(pdxch_proc_factory, nullptr);
121122

122123
amplitude_control_factory = std::make_shared<amplitude_controller_factory_spy>();
123124
ASSERT_NE(amplitude_control_factory, nullptr);
124125

125-
ul_proc_factory = create_downlink_processor_factory_sw(pdxch_proc_factory, amplitude_control_factory);
126-
ASSERT_NE(ul_proc_factory, nullptr);
126+
dl_proc_factory = create_downlink_processor_factory_sw(pdxch_proc_factory, amplitude_control_factory);
127+
ASSERT_NE(dl_proc_factory, nullptr);
127128
}
128129
}
129130

130131
void SetUp() override
131132
{
132-
ASSERT_NE(ul_proc_factory, nullptr);
133+
ASSERT_NE(dl_proc_factory, nullptr);
133134

134135
// Select parameters.
135136
unsigned nof_tx_ports = std::get<0>(GetParam());
136137
sampling_rate srate = std::get<1>(GetParam());
137-
subcarrier_spacing scs = std::get<2>(GetParam());
138-
cyclic_prefix cp = std::get<3>(GetParam());
138+
subcarrier_spacing scs = std::get<0>(std::get<2>(GetParam()));
139+
cyclic_prefix cp = std::get<1>(std::get<2>(GetParam()));
139140

140141
// Prepare configurations.
141142
config.sector_id = 0;
@@ -148,8 +149,8 @@ class LowerPhyDownlinkProcessorFixture : public ::testing::TestWithParam<LowerPh
148149
config.logger = &srslog::fetch_basic_logger("Low-PHY");
149150

150151
// Create processor.
151-
ul_processor = ul_proc_factory->create(config);
152-
ASSERT_NE(ul_processor, nullptr);
152+
dl_processor = dl_proc_factory->create(config);
153+
ASSERT_NE(dl_processor, nullptr);
153154

154155
// Select PDxCH processor spy.
155156
pdxch_proc_spy = &pdxch_proc_factory->get_spy();
@@ -158,16 +159,16 @@ class LowerPhyDownlinkProcessorFixture : public ::testing::TestWithParam<LowerPh
158159
amplitude_control_spy = amplitude_control_factory->get_entries().back();
159160
}
160161

161-
static constexpr unsigned nof_frames_test = 10;
162+
static constexpr unsigned nof_frames_test = 3;
162163
static std::mt19937 rgen;
163164
static std::uniform_int_distribution<unsigned> dist_bandwidth_prb;
164165
static std::uniform_real_distribution<double> dist_center_freq_Hz;
165166
static std::shared_ptr<pdxch_processor_factory_spy> pdxch_proc_factory;
166167
static std::shared_ptr<amplitude_controller_factory_spy> amplitude_control_factory;
167-
static std::shared_ptr<lower_phy_downlink_processor_factory> ul_proc_factory;
168+
static std::shared_ptr<lower_phy_downlink_processor_factory> dl_proc_factory;
168169

169170
downlink_processor_configuration config;
170-
std::unique_ptr<lower_phy_downlink_processor> ul_processor = nullptr;
171+
std::unique_ptr<lower_phy_downlink_processor> dl_processor = nullptr;
171172
pdxch_processor_spy* pdxch_proc_spy = nullptr;
172173
amplitude_controller_spy* amplitude_control_spy = nullptr;
173174
};
@@ -177,7 +178,7 @@ std::uniform_int_distribution<unsigned> LowerPhyDownlinkProcessorFixtu
177178
std::uniform_real_distribution<double> LowerPhyDownlinkProcessorFixture::dist_center_freq_Hz(1e8, 6e9);
178179
std::shared_ptr<pdxch_processor_factory_spy> LowerPhyDownlinkProcessorFixture::pdxch_proc_factory = nullptr;
179180
std::shared_ptr<amplitude_controller_factory_spy> LowerPhyDownlinkProcessorFixture::amplitude_control_factory = nullptr;
180-
std::shared_ptr<lower_phy_downlink_processor_factory> LowerPhyDownlinkProcessorFixture::ul_proc_factory = nullptr;
181+
std::shared_ptr<lower_phy_downlink_processor_factory> LowerPhyDownlinkProcessorFixture::dl_proc_factory = nullptr;
181182

182183
} // namespace
183184

@@ -201,7 +202,7 @@ TEST_P(LowerPhyDownlinkProcessorFixture, PdxchConnection)
201202
pdxch_processor_notifier_spy pdxch_proc_notifier_spy;
202203

203204
// Connect.
204-
ul_processor->connect(downlink_proc_notifier_spy, pdxch_proc_notifier_spy);
205+
dl_processor->connect(downlink_proc_notifier_spy, pdxch_proc_notifier_spy);
205206

206207
// Assert no notifications.
207208
ASSERT_EQ(downlink_proc_notifier_spy.get_total_count(), 0);
@@ -218,32 +219,32 @@ TEST_P(LowerPhyDownlinkProcessorFixture, PdxchRequestHandler)
218219
const pdxch_processor_request_handler* expected_request_handler = &pdxch_proc_spy->get_request_handler();
219220

220221
// Get actual request handler.
221-
const pdxch_processor_request_handler* request_handler = &ul_processor->get_downlink_request_handler();
222+
const pdxch_processor_request_handler* request_handler = &dl_processor->get_downlink_request_handler();
222223

223224
// Assert request handler.
224225
ASSERT_EQ(reinterpret_cast<const void*>(expected_request_handler), reinterpret_cast<const void*>(request_handler));
225226
}
226227

227228
TEST_P(LowerPhyDownlinkProcessorFixture, Flow)
228229
{
229-
unsigned nof_rx_ports = std::get<0>(GetParam());
230+
unsigned nof_tx_ports = std::get<0>(GetParam());
230231
sampling_rate srate = std::get<1>(GetParam());
231-
subcarrier_spacing scs = std::get<2>(GetParam());
232-
cyclic_prefix cp = std::get<3>(GetParam());
232+
subcarrier_spacing scs = std::get<0>(std::get<2>(GetParam()));
233+
cyclic_prefix cp = std::get<1>(std::get<2>(GetParam()));
233234

234235
unsigned base_symbol_size = srate.get_dft_size(scs);
235236

236-
baseband_gateway_buffer_dynamic buffer(nof_rx_ports, 2 * base_symbol_size);
237+
baseband_gateway_buffer_dynamic buffer(nof_tx_ports, 2 * base_symbol_size);
237238

238239
unsigned nof_symbols_per_slot = get_nsymb_per_slot(cp);
239240
unsigned nof_slots_per_subframe = get_nof_slots_per_subframe(scs);
240241

241242
// Create notifiers and connect.
242243
downlink_processor_notifier_spy downlink_proc_notifier_spy;
243244
pdxch_processor_notifier_spy pdxch_proc_notifier_spy;
244-
ul_processor->connect(downlink_proc_notifier_spy, pdxch_proc_notifier_spy);
245+
dl_processor->connect(downlink_proc_notifier_spy, pdxch_proc_notifier_spy);
245246

246-
downlink_processor_baseband& dl_proc_baseband = ul_processor->get_baseband();
247+
downlink_processor_baseband& dl_proc_baseband = dl_processor->get_baseband();
247248

248249
baseband_gateway_timestamp timestamp = 0;
249250
for (unsigned i_frame = 0, i_slot_frame = 0; i_frame != nof_frames_test; ++i_frame) {
@@ -310,10 +311,10 @@ TEST_P(LowerPhyDownlinkProcessorFixture, Flow)
310311
// Test baseband buffer sizes which are unaligned with OFDM symbol boundaries.
311312
TEST_P(LowerPhyDownlinkProcessorFixture, FlowUnalignedBuffer)
312313
{
313-
unsigned nof_rx_ports = std::get<0>(GetParam());
314+
unsigned nof_tx_ports = std::get<0>(GetParam());
314315
sampling_rate srate = std::get<1>(GetParam());
315-
subcarrier_spacing scs = std::get<2>(GetParam());
316-
cyclic_prefix cp = std::get<3>(GetParam());
316+
subcarrier_spacing scs = std::get<0>(std::get<2>(GetParam()));
317+
cyclic_prefix cp = std::get<1>(std::get<2>(GetParam()));
317318

318319
unsigned base_symbol_size = srate.get_dft_size(scs);
319320

@@ -323,12 +324,12 @@ TEST_P(LowerPhyDownlinkProcessorFixture, FlowUnalignedBuffer)
323324
// Create notifiers and connect.
324325
downlink_processor_notifier_spy downlink_proc_notifier_spy;
325326
pdxch_processor_notifier_spy pdxch_proc_notifier_spy;
326-
ul_processor->connect(downlink_proc_notifier_spy, pdxch_proc_notifier_spy);
327+
dl_processor->connect(downlink_proc_notifier_spy, pdxch_proc_notifier_spy);
327328

328-
downlink_processor_baseband& dl_proc_baseband = ul_processor->get_baseband();
329+
downlink_processor_baseband& dl_proc_baseband = dl_processor->get_baseband();
329330

330331
// Create basband buffer.
331-
baseband_gateway_buffer_dynamic buffer(nof_rx_ports, 3 * base_symbol_size);
332+
baseband_gateway_buffer_dynamic buffer(nof_tx_ports, 3 * base_symbol_size);
332333

333334
// Reset timestamp.
334335
baseband_gateway_timestamp timestamp = 0;
@@ -438,10 +439,10 @@ TEST_P(LowerPhyDownlinkProcessorFixture, FlowUnalignedBuffer)
438439
// Test a baseband buffer size comprising an entire slot.
439440
TEST_P(LowerPhyDownlinkProcessorFixture, FlowLargeBuffer)
440441
{
441-
unsigned nof_rx_ports = std::get<0>(GetParam());
442+
unsigned nof_tx_ports = std::get<0>(GetParam());
442443
sampling_rate srate = std::get<1>(GetParam());
443-
subcarrier_spacing scs = std::get<2>(GetParam());
444-
cyclic_prefix cp = std::get<3>(GetParam());
444+
subcarrier_spacing scs = std::get<0>(std::get<2>(GetParam()));
445+
cyclic_prefix cp = std::get<1>(std::get<2>(GetParam()));
445446

446447
unsigned base_symbol_size = srate.get_dft_size(scs);
447448

@@ -451,11 +452,11 @@ TEST_P(LowerPhyDownlinkProcessorFixture, FlowLargeBuffer)
451452
// Create notifiers and connect.
452453
downlink_processor_notifier_spy downlink_proc_notifier_spy;
453454
pdxch_processor_notifier_spy pdxch_proc_notifier_spy;
454-
ul_processor->connect(downlink_proc_notifier_spy, pdxch_proc_notifier_spy);
455+
dl_processor->connect(downlink_proc_notifier_spy, pdxch_proc_notifier_spy);
455456

456-
downlink_processor_baseband& dl_proc_baseband = ul_processor->get_baseband();
457+
downlink_processor_baseband& dl_proc_baseband = dl_processor->get_baseband();
457458

458-
baseband_gateway_buffer_dynamic buffer(nof_rx_ports, 20 * base_symbol_size);
459+
baseband_gateway_buffer_dynamic buffer(nof_tx_ports, 20 * base_symbol_size);
459460

460461
// Reset timestamp.
461462
baseband_gateway_timestamp timestamp = 0;
@@ -534,10 +535,10 @@ TEST_P(LowerPhyDownlinkProcessorFixture, FlowLargeBuffer)
534535
// Test generation of baseband samples for discontinous timestamps.
535536
TEST_P(LowerPhyDownlinkProcessorFixture, DiscontinuousProcessing)
536537
{
537-
unsigned nof_rx_ports = std::get<0>(GetParam());
538+
unsigned nof_tx_ports = std::get<0>(GetParam());
538539
sampling_rate srate = std::get<1>(GetParam());
539-
subcarrier_spacing scs = std::get<2>(GetParam());
540-
cyclic_prefix cp = std::get<3>(GetParam());
540+
subcarrier_spacing scs = std::get<0>(std::get<2>(GetParam()));
541+
cyclic_prefix cp = std::get<1>(std::get<2>(GetParam()));
541542

542543
unsigned base_symbol_size = srate.get_dft_size(scs);
543544
unsigned cp_symbol_0_size = cp.get_length(0, scs).to_samples(srate.to_Hz());
@@ -546,13 +547,13 @@ TEST_P(LowerPhyDownlinkProcessorFixture, DiscontinuousProcessing)
546547
// Create notifiers and connect.
547548
downlink_processor_notifier_spy downlink_proc_notifier_spy;
548549
pdxch_processor_notifier_spy pdxch_proc_notifier_spy;
549-
ul_processor->connect(downlink_proc_notifier_spy, pdxch_proc_notifier_spy);
550+
dl_processor->connect(downlink_proc_notifier_spy, pdxch_proc_notifier_spy);
550551

551-
downlink_processor_baseband& dl_proc_baseband = ul_processor->get_baseband();
552+
downlink_processor_baseband& dl_proc_baseband = dl_processor->get_baseband();
552553

553554
// Create baseband buffers.
554-
baseband_gateway_buffer_dynamic buffer_symbol_0(nof_rx_ports, base_symbol_size);
555-
baseband_gateway_buffer_dynamic buffer_symbol_2(nof_rx_ports, base_symbol_size);
555+
baseband_gateway_buffer_dynamic buffer_symbol_0(nof_tx_ports, base_symbol_size);
556+
baseband_gateway_buffer_dynamic buffer_symbol_2(nof_tx_ports, base_symbol_size);
556557

557558
// Set an initial timestamp.
558559
baseband_gateway_timestamp timestamp_symbol_0 = 7;
@@ -622,11 +623,11 @@ TEST_P(LowerPhyDownlinkProcessorFixture, DiscontinuousProcessing)
622623
}
623624

624625
// Creates test suite that combines all possible parameters.
625-
INSTANTIATE_TEST_SUITE_P(LowerPhyDownlinkProcessor,
626-
LowerPhyDownlinkProcessorFixture,
627-
::testing::Combine(::testing::Values(1, 2),
628-
::testing::Values(sampling_rate::from_MHz(7.68)),
629-
::testing::Values(subcarrier_spacing::kHz15,
630-
subcarrier_spacing::kHz30,
631-
subcarrier_spacing::kHz60),
632-
::testing::Values(cyclic_prefix::NORMAL, cyclic_prefix::EXTENDED)));
626+
INSTANTIATE_TEST_SUITE_P(
627+
LowerPhyDownlinkProcessor,
628+
LowerPhyDownlinkProcessorFixture,
629+
::testing::Combine(::testing::Values(1, 4),
630+
::testing::Values(sampling_rate::from_MHz(7.68)),
631+
::testing::Values(std::make_tuple(subcarrier_spacing::kHz15, cyclic_prefix::NORMAL),
632+
std::make_tuple(subcarrier_spacing::kHz30, cyclic_prefix::NORMAL),
633+
std::make_tuple(subcarrier_spacing::kHz60, cyclic_prefix::EXTENDED))));

tests/unittests/phy/lower/processors/downlink/pdxch/pdxch_processor_test_doubles.h

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,36 @@ class pdxch_processor_baseband_spy : public pdxch_processor_baseband
3131
symbol_context context;
3232
};
3333

34-
pdxch_processor_baseband_spy() : sample_dist(-1, 1) {}
34+
pdxch_processor_baseband_spy() : random_data(1009)
35+
{
36+
std::mt19937 rgen;
37+
std::uniform_real_distribution<float> sample_dist(-1, 1);
38+
std::generate(random_data.begin(), random_data.end(), [&sample_dist, &rgen]() {
39+
return cf_t(sample_dist(rgen), sample_dist(rgen));
40+
});
41+
}
3542

3643
void process_symbol(baseband_gateway_buffer_writer& samples, const symbol_context& context) override
3744
{
38-
for (unsigned i_channel = 0, i_channel_end = samples.get_nof_channels(); i_channel != i_channel_end; ++i_channel) {
39-
span<cf_t> channel_samples = samples.get_channel_buffer(i_channel);
40-
std::generate(channel_samples.begin(), channel_samples.end(), [this]() {
41-
return cf_t(sample_dist(rgen), sample_dist(rgen));
42-
});
45+
// Counter for the remaining samples to generate.
46+
std::size_t remaining = samples.get_nof_samples();
47+
span<cf_t> random_data_view(random_data);
48+
49+
while (remaining > 0) {
50+
// Number of samples to copy for this iteration.
51+
unsigned nof_copied_samples = std::min(random_data.size() - random_data_index, remaining);
52+
span<cf_t> random_samples = random_data_view.subspan(random_data_index, nof_copied_samples);
53+
54+
for (unsigned i_ch = 0, i_channel_end = samples.get_nof_channels(); i_ch != i_channel_end; ++i_ch) {
55+
span<cf_t> channel_samples =
56+
samples.get_channel_buffer(i_ch).subspan(samples.get_nof_samples() - remaining, nof_copied_samples);
57+
58+
srsvec::copy(channel_samples, random_samples);
59+
}
60+
61+
// Update remaining samples and buffer index.
62+
remaining -= nof_copied_samples;
63+
random_data_index = (random_data_index + nof_copied_samples) % random_data.size();
4364
}
4465

4566
entries.emplace_back();
@@ -53,9 +74,9 @@ class pdxch_processor_baseband_spy : public pdxch_processor_baseband
5374
void clear() { entries.clear(); }
5475

5576
private:
56-
std::vector<entry_t> entries;
57-
std::mt19937 rgen;
58-
std::uniform_real_distribution<float> sample_dist;
77+
unsigned random_data_index = 0;
78+
std::vector<cf_t> random_data;
79+
std::vector<entry_t> entries;
5980
};
6081

6182
class pdxch_processor_request_handler_spy : public pdxch_processor_request_handler

0 commit comments

Comments
 (0)