8 """This script run test cases with O-DU and O-RU 17 from itertools
import dropwhile
18 from datetime
import datetime
23 [25, 52, 79, 106, 133, 160, 216, 270, 0, 0, 0, 0, 0],
24 [11, 24, 38, 51, 65, 78, 106, 133, 162, 0, 217, 245, 273],
25 [0, 11, 18, 24, 31, 38, 51, 65, 79, 0, 107, 121, 135]
35 nRChBwOptions_keys = [
'5',
'10',
'15',
'20',
'25',
'30',
'40',
'50',
'60',
'70',
'80',
'90',
'100',
'200',
'400']
36 nRChBwOptions_values = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14]
37 nRChBwOptions = dict(zip(nRChBwOptions_keys, nRChBwOptions_values))
39 nRChBwOptions_keys_mu2and3 = [
'50',
'100',
'200',
'400']
40 nRChBwOptions_values_mu2and3 = [0,1,2,3]
41 nRChBwOptions_mu2and3 = dict(zip(nRChBwOptions_keys_mu2and3, nRChBwOptions_values_mu2and3))
45 all_test_cases = [(0, 0, 5, 0),
52 """ all_test_cases = [(1, 1, 100, 0), 59 #(1, 1, 100, 106), 25G not enough 62 #(1, 1, 100, 109), 25G not enough 64 #(1, 1, 100, 202), 25G not enough 70 #(1, 1, 100, 212), 25G not enough 77 dic_dir = dict({0:
'DL', 1:
'UL'})
78 dic_xu = dict({0:
'o-du', 1:
'o-ru'})
81 """Initializes console and logfile logger with given logging levels""" 83 logging.basicConfig(filename=
"runtests.log",
85 format=
"%(asctime)s: %(levelname)s: %(message)s",
88 logger = logging.getLogger()
89 handler = logging.StreamHandler()
90 handler.setLevel(console_level)
91 formatter = logging.Formatter(
"%(levelname)s: %(message)s")
92 handler.setFormatter(formatter)
93 logger.addHandler(handler)
96 """Configures parser and parses command line configuration""" 98 parser = argparse.ArgumentParser(description=
"Run test cases: category numerology bandwidth test_num")
100 parser.add_argument(
"--cat", type=int, default=0, help=
"Category: 0 (A) or 1 (B)", metavar=
"cat", dest=
"category")
101 parser.add_argument(
"--mu", type=int, default=0, help=
"numerology [0,1,3]", metavar=
"num", dest=
"numerology")
102 parser.add_argument(
"--bw", type=int, default=20, help=
"bandwidth [5,10,20,100]", metavar=
"bw", dest=
"bandwidth")
103 parser.add_argument(
"--testcase", type=int, default=0, help=
"test case number", metavar=
"testcase", dest=
"testcase")
106 options = parser.parse_args(args)
108 logging.debug(
"Options: category=%d num=%d bw=%d testcase=%d",
109 options.category, options.numerology, options.bandwidth, options.testcase)
113 """ function to check if a line 114 starts with some character. 118 return s.startswith(
'#')
127 nDlRB = nNumRbsPerSymF1[mu][nRChBwOptions.get(str(nDLBandwidth))]
128 nUlRB = nNumRbsPerSymF1[mu][nRChBwOptions.get(str(nULBandwidth))]
129 elif (mu >=2) & (mu <= 3):
130 nDlRB = nNumRbsPerSymF2[mu - 2][nRChBwOptions_mu2and3.get(str(nDLBandwidth))]
131 nUlRB = nNumRbsPerSymF2[mu - 2][nRChBwOptions_mu2and3.get(str(nULBandwidth))]
134 print(
"Incorrect arguments\n")
138 if 'compression' in globals():
143 print(
"compare results: {} [compression {}]\n".format(dic_dir.get(direction), comp))
150 if nFrameDuplexType == 1:
152 for i
in range(nTddPeriod):
154 SlotConfig.insert(i, sSlotConfig0)
156 SlotConfig.insert(i, sSlotConfig1)
158 SlotConfig.insert(i, sSlotConfig2)
160 SlotConfig.insert(i, sSlotConfig3)
162 SlotConfig.insert(i, sSlotConfig4)
164 SlotConfig.insert(i, sSlotConfig5)
166 SlotConfig.insert(i, sSlotConfig6)
168 SlotConfig.insert(i, sSlotConfig7)
170 SlotConfig.insert(i, sSlotConfig8)
172 SlotConfig.insert(i, sSlotConfig9)
174 raise Exception(
'i should not exceed nTddPeriod %d. The value of i was: {}'.format(nTddPeriod, i))
178 if (direction == 1) & (cat == 1):
179 flowId = ccNum*antNumUL
181 flowId = ccNum*antNum
183 for i
in range(0, flowId):
190 file_tst = xran_path+
"/app/logs/"+
"o-ru-rx_log_ant"+str(i)+
".txt" 191 file_ref = xran_path+
"/app/logs/"+
"o-du-play_ant"+str(i)+
".txt" 195 file_tst = xran_path+
"/app/logs/"+
"o-du-rx_log_ant"+str(i)+
".txt" 196 file_ref = xran_path+
"/app/logs/"+
"o-ru-play_ant"+str(i)+
".txt" 198 raise Exception(
'Direction is not supported %d'.format(direction))
200 print(
"test result :", file_tst)
201 print(
"test reference:", file_ref)
202 if os.path.exists(file_tst):
204 file_tst = open(file_tst,
'r') 206 print (
"Could not open/read file:", file_tst)
209 print(file_tst,
"doesn't exist")
212 if os.path.exists(file_ref):
214 file_ref = open(file_ref,
'r') 216 print (
"Could not open/read file:", file_ref)
219 print(file_tst,
"doesn't exist")
223 tst = file_tst.readlines()
224 ref = file_ref.readlines()
234 for slot_idx
in range(0, numSlots):
235 for sym_idx
in range(0, 14):
236 if nFrameDuplexType==1:
240 sym_dir = SlotConfig[slot_idx%nTddPeriod][sym_idx]
245 sym_dir = SlotConfig[slot_idx%nTddPeriod][sym_idx]
250 for line_idx
in range(0, nRB*12):
251 offset = (slot_idx*nRB*12*14) + sym_idx*nRB*12 + line_idx
252 line_tst = tst[offset].rstrip()
253 line_ref = ref[offset].rstrip()
256 tst_i_value = int(line_tst.split(
" ")[0]) & 0xFF80
257 tst_q_value = int(line_tst.split(
" ")[1]) & 0xFF80
258 ref_i_value = int(line_ref.split(
" ")[0]) & 0xFF80
259 ref_q_value = int(line_ref.split(
" ")[1]) & 0xFF80
261 print(
"check:",
"ant:[",i,
"]:",offset, slot_idx, sym_idx, line_idx,
":",
"tst: ", tst_i_value,
" ", tst_q_value,
" " ,
"ref: ", ref_i_value,
" ", ref_q_value,
" ")
262 if (tst_i_value != ref_i_value)
or (tst_q_value != ref_q_value) :
263 print(
"FAIL:",
"ant:[",i,
"]:",offset, slot_idx, sym_idx, line_idx,
":",
"tst: ", tst_i_value,
" ", tst_q_value,
" " ,
"ref: ", ref_i_value,
" ", ref_q_value,
" ")
269 if line_ref != line_tst:
270 print(
"FAIL:",
"ant:[",i,
"]:",offset, slot_idx, sym_idx, line_idx,
":",
"tst:", line_tst,
"ref:", line_ref)
273 except GetOutOfLoops:
280 logging.info(
"parse config files %s\n", test_cfg[0])
283 with open(test_cfg[0],
'r') as fh: 284 for curline
in dropwhile(is_comment, fh):
285 my_line = curline.rstrip().split(sep, 1)[0].strip()
287 lineList.append(my_line)
291 for line
in lineList:
292 exe_line = line.replace(
":",
",")
293 if exe_line.find(
"/") > 0 :
294 exe_line = exe_line.replace(
'./',
"'")
295 exe_line = exe_line+
"'" 297 code = compile(str(exe_line),
'<string>',
'exec')
298 exec (code, global_env, local_env)
300 for k, v
in local_env.items():
309 src_bin = xran_path+
"/app/mlog-o-du-c0.bin" 310 src_csv = xran_path+
"/app/mlog-o-du-hist.csv" 311 dst_bin = xran_path+
"/app/mlog-o-du-c0-cat"+str(cat)+
"-mu"+str(mu)+
"-bw"+str(bw)+
"-tcase"+str(tcase)+
".bin" 312 dst_csv = xran_path+
"/app/mlog-o-du-hist-cat"+str(cat)+
"-mu"+str(mu)+
"-bw"+str(bw)+
"-tcase"+str(tcase)+
".csv" 315 d_bin = shutil.copyfile(src_bin, dst_bin)
316 d_csv = shutil.copyfile(src_csv, dst_csv)
318 logging.info(
"MLog is not present\n")
321 logging.info(
"Mlog was copied\n")
323 print(
"Destination path:", d_bin)
324 print(
"Destination path:", d_csv)
326 d_bin = shutil.copyfile(src_bin, dst_bin)
327 d_csv = shutil.copyfile(src_csv, dst_csv)
335 src_bin = xran_path+
"/app/mlog-o-ru-c0.bin" 336 src_csv = xran_path+
"/app/mlog-o-ru-hist.csv" 337 dst_bin = xran_path+
"/app/mlog-o-ru-c0-cat"+str(cat)+
"-mu"+str(mu)+
"-bw"+str(bw)+
"-tcase"+str(tcase)+
".bin" 338 dst_csv = xran_path+
"/app/mlog-o-ru-hist-cat"+str(cat)+
"-mu"+str(mu)+
"-bw"+str(bw)+
"-tcase"+str(tcase)+
".csv" 340 d_bin = shutil.copyfile(src_bin, dst_bin)
341 d_csv = shutil.copyfile(src_csv, dst_csv)
350 d_bin = shutil.copyfile(src_bin, dst_bin)
351 d_csv = shutil.copyfile(src_csv, dst_csv)
353 logging.info(
"MLog is not present\n")
356 logging.info(
"Mlog was copied\n")
369 test_config = xran_path+
"/app/usecase/cat_b/mu{0:d}_{1:d}mhz".format(mu, bw)
371 test_config = xran_path+
"/app/usecase/mu{0:d}_{1:d}mhz".format(mu, bw)
373 print(
"Incorrect arguments\n")
376 test_config = test_config+
"/"+str(tcase)
378 app = xran_path+
"/app/build/sample-app" 380 logging.debug(
"run: %s %s", app, test_config)
381 logging.debug(
"Started script: master.py, XRAN path %s", xran_path)
385 eth_cp_dev = [
"0000:22:02.1",
"0000:22:0a.1"]
386 eth_up_dev = [
"0000:22:02.0",
"0000:22:0a.0"]
388 test_cfg.append(test_config+
"/config_file_o_du.dat")
389 test_cfg.append(test_config+
"/config_file_o_ru.dat")
392 os.chdir(xran_path+
"/app/")
398 os.system(
'rm -rf ./logs')
401 log_file_name.append(
"sampleapp_log_{}_cat_{}_mu{}_{}mhz_tst_{}.log".format(dic_xu.get(i),cat, mu, bw, tcase))
402 with open(log_file_name[i],
"w")
as f:
404 p = subprocess.Popen([app, test_cfg[i], eth_up_dev[i], eth_cp_dev[i]], stdout=f, stderr=f)
405 logfile_xu.insert(i, f)
406 processes.append((p, logfile_xu[i]))
408 logging.info(
"Running O-DU and O-RU see output in: %s %s\n", logfile_xu[0].name, logfile_xu[1].name)
409 for p, f
in processes:
412 if p.returncode != 0:
413 print(
"Application {} failed p.returncode:{}".format(dic_xu.get(i), p.returncode))
415 logging.info(
"FAIL\n")
417 sys.exit(p.returncode)
421 logging.info(
"O-DU and O-RU are done\n")
425 usecase_cfg =
parse_dat_file(cat, mu, bw, tcase, xran_path, test_cfg)
445 test_executed_total = 0
451 """Processes input files to produce IACA files""" 453 xran_path = os.getenv(
"XRAN_DIR")
457 logging.info(
"Started script: master.py, XRAN path %s", xran_path)
460 if len(sys.argv) == 1 :
461 run_total = len(all_test_cases)
463 print(
"Run All test cases {}\n".format(run_total))
466 cat = options.category
467 mu = options.numerology
468 bw = options.bandwidth
469 tcase = options.testcase
473 for test_run_ix
in range(0, run_total):
474 cat = all_test_cases[test_run_ix][0]
475 mu = all_test_cases[test_run_ix][1]
476 bw = all_test_cases[test_run_ix][2]
477 tcase = all_test_cases[test_run_ix][3]
479 res =
run_tcase(cat, mu, bw, tcase, xran_path)
481 test_results.append((cat, mu, bw, tcase,
'FAIL'))
484 test_results.append((cat, mu, bw, tcase,
'PASS'))
486 res =
run_tcase(cat, mu, bw, tcase, xran_path)
488 test_results.append((cat, mu, bw, tcase,
'FAIL'))
489 test_results.append((cat, mu, bw, tcase,
'PASS'))
491 with open(
'testresult.txt',
'w')
as reshandle:
492 json.dump(test_results, reshandle)
496 if __name__ ==
'__main__':
497 START_TIME = datetime.now()
499 END_TIME = datetime.now()
500 logging.debug(
"Start time: %s, end time: %s", START_TIME, END_TIME)
501 logging.info(
"Execution time: %s", END_TIME - START_TIME)
def compare_resuts(cat, mu, bw, tcase, xran_path, test_cfg, direction)
def run_tcase(cat, mu, bw, tcase, xran_path)
def parse_dat_file(cat, mu, bw, tcase, xran_path, test_cfg)
def make_copy_mlog(cat, mu, bw, tcase, xran_path)
def init_logger(console_level, logfile_level)