Front Haul Interface Library update to third seed code contribution
[o-du/phy.git] / fhi_lib / test / test_xran / prach_performance.cc
1 /******************************************************************************
2 *
3 *   Copyright (c) 2019 Intel.
4 *
5 *   Licensed under the Apache License, Version 2.0 (the "License");
6 *   you may not use this file except in compliance with the License.
7 *   You may obtain a copy of the License at
8 *
9 *       http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *   Unless required by applicable law or agreed to in writing, software
12 *   distributed under the License is distributed on an "AS IS" BASIS,
13 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *   See the License for the specific language governing permissions and
15 *   limitations under the License.
16 *
17 *******************************************************************************/
18
19
20 #include "common.hpp"
21 #include "xran_common.h"
22 #include "xran_fh_o_du.h"
23 #include "ethernet.h"
24 #include "xran_transport.h"
25 #include "xran_cp_api.h"
26
27 #include <stdint.h>
28
29
30 const std::string module_name = "Prach_test";
31
32
33 class PrachPerf : public KernelTests
34 {
35
36         private:
37     struct xran_section_gen_info *m_pSectResult = NULL;
38
39         protected:
40                 struct xran_fh_config m_xranConf;
41                 struct xran_device_ctx m_xran_dev_ctx;
42                 struct xran_prach_config *m_pPRACHConfig;
43                 struct xran_prach_cp_config  *m_pPrachCPConfig;
44
45     struct xran_section_gen_info *m_pSectGenInfo = NULL;
46     int m_maxSections = 8;  /*  not used */
47     int lastsymbol;
48
49     struct rte_mbuf *m_pTestBuffer;
50
51     struct xran_cp_gen_params m_params;
52     struct xran_recv_packet_info m_pktInfo;
53     struct xran_cp_gen_params m_result;
54
55     uint8_t     m_dir;
56     std::string m_dirStr;
57     uint8_t     m_sectionType;
58
59     uint8_t     m_ccId, m_antId;
60     uint8_t     m_seqId;
61     uint8_t     m_frameId, m_subframeId, m_slotId;
62     uint8_t     m_symStart, m_symNum;
63     uint16_t    *m_prbStart = NULL, *m_prbNum = NULL;
64
65     uint8_t     m_iqWidth, m_compMethod;
66     uint16_t    m_beamId;
67     uint16_t    m_reMask = 0xfff;
68     uint16_t    m_sectionId;
69     uint8_t     m_filterIndex;
70     //uint16_t    m_timeOffset;
71     uint8_t     m_fftSize;
72
73                 //define reference values
74         uint8_t     m_startSymId;
75         uint8_t     m_x;
76                 uint8_t         m_filterIdx;
77                 uint16_t        m_startPrbc;
78                 uint8_t         m_numPrbc;
79                 uint8_t         m_numSymbol;
80                 uint16_t        m_timeOffset;
81                 int32_t         m_freqOffset;
82                 uint8_t         m_nrofPrachInSlot;
83                 uint8_t         m_occassionsInPrachSlot;
84                 uint8_t         m_y[XRAN_PRACH_CANDIDATE_Y];
85                 uint8_t     m_isPRACHslot[XRAN_PRACH_CANDIDATE_SLOT];
86                 int             m_prach_start_symbol;
87                 int                     m_prach_last_symbol;
88                 uint8_t     m_SlotNrNum;
89
90
91         void SetUp() override
92   {
93         init_test("prach_performance");
94                 memset(&m_xranConf, 0, sizeof(struct xran_fh_config));
95                 memset(&m_xran_dev_ctx, 0, sizeof(struct xran_device_ctx));
96                 m_pPRACHConfig = &m_xranConf.prach_conf;
97                 m_pPrachCPConfig = &m_xran_dev_ctx.PrachCPConfig;
98
99                 //initialize input parameters
100         m_xranConf.frame_conf.nNumerology = get_input_parameter<uint8_t>("Numerology");
101         m_xranConf.frame_conf.nFrameDuplexType = get_input_parameter<uint8_t>("FrameDuplexType");
102         m_xranConf.log_level = get_input_parameter<uint32_t>("loglevel");
103
104         m_pPRACHConfig->nPrachConfIdx = get_input_parameter<uint8_t>("PrachConfIdx");
105         m_pPRACHConfig->nPrachFreqStart = get_input_parameter<uint16_t>("PrachFreqStart");
106         m_pPRACHConfig->nPrachFreqOffset = get_input_parameter<int32_t>("PrachFreqOffset");
107         m_pPRACHConfig->nPrachSubcSpacing = get_input_parameter<uint8_t>("PrachSubcSpacing");
108
109
110         m_frameId = get_input_parameter<uint8_t>("frameId");
111         m_subframeId = get_input_parameter<uint8_t>("subframeId");
112         m_slotId = get_input_parameter<uint8_t>("slotId");
113         m_beamId = get_input_parameter<uint16_t>("beamId");
114         m_ccId = get_input_parameter<uint8_t>("ccId");
115         m_antId = get_input_parameter<uint8_t>("antId");
116
117                 //initialize reference output
118         m_startSymId = get_reference_parameter<uint8_t>("startSymId");
119         m_x = get_reference_parameter<uint8_t>("x_value");
120                 m_filterIdx = get_reference_parameter<uint8_t>("filterIdx");
121         m_startPrbc = get_reference_parameter<uint16_t>("startPrbc");
122                 m_numPrbc = get_reference_parameter<uint8_t>("numPrbc");
123         m_timeOffset = get_reference_parameter<uint16_t>("timeOffset");
124                 m_freqOffset = get_reference_parameter<uint32_t>("freqOffset");
125         m_nrofPrachInSlot = get_reference_parameter<uint8_t>("nrofPrachInSlot");
126
127                 //get the values from a vector
128                 std::vector<uint8_t> y_vec = get_reference_parameter<std::vector<uint8_t>>("y_value");
129                 for(int i=0; i < XRAN_PRACH_CANDIDATE_Y; i++) {
130             m_y[i] = y_vec[i];
131         }
132
133         m_numSymbol = get_reference_parameter<uint8_t>("numSymbol");
134                 m_occassionsInPrachSlot = get_reference_parameter<uint8_t>("occassionsInPrachSlot");
135
136                 std::vector<uint8_t> index_vec = get_reference_parameter<std::vector<uint8_t>>("isPRACHslot");
137                 m_SlotNrNum = get_reference_parameter<uint8_t>("SlotNrNum");
138                 for(int i = 0; i < XRAN_PRACH_CANDIDATE_SLOT; i++){
139                         m_isPRACHslot[i]=0;
140                 }
141                 for(int i=0; i<m_SlotNrNum;i++){
142                         m_isPRACHslot[index_vec[i]]=1;
143                 }
144
145
146                 m_prach_start_symbol = get_reference_parameter<int>("prach_start_symbol");
147                 m_prach_last_symbol = get_reference_parameter<int>("prach_last_symbol");
148
149         /* allocate and prepare required data storage */
150         m_pSectGenInfo = new struct xran_section_gen_info[8];
151         ASSERT_NE(m_pSectGenInfo, nullptr);
152         m_params.sections = m_pSectGenInfo;
153
154         /* allocating an mbuf for packet generatrion */
155         m_pTestBuffer = (struct rte_mbuf*)rte_pktmbuf_alloc(_eth_mbuf_pool);
156         ASSERT_FALSE(m_pTestBuffer == NULL);
157
158     }
159
160     void TearDown() override
161     {
162
163                 if(m_pTestBuffer != NULL)
164                         rte_pktmbuf_free(m_pTestBuffer);
165                 if(m_pSectGenInfo)
166                         delete[] m_pSectGenInfo;
167
168                 return;
169     }
170 };
171
172 void performance_cp(void *pHandle,struct xran_cp_gen_params *params, struct xran_section_gen_info *sect_geninfo, struct xran_device_ctx *pxran_lib_ctx,
173                 uint8_t frame_id, uint8_t subframe_id, uint8_t slot_id,
174                 uint16_t beam_id, uint8_t cc_id, uint8_t prach_port_id, uint8_t seq_id)
175 {
176         struct rte_mbuf *mbuf;
177
178     mbuf = (struct rte_mbuf*)rte_pktmbuf_alloc(_eth_mbuf_pool);
179
180     generate_cpmsg_prach(pHandle, params, sect_geninfo, mbuf, pxran_lib_ctx,
181         frame_id, subframe_id, slot_id,
182         beam_id, cc_id, prach_port_id, seq_id);
183
184     seq_id++;
185
186     rte_pktmbuf_free(mbuf);
187 }
188
189 TEST_P(PrachPerf, PacketGen)//TestCaseName   TestName
190 {
191     int ret;
192     void *pHandle = NULL;
193
194     /* Preparing input data for prach config */
195         ret = xran_init_prach(&m_xranConf, &m_xran_dev_ctx);
196     ASSERT_TRUE(ret == XRAN_STATUS_SUCCESS);
197
198
199     ret = generate_cpmsg_prach(pHandle, &m_params, m_pSectGenInfo, m_pTestBuffer, &m_xran_dev_ctx,
200         m_frameId, m_subframeId, m_slotId,
201         m_beamId, m_ccId, m_antId, 0);
202     ASSERT_TRUE(ret == XRAN_STATUS_SUCCESS);
203
204
205         performance("C", module_name,
206             &performance_cp, pHandle, &m_params, m_pSectGenInfo, &m_xran_dev_ctx,
207         m_frameId, m_subframeId, m_slotId,
208         m_beamId, m_ccId, m_antId, 0);
209 }
210
211
212 INSTANTIATE_TEST_CASE_P(UnitTest, PrachPerf,
213         testing::ValuesIn(get_sequence(PrachPerf::get_number_of_cases("prach_performance"))));
214