mirror of
https://github.com/siemens-mobile-hacks/teakra.git
synced 2026-11-25 22:27:18 +00:00
67 lines
2.6 KiB
C++
67 lines
2.6 KiB
C++
#include <catch.hpp>
|
|
|
|
#include "../src/pmb887x_dsp_container.h"
|
|
|
|
TEST_CASE("Siemens DSP boot container has exact PLOAD DLOAD BRANCH encoding",
|
|
"[assembler][container]") {
|
|
using Teakra::Pmb887x::Container;
|
|
using Teakra::Pmb887x::Record;
|
|
using Teakra::Pmb887x::RecordType;
|
|
|
|
Container container{};
|
|
container.entry_point = 0x0100;
|
|
container.records = {
|
|
Record{RecordType::Pload, 0x0100, {0x34, 0x12, 0xCD, 0xAB}},
|
|
Record{RecordType::Dload, 0xFFFE, {0xEF, 0xBE}},
|
|
Record{RecordType::Branch, 0x0100, {}},
|
|
};
|
|
|
|
std::vector<u8> raw;
|
|
std::string error;
|
|
REQUIRE(Teakra::Pmb887x::SerializeContainer(container, raw, error));
|
|
const std::vector<u8> expected{
|
|
0x00, 0x00, 0x00, 0x01, 0x02, 0x00, 0x34, 0x12, 0xCD, 0xAB, 0x01,
|
|
0x00, 0xFE, 0xFF, 0x01, 0x00, 0xEF, 0xBE, 0x02, 0x00, 0x00, 0x01,
|
|
};
|
|
REQUIRE(raw == expected);
|
|
|
|
Container parsed;
|
|
REQUIRE(Teakra::Pmb887x::ParseContainer(expected, parsed, error));
|
|
REQUIRE(parsed.entry_point == 0x0100);
|
|
REQUIRE(parsed.records.size() == 3);
|
|
REQUIRE(parsed.records[0].type == RecordType::Pload);
|
|
REQUIRE(parsed.records[0].destination == 0x0100);
|
|
REQUIRE(parsed.records[0].data == (std::vector<u8>{0x34, 0x12, 0xCD, 0xAB}));
|
|
REQUIRE(parsed.records[1].type == RecordType::Dload);
|
|
REQUIRE(parsed.records[1].destination == 0xFFFE);
|
|
REQUIRE(parsed.records[1].data == (std::vector<u8>{0xEF, 0xBE}));
|
|
REQUIRE(parsed.records[2].type == RecordType::Branch);
|
|
}
|
|
|
|
TEST_CASE("Siemens DSP boot container has no fixed record-count limit", "[container]") {
|
|
using Teakra::Pmb887x::Container;
|
|
using Teakra::Pmb887x::Record;
|
|
using Teakra::Pmb887x::RecordType;
|
|
|
|
Container container{};
|
|
for (u16 index = 0; index < 300; ++index)
|
|
container.records.push_back(Record{RecordType::Pload, index, {0x00, 0x00}});
|
|
container.records.push_back(Record{RecordType::Branch, 0x0100, {}});
|
|
|
|
std::vector<u8> raw;
|
|
std::string error;
|
|
REQUIRE(Teakra::Pmb887x::SerializeContainer(container, raw, error));
|
|
|
|
Container parsed;
|
|
REQUIRE(Teakra::Pmb887x::ParseContainer(raw, parsed, error));
|
|
REQUIRE(parsed.records.size() == 301);
|
|
REQUIRE(parsed.records.back().type == RecordType::Branch);
|
|
}
|
|
|
|
TEST_CASE("Siemens DSP boot container rejects bytes after BRANCH", "[container]") {
|
|
const std::vector<u8> raw{0x02, 0x00, 0x00, 0x01, 0xFF};
|
|
Teakra::Pmb887x::Container container;
|
|
std::string error;
|
|
REQUIRE_FALSE(Teakra::Pmb887x::ParseContainer(raw, container, error));
|
|
REQUIRE(error == "DSP container has data after its BRANCH record");
|
|
}
|