add some more UF2 tests and sanity checks
Signed-off-by: Brian S. Stephan <bss@incorporeal.org>
This commit is contained in:
parent
4a7203d969
commit
e35d8dbf3d
@ -117,6 +117,10 @@ def convert_uf2_to_binary(uf2: bytearray) -> bytearray:
|
|||||||
|
|
||||||
binary += content[0:bytes_]
|
binary += content[0:bytes_]
|
||||||
old_uf2_addr = uf2_addr
|
old_uf2_addr = uf2_addr
|
||||||
|
|
||||||
|
# when this is all done we should have counted the expected number of blocks
|
||||||
|
if block_count != block_num + 1:
|
||||||
|
raise ValueError(f"not all expected blocks ({block_count}) were found, only got {block_num + 1}!")
|
||||||
return binary
|
return binary
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
SPDX-FileCopyrightText: © 2023 Brian S. Stephan <bss@incorporeal.org>
|
SPDX-FileCopyrightText: © 2023 Brian S. Stephan <bss@incorporeal.org>
|
||||||
SPDX-License-Identifier: GPL-3.0-or-later
|
SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
"""
|
"""
|
||||||
import math
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import unittest.mock as mock
|
import unittest.mock as mock
|
||||||
|
@ -166,6 +166,27 @@ def test_convert_binary_to_uf2_to_binary(whole_board_with_board_config_dump):
|
|||||||
assert whole_board_with_board_config_dump == binary
|
assert whole_board_with_board_config_dump == binary
|
||||||
|
|
||||||
|
|
||||||
|
def test_malformed_uf2(whole_board_with_board_config_dump):
|
||||||
|
"""Check that we expect a properly-formed UF2."""
|
||||||
|
uf2 = storage.convert_binary_to_uf2(whole_board_with_board_config_dump)
|
||||||
|
|
||||||
|
# truncated UF2 --- byte mismatch
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
storage.convert_uf2_to_binary(uf2[:-4])
|
||||||
|
|
||||||
|
# truncated uf2 --- counter is wrong
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
storage.convert_uf2_to_binary(uf2[512:])
|
||||||
|
|
||||||
|
# truncated uf2 --- total count is wrong
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
storage.convert_uf2_to_binary(uf2[:-512])
|
||||||
|
|
||||||
|
# malformed UF2 --- counter jumps in the middle, suggests total blocks is wrong
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
storage.convert_uf2_to_binary(uf2 + uf2)
|
||||||
|
|
||||||
|
|
||||||
@with_pb2s
|
@with_pb2s
|
||||||
def test_serialize_config_with_footer(storage_dump, config_binary):
|
def test_serialize_config_with_footer(storage_dump, config_binary):
|
||||||
"""Test that reserializing a read in config matches the original.
|
"""Test that reserializing a read in config matches the original.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user