Skip to content

Commit

Permalink
Merge pull request #36 from JPHutchins/tests/binary-lock
Browse files Browse the repository at this point in the history
Tests/binary lock
  • Loading branch information
JPHutchins authored Sep 22, 2024
2 parents d8d0635 + be19385 commit e2213b7
Show file tree
Hide file tree
Showing 67 changed files with 27,573 additions and 7 deletions.
50 changes: 49 additions & 1 deletion smp/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ def model_post_init(self, _: None) -> None:
exclude_unset=True,
exclude={'header', 'version', 'sequence', 'smp_data'},
exclude_none=True,
)
),
canonical=True,
)
if self.header is None: # create the header
object.__setattr__(
Expand Down Expand Up @@ -117,6 +118,53 @@ def model_post_init(self, _: None) -> None:
if self.smp_data is None:
object.__setattr__(self, 'smp_data', bytes(self.header) + data_bytes)

# # Uncomment this to create a record for a de/serialization regression lock
# self._log_serialized_bytes()

# def _log_serialized_bytes(self) -> None:
# import json
# import os

# from smp.image_management import HashBytes

# kwargs = self.model_dump(
# exclude_unset=True,
# exclude={'header', 'version', 'sequence', 'smp_data'},
# exclude_none=True,
# )

# message = f"{self.__class__.__module__}.{self.__class__.__qualname__}"

# log_dir = "serialization_logs"
# os.makedirs(log_dir, exist_ok=True)
# log_file = os.path.join(log_dir, f"{message}.json")

# def convert_bytes(obj: dict) -> dict:
# if isinstance(obj, dict):
# return {k: convert_bytes(v) for k, v in obj.items()}
# elif isinstance(obj, list):
# return [convert_bytes(i) for i in obj]
# elif isinstance(obj, tuple):
# return tuple(convert_bytes(i) for i in obj)
# elif isinstance(obj, bytes) or isinstance(obj, HashBytes):
# return obj.hex()
# else:
# return obj

# log_data = {
# "message": message,
# "version": self.version,
# "sequence": self.sequence,
# "kwargs": convert_bytes(kwargs),
# "bytes": self.BYTES.hex(),
# }

# try:
# with open(log_file, "a") as f:
# f.write(json.dumps(log_data) + "\n")
# except OSError as e:
# print(f"Failed to write to {log_file}: {e}")


class Request(_MessageBase, ABC):
...
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"message": "smp.file_management.FileCloseRequest", "version": 1, "sequence": 11, "kwargs": {}, "bytes": "0a00000100080b04a0"}
{"message": "smp.file_management.FileCloseRequest", "version": 1, "sequence": 11, "kwargs": {}, "bytes": "0a00000100080b04a0"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"message": "smp.file_management.FileCloseResponse", "version": 1, "sequence": 12, "kwargs": {}, "bytes": "0b00000100080c04a0"}
{"message": "smp.file_management.FileCloseResponse", "version": 1, "sequence": 12, "kwargs": {}, "bytes": "0b00000100080c04a0"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"message": "smp.file_management.FileDownloadRequest", "version": 1, "sequence": 0, "kwargs": {"off": 0, "name": "test_file.txt"}, "bytes": "0800001900080000a2636f666600646e616d656d746573745f66696c652e747874"}
{"message": "smp.file_management.FileDownloadRequest", "version": 1, "sequence": 0, "kwargs": {"off": 0, "name": "test_file.txt"}, "bytes": "0800001900080000a2636f666600646e616d656d746573745f66696c652e747874"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"message": "smp.file_management.FileDownloadResponse", "version": 1, "sequence": 1, "kwargs": {"off": 0, "data": "74657374", "len": 100}, "bytes": "0900001600080100a3636c656e1864636f66660064646174614474657374"}
{"message": "smp.file_management.FileDownloadResponse", "version": 1, "sequence": 1, "kwargs": {"off": 0, "data": "74657374", "len": 100}, "bytes": "0900001600080100a3636c656e1864636f66660064646174614474657374"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"message": "smp.file_management.FileHashChecksumRequest", "version": 1, "sequence": 6, "kwargs": {"name": "test.txt", "type": "crc32", "off": 0, "len": 100}, "bytes": "0800002500080602a4636c656e1864636f666600646e616d6568746573742e7478746474797065656372633332"}
{"message": "smp.file_management.FileHashChecksumRequest", "version": 1, "sequence": 6, "kwargs": {"name": "test.txt", "type": "crc32", "off": 0, "len": 100}, "bytes": "0800002500080602a4636c656e1864636f666600646e616d6568746573742e7478746474797065656372633332"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{"message": "smp.file_management.FileHashChecksumResponse", "version": 1, "sequence": 7, "kwargs": {"type": "crc32", "off": 0, "len": 100, "output": "74657374"}, "bytes": "0900002300080702a4636c656e1864636f6666006474797065656372633332666f75747075744474657374"}
{"message": "smp.file_management.FileHashChecksumResponse", "version": 1, "sequence": 7, "kwargs": {"type": "crc32", "off": 0, "len": 100, "output": "74657374"}, "bytes": "0900002300080702a4636c656e1864636f6666006474797065656372633332666f75747075744474657374"}
{"message": "smp.file_management.FileHashChecksumResponse", "version": 1, "sequence": 8, "kwargs": {"type": "crc32", "off": 0, "len": 100, "output": 1000000}, "bytes": "0900002300080802a4636c656e1864636f6666006474797065656372633332666f75747075741a000f4240"}
{"message": "smp.file_management.FileHashChecksumResponse", "version": 1, "sequence": 8, "kwargs": {"type": "crc32", "off": 0, "len": 100, "output": 1000000}, "bytes": "0900002300080802a4636c656e1864636f6666006474797065656372633332666f75747075741a000f4240"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"message": "smp.file_management.FileStatusRequest", "version": 1, "sequence": 4, "kwargs": {"name": "test.txt"}, "bytes": "0800000f00080401a1646e616d6568746573742e747874"}
{"message": "smp.file_management.FileStatusRequest", "version": 1, "sequence": 4, "kwargs": {"name": "test.txt"}, "bytes": "0800000f00080401a1646e616d6568746573742e747874"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"message": "smp.file_management.FileStatusResponse", "version": 1, "sequence": 5, "kwargs": {"len": 100}, "bytes": "0900000700080501a1636c656e1864"}
{"message": "smp.file_management.FileStatusResponse", "version": 1, "sequence": 5, "kwargs": {"len": 100}, "bytes": "0900000700080501a1636c656e1864"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"message": "smp.file_management.FileUploadRequest", "version": 1, "sequence": 2, "kwargs": {"off": 0, "data": "74657374", "name": "test.txt", "len": 1000}, "bytes": "0a00002500080200a4636c656e1903e8636f66660064646174614474657374646e616d6568746573742e747874"}
{"message": "smp.file_management.FileUploadRequest", "version": 1, "sequence": 2, "kwargs": {"off": 0, "data": "74657374", "name": "test.txt", "len": 1000}, "bytes": "0a00002500080200a4636c656e1903e8636f66660064646174614474657374646e616d6568746573742e747874"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"message": "smp.file_management.FileUploadResponse", "version": 1, "sequence": 3, "kwargs": {"off": 0}, "bytes": "0b00000600080300a1636f666600"}
{"message": "smp.file_management.FileUploadResponse", "version": 1, "sequence": 3, "kwargs": {"off": 0}, "bytes": "0b00000600080300a1636f666600"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"message": "smp.file_management.SupportedFileHashChecksumTypesRequest", "version": 1, "sequence": 9, "kwargs": {}, "bytes": "0800000100080903a0"}
{"message": "smp.file_management.SupportedFileHashChecksumTypesRequest", "version": 1, "sequence": 9, "kwargs": {}, "bytes": "0800000100080903a0"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"message": "smp.file_management.SupportedFileHashChecksumTypesResponse", "version": 1, "sequence": 10, "kwargs": {"types": {"crc32": {"format": 1, "size": 4}, "sha256": {"format": 0, "size": 32}}}, "bytes": "0900003400080a03a1657479706573a2656372633332a26473697a650466666f726d61740166736861323536a26473697a65182066666f726d617400"}
{"message": "smp.file_management.SupportedFileHashChecksumTypesResponse", "version": 1, "sequence": 10, "kwargs": {"types": {"crc32": {"format": 1, "size": 4}, "sha256": {"format": 0, "size": 32}}}, "bytes": "0900003400080a03a1657479706573a2656372633332a26473697a650466666f726d61740166736861323536a26473697a65182066666f726d617400"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{"message": "smp.image_management.ImageEraseRequest", "version": 1, "sequence": 14, "kwargs": {}, "bytes": "0a00000100010e05a0"}
{"message": "smp.image_management.ImageEraseRequest", "version": 1, "sequence": 14, "kwargs": {}, "bytes": "0a00000100010e05a0"}
{"message": "smp.image_management.ImageEraseRequest", "version": 1, "sequence": 14, "kwargs": {}, "bytes": "0a00000100010e05a0"}
{"message": "smp.image_management.ImageEraseRequest", "version": 1, "sequence": 15, "kwargs": {"slot": 0}, "bytes": "0a00000700010f05a164736c6f7400"}
{"message": "smp.image_management.ImageEraseRequest", "version": 1, "sequence": 15, "kwargs": {"slot": 0}, "bytes": "0a00000700010f05a164736c6f7400"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{"message": "smp.image_management.ImageEraseResponse", "version": 1, "sequence": 16, "kwargs": {}, "bytes": "0b00000100011005a0"}
{"message": "smp.image_management.ImageEraseResponse", "version": 1, "sequence": 16, "kwargs": {}, "bytes": "0b00000100011005a0"}
{"message": "smp.image_management.ImageEraseResponse", "version": 1, "sequence": 16, "kwargs": {}, "bytes": "0b00000100011005a0"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{"message": "smp.image_management.ImageStatesReadRequest", "version": 1, "sequence": 13, "kwargs": {}, "bytes": "0800000100010d00a0"}
{"message": "smp.image_management.ImageStatesReadRequest", "version": 1, "sequence": 13, "kwargs": {}, "bytes": "0800000100010d00a0"}
{"message": "smp.image_management.ImageStatesReadRequest", "version": 1, "sequence": 13, "kwargs": {}, "bytes": "0800000100010d00a0"}
Loading

0 comments on commit e2213b7

Please sign in to comment.