Skip to content

Commit

Permalink
Val: Un-mocking the TestApp with actual API-based implementation (#308)
Browse files Browse the repository at this point in the history
* sdk succesfully linked to TestApp


Signed-off-by: Lukas G <[email protected]>
Signed-off-by: Mateusz Grabuszyński <[email protected]>
  • Loading branch information
zLukas authored Jan 27, 2025
1 parent 6fac4a7 commit 3ba872a
Show file tree
Hide file tree
Showing 13 changed files with 311 additions and 377 deletions.
2 changes: 2 additions & 0 deletions CPPLINT.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
set noparent
exclude_files=tests
24 changes: 21 additions & 3 deletions tests/tools/TestApp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,31 @@ cmake_minimum_required(VERSION 3.10)

# Set the project name and version
project(TestApps VERSION 1.0)
# Include directories
include_directories(Inc)

set(SRC src/input.c src/mcm.c src/mcm_mock.c)
# Find the threading library
find_package(Threads REQUIRED)

# Find the BSD library
find_library(BSD_LIB bsd REQUIRED)

execute_process(
COMMAND git rev-parse --show-toplevel
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE GIT_REPO_ROOT
OUTPUT_STRIP_TRAILING_WHITESPACE
)
message(STATUS "************* root project dir: ${GIT_REPO_ROOT} *************")

set(INC ${GIT_REPO_ROOT}/sdk/include Inc)
set(SRC src/input.c src/mcm.c)

include_directories(${INC})

# Add the executable
add_executable(TxApp tx_app.c ${SRC})
add_executable(RxApp rx_app.c ${SRC})


target_link_libraries(TxApp PRIVATE memif ${CMAKE_THREAD_LIBS_INIT} ${BSD_LIB} mcm_dp)
target_link_libraries(RxApp PRIVATE memif ${CMAKE_THREAD_LIBS_INIT} ${BSD_LIB} mcm_dp)

12 changes: 8 additions & 4 deletions tests/tools/TestApp/Inc/input.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2025 Intel Corporation
*
* SPDX-License-Identifier: BSD-3-Clause
*/

#ifndef _INPUT_H_
#define _INPUT_H_

const char* parse_json_to_string(const char* file_name);
int is_mock_enabled();

char *parse_json_to_string(const char *file_name);

#endif /* _INPUT_H_*/
#endif /* _INPUT_H_ */
30 changes: 16 additions & 14 deletions tests/tools/TestApp/Inc/mcm.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@

/*
* SPDX-FileCopyrightText: Copyright (c) 2025 Intel Corporation
*
* SPDX-License-Identifier: BSD-3-Clause
*/

#ifndef _MCM_H_
#define _MCM_H_
#include "mcm_mock.h"

#define DUMMY_LEN 1
typedef struct mcm_ts{
MeshConnection *connection;
MeshClient *client;
}mcm_ts;

#include <stdio.h>
#include "mesh_dp.h"

int mcm_init_client(mcm_ts* mcm, const char* cfg);
int mcm_create_tx_connection(mcm_ts* mcm, const char* cfg);
int mcm_create_rx_connection(mcm_ts* mcm, const char* cfg);
int mcm_send_video_frame(mcm_ts* mcm, const char* frame, int frame_len);
int mcm_receive_video_frames(mcm_ts* mcm);
int file_to_buffer(FILE* fp, MeshBuffer* buf, int frame_size);
int mcm_init_client(MeshConnection **connection, MeshClient *client, const char *cfg);
int mcm_create_tx_connection(MeshConnection *connection, MeshClient *client, const char *cfg);
int mcm_create_rx_connection(MeshConnection *connection, MeshClient *client, const char *cfg);
int mcm_send_video_frames(MeshConnection *connection, const char *filename);
void read_data_in_loop(MeshConnection *connection, const char *filename);
int is_root();

#endif /* _MCM_H_*/
#endif /* _MCM_H_ */
35 changes: 0 additions & 35 deletions tests/tools/TestApp/Inc/mcm_mock.h

This file was deleted.

64 changes: 37 additions & 27 deletions tests/tools/TestApp/README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,46 @@
# TestApp

Application for utilizing MCM api,
Application for utilizing Media Communications Mesh SDK API.

*Disclaimer*
TX/RXapp is prepared for new api (/docs/sdk-json-proposal) that is not implemented yet, so, so far it works with simple mocks, that move a file from TxApp to RxApp.
## Prerequisities
before building this code following libreries need to be build and installed on host system:
* [grpc](grpcMedia-Communications-Mesh/sdk/README.md)
* [memif](Media-Communications-Mesh/sdk/3rdparty/libmemif/docs/buildinstructions_doc.rst)

test apps use them as shared libraries during linking stage, without them, compilation will fail.

## Usage
1. Create directory:
```shell
mkdir /tmp/MCM_MOCK
```
1. Build binaries:
```shell
mkdir build && cd build
cmake ..
make
touch client.json
touch connection.json
```
```shell
mkdir build && cd build
cmake ..
make
```

1. Run RxApp:
```shell
$ ./RxApp
launching RX App
RX App PID: 956656
reading client configuration...
reading connection configuration...
waiting for frames..
2. Prepare client and conneciton files for sender (TxApp) and receiver (RxApp)
```shell
touch client_tx.json
touch connection_tx.json
touch client_rx.json
touch connection_rx.json
```
> Note: The names of the files can differ from the ones presented above, but they must be reflected in the commands as in the following points.
Exemplary contents of those files can be found in [`client_example.json`](client_example.json) and [`connection_example.json`](connection_example.json). For more, check [appropriate documentation](../../../docs/sdk-json-proposal/SDK_API_WORKFLOW.md).

```
3. Run RxApp:
```shell
./RxApp <client_cfg.json> <connection_cfg.json> <path_to_output_file>
```
For example:
```shell
./RxApp client_rx.json connection_rx.json output_video.yuv
```

1. Run TxApp:
```shell
./TxApp <abs path to file to transmit> <RX App PID>
```
4. Run TxApp:
```shell
./TxApp <client_cfg.json> <connection_cfg.json> <path_to_input_file>
```
For example:
```shell
./RxApp client_tx.json connection_tx.json input_video.yuv
```
6 changes: 6 additions & 0 deletions tests/tools/TestApp/client_example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"apiVersion": "v1",
"apiConnectionString": "Server=127.0.0.1; Port=8002",
"apiDefaultTimeoutMicroseconds": 100000,
"maxMediaConnections": 32
}
15 changes: 15 additions & 0 deletions tests/tools/TestApp/connection_example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"connection": {
"multipointGroup": {
"urn": "ipv4:192.168.123.123"
}
},
"payload": {
"video": {
"width": 1920,
"height": 1080,
"fps": 60.0,
"pixelFormat": "yuv422p10rfc4175"
}
}
}
77 changes: 55 additions & 22 deletions tests/tools/TestApp/rx_app.c
Original file line number Diff line number Diff line change
@@ -1,26 +1,59 @@
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include "Inc/input.h"
#include "Inc/mcm.h"
#include <unistd.h>

