Skip to content

Commit 9602ebb

Browse files
committed
Add IPC test for devdax memory provider
Signed-off-by: Lukasz Dorau <[email protected]>
1 parent a557e05 commit 9602ebb

File tree

6 files changed

+148
-6
lines changed

6 files changed

+148
-6
lines changed

test/CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,22 @@ 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+
348+
build_umf_test(
349+
NAME
350+
ipc_devdax_prov_consumer
351+
SRCS
352+
ipc_devdax_prov_consumer.c
353+
common/ipc_common.c
354+
common/ipc_os_prov_common.c)
355+
build_umf_test(
356+
NAME
357+
ipc_devdax_prov_producer
358+
SRCS
359+
ipc_devdax_prov_producer.c
360+
common/ipc_common.c
361+
common/ipc_os_prov_common.c)
362+
add_umf_ipc_test(TEST ipc_devdax_prov)
347363
endif()
348364
if(UMF_BUILD_GPU_TESTS AND UMF_BUILD_LEVEL_ZERO_PROVIDER)
349365
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_devdax_prov.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
if [ "$UMF_TESTS_DEVDAX_PATH" = "" ]; then
13+
echo "Test skipped, UMF_TESTS_DEVDAX_PATH is not set"
14+
exit 0
15+
fi
16+
17+
if [ "$UMF_TESTS_DEVDAX_SIZE" = "" ]; then
18+
echo "Test skipped, UMF_TESTS_DEVDAX_SIZE is not set"
19+
exit 0
20+
fi
21+
22+
# port should be a number from the range <1024, 65535>
23+
PORT=$(( 1024 + ( $$ % ( 65535 - 1024 ))))
24+
25+
UMF_LOG_VAL="level:debug;flush:debug;output:stderr;pid:yes"
26+
27+
echo "Starting ipc_devdax_prov CONSUMER on port $PORT ..."
28+
UMF_LOG=$UMF_LOG_VAL ./umf_test-ipc_devdax_prov_consumer $PORT &
29+
30+
echo "Waiting 1 sec ..."
31+
sleep 1
32+
33+
echo "Starting ipc_devdax_prov PRODUCER on port $PORT ..."
34+
UMF_LOG=$UMF_LOG_VAL ./umf_test-ipc_devdax_prov_producer $PORT

test/ipc_devdax_prov_consumer.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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_devdax_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 < 2) {
18+
fprintf(stderr, "usage: %s <port>\n", argv[0]);
19+
return -1;
20+
}
21+
22+
int port = atoi(argv[1]);
23+
24+
char *path = getenv("UMF_TESTS_DEVDAX_PATH");
25+
if (path == NULL || path[0] == 0) {
26+
fprintf(stderr, "Test skipped, UMF_TESTS_DEVDAX_PATH is not set\n");
27+
return 0;
28+
}
29+
30+
char *size = getenv("UMF_TESTS_DEVDAX_SIZE");
31+
if (size == NULL || size[0] == 0) {
32+
fprintf(stderr, "Test skipped, UMF_TESTS_DEVDAX_SIZE is not set\n");
33+
return 0;
34+
}
35+
36+
umf_devdax_memory_provider_params_t devdax_params =
37+
umfDevDaxMemoryProviderParamsDefault(
38+
getenv("UMF_TESTS_DEVDAX_PATH"),
39+
atol(getenv("UMF_TESTS_DEVDAX_SIZE")));
40+
41+
return run_consumer(port, umfDevDaxMemoryProviderOps(), &devdax_params,
42+
memcopy, NULL);
43+
}

test/ipc_devdax_prov_producer.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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_devdax_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 < 2) {
18+
fprintf(stderr, "usage: %s <port>\n", argv[0]);
19+
return -1;
20+
}
21+
22+
int port = atoi(argv[1]);
23+
24+
char *path = getenv("UMF_TESTS_DEVDAX_PATH");
25+
if (path == NULL || path[0] == 0) {
26+
fprintf(stderr, "Test skipped, UMF_TESTS_DEVDAX_PATH is not set\n");
27+
return 0;
28+
}
29+
30+
char *size = getenv("UMF_TESTS_DEVDAX_SIZE");
31+
if (size == NULL || size[0] == 0) {
32+
fprintf(stderr, "Test skipped, UMF_TESTS_DEVDAX_SIZE is not set\n");
33+
return 0;
34+
}
35+
36+
umf_devdax_memory_provider_params_t devdax_params =
37+
umfDevDaxMemoryProviderParamsDefault(
38+
getenv("UMF_TESTS_DEVDAX_PATH"),
39+
atol(getenv("UMF_TESTS_DEVDAX_SIZE")));
40+
41+
return run_producer(port, umfDevDaxMemoryProviderOps(), &devdax_params,
42+
memcopy, NULL);
43+
}

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_devdax_prov_*)
92+
echo "- SKIPPED"
93+
continue; # skip testing helper binaries used by the ipc_devdax_prov_* tests
94+
;;
9195
umf_test-memspace_host_all)
9296
FILTER='--gtest_filter="-*allocsSpreadAcrossAllNumaNodes"'
9397
;;

0 commit comments

Comments
 (0)