Skip to content

Commit

Permalink
Add a test that constructs 1 million instructions into Program
Browse files Browse the repository at this point in the history
  • Loading branch information
ZehMatt committed Mar 1, 2025
1 parent 36b813c commit 3dff4c7
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/src/tests/tests.program.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <gtest/gtest.h>
#include <zasm/testdata/x86/instructions.hpp>
#include <zasm/zasm.hpp>

namespace zasm::tests
Expand Down Expand Up @@ -369,4 +370,23 @@ namespace zasm::tests
ASSERT_EQ(data, nullptr);
}

// Test to ensure that we stay under 4 GiB of memory with a large number of instructions.
TEST(ProgramTests, Test1MillionInstructions)
{
Program program(MachineMode::AMD64);

x86::Assembler assembler(program);

constexpr auto kMaxInstructions = 1'000'000;

for (size_t i = 0; i < kMaxInstructions; i++)
{
const auto& instrEntry = data::Instructions[i % std::size(data::Instructions)];

ASSERT_EQ(instrEntry.emitter(assembler), ErrorCode::None) << instrEntry.instrBytes << ", " << instrEntry.operation;
}

ASSERT_EQ(program.size(), kMaxInstructions);
}

} // namespace zasm::tests

0 comments on commit 3dff4c7

Please sign in to comment.