Skip to content

Commit

Permalink
Memif native library based functional tests (#177)
Browse files Browse the repository at this point in the history
Memif native library based functional tests.
Executables have been fixed and added to the build tests process:
- media-proxy/tests/memif_test_rx.c
- media-proxy/tests/memif_test_tx.c

Functional tests for inter process communication have been added,
as an extension to exisiting tests:
- tests/single-node-sample-apps/test_memif.sh

Tests include 2 cases where:
- sender is media_proxy sdk app and receiver is memif native app
- sender is memif native app and receiver is media_proxy sdk app

Signed-off-by: Milosz Linkiewicz <[email protected]>
  • Loading branch information
Mionsz authored Aug 21, 2024
1 parent 41c6c45 commit b2f2192
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 32 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@ media-proxy/protos/controller.pb.h
# For FFmpeg plugin
ffmpeg-plugin/FFmpeg/

docs/_build
docs/_build
media-proxy/tests/test.yuv
media-proxy/tests/memif_test_rx
media-proxy/tests/memif_test_tx
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ set(CMAKE_SKIP_RPATH TRUE)
# setup components folders
set(MCM_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(MP_DIR ${CMAKE_CURRENT_SOURCE_DIR}/media-proxy)
set(MP_TESTS_DIR ${MP_DIR}/tests)
set(SDK_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sdk)
set(TESTS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tests/unit)
set(SDK_INCLUDE_DIR ${SDK_DIR}/include)
Expand All @@ -37,6 +38,7 @@ option(BUILD_UNIT_TESTS "Build and enable unit tests" ON)
if (BUILD_UNIT_TESTS)
enable_testing()
add_subdirectory(${TESTS_DIR})
add_subdirectory(${MP_TESTS_DIR})
endif()

target_include_directories(media_proxy_lib PUBLIC ${SDK_INCLUDE_DIR})
Expand Down
16 changes: 16 additions & 0 deletions media-proxy/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# SPDX-FileCopyrightText: Copyright (c) 2024 Intel Corporation
#
# SPDX-License-Identifier: BSD-3-Clause

cmake_minimum_required(VERSION 3.16)
project(McmMeifTests VERSION 0.1.0 LANGUAGES CXX C)

set(CMAKE_C_STANDARD 11)

add_executable(memif_test_rx memif_test_rx.c)
target_include_directories(memif_test_rx PRIVATE ../include)
target_link_libraries(memif_test_rx PRIVATE mcm_dp)

add_executable(memif_test_tx memif_test_tx.c)
target_include_directories(memif_test_tx PRIVATE ../include)
target_link_libraries(memif_test_tx PRIVATE mcm_dp)
4 changes: 2 additions & 2 deletions media-proxy/tests/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# compile tests
# -DMEMIF_DBG_SHM
# -DMEMIF_DBG
gcc -DHAVE_MEMFD_CREATE -Wno-unused-result -I.. -I../../dependency/vpp/extras/libmemif/src -Iinclude -g -Og memif_test_tx.c ../../dependency/vpp/extras/libmemif/src/*.c -lpthread -o memif_test_tx
gcc -DHAVE_MEMFD_CREATE -Wno-unused-result -I.. -I../../dependency/vpp/extras/libmemif/src -Iinclude -g -Og memif_test_rx.c ../../dependency/vpp/extras/libmemif/src/*.c -lpthread -o memif_test_rx
gcc -DHAVE_MEMFD_CREATE -Wno-unused-result -I.. -I../include -I../../sdk/3rdparty/libmemif/src -Iinclude -g -Og memif_test_tx.c ../../sdk/3rdparty/libmemif/src/*.c -lpthread -o memif_test_tx
gcc -DHAVE_MEMFD_CREATE -Wno-unused-result -I.. -I../include -I../../sdk/3rdparty/libmemif/src -Iinclude -g -Og memif_test_rx.c ../../sdk/3rdparty/libmemif/src/*.c -lpthread -o memif_test_rx
# gcc -DHAVE_MEMFD_CREATE -Wno-unused-result -I.. -I../../dependency/vpp/extras/libmemif/src -Iinclude -g -Og ffmpeg_videosrc.c ../../dependency/vpp/extras/libmemif/src/*.c -lst_dpdk -lpthread -lavformat -lavcodec -lavutil -lavfilter -o ffmpeg_videosrc
# gcc -DHAVE_MEMFD_CREATE -Wno-unused-result -I.. -I../../dependency/vpp/extras/libmemif/src -Iinclude -g -Og filtering_video.c ../../dependency/vpp/extras/libmemif/src/*.c -lpthread -lavformat -lavcodec -lavutil -lavfilter -o filtering_video
2 changes: 1 addition & 1 deletion media-proxy/tests/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "libmemif.h"
#include "shm_memif.h"

#define FRAME_SIZE 5184000 // yuv422p10be (1920*1080*2.5)
#define FRAME_SIZE 8294400 // yuv422p10le (1920*1080*4)
#define FRAME_COUNT 1

/* maximum tx/rx memif buffers */
Expand Down
34 changes: 13 additions & 21 deletions media-proxy/tests/memif_test_rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ typedef struct {
FILE* video_fd;

size_t frame_idx;
uint16_t vid_width;
uint16_t vid_height;
uint16_t width;
uint16_t height;
size_t frame_size;
uint32_t frame_cnt;

Expand Down Expand Up @@ -148,9 +148,17 @@ int main(int argc, char** argv)
app_ctx.memif_app_name = APP_NAME;
app_ctx.memif_if_name = IF_NAME;
app_ctx.memif_socket_path = SOCKET_PATH;
app_ctx.width = 1920;
app_ctx.height = 1080;

while ((opt = getopt(argc, argv, "n:i:f:s:m")) != -1) {
while ((opt = getopt(argc, argv, "w:h:n:i:f:s:m")) != -1) {
switch (opt) {
case 'w':
app_ctx.width = atoi(optarg);
break;
case 'h':
app_ctx.height = atoi(optarg);
break;
case 'n':
app_ctx.memif_app_name = optarg;
break;
Expand All @@ -171,6 +179,7 @@ int main(int argc, char** argv)
exit(EXIT_FAILURE);
}
}
app_ctx.frame_size = (size_t)(app_ctx.width) * (size_t)(app_ctx.height) * 4;

printf("MemIF Mode : %s\n", is_master ? "Master" : "Slave");
printf("MemIF App Name: %s\n", app_ctx.memif_app_name);
Expand Down Expand Up @@ -203,7 +212,7 @@ int main(int argc, char** argv)
app_ctx.memif_if_id = IF_ID;
memif_conn_args.socket = memif_socket;
memif_conn_args.interface_id = app_ctx.memif_if_id;
memif_conn_args.buffer_size = FRAME_SIZE;
memif_conn_args.buffer_size = app_ctx.frame_size;
memif_conn_args.log2_ring_size = 2;
strncpy(memif_conn_args.interface_name, app_ctx.memif_if_name,
sizeof(memif_conn_args.interface_name));
Expand All @@ -220,23 +229,6 @@ int main(int argc, char** argv)
exit(-1);
}

/* Create memif interfaces
* Both interaces are assigned the same socket and same id to create a loopback. */
/*
memcpy(&app_ctx_1, &app_ctx, sizeof(app_context_t));
app_ctx_1.video_fn = "./output1.yuv";
app_ctx_1.memif_if_id = IF_ID + 1;
memif_conn_args.interface_id = app_ctx_1.memif_if_id;
INFO("Create memif interface.");
ret = memif_create(&memif_conn_1, &memif_conn_args,
on_connect, on_disconnect, on_receive, &app_ctx_1);
if (ret != MEMIF_ERR_SUCCESS) {
INFO("memif_create_socket: %s", memif_strerror(ret));
exit(-1);
}
*/

do {
// INFO("RX waiting event.");
ret = memif_poll_event(memif_socket, -1);
Expand Down
23 changes: 16 additions & 7 deletions media-proxy/tests/memif_test_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ typedef struct {
FILE* video_fd;

size_t frame_idx;
uint16_t vid_width;
uint16_t vid_height;
uint16_t width;
uint16_t height;
size_t frame_size;

bool loop_mode;
Expand All @@ -44,7 +44,7 @@ int build_frames(app_context_t* p_app_ctx, memif_buffer_t* tx_bufs, uint32_t buf
rewind(p_app_ctx->video_fd);
ret = 0;
} else {
perror("Error when read frame file");
perror("End of file. Read frame resulted in ");
ret = -1;
}
break;
Expand All @@ -60,7 +60,7 @@ int try_send_msg(app_context_t* p_app_ctx)

/* allocate memory */
uint16_t qid = 0;
uint32_t buf_size = FRAME_SIZE;
uint32_t buf_size = p_app_ctx->frame_size;
uint16_t tx_buf_num = 0, tx = 0;
memif_buffer_t* tx_bufs = NULL;
shm_connection_t* pmemif = &p_app_ctx->memif_intf;
Expand Down Expand Up @@ -214,9 +214,17 @@ int main(int argc, char** argv)
app_ctx.memif_if_name = IF_NAME;
app_ctx.memif_if_id = IF_ID;
app_ctx.memif_socket_path = SOCKET_PATH;
app_ctx.width = 1920;
app_ctx.height = 1080;

while ((opt = getopt(argc, argv, "n:i:d:f:s:ml")) != -1) {
while ((opt = getopt(argc, argv, "w:h:n:i:d:f:s:ml")) != -1) {
switch (opt) {
case 'w':
app_ctx.width = atoi(optarg);
break;
case 'h':
app_ctx.height = atoi(optarg);
break;
case 'n':
app_ctx.memif_app_name = optarg;
break;
Expand All @@ -239,10 +247,11 @@ int main(int argc, char** argv)
app_ctx.loop_mode = true;
break;
default: /* '?' */
fprintf(stderr, "Usage: %s [-n app_name] [-i interface_name] [-d interface_id] [-f file] [-s socket] [-m] [-l] \n", argv[0]);
fprintf(stderr, "Usage: %s [-w width] [-h height] [-n app_name] [-i interface_name] [-d interface_id] [-f file] [-s socket] [-m] [-l] \n", argv[0]);
exit(EXIT_FAILURE);
}
}
app_ctx.frame_size = (size_t)(app_ctx.width) * (size_t)(app_ctx.height) * 4;

printf("Input File : %s\n", app_ctx.video_fn);
printf("MemIF Mode : %s\n", is_master ? "Master" : "Slave");
Expand Down Expand Up @@ -273,7 +282,7 @@ int main(int argc, char** argv)
/* Create memif interfaces
* Both interaces are assigned the same socket and same id to create a loopback. */
memif_conn_args.socket = memif_socket;
memif_conn_args.buffer_size = FRAME_SIZE;
memif_conn_args.buffer_size = app_ctx.frame_size;
memif_conn_args.log2_ring_size = 2;
strncpy(memif_conn_args.interface_name, app_ctx.memif_if_name,
sizeof(memif_conn_args.interface_name));
Expand Down
3 changes: 3 additions & 0 deletions tests/single-node-sample-apps/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

# Directories
script_dir="$(readlink -f "$(dirname -- "${BASH_SOURCE[0]}")")"
. "${script_dir}/test_memif.sh"
bin_dir="$script_dir/../../out/bin"
out_dir="$script_dir/out"

Expand Down Expand Up @@ -373,6 +374,8 @@ do
case $test_option in
memif)
run_test_memif
run_test_memif_tx
run_test_memif_rx
;;
st20)
run_test_stXX st20
Expand Down
118 changes: 118 additions & 0 deletions tests/single-node-sample-apps/test_memif.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#!/bin/bash

# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2024 Intel Corporation

function run_test_memif_rx() {
# Notice: media_proxy does not take part in the direct memif communication.
# However, we start Tx and Rx media_proxy to check if they print expected
# messages and do not produce any errors.

# Notice: sender_app should be started before recver_app. Currently, this is
# the only successful scenario.
mkdir -p "$out_dir"
export socket_path="/run/mcm/mcm_rx_memif.sock"

info "Connection type: MEMIF libmemif_rx"

info "Starting Tx side media_proxy"
local tx_media_proxy_cmd="media_proxy -d $tx_vf_bdf -i 192.168.96.1 -t 8002"
run_in_background "$bin_dir/$tx_media_proxy_cmd" "$tx_media_proxy_out"
tx_media_proxy_pid=$!

sleep 1

info "Starting Rx side media_proxy"
local rx_media_proxy_cmd="media_proxy -d $rx_vf_bdf -i 192.168.96.2 -t 8003"
run_in_background "$bin_dir/$rx_media_proxy_cmd" "$rx_media_proxy_out"
rx_media_proxy_pid=$!

sleep 1

info "Starting sender_app"
export MCM_MEDIA_PROXY_PORT=8002
local sender_app_cmd="sender_app -s 192.168.96.2 -t st20 -w $width -h $height -f $fps -x $pixel_format -b $input_file -n $frames_number -o memif --socketpath=${socket_path}"
run_in_background "$bin_dir/$sender_app_cmd" "$sender_app_out"
sender_app_pid=$!

sleep 1

info "Starting memif_test_rx"
local recver_app_cmd="memif_test_rx -w $width -h $height -f $output_file -s $socket_path"
run_in_background "$bin_dir/$recver_app_cmd" "$recver_app_out"
recver_app_pid=$!

wait_completion "$wait_interval"
local timeout=$?

sleep 1

shutdown_apps

sleep 1

check_results
local error=$?

info "Cleanup"
cleanup

return $(($error || $timeout))
}

function run_test_memif_tx() {
# Notice: media_proxy does not take part in the direct memif communication.
# However, we start Tx and Rx media_proxy to check if they print expected
# messages and do not produce any errors.

# Notice: sender_app should be started before recver_app. Currently, this is
# the only successful scenario.
mkdir -p "$out_dir"
export socket_path="/run/mcm/mcm_rx_memif.sock"

info "Connection type: MEMIF libmemif_tx"

info "Starting Tx side media_proxy"
local tx_media_proxy_cmd="media_proxy -d $tx_vf_bdf -i 192.168.96.1 -t 8002"
run_in_background "$bin_dir/$tx_media_proxy_cmd" "$tx_media_proxy_out"
tx_media_proxy_pid=$!

sleep 1

info "Starting Rx side media_proxy"
local rx_media_proxy_cmd="media_proxy -d $rx_vf_bdf -i 192.168.96.2 -t 8003"
run_in_background "$bin_dir/$rx_media_proxy_cmd" "$rx_media_proxy_out"
rx_media_proxy_pid=$!

sleep 1

info "Starting memif_test_tx"
local sender_app_cmd="memif_test_tx -m -w $width -h $height -f $input_file -s $socket_path"
run_in_background "$bin_dir/$sender_app_cmd" "$sender_app_out"
sender_app_pid=$!

sleep 1

info "Starting recver_app"
export MCM_MEDIA_PROXY_PORT=8003
local recver_app_cmd="recver_app -r 192.168.96.1 -t st20 -w $width -h $height -f $fps -x $pixel_format -b $output_file -o memif --socketpath=$socket_path"
run_in_background "$bin_dir/$recver_app_cmd" "$recver_app_out"
recver_app_pid=$!

wait_completion "$wait_interval"
local timeout=$?

sleep 1

shutdown_apps

sleep 1

check_results
local error=$?

info "Cleanup"
cleanup

return $(($error || $timeout))
}

0 comments on commit b2f2192

Please sign in to comment.