def measure_per(self,server, client, numpkt): client_ip = configget("RADIO_TEST","client_ip") server_ip = configget("RADIO_TEST","server_ip") per_results = list() client.execute_command('wifi pkt rx') rates = [ ('wifi rate -m 7', 'N'),## 65mbps ('wifi rate -b 11', 'B')] ## 11mbps for rate in rates: server.execute_command(rate[0]) # server.execute_command('wifi pkt tx %s 100 10 10' % (client_ip)) # close loop time.sleep(0.1) # wait all packets are transmitted client.execute_command('wifi pkt rst_cnt') server.execute_command('wifi pkt tx %s 1000 %d 10' % (client_ip, numpkt), timeout_ms=30*1000) time.sleep(1) # wait all packets are transmitted rt, text = client.execute_command('wifi pkt cnt') res = CommandResult.parse(text) pkt_cnt = int(res.data['pkt_cnt']) rt, text = client.execute_command('wifi get_rssi') res = CommandResult.parse(text) rssi = int(res.data['rssi']) client_mac = client.get_mac() per_results.append((rate[1], pkt_cnt,rssi)) client.execute_command('wifi pkt stop') return per_results
def test(self): '''This function is to set the MFGID, ws_target, Pubkey, for the DUT''' perso_dic = { "set_mfgid" : configget("PERSO","MFG_ID").upper(), "set_wstarget" : configget("PERSO","wstarget"), "set_pubkey" : configget("PERSO","pubkey") } feuvert = True for key,value in perso_dic.items(): try: rt,text = self.dut.execute_command("perso %s %s"%(key,value),20000) res = CommandResult.parse(text) if res.rc !=0: self.logger.info("CSVFILE Personalization ok %s fail"%key) return False except: self.logger.info("Exception occurs during Personalization!!") self.logger.info("CSVFILE Personalization ok %s fail"%key) feuvert = False if feuvert: self.logger.info("CSVFILE Personalization ok ok pass") return True else: self.logger.info("CSVFILE Personalization ok ng fail") return False
def zoov_login(self, timeout_ms=12000): station_name = configget("TEST_STATION", "station_name").lower() station_version = configget("TEST_STATION", "station_version").lower() time_start = time.time() self.uart.flushInput() while True: msg_returned = self.get_shell(self.name, 2000) if msg_returned[0]: return True if "test-station login" in msg_returned[1]: self.send_command("teststation") probe_result, text = self.get_result(4000, "Password") self.send_command("test") probe_result, text = self.get_result(4000, "station name") elif "station name" in msg_returned[1]: self.logger.info( "======>>>>>>>>>>>>>> Login with station information") self.send_command("zoov01-%s" % station_name) time.sleep(0.5) self.send_command(station_version) probe_result, text = self.get_result(6000, station_name) if probe_result >= 0: return True elapsed_time = (time.time() - time_start) * 1000 if elapsed_time > timeout_ms: self.logger.warn("-->timeout: %d ms", elapsed_time) colorprint("cmd timeout", "RED") return False
def test(self): main01_config = configget("PERSO", "main_build_version") controller01_config = configget("PERSO", "controller_build_version") cmd_set = "get_firmware_version" res = CommandResult.parse(self.dut.execute_command(cmd_set, 10000)[1]) main01 = res.data['main_version'] controller01 = res.data['controller_version'] if res.rc != 0: self.logger.info("CSVFILE Check_Firmware ok ng fail") return False else: self.logger.info("CSVFILE Check_Firmware ok ok pass") return True
def test(self): ''' This function is to set MAC and the secret''' ''' Global MAC_label must be valide''' mac_input = self.dut.prop["mac_label"] ## Global MAC_label MAC_label = mac_input[:2] + ":" + mac_input[2:4] + ":" + mac_input[ 4:6] + ":" + mac_input[6:8] + ":" + mac_input[ 8:10] + ":" + mac_input[10:12] rc1, text = self.dut.execute_command("perso erase_all_settings", 4000) rc1, text = self.dut.execute_command("trace off", 4000) mac_file = configget("PERSO", "MAC_FILE") secret = "" ## read mac file, search for secret with open(mac_file, "r") as f: temp = f.readlines() for line in temp: if MAC_label in line: secret = line.split('\t')[1] if not secret: self.logger.debug("This MAC %s is not in the file!!" % MAC_label) self.logger.info("CSVFILE set_mac_secret ok no_secret fail") return False else: self.logger.debug( "The MAC is %s, and the secret has been found!!" % MAC_label) rc1, text = self.dut.execute_command( "perso %s %s" % ("set_mac", MAC_label), 5000) rc2, text = self.dut.execute_command( "perso %s %s" % ("set_secret", secret), 5000) if rc1 != 0 or rc2 != 0: self.logger.info("CSVFILE set_mac_secret ok NG fail") return False else: self.logger.info("CSVFILE set_mac_secret ok ok pass") return True
def test(self): rc, text = self.dut.execute_command("probe") res_data = CommandResult.parse(text) list_check = [ "mfg_id", "bl_version", "soft_version", "mac", "mcu_id", "secret" ] for item in list_check: try: oitem = configget("PERSO", item).strip() except: oitem = None if item in res_data.data: item_value = res_data.data[item] self.dut.prop[item] = item_value if oitem: if item_value.lower() == oitem.lower(): self.logger.info("CSVFILE probe_%s_checking " % item + oitem + " " + item_value + " pass") else: self.logger.info("CSVFILE probe_%s_checking " % item + oitem + " " + item_value + " fail") return False # value unexpected else: self.logger.info( "CSVFILE probe_%s_checking not_in_config " % item + item_value + " pass") else: self.logger.info( "CSVFILE probe_%s_checking not_in_probe_data " % item + "not_in_probe_data" + " fail") return False return True
def test(self): '''This function is to check Customization ID , very important for iOS installation.''' comm_hw_rev_target = configget("PERSO","comm_hw_rev") self.logger.info( "Comm_ID_check:") cmd_set = "get_main01_id" rc,text = self.dut.execute_command(cmd_set,2000) if rc != 0: self.logger.info( "Get Main01 ID fail") return False ''' COMM_dic = CommandResult.parse(text) COMM_id = COMM_dic.data["comm_id"] COMM_hw_rev_id = COMM_dic.data["comm_hw_rev"] self.logger.info( "CSVFILE COMM_ID xxxx %s PASS"%COMM_id) self.logger.info( "CSVFILE COMM_HW_REV_ID %s %s PASS"%(comm_hw_rev_target,COMM_hw_rev_id)) ''' cmd_set = "get_controller01_id" rc,text = self.dut.execute_command(cmd_set,2000) if rc != 0: self.logger.info( "Get Controller01 ID fail") return False return True """
def test(self): self.logger.info("Firmware need to be updated according to the config.") self.logger.info("COM port closed, ready to Flash") self.logger.info("++++++++++++++++++++++++ Flash Begin +++++++++++++++++++++++++++++++") jtag_flash = configget("TOOL","JTAG") path = "MCU_FLASH" script_name="flash_bl_512.jlink" # flash_cmd = jtag_flash + " " +path + os.sep + script_name flash_cmd = path + os.sep + "jlink_burn.bat" self.logger.info("====>%s"%flash_cmd) ret = os.system(flash_cmd) print("ret is %d"%ret) ################################### ################################### if ret == 0 or ret==1: self.logger.info("++++++++++++++++++++++++ Flash End +++++++++++++++++++++++++++++++") self.logger.info("Flash end! Wait for reboot! 15s") wait_time = 20 self.logger.info("++++++++++++++++++++++++ Flash End +++++++++++++++++++++++++++++++") return True else: self.logger.error("Flash programe fail!!") self.logger.info("++++++++++++++++++++++++ Flash End +++++++++++++++++++++++++++++++") return False
def __init__(self, port, serial_id="XXXX", baudrate=115200): super().__init__(port, baudrate, 0.1) station_name = configget("TEST_STATION", "station_name").lower() self.name = station_name self.__logfile = None self.__backlog = bytes() self.__pass = None # Pass/Fail status (tristate: None, True, False) self.__failure_reason = None # Reason of failure if __pass = False self.__logname = "" self.__test = True self.serial_id = serial_id
def test(self): ''' This function is to set the gat eway the bike''' gateway = configget("PERSO", "gateway_url") cmd_text = "gateway_get" res = CommandResult.parse(self.dut.execute_command(cmd_text, 5000)[1]) if res.rc == 0 and gateway == res.data['gateway']: self.logger.info("CSVFILE Set_Gateway ok ok pass") return True self.logger.info("CSVFILE Set_Gateway ok ng fail") return False
def test(self): '''This function is to set the current station pls to the utc time stamp at the end of the test.''' id = configget("PLS_INFO","CURRENT_STATION_ID") current_utc = int(time.time()) cmd_set_utc = "pls set %s %d"%(id,current_utc) r,text_ = self.dut.execute_command("pls set %s %d"%(id,current_utc),2000) if r != 0: self.logger.info( "CSVFILE pls_set_current_utc ok cmd_fail fail") return False else: self.logger.info( "CSVFILE pls_set_current_utc ok %d pass"%current_utc) return True
def test(self): #check V_SYS F1 = Fluke(configget("COM", "fluke1")) # if not F1.open(): # self.logger.info("FLUKE_V_SYS UART Problem, COM port open failed!!") # return False # else: time.sleep(2) v_sys = F1.get_voltage() res1 = compare_value("V_SYS", v_sys, 2.00, 5.00) #return True if res1==0 else False #check V3_SW F2 = Fluke(configget("COM", "fluke2")) # if not F2.open(): # self.logger.info("FLUKE_V3_SW UART Problem, COM port open failed!!") # return False # else: time.sleep(2) v3_sw = F2.get_voltage() res2 = compare_value("V3_SW", v3_sw, 0, 4.05) return True if res1 & res2 == 0 else False
def test(self): '''This function is to set Customization ID, very important for iOS installation.''' cust_id_target = configget("PERSO", "CUSTOM_ID") cmd_set = "customization_id set %s" % cust_id_target r, text_ = self.dut.execute_command(cmd_set, 2000) if r != 0: self.logger.info("set_customization finished, FAIL") self.logger.info("CSVFILE set_customization ok ng fail") return False else: self.logger.info("set_customization finished, OK") self.logger.info("CSVFILE set_customization ok ok pass") return True
def test(self): ''' This function is WiFi test of packet error rate. A golden sample is needed''' numpkt = 100 server_ip = configget("RADIO_TEST","server_ip") client_ip = configget("RADIO_TEST","client_ip") ssid = configget("RADIO_TEST","ssid") ref_com = configget("COM","REF") ref = DUT("ref",ref_com) if not ref.open(): self.logger.info("Golden board UART Problem, COM port open failed!!") return False mac_ref = ref.get_mac() ## reset and wifi init self.dut.send_command('reset') ref.send_command('reset') time.sleep(1) ref.execute_command('wifi init') self.dut.execute_command('wifi init') ## creat (server, client) pair pairs = ((ref, self.dut),(self.dut,ref)) for pair in pairs: server = pair[0] client = pair[1] if server.get_name() == "ref": mode = 'DUT_RX' self.logger.info("++++++++++++Golden Sample As the server, to send Packet to DUT++++++++++++++") else: mode = 'DUT_TX' self.logger.info("++++++++++++DUT As the sever, to send Packet to Golden Sample++++++++++++++") for channel in (1,13): server.execute_command('wifi ap_start %s %d' % (ssid,channel)) time.sleep(0.2) server.execute_command('wifi set_ip %s 255.255.255.0 %s %s' % ((server_ip,)*3)) time.sleep(0.2) client.execute_command('wifi join %s'%(ssid)) time.sleep(0.2) client.execute_command('wifi set_ip %s 255.255.255.0 %s %s' % (client_ip,server_ip,server_ip)) time.sleep(0.2) res = self.measure_per(server, client, numpkt) client.execute_command('wifi disconnect') server.execute_command('wifi clr_ip') server.execute_command('wifi ap_stop') ## every channel has N et B mode: count = 0 for j in (0,1): rssi_prefix = "channel_%d_%s_%s_rssi"%(channel,res[j][0],mode) pkt_prefix = "channel_%d_%s_%s_pkt"%(channel,res[j][0],mode) count = compare_value(pkt_prefix, res[j][1],configget("RADIO_TEST","nb_packet_min"),configget("RADIO_TEST","nb_packet_max")) count +=compare_value(rssi_prefix, res[j][2],configget("RADIO_TEST","rssi_min"),configget("RADIO_TEST","rssi_max")) if count <0 : return False time.sleep(2) self.logger.info(" wifi per test fini") return True
def test(self): '''This function is to check Customization ID , very important for iOS installation.''' cust_id_target = configget("PERSO","CUSTOM_ID") self.logger.info( "customization id check:") cmd_set = "customization_id get" r,text_ = self.dut.execute_command(cmd_set,2000) p = re.compile('(?P<cust_id>0x[0-9]*)') m = p.search(text_) cust_id = m.group('cust_id') if m != None else -1 if r != 0 or int(cust_id) != int(cust_id_target): self.logger.info( "customization id check FAIL") self.logger.info( "CSVFILE check_customization ok ng fail") return False else: self.logger.info( "get_customization finished, OK") self.logger.info( "CSVFILE check_customization ok ok pass") return True
def create_log_file(self, mac): """Create and open a log file.""" # Create logger directory, if needed log_dirname = './' + configget("TEST_STATION", "LOCAL_LOG") + os.sep + "serial_log" if not os.path.isdir(log_dirname): os.makedirs(log_dirname) # Create logger file date = time.strftime("%Y%m%d_%H%M%S", time.localtime()) filename = '%s/%s_%s_%s.log' % (log_dirname, mac, date, self.name) self.__logname = filename self.__logfile = open(filename, "a+b") # Flush the backlog self.__logfile.write(self.__backlog) self.__backlog = None
def test(self): '''This function is to check Customization ID , very important for iOS installation.''' cpu_hw_rev_target = configget("PERSO", "cpu_hw_rev") self.logger.info("CPU_ID_check:") cmd_set = "get_cpu_id" rc, text = self.dut.execute_command(cmd_set, 2000) if rc != 0: self.logger.info("CSVFILE CPU_ID xxxx -1 FAIL") self.logger.info("CSVFILE CPU_HW_REV_ID xxxx -1 FAIL") return False cpu_dic = CommandResult.parse(text) cpu_id = cpu_dic.data["cpu_id"] cpu_hw_rev_id = cpu_dic.data["cpu_hw_rev"] self.logger.info("CSVFILE CPU_ID xxxx %s PASS" % cpu_id) self.logger.info("CSVFILE CPU_HW_REV_ID %s %s PASS" % (cpu_hw_rev_target, cpu_hw_rev_id)) return True """
def open(self): # Open UART super(Zoovstation, self).open() self.uart.flushInput() station_number = configget("TEST_STATION", "station_number").lower() # need login with "test station" if not self.zoov_login(): return False # Open logfile if not self.__logname: self.create_log_file(station_number) else: filename = self.__logname self.__logfile = open(filename, "a+b") # Flush the backlog self.__logfile.write(self.__backlog) self.__backlog = None return True
def test(self): '''This function is to update firmware, put the DUT to reset and reboot with "boot hello" so that the wsflash can work''' toFlash = configget("PERSO", "FIRMWARE_BL_UPDATE") if toFlash == "N": self.logger.info("Firmware update disabled.") self.logger.info("CSVFILE firmware_update good good pass") elif toFlash == "Y": targetversion = int(configget("PERSO", "SOFT_VERSION")) com_port = configget("COM", "dut") try: targetBinName = configget("PERSO", "SOFT_BIN") wsflash = configget("TOOL", "WSFLASH") except: self.logger.info( "Config miss item: firmware binary path and/or the wsflash path." ) self.logger.info("CSVFILE firmware_update ng good fail") return False if int(self.dut.prop["soft_version"]) < targetversion: '''if firmware is smaller than config, to flash''' self.logger.info( "Firmware need to be updated according to the config.") self.dut.execute_command("mem write 32 0x4003E000 0x0") self.dut.send_command("standby 2") self.dut.uart.close() self.logger.info("COM port closed, ready to Flash") self.logger.info( "++++++++++++++++++++++++ Flash Begin +++++++++++++++++++++++++++++++" ) flash_cmd = "%s -f %s -s %s -e" % (wsflash, targetBinName, com_port) self.logger.info("====>%s" % flash_cmd) ret = os.system(flash_cmd) if ret == 0: self.logger.info( "++++++++++++++++++++++++ Flash End +++++++++++++++++++++++++++++++" ) self.logger.info("Flash end! Wait for reboot! 15s") wait_time = 16 for x in range(wait_time): self.logger.info( "========================= count down %d ============================" % (wait_time - x)) time.sleep(1) try: self.dut.uart.open() except: self.logger.error( "UART COM port re-open failed, Firmware update Fail" ) self.logger.info( "CSVFILE firmware_update ng good fail") return False result = WaitShell(self.dut).test(False) if result: self.logger.info( "CSVFILE firmware_update good good pass") return True else: self.logger.error( "DUT not rebooted properly, Firmware update Fail") self.logger.info( "CSVFILE firmware_update ng good fail") return False else: self.logger.error( "Flash programe fail, Firmware update Fail") self.logger.info("CSVFILE firmware_update ng good fail") return False
def main(isProd=True): """Define code in main to avoid execution if it is imported.""" ###################### init test ###################### time_begin = TOOL.init_test() test_result = True ###################### create log handler ###################### serialID = TOOL.scan_serial_id( "請掃描或輸入車身QR二維碼,Please scan the bike QR code:") log_file_name = logtool.log_name_gen("txt", serialID) logtool.init_logger(log_file_name) ###################### create DUT ###################### comport = configget("COM", "zoovstation") print(comport, serialID) dut = Zoov(comport, serialID) if not dut.open(): print("ERROR", "Failed to open COM port!") exit() ###################### create test sequence ###################### TOOL.flush_input() tests = [ WaitShellConnect(dut), # CheckBoardID_A100(dut), # SetSerialID(dut), # CheckBrake(dut), # CheckBatteryDetect(dut), CheckPowerLED(dut), # ExecuteCommand(dut,'low_power_check'), # CheckLight(dut), # ExecuteCommand(dut,'torque_calibration'), # MotorCalibration(dut), # ExecuteCommand(dut,"factory_mode_set --mode 3"), # ExecuteCommand(dut,"reboot") SetGateway(dut), ] ###################### RUN the test ###################### ## Production mode and Dianostic mode if isProd: for test in tests: if not test.run(): test_result = False break else: oklist = [] nglist = [] for test in tests: if not test.run(): nglist.append(test) else: oklist.append(test) if len(nglist) != 0: test_result = False ###################### Closing ###################### # dut.close() TOOL.flush_input() csvinfo = logtool.get_csv_info(test_result, serialID, time_begin) logtool.csvmaker(log_file_name, csvinfo) ###################### Display Result ##################### TOOL.show_result(test_result, pop=isProd) if not isProd: print_test_summary(oklist, nglist)
def test(self): toFlash = configget("PERSO", "FIRMWARE_BL_UPDATE") if toFlash == "N": self.logger.info("No need Flash,config to disabled.") elif toFlash == "Y": targetversion = int(configget("PERSO", "SOFT_VERSION")) com_port = configget("COM", "dut") try: targetBinName = configget("PERSO", "SOFT_BIN") wsflash = configget("TOOL", "WSFLASH") except: self.logger.info( "Config miss item: firmware binary path and/or the wsflash path." ) return False self.logger.info( "Firmware need to be updated according to the config.") self.dut.uart.close() self.logger.info("COM port closed, ready to Flash") self.logger.info( "++++++++++++++++++++++++ Flash Begin +++++++++++++++++++++++++++++++" ) flash_cmd = "%s -f %s -s %s -e" % (wsflash, targetBinName, com_port) self.logger.info("====>%s" % flash_cmd) ret = os.system(flash_cmd) ################################### ################################### if ret == 0: self.logger.info( "++++++++++++++++++++++++ Flash End +++++++++++++++++++++++++++++++" ) self.logger.info("Flash end! Wait for reboot! 15s") wait_time = 14 for x in range(wait_time): self.logger.info( "========================= count down %d ============================" % (wait_time - x)) time.sleep(1) try: self.dut.uart.open() except: self.logger.error( "UART COM port re-open failed, Firmware flash Fail") self.logger.info( "++++++++++++++++++++++++ Flash End +++++++++++++++++++++++++++++++" ) return False result = WaitShell(self.dut).test(False) if result: self.logger.info("Firmware flash finished") self.logger.info( "++++++++++++++++++++++++ Flash End +++++++++++++++++++++++++++++++" ) return True else: self.logger.error( "DUT not rebooted properly, Firmware flash Fail") self.logger.info( "++++++++++++++++++++++++ Flash End +++++++++++++++++++++++++++++++" ) return False else: self.logger.error("Flash programe fail!!") self.logger.info( "++++++++++++++++++++++++ Flash End +++++++++++++++++++++++++++++++" ) return False