Skip to content

Commit 76edd73

Browse files
Merge pull request #858 from staniewzki/ipc-coverity
Add tests for IPC not supported case
2 parents 4a2136e + b458c19 commit 76edd73

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

test/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,8 @@ endif()
404404

405405
add_umf_test(NAME ipc SRCS ipcAPI.cpp)
406406

407+
add_umf_test(NAME ipc_negative SRCS ipc_negative.cpp)
408+
407409
function(add_umf_ipc_test)
408410
# Parameters: * TEST - a name of the test * SRC_DIR - source files directory
409411
# path

test/ipcFixtures.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,12 @@ TEST_P(umfIpcTest, GetIPCHandleInvalidArgs) {
181181
get_umf_result_of_free(freeNotSupported, UMF_RESULT_SUCCESS));
182182
}
183183

184+
TEST_P(umfIpcTest, CloseIPCHandleInvalidPtr) {
185+
int local_var;
186+
auto ret = umfCloseIPCHandle(&local_var);
187+
EXPECT_EQ(ret, UMF_RESULT_ERROR_INVALID_ARGUMENT);
188+
}
189+
184190
TEST_P(umfIpcTest, BasicFlow) {
185191
constexpr size_t SIZE = 100;
186192
std::vector<int> expected_data(SIZE);

test/ipc_negative.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright (C) 2024 Intel Corporation
2+
// Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
3+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
5+
#include "base.hpp"
6+
#include "pool_null.h"
7+
#include "provider_null.h"
8+
9+
#include <umf/ipc.h>
10+
#include <umf/memory_pool.h>
11+
#include <umf/memory_provider.h>
12+
13+
#include <array>
14+
15+
struct IpcNotSupported : umf_test::test {
16+
protected:
17+
void SetUp() override {
18+
umf_memory_provider_ops_t provider_ops = UMF_NULL_PROVIDER_OPS;
19+
provider_ops.ipc.get_ipc_handle_size = nullptr;
20+
provider_ops.ipc.get_ipc_handle = nullptr;
21+
provider_ops.ipc.open_ipc_handle = nullptr;
22+
provider_ops.ipc.put_ipc_handle = nullptr;
23+
provider_ops.ipc.close_ipc_handle = nullptr;
24+
25+
umf_result_t ret;
26+
ret = umfMemoryProviderCreate(&provider_ops, nullptr, &provider);
27+
ASSERT_EQ(ret, UMF_RESULT_SUCCESS);
28+
29+
ret = umfPoolCreate(&UMF_NULL_POOL_OPS, provider, nullptr,
30+
UMF_POOL_CREATE_FLAG_OWN_PROVIDER, &pool);
31+
ASSERT_EQ(ret, UMF_RESULT_SUCCESS);
32+
}
33+
34+
void TearDown() override { umfPoolDestroy(pool); }
35+
36+
umf_memory_provider_handle_t provider;
37+
umf_memory_pool_handle_t pool;
38+
};
39+
40+
TEST_F(IpcNotSupported, GetIPCHandleSizeNotSupported) {
41+
size_t size;
42+
auto ret = umfPoolGetIPCHandleSize(pool, &size);
43+
EXPECT_EQ(ret, UMF_RESULT_ERROR_NOT_SUPPORTED);
44+
}
45+
46+
TEST_F(IpcNotSupported, OpenIPCHandleNotSupported) {
47+
// This data doesn't matter, as the ipc call is no-op
48+
std::array<uint8_t, 128> ipc_data = {};
49+
void *ptr;
50+
auto ret = umfOpenIPCHandle(
51+
pool, reinterpret_cast<umf_ipc_handle_t>(&ipc_data), &ptr);
52+
EXPECT_EQ(ret, UMF_RESULT_ERROR_NOT_SUPPORTED);
53+
}

0 commit comments

Comments
 (0)