Пример #1
0
def test_section_cmd_header_info():
    """Test presence of all keywords in info() method of section header cmd."""
    section_header = CmdSectionHeader(length=100)
    output = section_header.info()
    required_strings = ["UID", "Type"]
    for required_string in required_strings:
        assert required_string in output, f"String {required_string} is not in output"
Пример #2
0
def test_section_header_cmd():
    """Test section uid, section type, length, info value, size after append, export and parsing of
    CmdSectionHeader command."""
    cmd = CmdSectionHeader(section_uid=10, section_type=10, length=100)
    assert cmd.section_uid == 10
    assert cmd.section_type == 10
    assert cmd.length == 100

    data = cmd.export()
    assert len(data) == BaseCmd.SIZE

    cmd_parsed = CmdSectionHeader.parse(data=data)
    assert cmd == cmd_parsed
Пример #3
0
    def get_cmd_blocks_to_export(self) -> List[bytes]:
        """Export commands as bytes."""
        commands_bytes = b"".join(
            [command.export() for command in self.commands])
        section_header = CmdSectionHeader(length=len(commands_bytes))
        total = section_header.export() + commands_bytes

        data_blocks = [
            total[i:i + self.DATA_CHUNK_LENGTH]
            for i in range(0, len(total), self.DATA_CHUNK_LENGTH)
        ]
        data_blocks[-1] = align_block(data_blocks[-1],
                                      alignment=self.DATA_CHUNK_LENGTH)

        return data_blocks
Пример #4
0
    def export(self) -> bytes:
        """Export commands as bytes."""
        commands_bytes = b''.join(
            [command.export() for command in self.commands])
        section_header = CmdSectionHeader(length=len(commands_bytes))
        total = section_header.export() + commands_bytes

        data_blocks = [
            total[i:i + self.DATA_CHUNK_LENGTH]
            for i in range(0, len(total), self.DATA_CHUNK_LENGTH)
        ]
        data_blocks[-1] = align_block(data_blocks[-1],
                                      alignment=self.DATA_CHUNK_LENGTH)
        self.block_count = len(data_blocks)

        processed_blocks = [
            self._process_block(block_number, block_data)
            for block_number, block_data in reversed(
                list(enumerate(data_blocks, start=1)))
        ]
        final_data = b''.join(reversed(processed_blocks))
        return final_data
Пример #5
0
def test_section_cmd_header_offset():
    """Section header cmd size validity test."""
    section_header = CmdSectionHeader(length=100)
    data = section_header.export()
    with pytest.raises(SPSDKError):
        CmdSectionHeader.parse(data=data, offset=50)
Пример #6
0
def test_section_cmd_header_basic():
    """Test whether two section headers cmd are identical."""
    section_header = CmdSectionHeader(length=10)
    section_header2 = CmdSectionHeader(length=500)

    assert section_header != section_header2, "Two different images are the same!"