Files
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

154 lines
4.4 KiB
C++

// Copyright Advanced Micro Devices, Inc., or its affiliates.
// SPDX-License-Identifier: MIT
#include "CustomMatchers.hpp"
#include "ExpressionMatchers.hpp"
#include "TestContext.hpp"
#include <common/Utilities.hpp>
#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers.hpp>
#include <catch2/matchers/catch_matchers_floating_point.hpp>
#include <catch2/matchers/catch_matchers_string.hpp>
#include <rocRoller/Utilities/Error.hpp>
TEST_CASE("HipSuccessMatcher works", "[meta-test][gpu]")
{
std::vector<int> cpuValue = {5};
auto gpuValue = make_shared_device(cpuValue);
int copiedValue;
REQUIRE_THAT(hipMemcpy(&copiedValue, gpuValue.get(), sizeof(int), hipMemcpyDefault),
HasHipSuccess());
auto matcher = HasHipSuccess();
CHECK(matcher.match(hipSuccess));
CHECK_FALSE(matcher.match(hipErrorInvalidValue));
CHECK_THAT(matcher.describe(), Catch::Matchers::ContainsSubstring("Hip error"));
}
TEST_CASE("HipSuccessMatcher REQUIRE", "[meta-test][!shouldfail]")
{
hipError_t failure = hipErrorInvalidValue;
REQUIRE_THAT(failure, HasHipSuccess());
}
TEST_CASE("HipSuccessMatcher CHECK", "[meta-test][!shouldfail]")
{
hipError_t failure = hipErrorInvalidValue;
CHECK_THAT(failure, HasHipSuccess());
}
TEST_CASE("DeviceScalarMatcher works", "[meta-test][gpu]")
{
SECTION("Int")
{
std::vector<int> cpuValue = {5};
auto gpuValue = make_shared_device(cpuValue);
CHECK_THAT(gpuValue, HasDeviceScalarEqualTo(5));
auto differentValueChecker = HasDeviceScalarEqualTo(6);
SECTION("Failure")
{
CHECK_FALSE(differentValueChecker.match(gpuValue));
CHECK_THAT(differentValueChecker.describe(),
Catch::Matchers::ContainsSubstring("Device value: 5")
&& Catch::Matchers::ContainsSubstring("Expected Value: 6"));
}
SECTION("Success")
{
cpuValue[0] = 6;
REQUIRE_THAT(hipMemcpy(gpuValue.get(), cpuValue.data(), sizeof(int), hipMemcpyDefault),
HasHipSuccess());
CHECK(differentValueChecker.match(gpuValue));
}
}
SECTION("Float")
{
std::vector<float> cpuValue = {5.25f};
auto gpuValue = make_shared_device(cpuValue);
CHECK_THAT(gpuValue, HasDeviceScalarEqualTo(5.25f));
}
}
TEST_CASE("CustomDeviceScalarMatcher works", "[meta-test][gpu]")
{
std::vector<float> cpuValue = {5.0f};
auto gpuValue = make_shared_device(cpuValue);
auto expectedValue = cpuValue[0] + std::numeric_limits<float>::epsilon() * 10;
CHECK_THAT(gpuValue, HasDeviceScalar(Catch::Matchers::WithinULP(expectedValue, 10)));
auto differentValueChecker = HasDeviceScalar(Catch::Matchers::WithinULP(6.0f, 0));
SECTION("Failure")
{
CHECK_FALSE(differentValueChecker.match(gpuValue));
CHECK_THAT(differentValueChecker.describe(),
Catch::Matchers::ContainsSubstring("Device value: 5")
&& Catch::Matchers::ContainsSubstring("ULPs of"));
}
SECTION("Success")
{
cpuValue[0] = 6;
REQUIRE_THAT(hipMemcpy(gpuValue.get(), cpuValue.data(), sizeof(int), hipMemcpyDefault),
HasHipSuccess());
CHECK(differentValueChecker.match(gpuValue));
}
}
TEST_CASE("Expression matchers work", "[meta-test]")
{
using namespace rocRoller::Expression;
auto context = TestContext::ForDefaultTarget();
auto v0 = rocRoller::Register::Value::Placeholder(
context.get(), rocRoller::Register::Type::Vector, rocRoller::DataType::Int32, 1);
v0->allocateNow();
auto v0Ex = v0->expression();
auto one = literal(1);
auto two = literal(2);
CHECK_THAT(v0Ex, IdenticalTo(v0->expression()));
CHECK_THAT(v0Ex, EquivalentTo(v0->expression()));
CHECK_THAT(v0Ex, SimplifiesTo(v0->expression()));
CHECK_THAT(v0Ex + two, IdenticalTo(v0->expression() + two));
CHECK_THAT(v0Ex + two, EquivalentTo(v0->expression() + two));
CHECK_THAT(v0Ex + two, SimplifiesTo(v0->expression() + two));
CHECK_THAT(v0Ex + two, !IdenticalTo(two + v0Ex));
CHECK_THAT(v0Ex + two, EquivalentTo(two + v0Ex));
CHECK_THAT(v0Ex + two, SimplifiesTo(two + v0Ex));
CHECK_THAT(v0Ex * one, !IdenticalTo(v0Ex));
CHECK_THAT(v0Ex * one, !EquivalentTo(v0Ex));
CHECK_THAT(v0Ex * one, SimplifiesTo(v0Ex));
}