def test_upload_bank(self): """ Send and receive binary file, fail if file differs after reception :return: """ to_signal(self.main_window.bin_file_panel.combo_box.clearEditText)() new_file = os.path.join(RESOURCE, 'random.bin') self.main_window.send_file_for_emulation(new_file) downloaded_file_path = self.main_window.download_flash_bank() are_identical = filecmp.cmp(new_file, downloaded_file_path, shallow=False) diff_map = '' if not are_identical: with open(new_file) as n, open(downloaded_file_path) as d: nfile = n.read() dfile = d.read() addr = 0 for pair in zip(nfile, dfile): if pair[0] != pair[1]: diff_map += 'X' else: diff_map += '.' #if pair[0] != pair[1]: # print "Diff @0x{:08X}: n0x{:02X} != d0x{:02X}".format(addr, ord(pair[0]), ord(pair[1])) # addr += 1 bin_diff_map(diff_map) downloaded_file_path = self.main_window.download_flash_bank() print "download again to: ".format(downloaded_file_path) assert are_identical, "Downloaded file is not the same as transmitted one: {} != {}".format( new_file, downloaded_file_path)
def test_upload_sqeunce_sram(self): to_signal(self.main_window.bin_file_panel.combo_box.clearEditText)() new_file = os.path.join(RESOURCE, 'sequence.bin') self.main_window.send_file_for_emulation(new_file) downloaded_file_path = self.main_window.download_sram() are_identical = filecmp.cmp(new_file, downloaded_file_path, shallow=False) if not are_identical: diff_map = '' with open(new_file) as n, open(downloaded_file_path) as d: nfile = n.read() dfile = d.read() addr = 0 for pair in zip(nfile, dfile): if pair[0] != pair[1]: diff_map += 'X' print "Diff @0x{:08X}: n0x{:02X} != d0x{:02X}".format( addr, ord(pair[0]), ord(pair[1])) else: diff_map += '.' addr += 1 bin_diff_map(diff_map) assert are_identical, "Downloaded SRAM file is not the same as transmitted one: {} != {}".format( new_file, downloaded_file_path)
def get_console_text(self): """ gets and clears console text :return: """ text = self.console.console_text_browser.toPlainText() to_signal(self.console.clear)() return text
def get_received_file_path(self): t0 = time.time() to_signal(self.parent.get_current_bin_file)() while time.time() - t0 < 2: try: return self.parent.current_bin_file except AttributeError: time.sleep(0.1) return self.parent.current_bin_file
def send_file_for_emulation(self, file_path): self.insert_new_file_signal.emit(file_path) wait_for(timeout=1, test=lambda path: os.path.isfile(path) if path else False)\ (lambda arg: self.bin_file_panel.get_current_file())(self) to_signal(self.save_button_slot)() wait_for( timeout=60, test=lambda text: "File transmitted in" in text)(lambda arg: str( self.console.console_text_browser.toPlainText()))(self)
def setUp(self): to_signal(self.main_window.bin_file_panel.combo_box.clearEditText)() self.main_window.wait_for_freemem_print() self.main_window.wipe_banks() self.main_window.are_banks_wiped() self.main_window.bank1set_slot() self.main_window.is_bank1_set() with open(LOG_FILE, 'a') as f: console_text = self.main_window.get_console_text() f.write("#### setUp: {}:{} ####\n\n".format( self._testMethodName, tstamp())) f.write(console_text) f.write("\n\n")
def get_bank_name(self): try: del self.parent.bank_name except AttributeError: pass to_signal(self.parent.get_bank_name)() t0 = time.time() while time.time() - t0 < 5: try: return self.parent.bank_name except AttributeError: time.sleep(0.1) return self.parent.bank_name
def write_packets_procedure(self): self.send_rx_flush_req() self.disable_objects_for_transmission_signal.emit() time.sleep(0.5) t_start = time.time() bank_name_full = os.path.basename(self.bin_packets.bin_path) bank_name = os.path.splitext(bank_name_full)[0] self.progress_bar.set_title("SENDING: {}".format(bank_name_full)) to_signal(self.progress_bar.display).emit() tot_tx_bytes = 0 while self.progress_bar.isHidden(): time.sleep(0.1) packets = {p.b_address: p for p in self.bin_packets} packet = packets.get(packets.keys()[0]) max_timeout = len(packets) * self.__retx_timeout * 4 print "max timeout", max_timeout/60 debug("Sending bin with packetsize: {}".format(len(packet.payload))) while packets: if self.progress_bar.isHidden(): self.gui_communication_signal.emit("Upload procedure terminated") break self.check_resp_thr = GuiThread(self.check_repsonse, args=(MessageSender.context,)) self.check_resp_thr.start() self.send_packet(packet.payload, b_address=packet.b_address) while self.check_resp_thr.returned() is None: time.sleep(0.001) response = self.check_resp_thr.returned() if response == RxMessage.rx_id_tuple.index('ack'): self.tx_stats.ack() self.progress_bar.set_val_signal.emit(float(tot_tx_bytes) / self.bin_packets.packets_amount * 100) tot_tx_bytes += len(packet.payload) packets.pop(packet.b_address) try: packet = packets.get(packets.keys()[0]) except IndexError: pass elif response == RxMessage.rx_id_tuple.index('dtx'): self.tx_stats.dtx() else: self.tx_stats.nack() if time.time() - t_start > max_timeout: self.__tear_down() raise SendTimeout("TIMEOUT") else: if self.reload_sram(): self.parent_send_msg(MessageSender.ID.reload_sram) self.gui_communication_signal.emit("File transmitted in: {}".format(time.time() - t_start)) self.gui_communication_signal.emit(self.tx_stats) self.message_sender.send(m_id=MessageSender.ID.get_write_stats) self.set_bank_name(bank_name.replace('_sram', '')) to_signal(self.progress_bar.hide).emit() self.enable_objects_after_transmission_signal.emit()
def set_active_button(self, bank_no): to_signal(self.bank1pushButton.set_default_style_sheet)() to_signal(self.bank2pushButton.set_default_style_sheet)() to_signal(self.bank3pushButton.set_default_style_sheet)() set_green_style = \ [ self.bank1pushButton.set_green_style_sheet, self.bank2pushButton.set_green_style_sheet, self.bank3pushButton.set_green_style_sheet, ][bank_no] to_signal(set_green_style).emit()
def read_packets_procedure(self): self.disable_objects_for_transmission_signal.emit() self.message_sender.send(MessageSender.ID.rxflush) time.sleep(0.5) max_timeout = 20 t_start = time.time() self.progress_bar.set_title("RECEIVING") to_signal(self.progress_bar.display).emit() packet_num = 0 while self.progress_bar.isHidden(): time.sleep(0.1) while not self.receiver: if self.progress_bar.isHidden(): self.gui_communication_signal.emit("Read procedure terminated") break context = self.send_request(packet_num=packet_num) self.context_to_packet_map[context] = packet_num self.check_resp_thr = GuiThread(self.check_response, args=(context,)) self.check_resp_thr.start() while self.check_resp_thr.returned() is None: time.sleep(0.001) response = self.check_resp_thr.returned() if response == RxMessage.rx_id_tuple.index('ack'): self.tx_stats.ack() self.progress_bar.set_val_signal.emit(float(packet_num) / 16 * 100) packet_num += 1 else: self.tx_stats.nack() time.sleep(0.5) if time.time() - t_start > max_timeout: self.tear_down_on_fail() break else: self.gui_communication_signal.emit("File received in: {}".format(time.time() - t_start)) self.gui_communication_signal.emit(self.tx_stats) self.extra_teardown() to_signal(self.progress_bar.hide).emit() self.enable_objects_after_transmission_signal.emit() if self.auto_open(): self.event_handler.open_bin_file()
def __init__(self, config_file, apply_signal): QtGui.QWidget.__init__(self) self.setWindowTitle("CONFIG") self.x_siz, self.y_siz = 400, 200 self.mainGrid = QtGui.QGridLayout() self.mainGrid.setSpacing(1) self.__mainGrid_y_cnt = 0 self.__config_file = config_file Config.__init__(self, self.__config_file) self.apply_button = QtGui.QPushButton("APPLY") self.cancel_button = QtGui.QPushButton("Cancel") self.apply_button.clicked.connect(to_signal(to_signal( self.apply_slot))) self.cancel_button.clicked.connect(to_signal(self.close)) self.mainGrid.addWidget(self.apply_button, self.__mainGrid_y_cnt, 2, 1, 1) self.mainGrid.addWidget(self.cancel_button, self.__mainGrid_y_cnt, 0, 1, 1) self.setLayout(self.mainGrid) self.resize(self.x_siz, self.y_siz) self.apply_signal = apply_signal
def __init__(self, set_pin_signal): QtGui.QWidget.__init__(self) self.setWindowTitle("PIN setup") self.x_siz, self.y_siz = 300, 200 mainGrid = QtGui.QGridLayout() mainGrid.setSpacing(10) self.line_edit = QtGui.QLineEdit() self.label = QtGui.QLabel() self.__label_string = "Provide new PIN" self.label.setText(self.__label_string) self.ok_button = QtGui.QPushButton("OK") self.cancel_button = QtGui.QPushButton("Cancel") self.ok_button.clicked.connect(self.set_pin) self.cancel_button.clicked.connect(to_signal(self.close)) mainGrid.addWidget(self.label, 0, 0, 1, 1) mainGrid.addWidget(self.line_edit, 1, 0, 1, 2) mainGrid.addWidget(self.cancel_button, 2, 0, 1, 1) mainGrid.addWidget(self.ok_button, 2, 1, 1, 1) self.setLayout(mainGrid) self.resize(self.x_siz, self.y_siz) self.set_pin_signal = set_pin_signal self.show()
def test_if_sram_zero(self): """ Test if sram contains only zeros bytes after banks wiping :return: """ self.main_window.bank1set_slot() self.main_window.is_bank1_set() to_signal(self.main_window.bin_file_panel.combo_box.clear)() to_signal(self.main_window.bin_file_panel.combo_box.clearEditText)() to_signal(self.main_window.read_sram_button_slot)() self.main_window.is_downloaded_file_present() self.main_window.get_current_file() file_path = self.main_window.get_current_file.qget() addr = 0 with open(file_path) as f: chars = f.read() for c in chars: self.assertEqual( c, '\x00', "Sram file not zero at addr: {}, 0!={}".format( addr, format(hex(ord(c))))) addr += 1
def tearDownClass(cls): time.sleep(1) to_signal(cls.main_window.disconnect)() cls.main_window.is_disconnected() time.sleep(1) to_signal(cls.main_window.close)()
def editTextChanged_with_delay_connect_to_signal(self, ext_signal): self.edit_text_changed_signal = ext_signal self.editTextChanged.connect(to_signal(self.edit_text_changed_timer))
def disable_active_button(self): to_signal(self.bank1pushButton.set_default_style_sheet)() to_signal(self.bank2pushButton.set_default_style_sheet)() to_signal(self.bank3pushButton.set_default_style_sheet)()
def config_button_slot(self): to_signal(self.parent.config_button_slot).emit() return self.__get_parent_attr_with_timoeut('config_window')
def __tear_down(self): self.gui_communication_signal.emit("Upload failed") to_signal(self.progress_bar.hide).emit() self.enable_objects_after_transmission_signal.emit()