e9057f16d0b642172842a1fdc578af22d34d2248
[o-du/phy.git] / fhi_lib / test / test_xran / u_plane_functional.cc
1 /******************************************************************************\r
2 *\r
3 *   Copyright (c) 2019 Intel.\r
4 *\r
5 *   Licensed under the Apache License, Version 2.0 (the "License");\r
6 *   you may not use this file except in compliance with the License.\r
7 *   You may obtain a copy of the License at\r
8 *\r
9 *       http://www.apache.org/licenses/LICENSE-2.0\r
10 *\r
11 *   Unless required by applicable law or agreed to in writing, software\r
12 *   distributed under the License is distributed on an "AS IS" BASIS,\r
13 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
14 *   See the License for the specific language governing permissions and\r
15 *   limitations under the License.\r
16 *\r
17 *******************************************************************************/\r
18 \r
19 \r
20 #include "common.hpp"\r
21 #include "xran_common.h"\r
22 #include "xran_up_api.h"\r
23 #include "xran_fh_o_du.h"\r
24 #include "ethernet.h"\r
25 \r
26 #include <stdint.h>\r
27 \r
28 const std::string module_name = "u-plane";\r
29 \r
30 class U_planeCheck : public KernelTests\r
31 {\r
32 protected:\r
33     struct rte_mbuf *test_buffer;\r
34     char * iq_offset;\r
35     struct rte_mempool *test_eth_mbuf_pool;\r
36 \r
37     void SetUp() override\r
38     {\r
39         init_test("u_plane_functional");\r
40         test_buffer = (struct rte_mbuf*)rte_pktmbuf_alloc(_eth_mbuf_pool);\r
41 \r
42         if(test_buffer == NULL) {\r
43             std::cout << __func__ << ":" << __LINE__ << " Failed to allocatte a packet buffer!" << std::endl;\r
44             return;\r
45         }\r
46         iq_offset = rte_pktmbuf_mtod(test_buffer, char * );\r
47         iq_offset = iq_offset + sizeof(struct ether_hdr) +\r
48                                     sizeof (struct xran_ecpri_hdr) +\r
49                                     sizeof (struct radio_app_common_hdr) +\r
50                                     sizeof(struct data_section_hdr);\r
51     }\r
52 \r
53     /* It's called after an execution of the each test case.*/\r
54     void TearDown() override\r
55     {\r
56         rte_pktmbuf_free(test_buffer);\r
57     }\r
58 };\r
59 \r
60 /* simple test of DL and UL functionality */\r
61 TEST_P(U_planeCheck, Test_DLUL)\r
62 {\r
63     enum xran_pkt_dir direction =  XRAN_DIR_DL;\r
64     uint16_t section_id = 7;\r
65     enum xran_input_byte_order iq_buf_byte_order = XRAN_CPU_LE_BYTE_ORDER;\r
66     uint8_t frame_id = 99;\r
67     uint8_t subframe_id  = 9;\r
68     uint8_t slot_id = 10;\r
69     uint8_t symbol_no = 7;\r
70     int prb_start = 0;\r
71     int prb_num = 66;\r
72     uint8_t CC_ID = 0;\r
73     uint8_t RU_Port_ID = 0;\r
74     uint8_t seq_id =0;\r
75     uint32_t do_copy = 0;\r
76     uint8_t compMeth = 0;\r
77     uint8_t iqWidth =  16;\r
78 \r
79     int32_t prep_bytes;\r
80     struct xran_ecpri_hdr *ecpri_hdr = NULL;\r
81     struct radio_app_common_hdr *app_hdr = NULL;\r
82     struct data_section_hdr *section_hdr = NULL;\r
83 \r
84     char *pChar = NULL;\r
85     uint16_t payl_size = 0;\r
86     struct data_section_hdr res_sect;\r
87 \r
88     prep_bytes = prepare_symbol_ex(direction,\r
89                                 section_id,\r
90                                 test_buffer,\r
91                                 (struct rb_map *)iq_offset,\r
92                                 compMeth,\r
93                                 iqWidth,\r
94                                 iq_buf_byte_order,\r
95                                 frame_id,\r
96                                 subframe_id,\r
97                                 slot_id,\r
98                                 symbol_no,\r
99                                 prb_start,\r
100                                 prb_num,\r
101                                 CC_ID,\r
102                                 RU_Port_ID,\r
103                                 seq_id,\r
104                                 do_copy);\r
105 \r
106     ASSERT_EQ(prep_bytes, 3168);\r
107 \r
108     pChar = rte_pktmbuf_mtod(test_buffer, char*);\r
109 \r
110     ecpri_hdr = (struct xran_ecpri_hdr *)(pChar + sizeof(struct ether_hdr));\r
111     app_hdr = (struct radio_app_common_hdr *)(pChar + sizeof(struct ether_hdr)\r
112                                               + sizeof (struct xran_ecpri_hdr));\r
113     section_hdr = (struct data_section_hdr *)(pChar + sizeof(struct ether_hdr) +\r
114                                             sizeof (struct xran_ecpri_hdr) +\r
115                                             sizeof(struct radio_app_common_hdr));\r
116 \r
117     ASSERT_EQ (ecpri_hdr->cmnhdr.ecpri_mesg_type,  ECPRI_IQ_DATA);\r
118     payl_size =  rte_be_to_cpu_16(ecpri_hdr->cmnhdr.ecpri_payl_size);\r
119     ASSERT_EQ (payl_size,  3180);\r
120 \r
121     ASSERT_EQ(app_hdr->data_direction, direction);\r
122     ASSERT_EQ(app_hdr->frame_id, frame_id);\r
123 \r
124     res_sect.fields.all_bits = rte_be_to_cpu_32(section_hdr->fields.all_bits);\r
125     ASSERT_EQ(res_sect.fields.num_prbu, prb_num);\r
126     ASSERT_EQ(res_sect.fields.sect_id, section_id);\r
127 \r
128     {\r
129         /* UL direction */\r
130         void *iq_samp_buf;\r
131         struct ecpri_seq_id seq;\r
132         int num_bytes = 0;\r
133 \r
134         uint8_t CC_ID = 0;\r
135         uint8_t Ant_ID = 0;\r
136         uint8_t frame_id = 0;\r
137         uint8_t subframe_id = 0;\r
138         uint8_t slot_id = 0;\r
139         uint8_t symb_id = 0;\r
140 \r
141         uint8_t compMeth = 0;\r
142         uint8_t iqWidth = 0;\r
143 \r
144 \r
145         uint16_t num_prbu;\r
146         uint16_t start_prbu;\r
147         uint16_t sym_inc;\r
148         uint16_t rb;\r
149         uint16_t sect_id;\r
150 \r
151         int32_t prep_bytes;\r
152 \r
153         char *pChar = NULL;\r
154 \r
155 \r
156         num_bytes = xran_extract_iq_samples(test_buffer,\r
157                                 &iq_samp_buf,\r
158                                 &CC_ID,\r
159                                 &Ant_ID,\r
160                                 &frame_id,\r
161                                 &subframe_id,\r
162                                 &slot_id,\r
163                                 &symb_id,\r
164                                 &seq,\r
165                                 &num_prbu,\r
166                                 &start_prbu,\r
167                                 &sym_inc,\r
168                                 &rb,\r
169                                 &sect_id,\r
170                                 0,\r
171                                 &compMeth,\r
172                                 &iqWidth);\r
173 \r
174         ASSERT_EQ(num_bytes, 3182);\r
175         ASSERT_EQ(prb_num, 66);\r
176         ASSERT_EQ(CC_ID, 0);\r
177     }\r
178 }\r
179 \r
180 INSTANTIATE_TEST_CASE_P(UnitTest, U_planeCheck,\r
181                         testing::ValuesIn(get_sequence(U_planeCheck::get_number_of_cases("u_plane_functional"))));\r
182 \r
183 \r