Skip to content

Commit 3dff4c7

Browse files
committed
Add a test that constructs 1 million instructions into Program
1 parent 36b813c commit 3dff4c7

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

tests/src/tests/tests.program.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <gtest/gtest.h>
2+
#include <zasm/testdata/x86/instructions.hpp>
23
#include <zasm/zasm.hpp>
34

45
namespace zasm::tests
@@ -369,4 +370,23 @@ namespace zasm::tests
369370
ASSERT_EQ(data, nullptr);
370371
}
371372

373+
// Test to ensure that we stay under 4 GiB of memory with a large number of instructions.
374+
TEST(ProgramTests, Test1MillionInstructions)
375+
{
376+
Program program(MachineMode::AMD64);
377+
378+
x86::Assembler assembler(program);
379+
380+
constexpr auto kMaxInstructions = 1'000'000;
381+
382+
for (size_t i = 0; i < kMaxInstructions; i++)
383+
{
384+
const auto& instrEntry = data::Instructions[i % std::size(data::Instructions)];
385+
386+
ASSERT_EQ(instrEntry.emitter(assembler), ErrorCode::None) << instrEntry.instrBytes << ", " << instrEntry.operation;
387+
}
388+
389+
ASSERT_EQ(program.size(), kMaxInstructions);
390+
}
391+
372392
} // namespace zasm::tests

0 commit comments

Comments
 (0)