oaknut/tests/basic.cpp

31 lines
582 B
C++
Raw Normal View History

2022-07-03 21:21:36 +02:00
// SPDX-FileCopyrightText: Copyright (c) 2022 merryhime <https://mary.rs>
2022-07-03 12:12:20 +02:00
// SPDX-License-Identifier: MIT
2022-07-02 21:31:43 +02:00
#include <cstdint>
#include <cstdio>
2022-07-03 12:12:20 +02:00
#include <catch2/catch_test_macros.hpp>
2022-07-02 21:31:43 +02:00
2022-07-09 21:14:06 +02:00
#include "oaknut/code_block.hpp"
2022-07-02 21:31:43 +02:00
#include "oaknut/oaknut.hpp"
2022-07-03 12:12:20 +02:00
TEST_CASE("Basic Test")
2022-07-02 21:31:43 +02:00
{
using namespace oaknut;
using namespace oaknut::util;
2022-07-09 21:14:06 +02:00
CodeBlock mem{4096};
CodeGenerator code{mem.ptr()};
mem.unprotect();
2022-07-02 21:31:43 +02:00
code.MOVZ(W0, 42);
code.RET(X30);
2022-07-09 21:14:06 +02:00
mem.protect();
mem.invalidate_all();
2022-07-02 21:31:43 +02:00
2022-07-09 21:14:06 +02:00
int result = ((int (*)())mem.ptr())();
2022-07-03 12:12:20 +02:00
REQUIRE(result == 42);
2022-07-02 21:31:43 +02:00
}