diff --git a/.gitignore b/.gitignore index 72e1c34c..7820098f 100644 --- a/.gitignore +++ b/.gitignore @@ -26,4 +26,7 @@ media-proxy/protos/controller.pb.h # For FFmpeg plugin ffmpeg-plugin/FFmpeg/ -docs/_build \ No newline at end of file +docs/_build +media-proxy/tests/test.yuv +media-proxy/tests/memif_test_rx +media-proxy/tests/memif_test_tx diff --git a/CMakeLists.txt b/CMakeLists.txt index 82dda054..f8bf11a2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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}) diff --git a/media-proxy/tests/CMakeLists.txt b/media-proxy/tests/CMakeLists.txt new file mode 100644 index 00000000..a52249c3 --- /dev/null +++ b/media-proxy/tests/CMakeLists.txt @@ -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) diff --git a/media-proxy/tests/build.sh b/media-proxy/tests/build.sh index f79372c5..8858325c 100755 --- a/media-proxy/tests/build.sh +++ b/media-proxy/tests/build.sh @@ -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 diff --git a/media-proxy/tests/common.h b/media-proxy/tests/common.h index 3f8706d4..22a93b2d 100644 --- a/media-proxy/tests/common.h +++ b/media-proxy/tests/common.h @@ -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 */ diff --git a/media-proxy/tests/memif_test_rx.c b/media-proxy/tests/memif_test_rx.c index c4cac4b1..1e8ac8f6 100644 --- a/media-proxy/tests/memif_test_rx.c +++ b/media-proxy/tests/memif_test_rx.c @@ -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; @@ -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; @@ -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); @@ -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)); @@ -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); diff --git a/media-proxy/tests/memif_test_tx.c b/media-proxy/tests/memif_test_tx.c index 6ec3c33c..6498efc5 100644 --- a/media-proxy/tests/memif_test_tx.c +++ b/media-proxy/tests/memif_test_tx.c @@ -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; @@ -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; @@ -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; @@ -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; @@ -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"); @@ -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)); diff --git a/tests/single-node-sample-apps/test.sh b/tests/single-node-sample-apps/test.sh index 888c441d..66a72580 100755 --- a/tests/single-node-sample-apps/test.sh +++ b/tests/single-node-sample-apps/test.sh @@ -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" @@ -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 diff --git a/tests/single-node-sample-apps/test_memif.sh b/tests/single-node-sample-apps/test_memif.sh new file mode 100755 index 00000000..64e9ed60 --- /dev/null +++ b/tests/single-node-sample-apps/test_memif.sh @@ -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)) +}