const char* client_cfg;
const char* conn_cfg;

int main(int argc, char* argv[]){

printf("launching RX App \n");
printf("RX App PID: %d\n", getpid());
printf("reading client configuration... \n");
client_cfg = parse_json_to_string("client.json");
printf("reading connection configuration... \n");
conn_cfg = parse_json_to_string("connection.json");
mcm_ts mcm;
mcm_init_client(&mcm, client_cfg);
mcm_create_rx_connection(&mcm, conn_cfg);
printf("waiting for frames... \n");
while(1){
// mcm_create_rx_connection(&mcm, conn_cfg);
// mcm_receive_video_frames(&mcm);
}
return 0;
}
char *client_cfg;
char *conn_cfg;

int main(int argc, char *argv[]) {
if (!is_root()) {
fprintf(stderr, "This program must be run as root. Exiting.\n");
exit(EXIT_FAILURE);
}
if (argc != 4) {
fprintf(stderr, "Usage: %s <client_cfg.json> <connection_cfg.json> <path_to_output_file>\n",
argv[0]);
exit(EXIT_FAILURE);
}

char *client_cfg_file = argv[1];
char *conn_cfg_file = argv[2];
char *out_filename = argv[3];

MeshConnection *connection = NULL;
MeshClient *client = NULL;

printf("[RX] Launching RX App \n");
printf("[RX] Reading client configuration... \n");
client_cfg = parse_json_to_string(client_cfg_file);
printf("[RX] Reading connection configuration... \n");
conn_cfg = parse_json_to_string(conn_cfg_file);

/* Initialize mcm client */
int err = mesh_create_client_json(&client, client_cfg);
if (err) {
printf("[RX] Failed to create mesh client: %s (%d)\n", mesh_err2str(err), err);
goto safe_exit;
}

/* Create mesh connection */
err = mesh_create_rx_connection(client, &connection, conn_cfg);
if (err) {
printf("[RX] Failed to create connection: %s (%d)\n", mesh_err2str(err), err);
mesh_delete_client(&client);
goto safe_exit;
}
printf("[RX] Waiting for frames... \n");
read_data_in_loop(connection, out_filename);
printf("[RX] Shuting down connection and client\n");
mesh_delete_connection(&connection);
mesh_delete_client(&client);
printf("[RX] Shutdown completed exiting\n");

safe_exit:
free(client_cfg);
free(conn_cfg);
return err;
}
17 changes: 8 additions & 9 deletions tests/tools/TestApp/src/input.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#include "input.h"
/*
* SPDX-FileCopyrightText: Copyright (c) 2025 Intel Corporation
*
* SPDX-License-Identifier: BSD-3-Clause
*/

#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <string.h>
#include "input.h"


const char* parse_json_to_string(const char* file_name) {
char *parse_json_to_string(const char *file_name) {
FILE *input_fp = fopen(file_name, "rb");
if (input_fp == NULL) {
perror("Failed to open a file");
Expand All @@ -19,7 +23,7 @@ const char* parse_json_to_string(const char* file_name) {
fseek(input_fp, 0, SEEK_SET); // Rewind to the beginning of the file

// Allocate memory to hold the file contents plus a null terminator
char *buffer = (char*)malloc(file_size + 1);
char *buffer = (char *)malloc(file_size + 1);
if (buffer == NULL) {
perror("Failed to allocate memory");
fclose(input_fp);
Expand All @@ -44,8 +48,3 @@ const char* parse_json_to_string(const char* file_name) {
// Return the buffer as a const char*
return buffer;
}

int is_mock_enabled(int argc, char *argv[]){
return (argc == 2 && strcmp("mock", argv[1]) == 0) ? 1 : 0;
}

Loading

0 comments on commit 3ba872a

Please sign in to comment.