Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and improve eof.read_valid_eof1_header test #659

Merged
merged 2 commits into from
Jun 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 26 additions & 9 deletions test/unittests/eof_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,41 @@ TEST(eof, read_valid_eof1_header)
{
std::string code;
uint16_t types_size;
uint16_t code_size;
uint16_t data_size;
std::vector<uint16_t> code_sizes;
};
std::string nops_255;
for (int i = 0; i < 255; ++i)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be fill_n().

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, because fill_n() is only for filling with one repeated character.

nops_255 += "5B";

std::string section_size_1_256;
for (int i = 0; i < 256; ++i)
section_size_1_256 += "0001";

const TestCase test_cases[] = {
{"EF00 01 010004 0200010001 030000 00 00000000 00", 4, 1, 0},
{"EF00 01 010004 0200010006 030000 00 00000400 600160005500", 4, 6, 0},
{"EF00 01 010004 0200010001 030001 00 00000000 00 00 AA", 4, 1, 1},
{"EF00 01 010004 0200010006 030004 00 00000000 600160005500 AABBCCDD", 4, 6, 4},
{"EF00 01 010004 0200010100 031000 00 00000000" + std::string(256, '0') +
std::string(4096, 'F'),
4, 256, 4096},
{"EF00 01 010004 0200010001 030000 00 00000000 00", 4, 0, {1}},
{"EF00 01 010004 0200010006 030000 00 00000002 600160005500", 4, 0, {6}},
{"EF00 01 010004 0200010001 030001 00 00000000 00 AA", 4, 1, {1}},
{"EF00 01 010004 0200010006 030004 00 00000002 600160005500 AABBCCDD", 4, 4, {6}},
{"EF00 01 01000C 020003000100020003 030000 00 000000000000000000000000 00 5B00 5B5B00", 12,
0, {1, 2, 3}},
{"EF00 01 01000C 020003000100020003 030004 00 000000000000000000000000 00 5B00 5B5B00 "
"FFFFFFFF",
12, 4, {1, 2, 3}},
{"EF00 01 010004 0200010100 031000 00 00000000" + nops_255 + "00" + std::string(8192, 'F'),
4, 4096, {256}},
{"EF00 01 010400 020100" + section_size_1_256 + " 031000 00 " +
std::string(4 * 256 * 2, '0') + std::string(512, '0') + std::string(8192, 'F'),
4 * 256, 4096, std::vector<uint16_t>(256, 1)},
};

for (const auto& test_case : test_cases)
{
const auto code = from_spaced_hex(test_case.code).value();
EXPECT_EQ(validate_eof(EVMC_CANCUN, code), EOFValidationError::success) << test_case.code;

const auto header = read_valid_eof1_header(code);
EXPECT_EQ(header.code_sizes[0], test_case.code_size) << test_case.code;
EXPECT_EQ(header.code_sizes, test_case.code_sizes) << test_case.code;
EXPECT_EQ(header.data_size, test_case.data_size) << test_case.code;
EXPECT_EQ(header.types.size() * 4, test_case.types_size) << test_case.code;
}
Expand Down