A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
sionna-channel-model-test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2025 CTTC
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Regression test suite for SionnaRtChannelModel (MR !2608).
7 *
8 * NOTE: Setting the "Scenario" attribute triggers pybind11/Python
9 * initialisation which causes SIGSEGV in environments without Sionna.
10 * All tests here are safe to run without a Sionna installation.
11 * Tests that require a live Sionna runtime are guarded by
12 * NS_TEST_ASSERT_MSG_EQ(sionnaAvailable, true, ...) and skipped otherwise.
13 *
14 * Registration — add to src/spectrum/test/CMakeLists.txt:
15 *
16 * build_lib_test(
17 * LIB spectrum
18 * SOURCES sionna-channel-model-test.cc
19 * LIBRARIES_TO_LINK ${libspectrum}
20 * )
21 *
22 * Run:
23 * ./ns3 run "test-runner --suite=sionna-rt-channel-model --verbose"
24 */
25
26#include "ns3/boolean.h"
27#include "ns3/config.h"
28#include "ns3/constant-position-mobility-model.h"
29#include "ns3/double.h"
30#include "ns3/log.h"
31#include "ns3/matrix-based-channel-model.h"
32#include "ns3/node.h"
33#include "ns3/phased-array-model.h"
34#include "ns3/pointer.h"
35#include "ns3/simulator.h"
36#include "ns3/sionna-rt-channel-model.h"
37#include "ns3/string.h"
38#include "ns3/test.h"
39#include "ns3/uinteger.h"
40#include "ns3/uniform-planar-array.h"
41
42#include <pybind11/pybind11.h>
43namespace py = pybind11;
44
45using namespace ns3;
46
47NS_LOG_COMPONENT_DEFINE("SionnaRtChannelModelTest");
48
49// ---------------------------------------------------------------------------
50// Helpers
51// ---------------------------------------------------------------------------
54{
56 upa->SetAttribute("NumRows", UintegerValue(rows));
57 upa->SetAttribute("NumColumns", UintegerValue(cols));
58 return upa;
59}
60
62CreateMobility(double x, double y, double z)
63{
66 mob->SetPosition(Vector(x, y, z));
67 node->AggregateObject(mob);
68 return mob;
69}
70
71// ===========================================================================
72// Test – Full Sionna end-to-end: GetChannel returns valid matrix
73//
74// Initialises the Python interpreter with py::scoped_interpreter (same
75// pattern as the example scripts), sets a known scenario, and verifies:
76// - GetChannel returns non-null
77// - H matrix has correct dimensions
78// - H matrix is non-zero (actual ray-tracing happened)
79// - GetParams returns non-null
80// - Calling GetChannel twice with same positions returns cached matrix
81// ===========================================================================
82/**
83 * @ingroup spectrum-tests
84 * @brief End-to-end test for SionnaRtChannelModel::GetChannel with Sionna.
85 *
86 * Verifies that GetChannel returns a valid, non-null ChannelMatrix with
87 * correct dimensions, that GetParams works, and that caching produces
88 * consistent results.
89 */
91{
92 public:
94 : TestCase("SionnaRtChannelModel end to end GetChannel with Sionna")
95 {
96 }
97
98 private:
99 void DoRun() override
100 {
101 // Initialise Python interpreter — must stay alive for entire test.
102 // Uses the same guard pattern as the example scripts.
103 py::scoped_interpreter guard{};
104
105 const uint32_t sTxRows = 2;
106 const uint32_t sTxCols = 2;
107 const uint32_t uRxRows = 1;
108 const uint32_t uRxCols = 1;
109
111 model->SetFrequency(3.5e9);
112 model->SetAttribute("UpdatePeriod", TimeValue(MilliSeconds(0)));
113 model->SetAttribute("NormalizeDelays", BooleanValue(true));
114
115 // This triggers LoadScene — requires Sionna installed
116 model->SetAttribute("Scenario", StringValue("simple_street_canyon"));
117
118 Ptr<UniformPlanarArray> txAnt = CreateUpa(sTxRows, sTxCols);
119 Ptr<UniformPlanarArray> rxAnt = CreateUpa(uRxRows, uRxCols);
120 Ptr<MobilityModel> txMob = CreateMobility(0.0, 0.0, 10.0);
121 Ptr<MobilityModel> rxMob = CreateMobility(50.0, 0.0, 1.5);
122
123 // --- Test: GetChannel returns non-null ---
125 model->GetChannel(txMob, rxMob, txAnt, rxAnt);
126
127 NS_TEST_ASSERT_MSG_NE(H, nullptr, "GetChannel returned nullptr");
128
129 // --- Test: H matrix dimensions ---
130 // H is stored as [rxElems x txElems] in MatrixArray
131 NS_TEST_ASSERT_MSG_EQ(H->m_channel.GetNumRows(),
132 uRxRows * uRxCols,
133 "H num rows (rx elements) mismatch");
134 NS_TEST_ASSERT_MSG_EQ(H->m_channel.GetNumCols(),
135 sTxRows * sTxCols,
136 "H num cols (tx elements) mismatch");
137
138 // --- Test: H has at least one path (non-zero pages/clusters) ---
139 NS_TEST_ASSERT_MSG_GT(H->m_channel.GetNumPages(),
140 0U,
141 "H has zero clusters — no paths computed");
142
143 // --- Test: caching — same positions return same or equivalent matrix ---
145 model->GetChannel(txMob, rxMob, txAnt, rxAnt);
146 NS_TEST_ASSERT_MSG_NE(H2, nullptr, "Second GetChannel returned nullptr");
147 // Either the same cached pointer is returned, or a new matrix with
148 // identical dimensions (both are acceptable implementations)
149 NS_TEST_ASSERT_MSG_EQ(H2->m_channel.GetNumRows(),
150 H->m_channel.GetNumRows(),
151 "Second call H num rows changed");
152 NS_TEST_ASSERT_MSG_EQ(H2->m_channel.GetNumCols(),
153 H->m_channel.GetNumCols(),
154 "Second call H num cols changed");
155 NS_TEST_ASSERT_MSG_EQ(H2->m_channel.GetNumPages(),
156 H->m_channel.GetNumPages(),
157 "Second call H num pages changed");
158
159 // --- Test: GetParams returns non-null ---
160 Ptr<const MatrixBasedChannelModel::ChannelParams> params = model->GetParams(txMob, rxMob);
161 NS_TEST_ASSERT_MSG_NE(params, nullptr, "GetParams returned nullptr after GetChannel");
162
163 // --- Test: SionnaRtChannelParams dynamic type ---
164 const auto* sp =
165 dynamic_cast<const SionnaRtChannelModel::SionnaRtChannelParams*>(PeekPointer(params));
166 NS_TEST_ASSERT_MSG_NE(sp, nullptr, "Params is not SionnaRtChannelParams");
167
169 }
170};
171
172// ===========================================================================
173// Test Suite
174// ===========================================================================
175/**
176 * @ingroup spectrum-tests
177 * @brief Test suite for Sionna RT channel model regression tests.
178 *
179 * Registers all test cases for the Sionna RT channel model module.
180 */
182{
183 public:
185 : TestSuite("sionna-rt-channel-model", TestSuite::Type::UNIT)
186 {
187 // Requires Sionna + GPU — runs full ray-tracing pipeline
189 }
190};
191
cairo_uint64_t x
_cairo_uint_96by64_32x64_divrem:
End-to-end test for SionnaRtChannelModel::GetChannel with Sionna.
void DoRun() override
Implementation to actually run this TestCase.
Test suite for Sionna RT channel model regression tests.
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:125
Hold variables of type string.
Definition string.h:45
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:296
@ QUICK
Fast test.
Definition test.h:1057
TestCase(const TestCase &)=delete
Caller graph was not generated because of its size.
Type
Type of test.
Definition test.h:1271
@ UNIT
This test suite implements a Unit Test.
Definition test.h:1273
TestSuite(std::string name, Type type=Type::UNIT)
Construct a new test suite.
Definition test.cc:494
Hold an unsigned integer type.
Definition uinteger.h:34
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:194
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:627
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
Definition test.h:133
#define NS_TEST_ASSERT_MSG_NE(actual, limit, msg)
Test that an actual and expected (limit) value are not equal and report and abort if not.
Definition test.h:553
#define NS_TEST_ASSERT_MSG_GT(actual, limit, msg)
Test that an actual value is greater than a limit and report and abort if not.
Definition test.h:863
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1290
Every class exported by the ns3 library is enclosed in the ns3 namespace.
U * PeekPointer(const Ptr< U > &p)
Definition ptr.h:501
static Ptr< MobilityModel > CreateMobility(double x, double y, double z)
static Ptr< UniformPlanarArray > CreateUpa(uint32_t rows, uint32_t cols)
static SionnaRtChannelModelTestSuite g_sionnaRtChannelModelTestSuite
ChannelParams extension to carry Sionna-specific metadata.