-
Notifications
You must be signed in to change notification settings - Fork 14
/
srsPDSCHModulatorUnittest.m
185 lines (155 loc) · 8.21 KB
/
srsPDSCHModulatorUnittest.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
%srsPDSCHModulatorUnittest Unit tests for PDSCH symbol modulator functions.
% This class implements unit tests for the PDSCH symbol modulator functions using the
% matlab.unittest framework. The simplest use consists in creating an object with
% testCase = srsPDSCHModulatorUnittest
% and then running all the tests with
% testResults = testCase.run
%
% srsPDSCHModulatorUnittest Properties (Constant):
%
% srsBlock - The tested block (i.e., 'pdsch_modulator').
% srsBlockType - The type of the tested block, including layer
% (i.e., 'phy/upper/channel_processors/pdsch').
%
% srsPDSCHModulatorUnittest Properties (ClassSetupParameter):
%
% outputPath - Path to the folder where the test results are stored.
%
% srsPDSCHModulatorUnittest Properties (TestParameter):
%
% SymbolAllocation - Symbols allocated to the PDSCH transmission.
% Modulation - Modulation scheme.
% NumLayers - Number of transmission layers.
%
% srsPDSCHModulatorUnittest Methods (TestTags = {'testvector'}):
%
% testvectorGenerationCases - Generates a test vector according to the provided
% parameters.
%
% srsPDSCHModulatorUnittest Methods (Access = protected):
%
% addTestIncludesToHeaderFile - Adds include directives to the test header file.
% addTestDefinitionToHeaderFile - Adds details (e.g., type/variable declarations)
% to the test header file.
%
% See also matlab.unittest.
% Copyright 2021-2024 Software Radio Systems Limited
%
% This file is part of srsRAN-matlab.
%
% srsRAN-matlab is free software: you can redistribute it and/or
% modify it under the terms of the BSD 2-Clause License.
%
% srsRAN-matlab is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% BSD 2-Clause License for more details.
%
% A copy of the BSD 2-Clause License can be found in the LICENSE
% file in the top-level directory of this distribution.
classdef srsPDSCHModulatorUnittest < srsTest.srsBlockUnittest
properties (Constant)
%Name of the tested block.
srsBlock = 'pdsch_modulator'
%Type of the tested block.
srsBlockType = 'phy/upper/channel_processors/pdsch'
end
properties (ClassSetupParameter)
%Path to results folder (old 'pdsch_modulator' tests will be erased).
outputPath = {['testPDSCHModulator', char(datetime('now', 'Format', 'yyyyMMdd''T''HHmmss'))]}
end
properties (TestParameter)
%Symbols allocated to the PDSCH transmission. The symbol allocation is described
% by a two-element array with the starting symbol (0...13) and the length (1...14)
% of the PDSCH transmission. Example: [0, 14].
SymbolAllocation = {[0, 14], [1, 13], [2, 12]}
%Modulation scheme ('QPSK', '16QAM', '64QAM', '256QAM').
Modulation = {'QPSK', '16QAM', '64QAM', '256QAM'}
%Number of transmission layers (1, 2, 4).
NumLayers = {1, 2, 4}
end
methods (Access = protected)
function addTestIncludesToHeaderFile(~, fileID)
%addTestIncludesToHeaderFile Adds include directives to the test header file.
fprintf(fileID, '#include "../../../support/resource_grid_test_doubles.h"\n');
fprintf(fileID, '#include "srsran/phy/upper/channel_processors/pdsch/pdsch_modulator.h"\n');
fprintf(fileID, '#include "srsran/ran/precoding/precoding_codebooks.h"\n');
fprintf(fileID, '#include "srsran/support/file_vector.h"\n');
end
function addTestDefinitionToHeaderFile(obj, fileID)
%addTestDetailsToHeaderFile Adds details (e.g., type/variable declarations) to the test header file.
addTestDefinitionToHeaderFilePHYchproc(obj, fileID);
end
end % of methods (Access = protected)
methods (Test, TestTags = {'testvector'})
function testvectorGenerationCases(testCase, SymbolAllocation, Modulation, NumLayers)
%testvectorGenerationCases Generates a test vector for the given SymbolAllocation,
% Modulation scheme and number of layers. Other parameters (e.g.,
% the RNTI) are generated randomly.
import srsLib.phy.helpers.srsGetBitsSymbol
import srsLib.phy.helpers.srsModulationFromMatlab
import srsLib.phy.upper.channel_processors.srsPDSCHmodulator
import srsLib.phy.upper.signal_processors.srsPDSCHdmrs
import srsTest.helpers.array2str
import srsTest.helpers.rbAllocationIndexes2String
import srsTest.helpers.symbolAllocationMask2string
import srsTest.helpers.writeResourceGridEntryFile
import srsTest.helpers.writeUint8File
% Generate a unique test ID.
testID = testCase.generateTestID;
% Generate default carrier configuration.
carrier = nrCarrierConfig;
% Configure the PDSCH according to the test parameters.
pdsch = nrPDSCHConfig( ...
SymbolAllocation=SymbolAllocation, ...
Modulation=Modulation, ...
NumLayers=NumLayers ...
);
% Set randomized values.
pdsch.NID = randi([1, 1023]);
pdsch.RNTI = randi([1, 65535]);
modOrder1 = srsGetBitsSymbol(pdsch.Modulation);
modString1 = srsModulationFromMatlab(pdsch.Modulation, 'full');
% Calculate number of encoded bits.
nBits = length(nrPDSCHIndices(carrier, pdsch, "IndexStyle", "subscript")) * modOrder1;
% Generate codewords.
cws = randi([0,1], nBits, 1);
% Write the DLSCH cw to a binary file.
testCase.saveDataFile('_test_input', testID, @writeUint8File, cws);
% Call the PDSCH symbol modulation Matlab functions.
[modulatedSymbols, symbolIndices] = srsPDSCHmodulator(carrier, pdsch, cws);
% Write each complex symbol into a binary file, and the associated indices to another.
testCase.saveDataFile('_test_output', testID, ...
@writeResourceGridEntryFile, modulatedSymbols, symbolIndices);
% Generate DMRS symbol mask.
[~, symbolIndices] = srsPDSCHdmrs(carrier, pdsch);
dmrsSymbolMask = symbolAllocationMask2string(symbolIndices);
% Generate the test case entry.
reservedString = '{}';
RBAllocationString = rbAllocationIndexes2String(pdsch.PRBSet);
DMRSTypeString = sprintf('dmrs_type::TYPE%d', pdsch.DMRS.DMRSConfigurationType);
precodingString = ['precoding_configuration::make_wideband(make_identity(' num2str(NumLayers) '))'];
configCell = {...
pdsch.RNTI,... % rnti
carrier.NSizeGrid, ... % bwp_size_rb
carrier.NStartGrid, ... % bwp_start_rb
modString1, ... % modulation1
modString1, ... % modulation2
RBAllocationString, ... % freq_allocation
pdsch.SymbolAllocation(1), ... % start_symbol_index
pdsch.SymbolAllocation(2), ... % nof_symbols
dmrsSymbolMask, ... % dmrs_symb_pos
DMRSTypeString, ... % dmrs_config_type
pdsch.DMRS.NumCDMGroupsWithoutData, ... % nof_cmd_groups_without_data
pdsch.NID, ... % n_id
1.0, ... % scaling
reservedString, ... % reserved
precodingString... % precoding
};
testCaseString = testCase.testCaseToString(testID, configCell, true, ...
'_test_input', '_test_output');
% Add the test to the file header.
testCase.addTestToHeaderFile(testCase.headerFileID, testCaseString);
end % of function testvectorGenerationCases
end % of methods (Test, TestTags = {'testvector'})
end % of classdef srsPDSCHModulatorUnittest