Skip to content

Commit

Permalink
Tests for RJUMP* instruction validation
Browse files Browse the repository at this point in the history
  • Loading branch information
gumb0 committed Oct 6, 2021
1 parent cda0dbe commit f9c19b3
Showing 1 changed file with 99 additions and 0 deletions.
99 changes: 99 additions & 0 deletions test/unittests/eof_validation_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,102 @@ TEST(eof_validation, EOF1_truncated_push)
EXPECT_EQ(validate_eof(container), EOFValidationErrror::success) << hex(container);
}
}

TEST(eof_validation, EOF1_valid_rjump)
{
// offset = 0
EXPECT_EQ(validate_eof(from_hex("EF0001 010004 00 5C000000")), EOFValidationErrror::success);

// offset = 3
EXPECT_EQ(
validate_eof(from_hex("EF0001 010007 00 5C000300000000")), EOFValidationErrror::success);

// offset = -4
EXPECT_EQ(validate_eof(from_hex("EF0001 010004 00 005CFFFC")), EOFValidationErrror::success);
}

TEST(eof_validation, EOF1_valid_rjumpi)
{
// offset = 0
EXPECT_EQ(
validate_eof(from_hex("EF0001 010006 00 60005D000000")), EOFValidationErrror::success);

// offset = 3
EXPECT_EQ(validate_eof(from_hex("EF0001 010009 00 60005D000300000000")),
EOFValidationErrror::success);

// offset = -5
EXPECT_EQ(validate_eof(from_hex("EF0001 010005 00 60005DFFFB")), EOFValidationErrror::success);
}

TEST(eof_validation, EOF1_rjump_truncated)
{
EXPECT_EQ(
validate_eof(from_hex("EF0001 010001 00 5C")), EOFValidationErrror::truncated_immediate);

EXPECT_EQ(
validate_eof(from_hex("EF0001 010002 00 5C00")), EOFValidationErrror::truncated_immediate);
}

TEST(eof_validation, EOF1_rjumpi_truncated)
{
EXPECT_EQ(
validate_eof(from_hex("EF0001 010001 00 5D")), EOFValidationErrror::truncated_immediate);

EXPECT_EQ(
validate_eof(from_hex("EF0001 010002 00 5D00")), EOFValidationErrror::truncated_immediate);
}

TEST(eof_validation, EOF1_rjump_invalid_destination)
{
// Into header (offset = -5)
EXPECT_EQ(validate_eof(from_hex("EF0001 010003 00 5CFFFB")),
EOFValidationErrror::invalid_rjump_destination);

// To before code begin (offset = -13)
EXPECT_EQ(validate_eof(from_hex("EF0001 010003 00 5CFFF3")),
EOFValidationErrror::invalid_rjump_destination);

// To after code end (offset = 1)
EXPECT_EQ(validate_eof(from_hex("EF0001 010003 00 5C0001")),
EOFValidationErrror::invalid_rjump_destination);

// To code end (offset = 0)
EXPECT_EQ(validate_eof(from_hex("EF0001 010003 00 5C0000")),
EOFValidationErrror::invalid_rjump_destination);

// To the same RJUMP immediate (offset = -1)
EXPECT_EQ(validate_eof(from_hex("EF0001 010003 00 5CFFFF")),
EOFValidationErrror::invalid_rjump_destination);

// To PUSH immediate (offset = -4)
EXPECT_EQ(validate_eof(from_hex("EF0001 010005 00 60005CFFFC")),
EOFValidationErrror::invalid_rjump_destination);
}

TEST(eof_validation, EOF1_rjumpi_invalid_destination)
{
// Into header (offset = -7)
EXPECT_EQ(validate_eof(from_hex("EF0001 010005 00 60005DFFF9")),
EOFValidationErrror::invalid_rjump_destination);

// To before code begin (offset = -15)
EXPECT_EQ(validate_eof(from_hex("EF0001 010005 00 60005DFFF1")),
EOFValidationErrror::invalid_rjump_destination);

// To after code end (offset = 1)
EXPECT_EQ(validate_eof(from_hex("EF0001 010005 00 60005D0001")),
EOFValidationErrror::invalid_rjump_destination);

// To code end (offset = 0)
EXPECT_EQ(validate_eof(from_hex("EF0001 010005 00 60005D0000")),
EOFValidationErrror::invalid_rjump_destination);

// To the same RJUMPI immediate (offset = -1)
EXPECT_EQ(validate_eof(from_hex("EF0001 010005 00 60005DFFFF")),
EOFValidationErrror::invalid_rjump_destination);

// To PUSH immediate (offset = -4)
EXPECT_EQ(validate_eof(from_hex("EF0001 010005 00 60005DFFFC")),
EOFValidationErrror::invalid_rjump_destination);
}

0 comments on commit f9c19b3

Please sign in to comment.