def __init__(self, crbName, target, nic, suite, perf=False): """ copy desc from #Name#_test_plan.rst to TestResult_#Name#.rst """ try: path = [path2Result, crbName, target, nic] # ensure the level folder exist for node in range(0, len(path)): if not os.path.exists('/'.join(path[:node + 1])): for level in range(node, len(path)): os.mkdir('/'.join(path[:level + 1])) break self.rstName = "%s/TestResult_%s.rst" % ('/'.join(path), suite) rstReport = open(self.rstName, 'w') if perf is True: self.rstAnnexName = "%s/TestResult_%s_Annex.rst" % ( '/'.join(path), suite) rstAnnexReport = open(self.rstAnnexName, 'w') f = open("%s/%s_test_plan.rst" % (path2Plan, suite), 'r') for line in f: if line[:13] == "Prerequisites": break rstReport.write(line) if perf is True: rstAnnexReport.write(line) f.close() rstReport.close() except Exception as e: raise VerifyFailure("RST Error: " + str(e))
def check_8023ad_agg_modes(self, slaves, bond_mode): ''' check aggregator mode ''' check_results = [] default_agg_mode = 'stable' for mode in self.AGG_MODES: try: self.bond_inst.start_testpmd() bond_port = self.set_8023ad_bonded(slaves, bond_mode) cur_agg_mode = self.get_8023ad_agg_mode(bond_port) if cur_agg_mode != default_agg_mode: fmt = ("link bonding mode 4 (802.3ad) default agg mode " "isn't {0}") msg = fmt.format(default_agg_mode) self.logger.warning(msg) # ignore default mode if mode == default_agg_mode: fmt = ("link bonding mode 4 (802.3ad) " "current agg mode is {0}") msg = fmt.format(mode) self.logger.info(msg) continue cmds = [["port stop all", '', 15], ["port start all", '', 15]] self.bond_inst.d_console(cmds) self.set_8023ad_agg_mode(bond_port, mode) except Exception as e: check_results.append(e) print traceback.format_exc() finally: self.bond_inst.close_testpmd() time.sleep(2) if check_results: for result in check_results: self.logger.error(result) raise VerifyFailure('check_8023ad_agg_modes is failed')
def check_process_exist(self, process_name='testpmd'): status = self.check_process_status(process_name) if not status: msg = "{0} process exceptional quit".format(process_name) out = self.parent.dut.session.session.get_output_all() self.logger.info(out) raise VerifyFailure(msg)
def check_packet_transmission(self, pkt_types, layer_configs=None): time.sleep(1) for pkt_type in pkt_types.keys(): pkt_names = pkt_types[pkt_type] pkt = Packet(pkt_type=pkt_type) if layer_configs: for layer in layer_configs.keys(): pkt.config_layer(layer, layer_configs[layer]) inst = self.tester.tcpdump_sniff_packets(self.tester_iface, count=1, timeout=8) pkt.send_pkt(tx_port=self.tester_iface) out = self.dut.get_session_output(timeout=2) time.sleep(1) self.tester.load_tcpdump_sniff_packets(inst) if self.printFlag: # debug output print out for pkt_layer_name in pkt_names: if self.printFlag: # debug output print pkt_layer_name if pkt_layer_name not in out: print utils.RED("Fail to detect %s" % pkt_layer_name) if not self.printFlag: raise VerifyFailure("Failed to detect %s" % pkt_layer_name) else: print utils.GREEN("Detected %s successfully" % pkt_type) time.sleep(1)
def verify(self, passed, description): if not passed: if self._enable_debug: print RED("Error happened, dump command history...") self.dump_history() print "Error \"%s\" happened" % RED(description) print RED("History dump finished.") raise VerifyFailure(description)
def backup_check_traffic(self): mode = MODE_ACTIVE_BACKUP msg = "begin checking bonding backup(stacked) mode transmission" self.logger.info(msg) results = self.check_traffic(mode) if results: for item in results: self.logger.error(item) raise VerifyFailure("backup(stacked) mode: rx failed")
def xor_check_rx(self): mode = MODE_XOR_BALANCE msg = "begin checking bonding xor(stacked) mode transmission" self.logger.info(msg) results = self.check_traffic(mode) if results: for item in results: self.logger.error(item) raise VerifyFailure("xor(stacked) mode: rx failed")
def backup_check_traffic_with_slave_down(self): mode = MODE_ACTIVE_BACKUP self.logger.info("begin checking bonding backup(stacked) " "mode transmission with one slave down") results = self.check_traffic_with_one_slave_down(mode) if results: for item in results: self.logger.error(item) msg = "backup(stacked) mode: rx with one slave down failed" raise VerifyFailure(msg)
def check_packet_transmission(self, pkt_types): time.sleep(1) for pkt_type in pkt_types.keys(): intf = self.src_intf pkt = Packet(pkt_type=pkt_type) # set packet every layer's input parameters if 'layer_configs' in pkt_types[pkt_type].keys(): pkt_configs = pkt_types[pkt_type]['layer_configs'] if pkt_configs: for layer in pkt_configs.keys(): pkt.config_layer(layer, pkt_configs[layer]) pkt.send_pkt(tx_port=self.src_intf) # check vm testpmd packet received information if 'vm' in pkt_types[pkt_type].keys(): out = self.vm0_testpmd.get_output(timeout=2) if self.printFlag: # debug output print out for pkt_attribute in pkt_types[pkt_type]['vm']: if self.printFlag: # debug output print pkt_attribute if pkt_attribute not in out: print utils.RED('Fail to detect %s' % pkt_attribute) if not self.printFlag: # print out all info in debug mode raise VerifyFailure('Failed to detect %s' % pkt_attribute) print utils.GREEN('VM detected %s successfully' % pkt_type) # check dut testpmd packet received information if 'dut' in pkt_types[pkt_type].keys(): out = self.host_testpmd.get_output(timeout=2) if self.printFlag: # debug output print out for pkt_attribute in pkt_types[pkt_type]['dut']: if self.printFlag: # debug output print pkt_attribute if pkt_attribute not in out: print utils.RED('Fail to detect %s' % pkt_attribute) if not self.printFlag: # print out all info in debug mode raise VerifyFailure('Failed to detect %s' % pkt_attribute) print utils.GREEN('DUT detected %s successfully' % pkt_type) time.sleep(1)
def get_pci_link(self, slaves): ''' get slaves ports pci address ''' slaves_pci = [] for port_id in slaves: slaves_pci.append(self.dut.ports_info[port_id]['pci']) if not slaves_pci: msg = "can't find tx_port pci" self.logger.error(msg) raise VerifyFailure(msg) return slaves_pci
def xor_check_stacked_rx_one_slave_down(self): mode = MODE_XOR_BALANCE self.logger.info("begin checking bonding xor(stacked) mode " "transmission with one slave down") results = self.check_traffic_with_one_slave_down(mode) if results: for item in results: self.logger.error(item) msg = "xor(stacked) mode: rx with one slave down failed" raise VerifyFailure(msg)
def run_test(self, pkt_types): time.sleep(1) for pkt_type in pkt_types.keys(): pkt_names = pkt_types[pkt_type] pkt = Packet(pkt_type=pkt_type) pkt.send_pkt(tx_port=self.tester_iface) out = self.dut.get_session_output(timeout=2) for pkt_layer_name in pkt_names: if pkt_layer_name not in out: print utils.RED("Fail to detect %s" % pkt_layer_name) raise VerifyFailure("Failed to detect %s" % pkt_layer_name) print utils.GREEN("Detected %s successfully" % pkt_type)
def test_basic_behav_promisc_mode(self): ''' test 802.3ad basic behavior(bond port promisc mode) ''' msg = '' slaves, bond_port = self.run_dpdk_functional_pre() try: self.check_bonded_device_promisc_mode(slaves, bond_port) except Exception as e: msg = "bonding 8023ad check promisc mode failed" self.run_dpdk_functional_post() if msg: raise VerifyFailure(msg)
def dts_run_commands(crb, dts_commands): """ Run dts input commands """ for dts_command in dts_commands: command = dts_command['command'] if dts_command['host'] in crb.NAME: if crb.stage == dts_command['stage']: ret = crb.send_expect(command, expected="# ", verify=True) if type(ret) is int: log_handler.error("[%s] return failure" % command) if dts_command['verify'] is True: raise VerifyFailure("Command execution failed")
def test_command_line_option(self): ''' test 802.3ad bonding configs with commandline option ''' msgs = [] for agg_mode in self.AGG_MODES: bond_port, cur_slaves, tx_port_id = self.run_test_pre(agg_mode) msgs += self.check_cmd_line_option_status(agg_mode, bond_port, cur_slaves) self.bond_inst.close_testpmd() if msgs: for msg in msgs: self.logger.warning(msg) msg = 'fail to config from command line at {0}'.format(agg_mode) raise VerifyFailure(msg)
def close_testpmd(self): if self.testpmd_status == 'close': return None output = self.stop_testpmd() time.sleep(1) self.testpmd.quit() time.sleep(10) if self.check_process_status(): raise VerifyFailure("testpmd close failed") else: self.logger.info("close testpmd successful") self.testpmd_status = 'close' return output
def test_basic_behav_upDown(self): ''' test 802.3ad basic behavior(bond port link up/down) ''' msg = '' slaves, bond_port = self.run_dpdk_functional_pre() try: self.check_bonded_device_up_down(bond_port) except Exception as e: msg = "bonding 8023ad check link up/down failed" self.run_dpdk_functional_post() if msg: raise VerifyFailure(msg)
def test_basic_behav_mac(self): ''' test 802.3ad basic behavior(bond port mac address) ''' msg = '' slaves, bond_port = self.run_dpdk_functional_pre() try: self.bonding_8023ad_check_macs(slaves, bond_port) self.check_bonded_device_mac_change(slaves, bond_port) except Exception as e: msg = "bonding 8023ad check mac failed" self.run_dpdk_functional_post() if msg: raise VerifyFailure(msg)
def check_bonded_device_up_down(self, bond_port): # stop bonded device cmd = "port stop {0}".format(bond_port) self.bond_inst.d_console(cmd) status = self.bond_inst.get_port_info(bond_port, 'link_status') if status != 'down': msg = "bond port {0} fail to set down".format(bond_port) self.logger.error(msg) raise VerifyFailure(msg) else: msg = "bond port {0} set down successful !".format(bond_port) self.logger.info(msg) # start bonded device cmds = ["port start {0}".format(bond_port), '', 10] self.bond_inst.d_console(cmds) status = self.bond_inst.get_port_info(bond_port, 'link_status') if status != 'up': msg = "bond port {0} fail to set up".format(bond_port) self.logger.error(msg) raise VerifyFailure(msg) else: msg = "bond port {0} set up successful !".format(bond_port) self.logger.info(msg)
def __init__(self, crb, target, nic): # Ensure the folder exist try: path = '/'.join([Plotting.path_2_result, crb, target, nic, Plotting.plots_subfolder]) if not os.path.exists(path): os.makedirs(path) self.plots_path = path except Exception as e: raise VerifyFailure("Plot Error: " + str(e))
def set_8023ad_agg_mode(self, bond_port, mode="bandwidth"): """ set bonding agg_mode <port_id> <agg_name> Set 802.11AD Aggregator Mode """ cmd = "set bonding agg_mode %d %s" % (bond_port, mode) self.bond_inst.d_console(cmd) cur_mode = self.bond_inst.get_bonding_info(bond_port, 'agg_mode') if mode == cur_mode: fmt = "set bonding agg_mode <{0}> successfully" self.logger.info(fmt.format(mode)) else: msg = "failed to set bonding agg_mode <{0}>".format(mode) self.logger.error(msg) raise VerifyFailure(msg)
def test_basic_behav_startStop(self): ''' test 802.3ad basic behavior(bond port start/stop) ''' msg = '' slaves, bond_port = self.run_dpdk_functional_pre() try: for _ in range(10): self.check_bonded_device_start(bond_port) self.stop_bonded_device(bond_port) except Exception as e: print traceback.format_exc() msg = "bonding 8023ad check start/stop failed" self.run_dpdk_functional_post() if msg: raise VerifyFailure(msg)
def run_nvgre_cope(self, pkt_nvgre): time.sleep(1) for pkts in pkt_nvgre: pkt = Packet() pkt.assign_layers(pkts[2]) if 'inner_icmp' in pkts[2]: pkt.config_layers([('ipv6',{'nh':47}), ('inner_ipv6', {'nh': 58})]) else: pkt.config_layers([('ipv6',{'nh':47}),('inner_ipv6', {'nh': 132})]) pkt.send_pkt(tx_port=self.tester_iface) out = self.dut.get_session_output(timeout=2) for pkt_layer_name in pkts[1]: if pkt_layer_name not in out: print utils.RED("Fail to detect %s" % pkt_layer_name) raise VerifyFailure("Failed to detect %s" % pkt_layer_name) print utils.GREEN("Detected %s successfully" % pkts[0])
def check_bonded_device_queue_config(self, *devices): ''' check if master bonded device/slave device queue configuration is the same. ''' # get master bonded device queue configuration master = self.bond_inst.get_port_info(devices[0], 'queue_config') # get slave device queue configuration for port_id in devices[1:]: config = self.bond_inst.get_port_info(port_id, 'queue_config') if cmp(config, master) == 0: continue msg = ("slave bonded port [{0}] is " "different to top bonded port [{1}]").format( port_id, devices[0]) raise VerifyFailure('bonded device queue config:: ' + msg)
def dts_parse_commands(commands): """ Parse command information from dts arguments """ dts_commands = [] if commands is None: return dts_commands args_format = {"shell": 0, "crb": 1, "stage": 2, "check": 3, "max_num": 4} cmd_fmt = r"\[(.*)\]" for command in commands: args = command.split(':') if len(args) != args_format['max_num']: log_handler.error("Command [%s] is lack of arguments" % command) raise VerifyFailure("commands input is not corrected") continue dts_command = {} m = re.match(cmd_fmt, args[0]) if m: cmds = m.group(1).split(',') shell_cmd = "" for cmd in cmds: shell_cmd += cmd shell_cmd += ' ' dts_command['command'] = shell_cmd[:-1] else: dts_command['command'] = args[0] if args[1] == "tester": dts_command['host'] = "tester" else: dts_command['host'] = "dut" if args[2] == "post-init": dts_command['stage'] = "post-init" else: dts_command['stage'] = "pre-init" if args[3] == "ignore": dts_command["verify"] = False else: dts_command["verify"] = True dts_commands.append(dts_command) return dts_commands
def run_test(self, sw_ptype, pkt_types, chk_types): """ Generate and send packet according to packet type, detect each packet layer. """ for pkt_type in pkt_types.keys(): if chk_types != None: pkt_names = chk_types[pkt_type] else: pkt_names = pkt_types[pkt_type] pkt = Packet(pkt_type=pkt_type) pkt.send_pkt(tx_port=self.tester_iface) out = self.dut.get_session_output(timeout=2) self.verify(sw_ptype in out, "Failed to detect correct ptype value") for pkt_layer_name in pkt_names: if pkt_layer_name not in out: print utils.RED("Fail to detect %s" % pkt_layer_name) raise VerifyFailure("Failed to detect %s" % pkt_layer_name) print utils.GREEN("Detected %s successfully" % pkt_type)
def check_8023ad_dedicated_queues(self, slaves, bond_mode): ''' check 802.3ad dedicated queues ''' check_results = [] default_slow_queue = 'unknown' for mode in self.DEDICATED_QUEUES: try: self.bond_inst.start_testpmd() bond_port = self.set_8023ad_bonded(slaves, bond_mode) self.set_8023ad_dedicated_queues(bond_port, mode) except Exception as e: check_results.append(e) print traceback.format_exc() finally: self.bond_inst.close_testpmd() time.sleep(2) if check_results: for result in check_results: self.logger.error(result) raise VerifyFailure('check_8023ad_dedicated_queues is failed')
def test_wrong_coremask(self): """ Check coremask parsing for wrong coremasks. """ wrong_coremasks = [ "GARBAGE", "0xJF", "0xFJF", "0xFFJ", "0xJ11", "0x1J1", "0x11J", "JF", "FJF", "FFJ", "J11", "1J1", "11J", "jf", "fjf", "ffj", "FF0x", "ff0x", "", "0x", "0" ] for coremask in wrong_coremasks: command = command_line % (self.target, coremask, self.mem_channel) try: out = self.dut.send_expect(command, "# ", 5) self.verify("EAL: invalid coremask" in out, "Wrong core mask (%s) accepted" % coremask) except: self.dut.send_expect("quit", "# ", 5) raise VerifyFailure("Wrong core mask (%s) accepted" % coremask)
def test_l2pkt_detect(self): """ Check whether L2 packet can be detected" """ self.verify(("fortville" in self.nic or "fortpark_TLV" in self.nic), "L2 packet detect only support by Fortville") self.L2_types = { "TIMESYNC": "L2_ETHER_TIMESYNC", "ARP": "L2_ETHER_ARP", "LLDP": "L2_ETHER_LLDP", } for l2_type in self.L2_types.keys(): pkt_name = self.L2_types[l2_type] pkt = Packet(pkt_type=l2_type) pkt.send_pkt(tx_port=self.tester_iface) out = self.dut.get_session_output(timeout=2) if pkt_name in out: print utils.GREEN("Detected L2 %s successfully" % l2_type) else: raise VerifyFailure("Failed to detect L2 %s" % l2_type)
def preset_testpmd(self, core_mask, options='', eal_param=''): try: self.testpmd.start_testpmd( core_mask, param=' '.join(options), eal_param=eal_param) except TimeoutException: # check if testpmd quit try: self.check_process_exist() except Exception as e: self.testpmd_status = 'close' msg = "execute '{0}' timeout".format(item[0]) self.logger.error(msg_pipe(timeout)) raise TimeoutException(msg) # wait lsc event udpate done time.sleep(10) # check if testpmd has bootep up if self.check_process_status(): self.logger.info("testpmd boot up successful") else: raise VerifyFailure("testpmd boot up failed") self.d_console(self.preset_testpmd_cmds) self.preset_testpmd_cmds = [] time.sleep(1)