Skip to content

Commit

Permalink
Update the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ZehMatt committed Jun 18, 2024
1 parent 371b6af commit 0892476
Showing 1 changed file with 70 additions and 7 deletions.
77 changes: 70 additions & 7 deletions tests/src/tests/tests.serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1229,30 +1229,33 @@ namespace zasm::tests
std::string("Error at node \"and rbp, 0x123456789abcdf\" with id 0: Impossible instruction"));
}

TEST(SerializationTests, TestSerializationJecxzBad)
template<typename TMnemonic>
static void TestSerializationLabelRangeBad(MachineMode mode, TMnemonic mnemonic, const char* mnemonicName)
{
Program program(MachineMode::AMD64);
Program program(mode);

x86::Assembler a(program);
auto labelLoop = a.createLabel();
ASSERT_EQ(a.jecxz(labelLoop), ErrorCode::None);
ASSERT_EQ(a.emit(mnemonic, labelLoop), ErrorCode::None);
ASSERT_EQ(a.dd(0, 256), ErrorCode::None);
ASSERT_EQ(a.bind(labelLoop), ErrorCode::None);

Serializer serializer;
auto res = serializer.serialize(program, 0x140015000);
ASSERT_EQ(res, ErrorCode::AddressOutOfRange);

ASSERT_EQ(res.getErrorMessage(), std::string("Error at node \"jecxz L0\" with id 0: Label out of range for operand 0"));
const auto errMsg = std::string("Error at node \"") + mnemonicName
+ " L0\" with id 0: Label out of range for operand 0";
ASSERT_EQ(res.getErrorMessage(), errMsg);
}

TEST(SerializationTests, TestSerializationJecxzGood)
template<typename TMnemonic> static void TestSerializationLabelRangeGood(MachineMode mode, TMnemonic mnemonic)
{
Program program(MachineMode::AMD64);
Program program(mode);

x86::Assembler a(program);
auto labelLoop = a.createLabel();
ASSERT_EQ(a.jecxz(labelLoop), ErrorCode::None);
ASSERT_EQ(a.emit(mnemonic, labelLoop), ErrorCode::None);
ASSERT_EQ(a.dd(0), ErrorCode::None);
ASSERT_EQ(a.bind(labelLoop), ErrorCode::None);

Expand All @@ -1261,6 +1264,66 @@ namespace zasm::tests
ASSERT_EQ(res, ErrorCode::None);
}

TEST(SerializationTests, TestSerializationJcxzBad)
{
TestSerializationLabelRangeBad(MachineMode::I386, x86::Mnemonic::Jcxz, "jcxz");
}

TEST(SerializationTests, TestSerializationJcxzGood)
{
TestSerializationLabelRangeGood(MachineMode::I386, x86::Mnemonic::Jcxz);
}

TEST(SerializationTests, TestSerializationJecxzBad)
{
TestSerializationLabelRangeBad(MachineMode::AMD64, x86::Mnemonic::Jecxz, "jecxz");
}

TEST(SerializationTests, TestSerializationJecxzGood)
{
TestSerializationLabelRangeGood(MachineMode::AMD64, x86::Mnemonic::Jecxz);
}

TEST(SerializationTests, TestSerializationJrcxzBad)
{
TestSerializationLabelRangeBad(MachineMode::AMD64, x86::Mnemonic::Jrcxz, "jrcxz");
}

TEST(SerializationTests, TestSerializationJrcxzGood)
{
TestSerializationLabelRangeGood(MachineMode::AMD64, x86::Mnemonic::Jrcxz);
}

TEST(SerializationTests, TestSerializationLoopBad)
{
TestSerializationLabelRangeBad(MachineMode::AMD64, x86::Mnemonic::Loop, "loop");
}

TEST(SerializationTests, TestSerializationLoopGood)
{
TestSerializationLabelRangeGood(MachineMode::AMD64, x86::Mnemonic::Loop);
}

TEST(SerializationTests, TestSerializationLoopeBad)
{
TestSerializationLabelRangeBad(MachineMode::AMD64, x86::Mnemonic::Loope, "loope");
}

TEST(SerializationTests, TestSerializationLoopeGood)
{
TestSerializationLabelRangeGood(MachineMode::AMD64, x86::Mnemonic::Loope);
}

TEST(SerializationTests, TestSerializationLoopneBad)
{
TestSerializationLabelRangeBad(MachineMode::AMD64, x86::Mnemonic::Loopne, "loopne");
}

TEST(SerializationTests, TestSerializationLoopneGood)
{
TestSerializationLabelRangeGood(MachineMode::AMD64, x86::Mnemonic::Loopne);
}

TEST(SerializationTests, TestBadMemoryDisplacement)
{
Program program(MachineMode::AMD64);
Expand Down

0 comments on commit 0892476

Please sign in to comment.