Skip to content

Commit

Permalink
fix(tests/intelhex): make sure file is closed on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdragun authored and dobairoland committed Nov 13, 2023
1 parent afaa7d2 commit 900d385
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
19 changes: 14 additions & 5 deletions test/test_esptool.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,22 +396,27 @@ def test_adjacent_flash(self):
self.verify_readback(4096, 50 * 1024, "images/fifty_kb.bin")

def test_short_flash_hex(self):
_, f = tempfile.mkstemp(suffix=".hex")
fd, f = tempfile.mkstemp(suffix=".hex")
try:
self.run_esptool(f"merge_bin --format hex 0x0 images/one_kb.bin -o {f}")
# make sure file is closed before running next command (mainly for Windows)
os.close(fd)
self.run_esptool(f"write_flash 0x0 {f}")
self.verify_readback(0, 1024, "images/one_kb.bin")
finally:
os.unlink(f)

def test_adjacent_flash_hex(self):
_, f1 = tempfile.mkstemp(suffix=".hex")
_, f2 = tempfile.mkstemp(suffix=".hex")
fd1, f1 = tempfile.mkstemp(suffix=".hex")
fd2, f2 = tempfile.mkstemp(suffix=".hex")
try:
self.run_esptool(f"merge_bin --format hex 0x0 images/sector.bin -o {f1}")
# make sure file is closed before running next command (mainly for Windows)
os.close(fd1)
self.run_esptool(
f"merge_bin --format hex 0x1000 images/fifty_kb.bin -o {f2}"
)
os.close(fd2)
self.run_esptool(f"write_flash 0x0 {f1} 0x1000 {f2}")
self.verify_readback(0, 4096, "images/sector.bin")
self.verify_readback(4096, 50 * 1024, "images/fifty_kb.bin")
Expand All @@ -420,11 +425,13 @@ def test_adjacent_flash_hex(self):
os.unlink(f2)

def test_adjacent_flash_mixed(self):
_, f = tempfile.mkstemp(suffix=".hex")
fd, f = tempfile.mkstemp(suffix=".hex")
try:
self.run_esptool(
f"merge_bin --format hex 0x1000 images/fifty_kb.bin -o {f}"
)
# make sure file is closed before running next command (mainly for Windows)
os.close(fd)
self.run_esptool(f"write_flash 0x0 images/sector.bin 0x1000 {f}")
self.verify_readback(0, 4096, "images/sector.bin")
self.verify_readback(4096, 50 * 1024, "images/fifty_kb.bin")
Expand Down Expand Up @@ -1063,12 +1070,14 @@ def test_load_ram_hex(self):
The "hello world" binary programs for each chip print
"Hello world!\n" to the serial port.
"""
_, f = tempfile.mkstemp(suffix=".hex")
fd, f = tempfile.mkstemp(suffix=".hex")
try:
self.run_esptool(
f"merge_bin --format hex -o {f} 0x0 "
f"images/ram_helloworld/helloworld-{arg_chip}.bin"
)
# make sure file is closed before running next command (mainly for Windows)
os.close(fd)
self.run_esptool(f"load_ram {f}")
self.verify_output(
[b"Hello world!", b'\xce?\x13\x05\x04\xd0\x97A\x11"\xc4\x06\xc67\x04']
Expand Down
10 changes: 5 additions & 5 deletions test/test_merge_bin.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,11 @@ def test_merge_bin2hex(self):
# convert back and verify the result against the source bin file
with tempfile.NamedTemporaryFile(suffix=".hex", delete=False) as hex:
hex.write(merged)
merged_bin = self.run_merge_bin(
"esp32",
[(0x1000, hex.name)],
options=["--format", "raw"],
)
merged_bin = self.run_merge_bin(
"esp32",
[(0x1000, hex.name)],
options=["--format", "raw"],
)
source = read_image("bootloader_esp32.bin")
# verify that padding was done correctly
assert b"\xFF" * 0x1000 == merged_bin[:0x1000]
Expand Down

0 comments on commit 900d385

Please sign in to comment.