Skip to content

Commit

Permalink
increase test coverage to sigment offset case
Browse files Browse the repository at this point in the history
  • Loading branch information
RubBra committed Sep 9, 2024
1 parent 330aa47 commit 48fe67c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/mwr/utils/ihex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static inline u8 ihex_byte(const string& line, size_t off) {
}

template <typename T>
static inline T vec_to(const std::vector<u8>& vec) {
static inline u64 vec_to(const std::vector<u8>& vec) {
constexpr size_t num_bytes = sizeof(T);
MWR_ERROR_ON(num_bytes > vec.size(), "reading beyond given vector");
T result = 0;
Expand Down Expand Up @@ -76,7 +76,7 @@ static inline ihex_record process_line(const string& line) {
case IHEX_EOF:
if (nr_bytes != 0x00 || addr != 0x0000)
return { INVALID_DESCRIPTOR, 0, {} };
break;
return { IHEX_EOF, 0, {} };
case IHEX_EX_SEG:
case IHEX_EX_LIN_ADDR:
if (nr_bytes != 0x02 || addr != 0x0000)
Expand All @@ -102,8 +102,8 @@ ihex::ihex(const string& filename): m_start_addr(), m_records() {
ifstream file(filename);
MWR_ERROR_ON(!file, "Cannot open ihex file '%s'", filename.c_str());

u32 seg_offset = 0;
u32 linear_offset = 0;
u64 seg_offset = 0;
u64 linear_offset = 0;
string line;
while (getline(file, line)) {
line = trim(line);
Expand Down Expand Up @@ -134,7 +134,7 @@ ihex::ihex(const string& filename): m_start_addr(), m_records() {
}
}
MWR_REPORT_ON(m_records.size() == 0,
"File '%s' does not seem to be in intel hex format",
"File '%s' does not seem to be in Intel hex format",
filename.c_str());
}

Expand Down
2 changes: 2 additions & 0 deletions test/resources/sample.ihex
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
:100110002146017E17C20001FF5F16002148011928
:020000040800F2//extended linear address by 0x800 << 16
:10012000194E79234623965778239EDA3F01B2CAA7
:0200000200001FA//extended linear address by 0x1 << 4
:100130003F0156702B5E712B722B732146013421C7
:100130003F0156702B5E712B722B732146013421C6 //broken checksum -> should not appear as line in test
:00000001FF//eof
2 changes: 1 addition & 1 deletion test/utils/ihex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ TEST(ihex, load) {
EXPECT_EQ(reader.records()[0].addr, 0x0100);
EXPECT_EQ(reader.records()[1].addr, 0x0110);
EXPECT_EQ(reader.records()[2].addr, 0x0120 | 0x800 << 16);
EXPECT_EQ(reader.records()[3].addr, 0x0130 | 0x800 << 16);
EXPECT_EQ(reader.records()[3].addr, 0x0130 | 0x800 << 16 | 0x1 << 4);

EXPECT_EQ(reader.records()[0].data, V1);
EXPECT_EQ(reader.records()[1].data, V2);
Expand Down

0 comments on commit 48fe67c

Please sign in to comment.