Skip to content

Commit 1b94355

Browse files
committed
Add IPC test for file memory provider
Signed-off-by: Lukasz Dorau <[email protected]>
1 parent e00f100 commit 1b94355

File tree

6 files changed

+123
-6
lines changed

6 files changed

+123
-6
lines changed

test/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,21 @@ if(LINUX)
344344
common/ipc_os_prov_common.c)
345345
add_umf_ipc_test(TEST ipc_os_prov_anon_fd)
346346
add_umf_ipc_test(TEST ipc_os_prov_shm)
347+
build_umf_test(
348+
NAME
349+
ipc_file_prov_consumer
350+
SRCS
351+
ipc_file_prov_consumer.c
352+
common/ipc_common.c
353+
common/ipc_os_prov_common.c)
354+
build_umf_test(
355+
NAME
356+
ipc_file_prov_producer
357+
SRCS
358+
ipc_file_prov_producer.c
359+
common/ipc_common.c
360+
common/ipc_os_prov_common.c)
361+
add_umf_ipc_test(TEST ipc_file_prov)
347362
endif()
348363
if(UMF_BUILD_GPU_TESTS AND UMF_BUILD_LEVEL_ZERO_PROVIDER)
349364
build_umf_test(

test/common/ipc_common.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
#define INET_ADDR "127.0.0.1"
1818
#define MSG_SIZE 1024
19-
#define RECV_BUFF_SIZE 1024
2019

2120
// consumer's response message
2221
#define CONSUMER_MSG \
@@ -111,7 +110,6 @@ int run_consumer(int port, umf_memory_provider_ops_t *provider_ops,
111110
void *provider_params, memcopy_callback_t memcopy_callback,
112111
void *memcopy_ctx) {
113112
char consumer_message[MSG_SIZE];
114-
char recv_buffer[RECV_BUFF_SIZE];
115113
int producer_socket = -1;
116114
int ret = -1;
117115
umf_memory_provider_handle_t provider = NULL;
@@ -138,16 +136,20 @@ int run_consumer(int port, umf_memory_provider_ops_t *provider_ops,
138136
goto err_umfMemoryProviderDestroy;
139137
}
140138

139+
// allocate the zeroed receive buffer
140+
char *recv_buffer = calloc(1, IPC_handle_size);
141+
if (!recv_buffer) {
142+
fprintf(stderr, "[consumer] ERROR: out of memory\n");
143+
goto err_umfMemoryProviderDestroy;
144+
}
145+
141146
producer_socket = consumer_connect(port);
142147
if (producer_socket < 0) {
143148
goto err_umfMemoryProviderDestroy;
144149
}
145150

146-
// zero the receive buffer
147-
memset(recv_buffer, 0, RECV_BUFF_SIZE);
148-
149151
// receive a producer's message
150-
ssize_t recv_len = recv(producer_socket, recv_buffer, RECV_BUFF_SIZE, 0);
152+
ssize_t recv_len = recv(producer_socket, recv_buffer, IPC_handle_size, 0);
151153
if (recv_len < 0) {
152154
fprintf(stderr, "[consumer] ERROR: recv() failed\n");
153155
goto err_close_producer_socket;

test/ipc_file_prov.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#
2+
# Copyright (C) 2024 Intel Corporation
3+
#
4+
# Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
5+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
#
7+
8+
#!/bin/bash
9+
10+
set -e
11+
12+
FILE_NAME="/tmp/umf_file_provider_$$"
13+
14+
# port should be a number from the range <1024, 65535>
15+
PORT=$(( 1024 + ( $$ % ( 65535 - 1024 ))))
16+
17+
UMF_LOG_VAL="level:debug;flush:debug;output:stderr;pid:yes"
18+
19+
# make sure the temp file does not exist
20+
rm -f ${FILE_NAME}
21+
22+
echo "Starting ipc_file_prov CONSUMER on port $PORT ..."
23+
UMF_LOG=$UMF_LOG_VAL ./umf_test-ipc_file_prov_consumer $PORT $FILE_NAME &
24+
25+
echo "Waiting 1 sec ..."
26+
sleep 1
27+
28+
echo "Starting ipc_file_prov PRODUCER on port $PORT ..."
29+
UMF_LOG=$UMF_LOG_VAL ./umf_test-ipc_file_prov_producer $PORT $FILE_NAME
30+
31+
# remove the SHM file
32+
rm -f ${FILE_NAME}

test/ipc_file_prov_consumer.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (C) 2024 Intel Corporation
3+
*
4+
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
5+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
*/
7+
8+
#include <stdio.h>
9+
#include <stdlib.h>
10+
11+
#include <umf/providers/provider_file_memory.h>
12+
13+
#include "ipc_common.h"
14+
#include "ipc_os_prov_common.h"
15+
16+
int main(int argc, char *argv[]) {
17+
if (argc < 3) {
18+
fprintf(stderr, "usage: %s <port> <file_name>\n", argv[0]);
19+
return -1;
20+
}
21+
22+
int port = atoi(argv[1]);
23+
char *file_name = argv[2];
24+
25+
umf_file_memory_provider_params_t file_params;
26+
27+
file_params = umfFileMemoryProviderParamsDefault(file_name);
28+
file_params.visibility = UMF_MEM_MAP_SHARED;
29+
30+
return run_consumer(port, umfFileMemoryProviderOps(), &file_params, memcopy,
31+
NULL);
32+
}

test/ipc_file_prov_producer.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (C) 2024 Intel Corporation
3+
*
4+
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
5+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
*/
7+
8+
#include <stdio.h>
9+
#include <stdlib.h>
10+
11+
#include <umf/providers/provider_file_memory.h>
12+
13+
#include "ipc_common.h"
14+
#include "ipc_os_prov_common.h"
15+
16+
int main(int argc, char *argv[]) {
17+
if (argc < 3) {
18+
fprintf(stderr, "usage: %s <port> <file_name>\n", argv[0]);
19+
return -1;
20+
}
21+
22+
int port = atoi(argv[1]);
23+
char *file_name = argv[2];
24+
25+
umf_file_memory_provider_params_t file_params;
26+
27+
file_params = umfFileMemoryProviderParamsDefault(file_name);
28+
file_params.visibility = UMF_MEM_MAP_SHARED;
29+
30+
return run_producer(port, umfFileMemoryProviderOps(), &file_params, memcopy,
31+
NULL);
32+
}

test/test_valgrind.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ for test in $(ls -1 umf_test-*); do
8888
echo "- SKIPPED"
8989
continue; # skip testing helper binaries used by the ipc_os_prov_* tests
9090
;;
91+
umf_test-ipc_file_prov_*)
92+
echo "- SKIPPED"
93+
continue; # skip testing helper binaries used by the ipc_file_prov test
94+
;;
9195
umf_test-memspace_host_all)
9296
FILTER='--gtest_filter="-*allocsSpreadAcrossAllNumaNodes"'
9397
;;

0 commit comments

Comments
 (0)