From 661ecba8d029b6f42be45b680eef7e5633901f12 Mon Sep 17 00:00:00 2001 From: Krzysztof Swiecicki Date: Tue, 28 Nov 2023 17:33:12 +0100 Subject: [PATCH] [UR] Add tests for lifetime validation --- test/layers/validation/CMakeLists.txt | 1 + test/layers/validation/fixtures.hpp | 45 +++++++++++++++++------ test/layers/validation/lifetime.cpp | 21 +++++++++++ test/layers/validation/lifetime.out.match | 7 ++++ 4 files changed, 62 insertions(+), 12 deletions(-) create mode 100644 test/layers/validation/lifetime.cpp create mode 100644 test/layers/validation/lifetime.out.match diff --git a/test/layers/validation/CMakeLists.txt b/test/layers/validation/CMakeLists.txt index 944202e0d2..9b1f5734c0 100644 --- a/test/layers/validation/CMakeLists.txt +++ b/test/layers/validation/CMakeLists.txt @@ -52,3 +52,4 @@ endfunction() add_validation_test(parameters parameters.cpp) add_validation_match_test(leaks leaks.out.match leaks.cpp) add_validation_match_test(leaks_mt leaks_mt.out.match leaks_mt.cpp) +add_validation_match_test(lifetime lifetime.out.match lifetime.cpp) diff --git a/test/layers/validation/fixtures.hpp b/test/layers/validation/fixtures.hpp index 4071bbecad..d1ba20b739 100644 --- a/test/layers/validation/fixtures.hpp +++ b/test/layers/validation/fixtures.hpp @@ -30,36 +30,57 @@ struct urTest : ::testing::Test { ur_loader_config_handle_t loader_config = nullptr; }; -struct valPlatformsTest : urTest { +struct valAdaptersTest : urTest { void SetUp() override { urTest::SetUp(); uint32_t adapter_count; ASSERT_EQ(urAdapterGet(0, nullptr, &adapter_count), UR_RESULT_SUCCESS); + ASSERT_GT(adapter_count, 0); adapters.resize(adapter_count); ASSERT_EQ(urAdapterGet(adapter_count, adapters.data(), nullptr), UR_RESULT_SUCCESS); - - uint32_t count; - ASSERT_EQ( - urPlatformGet(adapters.data(), adapter_count, 0, nullptr, &count), - UR_RESULT_SUCCESS); - ASSERT_NE(count, 0); - platforms.resize(count); - ASSERT_EQ(urPlatformGet(adapters.data(), adapter_count, count, - platforms.data(), nullptr), - UR_RESULT_SUCCESS); } void TearDown() override { - for (auto &adapter : adapters) { + for (auto adapter : adapters) { ASSERT_EQ(urAdapterRelease(adapter), UR_RESULT_SUCCESS); } urTest::TearDown(); } std::vector adapters; +}; + +struct valAdapterTest : valAdaptersTest { + + void SetUp() { + valAdaptersTest::SetUp(); + adapter = adapters[0]; // TODO - which to choose? + } + + ur_adapter_handle_t adapter; +}; + +struct valPlatformsTest : valAdaptersTest { + + void SetUp() override { + valAdaptersTest::SetUp(); + + uint32_t count; + ASSERT_EQ(urPlatformGet(adapters.data(), + static_cast(adapters.size()), 0, + nullptr, &count), + UR_RESULT_SUCCESS); + ASSERT_NE(count, 0); + platforms.resize(count); + ASSERT_EQ(urPlatformGet(adapters.data(), + static_cast(adapters.size()), count, + platforms.data(), nullptr), + UR_RESULT_SUCCESS); + } + std::vector platforms; }; diff --git a/test/layers/validation/lifetime.cpp b/test/layers/validation/lifetime.cpp new file mode 100644 index 0000000000..4c642fedb0 --- /dev/null +++ b/test/layers/validation/lifetime.cpp @@ -0,0 +1,21 @@ +// Copyright (C) 2023 Intel Corporation +// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions. +// See LICENSE.TXT +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +#include "fixtures.hpp" + +TEST_F(urTest, testUrAdapterHandleLifetimeExpectFail) { + size_t size = 0; + ur_adapter_handle_t adapter = (ur_adapter_handle_t)0xC0FFEE; + ur_adapter_info_t info_type = UR_ADAPTER_INFO_BACKEND; + ASSERT_EQ(urAdapterGetInfo(adapter, info_type, 0, nullptr, &size), + UR_RESULT_ERROR_INVALID_ARGUMENT); +} + +TEST_F(valAdapterTest, testUrAdapterHandleLifetimeExpectSuccess) { + size_t size = 0; + ur_adapter_info_t info_type = UR_ADAPTER_INFO_BACKEND; + ASSERT_EQ(urAdapterGetInfo(adapter, info_type, 0, nullptr, &size), + UR_RESULT_SUCCESS); +} diff --git a/test/layers/validation/lifetime.out.match b/test/layers/validation/lifetime.out.match new file mode 100644 index 0000000000..c454500641 --- /dev/null +++ b/test/layers/validation/lifetime.out.match @@ -0,0 +1,7 @@ +{{IGNORE}} +[ RUN ] urTest.testUrAdapterHandleLifetimeExpectFail + [ERROR]: There are no valid references to handle {{[0-9xa-fA-F]+}} +{{IGNORE}} +[ RUN ] valAdapterTest.testUrAdapterHandleLifetimeExpectSuccess +{{^(?!.*There are no valid references to handle).*$}} +{{IGNORE}}