Lines Matching refs:self
63 def __init__(self, rfc2217_port=None): argument
64 self.port = rfc2217_port or self.get_free_port()
65 self.cmd = [
69 str(self.port),
72 self.server_output_file = open(f"{TEST_DIR}/{str(arg_chip)}_server.out", "a")
73 self.server_output_file.write("************************************")
74 self.p = None
75 self.wait_for_server_starts(attempts_count=5)
85 def wait_for_server_starts(self, attempts_count): argument
88 self.p = subprocess.Popen(
89 self.cmd,
91 stdout=self.server_output_file,
97 result = s.connect_ex(("localhost", self.port))
108 self.p.terminate()
111 def __enter__(self): argument
112 return self
114 def __exit__(self, type, value, traceback): argument
115 self.server_output_file.close()
116 self.p.terminate()
122 def run_espsecure(self, args): argument
136 def run_esptool(self, args, baud=None, chip=None, port=None, preload=True): argument
215 def run_esptool_error(self, args, baud=None, chip=None): argument
223 self.run_esptool(args, baud, chip)
229 def setup_class(self): argument
233 self.stored_dir = os.getcwd()
237 def teardown_class(self): argument
239 os.chdir(self.stored_dir)
241 def readback(self, offset, length, spi_connection=None): argument
250 self.run_esptool(cmd)
262 def diff(self, readback, compare_to): argument
269 self, offset, length, compare_to, is_bootloader=False, spi_connection=None argument
271 rb = self.readback(offset, length, spi_connection)
285 self.diff(rb, ct)
290 def valid_key_present(self): argument
300 def test_blank_efuse_encrypt_write_abort(self): argument
304 if self.valid_key_present() is True:
307 self.run_esptool(
312 output = self.run_esptool_error(
317 def test_blank_efuse_encrypt_write_continue1(self): argument
325 if self.valid_key_present() is True:
328 self.run_esptool(
332 self.run_esptool("read_flash 0x10000 192 images/read_encrypted_flash.bin")
333 self.run_espsecure(
356 def test_blank_efuse_encrypt_write_continue2(self): argument
364 if self.valid_key_present() is True:
367 self.run_esptool(
371 self.run_esptool("read_flash 0x10000 192 images/read_encrypted_flash.bin")
372 self.run_espsecure(
395 def test_short_flash(self): argument
396 self.run_esptool("write_flash 0x0 images/one_kb.bin")
397 self.verify_readback(0, 1024, "images/one_kb.bin")
400 def test_highspeed_flash(self): argument
401 self.run_esptool("write_flash 0x0 images/fifty_kb.bin", baud=921600)
402 self.verify_readback(0, 50 * 1024, "images/fifty_kb.bin")
404 def test_adjacent_flash(self): argument
405 self.run_esptool("write_flash 0x0 images/sector.bin 0x1000 images/fifty_kb.bin")
406 self.verify_readback(0, 4096, "images/sector.bin")
407 self.verify_readback(4096, 50 * 1024, "images/fifty_kb.bin")
409 def test_short_flash_hex(self): argument
412 self.run_esptool(f"merge_bin --format hex 0x0 images/one_kb.bin -o {f}")
415 self.run_esptool(f"write_flash 0x0 {f}")
416 self.verify_readback(0, 1024, "images/one_kb.bin")
420 def test_adjacent_flash_hex(self): argument
424 self.run_esptool(f"merge_bin --format hex 0x0 images/sector.bin -o {f1}")
427 self.run_esptool(
431 self.run_esptool(f"write_flash 0x0 {f1} 0x1000 {f2}")
432 self.verify_readback(0, 4096, "images/sector.bin")
433 self.verify_readback(4096, 50 * 1024, "images/fifty_kb.bin")
438 def test_adjacent_flash_mixed(self): argument
441 self.run_esptool(
446 self.run_esptool(f"write_flash 0x0 images/sector.bin 0x1000 {f}")
447 self.verify_readback(0, 4096, "images/sector.bin")
448 self.verify_readback(4096, 50 * 1024, "images/fifty_kb.bin")
452 def test_adjacent_independent_flash(self): argument
453 self.run_esptool("write_flash 0x0 images/sector.bin")
454 self.verify_readback(0, 4096, "images/sector.bin")
455 self.run_esptool("write_flash 0x1000 images/fifty_kb.bin")
456 self.verify_readback(4096, 50 * 1024, "images/fifty_kb.bin")
458 self.verify_readback(0, 4096, "images/sector.bin")
463 def test_last_bytes_of_32M_flash(self): argument
467 self.run_esptool("write_flash {} images/one_kb.bin".format(hex(offset)))
471 self.run_esptool("write_flash {} images/one_kb_all_ef.bin".format(hex(offset2)))
472 self.verify_readback(offset, image_size, "images/one_kb.bin")
477 def test_write_larger_area_to_32M_flash(self): argument
479 self.run_esptool("write_flash {} images/one_mb.bin".format(hex(offset)))
483 self.run_esptool("write_flash {} images/one_kb_all_ef.bin".format(hex(offset2)))
484 self.verify_readback(offset, 1 * 1024 * 1024, "images/one_mb.bin")
486 def test_correct_offset(self): argument
488 self.run_esptool("write_flash 0x2000 images/sector.bin")
490 three_sectors = self.readback(0, 0x3000)
497 def test_no_compression_flash(self): argument
498 self.run_esptool(
501 self.verify_readback(0, 4096, "images/sector.bin")
502 self.verify_readback(4096, 50 * 1024, "images/fifty_kb.bin")
506 def test_compressed_nostub_flash(self): argument
507 self.run_esptool(
510 self.verify_readback(0, 4096, "images/sector.bin")
511 self.verify_readback(4096, 50 * 1024, "images/fifty_kb.bin")
513 def _test_partition_table_then_bootloader(self, args): argument
514 self.run_esptool(args + " 0x4000 images/partitions_singleapp.bin")
515 self.verify_readback(0x4000, 96, "images/partitions_singleapp.bin")
516 self.run_esptool(args + " 0x1000 images/bootloader_esp32.bin")
517 self.verify_readback(0x1000, 7888, "images/bootloader_esp32.bin", True)
518 self.verify_readback(0x4000, 96, "images/partitions_singleapp.bin")
520 def test_partition_table_then_bootloader(self): argument
521 self._test_partition_table_then_bootloader("write_flash --force")
523 def test_partition_table_then_bootloader_no_compression(self): argument
524 self._test_partition_table_then_bootloader("write_flash --force -u")
526 def test_partition_table_then_bootloader_nostub(self): argument
527 self._test_partition_table_then_bootloader("--no-stub write_flash --force")
534 def test_length_not_aligned_4bytes(self): argument
535 self.run_esptool("write_flash 0x0 images/not_4_byte_aligned.bin")
537 def test_length_not_aligned_4bytes_no_compression(self): argument
538 self.run_esptool("write_flash -u 0x0 images/not_4_byte_aligned.bin")
542 def test_write_overlap(self): argument
543 output = self.run_esptool_error(
550 def test_repeated_address(self): argument
551 output = self.run_esptool_error(
558 def test_write_sector_overlap(self): argument
561 output = self.run_esptool_error(
566 def test_write_no_overlap(self): argument
567 output = self.run_esptool(
572 def test_compressible_file(self): argument
578 self.run_esptool(f"write_flash 0x10000 {input_file.name}")
582 def test_compressible_non_trivial_file(self): argument
592 self.run_esptool(f"write_flash 0x10000 {input_file.name}")
597 def test_zero_length(self): argument
599 output = self.run_esptool(
602 self.verify_readback(0x10000, 1024, "images/one_kb.bin")
606 def test_single_byte(self): argument
607 self.run_esptool("write_flash 0x0 images/onebyte.bin")
608 self.verify_readback(0x0, 1, "images/onebyte.bin")
610 def test_erase_range_messages(self): argument
611 output = self.run_esptool(
628 def test_write_image_for_another_target(self): argument
629 output = self.run_esptool_error(
643 def test_write_image_for_another_revision(self): argument
644 output = self.run_esptool_error(
654 def test_flash_with_min_max_rev(self): argument
656 output = self.run_esptool_error(
666 def test_erase_before_write(self): argument
667 output = self.run_esptool("write_flash --erase-all 0x0 images/one_kb.bin")
672 def test_flash_not_aligned_nostub(self): argument
673 output = self.run_esptool("--no-stub write_flash 0x1 images/one_kb.bin")
682 def test_flash_overclocked(self): argument
692 output = self.run_esptool(
713 output = self.run_esptool(
724 def test_flash_watchdogs(self): argument
747 output = self.run_esptool(
770 def test_show_security_info(self): argument
771 res = self.run_esptool("get_security_info")
790 def test_high_offset(self): argument
791 self.run_esptool("write_flash -fs 4MB 0x300000 images/one_kb.bin")
792 self.verify_readback(0x300000, 1024, "images/one_kb.bin")
794 def test_high_offset_no_compression(self): argument
795 self.run_esptool("write_flash -u -fs 4MB 0x300000 images/one_kb.bin")
796 self.verify_readback(0x300000, 1024, "images/one_kb.bin")
798 def test_large_image(self): argument
799 self.run_esptool("write_flash -fs 4MB 0x280000 images/one_mb.bin")
800 self.verify_readback(0x280000, 0x100000, "images/one_mb.bin")
802 def test_large_no_compression(self): argument
803 self.run_esptool("write_flash -u -fs 4MB 0x280000 images/one_mb.bin")
804 self.verify_readback(0x280000, 0x100000, "images/one_mb.bin")
808 def test_invalid_size_arg(self): argument
809 self.run_esptool_error("write_flash -fs 10MB 0x6000 images/one_kb.bin")
811 def test_write_past_end_fails(self): argument
812 output = self.run_esptool_error(
818 def test_write_no_compression_past_end_fails(self): argument
819 output = self.run_esptool_error(
829 def test_flash_size_keep(self): argument
839 self.run_esptool(f"write_flash -fs keep {offset} {image}")
841 self.verify_readback(offset, image_len, image)
846 def test_read_nostub_high_offset(self): argument
849 self.run_esptool(f"write_flash -fs detect {offset} images/one_kb.bin")
853 self.run_esptool(
867 self.diff(rb, ct)
872 def test_flash_id(self): argument
874 res = self.run_esptool("flash_id")
879 def test_flash_id_expand_args(self): argument
887 res = self.run_esptool(f"@{arg_file.name}")
894 def test_flash_id_trace(self): argument
896 res = self.run_esptool("--trace flash_id")
917 def test_flash_size(self): argument
923 res = self.run_esptool("flash_id")
929 def test_flash_sfdp(self): argument
931 res = self.run_esptool("read_flash_sfdp 0 4")
933 res = self.run_esptool("read_flash_sfdp 1 3")
943 def test_short_flash_to_external_stub(self): argument
945 self.run_esptool("write_flash 0x0 images/one_kb.bin")
946 self.run_esptool(
950 self.verify_readback(0, 1024, "images/one_kb.bin")
951 self.verify_readback(0, 1024, "images/sector.bin", spi_connection=self.conn)
954 self.run_esptool(
957 self.run_esptool("write_flash 0x0 images/sector.bin")
959 self.verify_readback(0, 1024, "images/sector.bin")
960 self.verify_readback(0, 1024, "images/one_kb.bin", spi_connection=self.conn)
962 def test_short_flash_to_external_ROM(self): argument
964 self.run_esptool("--no-stub write_flash 0x0 images/one_kb.bin")
965 self.run_esptool(
969 self.verify_readback(0, 1024, "images/one_kb.bin")
970 self.verify_readback(0, 1024, "images/sector.bin", spi_connection=self.conn)
973 self.run_esptool(
976 self.run_esptool("--no-stub write_flash 0x0 images/sector.bin")
978 self.verify_readback(0, 1024, "images/sector.bin")
979 self.verify_readback(0, 1024, "images/one_kb.bin", spi_connection=self.conn)
983 def test_stub_reuse_with_synchronization(self): argument
985 res = self.run_esptool(
989 res = self.run_esptool(
996 def test_stub_reuse_without_synchronization(self): argument
1005 res = self.run_esptool("--after no_reset_stub flash_id")
1007 res = self.run_esptool("--before no_reset_no_sync flash_id")
1013 def test_chip_erase(self): argument
1014 self.run_esptool("write_flash 0x10000 images/one_kb.bin")
1015 self.verify_readback(0x10000, 0x400, "images/one_kb.bin")
1016 self.run_esptool("erase_flash")
1017 empty = self.readback(0x10000, 0x400)
1020 def test_region_erase(self): argument
1021 self.run_esptool("write_flash 0x10000 images/one_kb.bin")
1022 self.run_esptool("write_flash 0x11000 images/sector.bin")
1023 self.verify_readback(0x10000, 0x400, "images/one_kb.bin")
1024 self.verify_readback(0x11000, 0x1000, "images/sector.bin")
1026 self.run_esptool("erase_region 0x10000 0x1000")
1027 self.verify_readback(0x11000, 0x1000, "images/sector.bin")
1028 empty = self.readback(0x10000, 0x1000)
1031 def test_region_erase_all(self): argument
1032 res = self.run_esptool("erase_region 0x0 ALL")
1035 def test_large_region_erase(self): argument
1037 self.run_esptool("erase_region 0x0 0x100000")
1041 def test_end_sector(self): argument
1042 self.run_esptool("write_flash 0x10000 images/sector.bin")
1043 self.run_esptool("write_flash 0x0FC00 images/one_kb.bin")
1044 self.verify_readback(0x0FC00, 0x400, "images/one_kb.bin")
1045 self.verify_readback(0x10000, 0x1000, "images/sector.bin")
1047 def test_end_sector_uncompressed(self): argument
1048 self.run_esptool("write_flash -u 0x10000 images/sector.bin")
1049 self.run_esptool("write_flash -u 0x0FC00 images/one_kb.bin")
1050 self.verify_readback(0x0FC00, 0x400, "images/one_kb.bin")
1051 self.verify_readback(0x10000, 0x1000, "images/sector.bin")
1053 def test_overlap(self): argument
1054 self.run_esptool("write_flash 0x20800 images/sector.bin")
1055 self.verify_readback(0x20800, 0x1000, "images/sector.bin")
1060 def test_verify_success(self): argument
1061 self.run_esptool("write_flash 0x5000 images/one_kb.bin")
1062 self.run_esptool("verify_flash 0x5000 images/one_kb.bin")
1064 def test_verify_failure(self): argument
1065 self.run_esptool("write_flash 0x6000 images/sector.bin")
1066 output = self.run_esptool_error(
1072 def test_verify_unaligned_length(self): argument
1073 self.run_esptool("write_flash 0x0 images/not_4_byte_aligned.bin")
1074 self.run_esptool("verify_flash 0x0 images/not_4_byte_aligned.bin")
1079 def test_read_mac(self): argument
1080 output = self.run_esptool("read_mac")
1088 def test_read_chip_id(self): argument
1089 output = self.run_esptool("chip_id")
1099 def test_memory_dump(self): argument
1100 output = self.run_esptool("dump_mem 0x50000000 128 memout.bin")
1104 def test_memory_write(self): argument
1105 output = self.run_esptool("write_mem 0x400C0000 0xabad1dea 0x0000ffff")
1110 def test_memory_read(self): argument
1111 output = self.run_esptool("read_mem 0x400C0000")
1119 def setup_class(self): argument
1120 super(TestKeepImageSettings, self).setup_class()
1121 self.BL_IMAGE = f"images/bootloader_{arg_chip}.bin"
1122 self.flash_offset = esptool.CHIP_DEFS[arg_chip].BOOTLOADER_FLASH_OFFSET
1123 with open(self.BL_IMAGE, "rb") as f:
1124 self.header = f.read(8)
1130 def test_keep_does_not_change_settings(self): argument
1132 self.run_esptool(f"write_flash -fs keep {self.flash_offset:#x} {self.BL_IMAGE}")
1133 self.verify_readback(self.flash_offset, 8, self.BL_IMAGE, False)
1135 self.run_esptool(
1139 self.verify_readback(self.flash_offset, 8, self.BL_IMAGE, False)
1141 self.run_esptool(
1150 def test_detect_size_changes_size(self): argument
1151 self.run_esptool(
1154 readback = self.readback(self.flash_offset, 8)
1155 assert self.header[:3] == readback[:3] # first 3 bytes unchanged
1156 assert self.header[3] != readback[3] # size_freq byte changed
1157 assert self.header[4:] == readback[4:] # rest unchanged
1163 def test_explicit_set_size_freq_mode(self): argument
1164 self.run_esptool(
1169 readback = self.readback(self.flash_offset, 8)
1170 assert self.header[0] == readback[0]
1171 assert self.header[1] == readback[1]
1174 assert 3 != self.header[2] # original image not dout mode
1177 assert self.header[3] != readback[3] # size/freq values have changed
1178 assert self.header[4:] == readback[4:] # entrypoint address hasn't changed
1181 self.run_esptool(
1185 self.run_esptool_error(f"verify_flash {self.flash_offset:#x} {self.BL_IMAGE}")
1196 def verify_output(self, expected_out: List[bytes]): argument
1211 def test_load_ram(self): argument
1217 self.run_esptool(f"load_ram images/ram_helloworld/helloworld-{arg_chip}.bin")
1218 self.verify_output(
1222 def test_load_ram_hex(self): argument
1230 self.run_esptool(
1236 self.run_esptool(f"load_ram {f}")
1237 self.verify_output(
1246 def test_deep_sleep_flash(self): argument
1258 self.run_esptool("write_flash 0x0 images/esp8266_deepsleep.bin", baud=230400)
1262 self.run_esptool("write_flash 0x0 images/fifty_kb.bin", baud=230400)
1263 self.verify_readback(0, 50 * 1024, "images/fifty_kb.bin")
1272 def test_flash_header_rewrite(self): argument
1276 output = self.run_esptool(
1287 def test_flash_header_no_magic_no_rewrite(self): argument
1292 output = self.run_esptool(
1296 self.verify_readback(bl_offset, 1024, image)
1300 def _check_output(self, output): argument
1308 def test_auto_detect(self): argument
1309 output = self.run_esptool("chip_id", chip="auto")
1310 self._check_output(output)
1317 def test_auto_detect_virtual_port(self): argument
1319 output = self.run_esptool(
1324 self._check_output(output)
1326 def test_highspeed_flash_virtual_port(self): argument
1329 self.run_esptool(
1334 self.verify_readback(0, 50 * 1024, "images/fifty_kb.bin")
1337 def pty_port(self): argument
1346 def test_pty_port(self, pty_port): argument
1363 def _test_read_write(self, esp): argument
1401 def test_read_write_memory_rom(self): argument
1406 self._test_read_write(esp)
1410 def test_read_write_memory_stub(self): argument
1416 self._test_read_write(esp)
1423 def test_read_write_flash_status(self): argument
1425 res = self.run_esptool("read_flash_status")
1428 res = self.run_esptool(f"write_flash_status {match.group(1)}")
1433 def test_read_chip_description(self): argument
1443 def test_read_get_chip_features(self): argument
1465 def verify_image(self, offset, length, image, compare_to): argument
1476 self.diff(rb, ct)
1478 def test_make_image(self): argument
1479 output = self.run_esptool(
1486 self.verify_image(16, 4096, "test0x00000.bin", "images/sector.bin")
1487 self.verify_image(
1503 def __init__(self, file_path, file_content): argument
1504 self.file_path = file_path
1505 self.file_content = file_content
1507 def __enter__(self): argument
1508 with open(self.file_path, "w") as cfg_file:
1509 cfg_file.write(self.file_content)
1512 def __exit__(self, exc_type, exc_value, exc_tb): argument
1513 os.unlink(self.file_path)
1514 assert not os.path.exists(self.file_path)
1524 def test_load_config_file(self): argument
1527 with self.ConfigFile(config_file_path, self.dummy_config):
1528 output = self.run_esptool("version")
1535 with self.ConfigFile(config_file_path, "[wrong section name]"):
1536 output = self.run_esptool("version")
1541 with self.ConfigFile(config_file_path, faulty_config):
1542 output = self.run_esptool("version")
1553 with self.ConfigFile(config_file_path, faulty_config):
1554 output = self.run_esptool("version")
1559 with self.ConfigFile(config_file_path, self.dummy_config):
1560 output = self.run_esptool("version")
1564 def test_load_config_file_with_env_var(self): argument
1566 with self.ConfigFile(config_file_path, self.dummy_config):
1568 output = self.run_esptool("version")
1575 output = self.run_esptool("version")
1584 def test_custom_reset_sequence(self): argument
1594 with self.ConfigFile(config_file_path, reset_seq_config):
1595 output = self.run_esptool_error("flash_id")
1604 with self.ConfigFile(config_file_path, invalid_reset_seq_config):
1605 output = self.run_esptool_error("flash_id")
1609 def test_open_port_attempts(self): argument
1619 with self.ConfigFile(config_file_path, config):
1620 output = self.run_esptool_error("flash_id")