Skip to content

Commit 8d2288f

Browse files
dvdgrgrttcodebot
authored andcommitted
tests: update resource_grid_doubles
Resource grid doubles was still using cf_t instead of cbf16_t. After introducing the change, some tests had to be updated, too.
1 parent 01cf2c2 commit 8d2288f

29 files changed

+273
-253
lines changed

tests/unittests/phy/lower/modulation/ofdm_demodulator_unittest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include <random>
1919

2020
/// Defines the maximum allowed error at the OFDM demodulator output.
21-
static constexpr float ASSERT_MAX_ERROR = 1e-6;
21+
static constexpr float ASSERT_MAX_ERROR = 1.0F / 128.0F;
2222

2323
using namespace srsran;
2424

tests/unittests/phy/lower/modulation/ofdm_demodulator_vectortest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "srsran/support/test_utils.h"
1616

1717
/// Defines the maximum allowed error at the OFDM demodulator output.
18-
static constexpr float ASSERT_MAX_ERROR = 1e-4;
18+
static constexpr float ASSERT_MAX_ERROR = 5e-3;
1919

2020
using namespace srsran;
2121

tests/unittests/phy/lower/modulation/ofdm_modulator_test_data.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#pragma once
1212

13-
// This file was generated using the following MATLAB class on 14-09-2023 (seed 0):
13+
// This file was generated using the following MATLAB class on 27-06-2024 (seed 0):
1414
// + "srsOFDMModulatorUnittest.m"
1515

1616
#include "srsran/phy/lower/modulation/ofdm_modulator.h"
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:dd54d4698778a45481639f3f3ab154f227c1d18d021a75f70ce8792d28540555
3-
size 5836917
2+
oid sha256:ea539026b2258f3f4f9eea4338435bed20e64a4a3eed866a3ad1533d1966f8b5
3+
size 5836965

tests/unittests/phy/lower/modulation/ofdm_modulator_vectortest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "srsran/support/test_utils.h"
1616

1717
/// Defines the maximum allowed error at the OFDM modulator output.
18-
static constexpr float ASSERT_MAX_ERROR = 2e-5;
18+
static constexpr float ASSERT_MAX_ERROR = 5e-5;
1919

2020
using namespace srsran;
2121

@@ -72,7 +72,7 @@ int main()
7272
float error =
7373
std::abs(output[i] - modulated[i]) / std::sqrt(static_cast<float>(test_case.test_config.config.dft_size));
7474
TESTASSERT(error < ASSERT_MAX_ERROR,
75-
"Sample index {} error {} exceeds maximum allowed ({}). Expedted symbol {} but got {}.",
75+
"Sample index {} error {} exceeds maximum allowed ({}). Expected symbol {} but got {}.",
7676
i,
7777
error,
7878
ASSERT_MAX_ERROR,

tests/unittests/phy/support/resource_grid_test_doubles.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "srsran/support/file_vector.h"
2424
#include "srsran/support/srsran_assert.h"
2525
#include "srsran/support/srsran_test.h"
26+
#include <complex>
2627
#include <map>
2728
#include <mutex>
2829
#include <random>
@@ -139,7 +140,7 @@ class resource_grid_writer_spy : public resource_grid_writer
139140
entry.symbol,
140141
entry.subcarrier);
141142

142-
cf_t value = entries.at(key);
143+
cf_t value = to_cf(entries.at(key));
143144
float err = std::abs(entry.value - value);
144145
TESTASSERT(err < ASSERT_MAX_ERROR, "Mismatched value {} but expected {}", value, entry.value);
145146
}
@@ -148,7 +149,7 @@ class resource_grid_writer_spy : public resource_grid_writer
148149
/// \brief Asserts that the mapped resource elements match with a list of expected entries.
149150
///
150151
/// This method asserts that mapped resource elements using the put() methods match a list of expected entries
151-
/// without considering any writing order, while using a parametrizable maximkum error threshold.
152+
/// without considering any writing order, while using a parametrizable maximum error threshold.
152153
///
153154
/// \param[in] expected_entries Provides a list of golden symbols to assert.
154155
/// \param[in] max_error Provides the maximum allowable error when comparing the data in the entries.
@@ -167,7 +168,7 @@ class resource_grid_writer_spy : public resource_grid_writer
167168
entry.symbol,
168169
entry.subcarrier);
169170

170-
cf_t value = entries.at(key);
171+
cf_t value = to_cf(entries.at(key));
171172
float err = std::abs(entry.value - value);
172173
TESTASSERT(err < max_error, "Mismatched value {} but expected {}", value, entry.value);
173174
}
@@ -191,7 +192,7 @@ class resource_grid_writer_spy : public resource_grid_writer
191192
static constexpr float ASSERT_MAX_ERROR = 1e-6;
192193

193194
/// Stores the resource grid written entries.
194-
std::map<entry_key_t, cf_t> entries;
195+
std::map<entry_key_t, cbf16_t> entries;
195196

196197
/// Protects concurrent write to entries.
197198
std::mutex entries_mutex;
@@ -244,7 +245,7 @@ class resource_grid_writer_spy : public resource_grid_writer
244245
entries.size() + 1);
245246

246247
// Write element.
247-
entries.emplace(key, value);
248+
entries.emplace(key, to_cbf16(value));
248249
}
249250
};
250251

