Skip to content
This repository has been archived by the owner on Mar 5, 2024. It is now read-only.

Commit

Permalink
oaknut: tests: Only run arm64-specific tests on arm64
Browse files Browse the repository at this point in the history
  • Loading branch information
merryhime committed Jan 30, 2024
1 parent 8395b79 commit 496ff1b
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 37 deletions.
44 changes: 25 additions & 19 deletions tests/_feature_detect.cpp
Expand Up @@ -5,8 +5,12 @@

#include <catch2/catch_test_macros.hpp>

#include "oaknut/feature_detection/feature_detection.hpp"
#include "oaknut/feature_detection/feature_detection_idregs.hpp"
#include "architecture.hpp"

#ifdef ON_ARM64

# include "oaknut/feature_detection/feature_detection.hpp"
# include "oaknut/feature_detection/feature_detection_idregs.hpp"

using namespace oaknut;

Expand All @@ -16,16 +20,16 @@ TEST_CASE("Print CPU features (Default)")

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
# 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
# if OAKNUT_SUPPORTS_READING_ID_REGISTERS == 1

TEST_CASE("Print CPU features (Using CPUID)")
{
Expand All @@ -36,16 +40,16 @@ TEST_CASE("Print CPU features (Using CPUID)")

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
# 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
# elif OAKNUT_SUPPORTS_READING_ID_REGISTERS == 2

TEST_CASE("Print CPU features (Using CPUID)")
{
Expand All @@ -58,14 +62,16 @@ TEST_CASE("Print CPU features (Using CPUID)")

std::printf("CPU Features (CPUID method - Core %zu): ", core_index);

# 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
# 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);
}
}

# endif

#endif
6 changes: 6 additions & 0 deletions tests/architecture.hpp
@@ -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
36 changes: 21 additions & 15 deletions tests/basic.cpp
Expand Up @@ -7,14 +7,18 @@

#include <catch2/catch_test_macros.hpp>

#include "oaknut/code_block.hpp"
#include "oaknut/dual_code_block.hpp"
#include "architecture.hpp"
#include "oaknut/oaknut.hpp"
#include "rand_int.hpp"

using namespace oaknut;
using namespace oaknut::util;

#ifdef ON_ARM64

# include "oaknut/code_block.hpp"
# include "oaknut/dual_code_block.hpp"

TEST_CASE("Basic Test")
{
CodeBlock mem{4096};
Expand Down Expand Up @@ -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]")
{
CodeBlock mem{4096};
Expand Down Expand Up @@ -325,3 +316,18 @@ TEST_CASE("MOVP2R (4GiB boundary)")
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);
}
12 changes: 9 additions & 3 deletions tests/vector_code_gen.cpp
Expand Up @@ -9,9 +9,13 @@

#include <catch2/catch_test_macros.hpp>

#include "oaknut/code_block.hpp"
#include "oaknut/oaknut.hpp"
#include "rand_int.hpp"
#include "architecture.hpp"

#ifdef ON_ARM64

# include "oaknut/code_block.hpp"
# include "oaknut/oaknut.hpp"
# include "rand_int.hpp"

using namespace oaknut;
using namespace oaknut::util;
Expand Down Expand Up @@ -83,3 +87,5 @@ TEST_CASE("Fibonacci (VectorCodeGenerator)")
REQUIRE(fib(5) == 5);
REQUIRE(fib(9) == 34);
}

#endif

0 comments on commit 496ff1b

Please sign in to comment.