oaknut: tests: Only run arm64-specific tests on arm64

This commit is contained in:
Merry 2024-01-30 10:32:34 +00:00
parent 8395b79cf2
commit 496ff1b546
4 changed files with 70 additions and 46 deletions

View file

@ -5,8 +5,12 @@
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_test_macros.hpp>
#include "oaknut/feature_detection/feature_detection.hpp" #include "architecture.hpp"
#include "oaknut/feature_detection/feature_detection_idregs.hpp"
#ifdef ON_ARM64
# include "oaknut/feature_detection/feature_detection.hpp"
# include "oaknut/feature_detection/feature_detection_idregs.hpp"
using namespace oaknut; using namespace oaknut;
@ -16,26 +20,6 @@ TEST_CASE("Print CPU features (Default)")
std::fputs("CPU Features: ", stdout); std::fputs("CPU Features: ", stdout);
#define OAKNUT_CPU_FEATURE(name) \
if (features.has(CpuFeature::name)) \
std::fputs(#name " ", stdout);
#include "oaknut/impl/cpu_feature.inc.hpp"
#undef OAKNUT_CPU_FEATURE
std::fputs("\n", stdout);
}
#if OAKNUT_SUPPORTS_READING_ID_REGISTERS == 1
TEST_CASE("Print CPU features (Using CPUID)")
{
std::optional<id::IdRegisters> id_regs = read_id_registers();
REQUIRE(!!id_regs);
CpuFeatures features = detect_features_via_id_registers(*id_regs);
std::fputs("CPU Features (CPUID method): ", stdout);
# define OAKNUT_CPU_FEATURE(name) \ # define OAKNUT_CPU_FEATURE(name) \
if (features.has(CpuFeature::name)) \ if (features.has(CpuFeature::name)) \
std::fputs(#name " ", stdout); std::fputs(#name " ", stdout);
@ -45,7 +29,27 @@ TEST_CASE("Print CPU features (Using CPUID)")
std::fputs("\n", stdout); std::fputs("\n", stdout);
} }
#elif OAKNUT_SUPPORTS_READING_ID_REGISTERS == 2 # if OAKNUT_SUPPORTS_READING_ID_REGISTERS == 1
TEST_CASE("Print CPU features (Using CPUID)")
{
std::optional<id::IdRegisters> id_regs = read_id_registers();
REQUIRE(!!id_regs);
CpuFeatures features = detect_features_via_id_registers(*id_regs);
std::fputs("CPU Features (CPUID method): ", stdout);
# define OAKNUT_CPU_FEATURE(name) \
if (features.has(CpuFeature::name)) \
std::fputs(#name " ", stdout);
# include "oaknut/impl/cpu_feature.inc.hpp"
# undef OAKNUT_CPU_FEATURE
std::fputs("\n", stdout);
}
# elif OAKNUT_SUPPORTS_READING_ID_REGISTERS == 2
TEST_CASE("Print CPU features (Using CPUID)") TEST_CASE("Print CPU features (Using CPUID)")
{ {
@ -58,14 +62,16 @@ TEST_CASE("Print CPU features (Using CPUID)")
std::printf("CPU Features (CPUID method - Core %zu): ", core_index); std::printf("CPU Features (CPUID method - Core %zu): ", core_index);
# define OAKNUT_CPU_FEATURE(name) \ # define OAKNUT_CPU_FEATURE(name) \
if (features.has(CpuFeature::name)) \ if (features.has(CpuFeature::name)) \
std::fputs(#name " ", stdout); std::fputs(#name " ", stdout);
# include "oaknut/impl/cpu_feature.inc.hpp" # include "oaknut/impl/cpu_feature.inc.hpp"
# undef OAKNUT_CPU_FEATURE # undef OAKNUT_CPU_FEATURE
std::fputs("\n", stdout); std::fputs("\n", stdout);
} }
} }
# endif
#endif #endif

6
tests/architecture.hpp Normal file
View file

@ -0,0 +1,6 @@
// SPDX-FileCopyrightText: Copyright (c) 2024 merryhime <https://mary.rs>
// SPDX-License-Identifier: MIT
#if defined(__ARM64__) || defined(__aarch64__) || defined(_M_ARM64)
# define ON_ARM64
#endif

View file

@ -7,14 +7,18 @@
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_test_macros.hpp>
#include "oaknut/code_block.hpp" #include "architecture.hpp"
#include "oaknut/dual_code_block.hpp"
#include "oaknut/oaknut.hpp" #include "oaknut/oaknut.hpp"
#include "rand_int.hpp" #include "rand_int.hpp"
using namespace oaknut; using namespace oaknut;
using namespace oaknut::util; using namespace oaknut::util;
#ifdef ON_ARM64
# include "oaknut/code_block.hpp"
# include "oaknut/dual_code_block.hpp"
TEST_CASE("Basic Test") TEST_CASE("Basic Test")
{ {
CodeBlock mem{4096}; CodeBlock mem{4096};
@ -196,19 +200,6 @@ TEST_CASE("ADR", "[slow]")
} }
} }
TEST_CASE("PageOffset (rollover)")
{
REQUIRE(PageOffset<21, 12>::encode(0x0000000088e74000, 0xffffffffd167dece) == 0xd2202);
}
TEST_CASE("PageOffset (page boundary)")
{
REQUIRE(PageOffset<21, 12>::encode(0x0001000000000002, 0x0001000000000001) == 0);
REQUIRE(PageOffset<21, 12>::encode(0x0001000000000001, 0x0001000000000002) == 0);
REQUIRE(PageOffset<21, 12>::encode(0x0001000000001000, 0x0001000000000fff) == 0x1fffff);
REQUIRE(PageOffset<21, 12>::encode(0x0001000000000fff, 0x0001000000001000) == 0x080000);
}
TEST_CASE("ADRP", "[slow]") TEST_CASE("ADRP", "[slow]")
{ {
CodeBlock mem{4096}; CodeBlock mem{4096};
@ -325,3 +316,18 @@ TEST_CASE("MOVP2R (4GiB boundary)")
test(-i); test(-i);
} }
} }
#endif
TEST_CASE("PageOffset (rollover)")
{
REQUIRE(PageOffset<21, 12>::encode(0x0000000088e74000, 0xffffffffd167dece) == 0xd2202);
}
TEST_CASE("PageOffset (page boundary)")
{
REQUIRE(PageOffset<21, 12>::encode(0x0001000000000002, 0x0001000000000001) == 0);
REQUIRE(PageOffset<21, 12>::encode(0x0001000000000001, 0x0001000000000002) == 0);
REQUIRE(PageOffset<21, 12>::encode(0x0001000000001000, 0x0001000000000fff) == 0x1fffff);
REQUIRE(PageOffset<21, 12>::encode(0x0001000000000fff, 0x0001000000001000) == 0x080000);
}

View file

@ -9,9 +9,13 @@
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_test_macros.hpp>
#include "oaknut/code_block.hpp" #include "architecture.hpp"
#include "oaknut/oaknut.hpp"
#include "rand_int.hpp" #ifdef ON_ARM64
# include "oaknut/code_block.hpp"
# include "oaknut/oaknut.hpp"
# include "rand_int.hpp"
using namespace oaknut; using namespace oaknut;
using namespace oaknut::util; using namespace oaknut::util;
@ -83,3 +87,5 @@ TEST_CASE("Fibonacci (VectorCodeGenerator)")
REQUIRE(fib(5) == 5); REQUIRE(fib(5) == 5);
REQUIRE(fib(9) == 34); REQUIRE(fib(9) == 34);
} }
#endif