@@ -277,7 +278,7 @@ class resource_grid_reader_spy : public resource_grid_reader
277278
{
278279
++count;
279280
mask.for_each(0, mask.size(), [&](unsigned i_subc) {
280-
symbols.front() = get(static_cast<uint8_t>(port), l, k_init + i_subc);
281+
symbols.front() = to_cf(get(static_cast<uint8_t>(port), l, k_init + i_subc));
281282
symbols = symbols.last(symbols.size() - 1);
282283
});
283284

@@ -306,7 +307,7 @@ class resource_grid_reader_spy : public resource_grid_reader
306307
++count;
307308
cf_t* symbol_ptr = symbols.data();
308309
for (unsigned k = k_init, k_end = k_init + stride * symbols.size(); k != k_end; k += stride) {
309-
*(symbol_ptr++) = get(port, l, k);
310+
*(symbol_ptr++) = to_cf(get(port, l, k));
310311
}
311312
}
312313

@@ -315,7 +316,7 @@ class resource_grid_reader_spy : public resource_grid_reader
315316
++count;
316317
cbf16_t* symbol_ptr = symbols.data();
317318
for (unsigned k = k_init, k_end = k_init + symbols.size(); k != k_end; ++k) {
318-
*(symbol_ptr++) = to_cbf16(get(port, l, k));
319+
*(symbol_ptr++) = get(port, l, k);
319320
}
320321
}
321322

@@ -328,7 +329,7 @@ class resource_grid_reader_spy : public resource_grid_reader
328329
std::fill(temp_view.begin(), temp_view.end(), to_cbf16(nan));
329330

330331
// Write the available entries.
331-
for (auto& e : entries) {
332+
for (const auto& e : entries) {
332333
if ((std::get<0>(e.first) == port) && (std::get<1>(e.first) == l)) {
333334
temp_view[std::get<2>(e.first)] = e.second;
334335
}
@@ -370,12 +371,12 @@ class resource_grid_reader_spy : public resource_grid_reader
370371
using entry_key_t = std::tuple<uint8_t, uint8_t, uint16_t>;
371372

372373
/// Stores the resource grid written entries.
373-
std::map<entry_key_t, cf_t> entries;
374+
std::map<entry_key_t, cbf16_t> entries;
374375

375376
/// Temporal storage of the method get_view(). It is overwritten every time get_view() is called.
376377
mutable std::vector<cbf16_t> temp_view;
377378

378-
cf_t get(uint8_t port, uint8_t symbol, uint16_t subcarrier) const
379+
cbf16_t get(uint8_t port, uint8_t symbol, uint16_t subcarrier) const
379380
{
380381
// Generate key.
381382
entry_key_t key{port, symbol, subcarrier};

tests/unittests/phy/upper/channel_processors/pbch_modulator_test.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ int main()
4040
// Load output golden data
4141
const std::vector<resource_grid_writer_spy::expected_entry_t> testvector_symbols = test_case.symbols.read();
4242

43+
// Tolerance: max BF16 error times sqrt(2), since we are taking the modulus.
44+
constexpr float tolerance = M_SQRT2f32 / 256.0;
4345
// Assert resource grid entries.
44-
grid.assert_entries(testvector_symbols);
46+
grid.assert_entries(testvector_symbols, tolerance);
4547
}
4648
return 0;
4749
}

tests/unittests/phy/upper/channel_processors/pdcch_modulator_test.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ int main()
5050
// Load output golden data
5151
const std::vector<resource_grid_writer_spy::expected_entry_t> testvector_symbols = test_case.symbols.read();
5252

53+
// Tolerance: max BF16 error times sqrt(2), since we are taking the modulus.
54+
constexpr float tolerance = M_SQRT2f32 / 256.0;
5355
// Assert resource grid entries.
54-
grid.assert_entries(testvector_symbols);
56+
grid.assert_entries(testvector_symbols, tolerance);
5557
}
5658

5759
return 0;

tests/unittests/phy/upper/channel_processors/pdcch_processor_vectortest.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,10 @@ TEST_P(PdcchProcessorFixture, FromVector)
100100
// Load output golden data
101101
const std::vector<resource_grid_writer_spy::expected_entry_t> expected = test_case.data.read();
102102

103+
// Tolerance: max BF16 error times sqrt(2), since we are taking the modulus.
104+
constexpr float tolerance = M_SQRT2f32 / 256.0;
103105
// Assert resource grid entries.
104-
grid.assert_entries(expected);
106+
grid.assert_entries(expected, tolerance);
105107
}
106108

107109
// Creates test suite that combines all possible parameters.

tests/unittests/phy/upper/channel_processors/pdsch_modulator_test.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,11 @@ int main()
6464
// Read resource grid data.
6565
std::vector<resource_grid_writer_spy::expected_entry_t> rg_entries = test_case.symbols.read();
6666

67+
// Tolerance: max BF16 error times sqrt(2), since we are taking the modulus.
68+
constexpr float tolerance = M_SQRT2f32 / 256.0;
6769
// Assert resource grid entries.
68-
grid.assert_entries(rg_entries);
70+
grid.assert_entries(rg_entries, tolerance);
6971
}
7072

7173
return 0;
72-
}
74+
}

0 commit comments

Comments
 (0)