diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 8450f049fc..4b1cf2242b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -379,6 +379,8 @@ endif() add_umf_test(NAME ipc SRCS ipcAPI.cpp) +add_umf_test(NAME ipc_negative SRCS ipc_negative.cpp) + function(add_umf_ipc_test) # Parameters: * TEST - a name of the test * SRC_DIR - source files directory # path diff --git a/test/ipcFixtures.hpp b/test/ipcFixtures.hpp index 776ea7aabc..79cea38641 100644 --- a/test/ipcFixtures.hpp +++ b/test/ipcFixtures.hpp @@ -166,6 +166,12 @@ TEST_P(umfIpcTest, GetIPCHandleInvalidArgs) { EXPECT_EQ(ret, UMF_RESULT_SUCCESS); } +TEST_P(umfIpcTest, CloseIPCHandleInvalidPtr) { + int local_var; + auto ret = umfCloseIPCHandle(&local_var); + EXPECT_EQ(ret, UMF_RESULT_ERROR_INVALID_ARGUMENT); +} + TEST_P(umfIpcTest, BasicFlow) { constexpr size_t SIZE = 100; std::vector expected_data(SIZE); diff --git a/test/ipc_negative.cpp b/test/ipc_negative.cpp new file mode 100644 index 0000000000..5407422ead --- /dev/null +++ b/test/ipc_negative.cpp @@ -0,0 +1,53 @@ +// Copyright (C) 2024 Intel Corporation +// Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +#include "base.hpp" +#include "pool_null.h" +#include "provider_null.h" + +#include +#include +#include + +#include + +struct IpcNotSupported : umf_test::test { + protected: + void SetUp() override { + umf_memory_provider_ops_t provider_ops = UMF_NULL_PROVIDER_OPS; + provider_ops.ipc.get_ipc_handle_size = nullptr; + provider_ops.ipc.get_ipc_handle = nullptr; + provider_ops.ipc.open_ipc_handle = nullptr; + provider_ops.ipc.put_ipc_handle = nullptr; + provider_ops.ipc.close_ipc_handle = nullptr; + + umf_result_t ret; + ret = umfMemoryProviderCreate(&provider_ops, nullptr, &provider); + ASSERT_EQ(ret, UMF_RESULT_SUCCESS); + + ret = umfPoolCreate(&UMF_NULL_POOL_OPS, provider, nullptr, + UMF_POOL_CREATE_FLAG_OWN_PROVIDER, &pool); + ASSERT_EQ(ret, UMF_RESULT_SUCCESS); + } + + void TearDown() override { umfPoolDestroy(pool); } + + umf_memory_provider_handle_t provider; + umf_memory_pool_handle_t pool; +}; + +TEST_F(IpcNotSupported, GetIPCHandleSizeNotSupported) { + size_t size; + auto ret = umfPoolGetIPCHandleSize(pool, &size); + EXPECT_EQ(ret, UMF_RESULT_ERROR_NOT_SUPPORTED); +} + +TEST_F(IpcNotSupported, OpenIPCHandleNotSupported) { + // This data doesn't matter, as the ipc call is no-op + std::array ipc_data = {}; + void *ptr; + auto ret = umfOpenIPCHandle( + pool, reinterpret_cast(&ipc_data), &ptr); + EXPECT_EQ(ret, UMF_RESULT_ERROR_NOT_SUPPORTED); +}