Skip to content

Commit 43a8d4b

Browse files
zLukasko80
authored andcommitted
Val: Un-mocking the TestApp with actual API-based implementation (OpenVisualCloud#308)
* sdk succesfully linked to TestApp Signed-off-by: Lukas G <[email protected]> Signed-off-by: Mateusz Grabuszyński <[email protected]>
1 parent a6280c9 commit 43a8d4b

File tree

13 files changed

+311
-377
lines changed

13 files changed

+311
-377
lines changed

CPPLINT.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
set noparent
2+
exclude_files=tests

tests/tools/TestApp/CMakeLists.txt

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,31 @@ cmake_minimum_required(VERSION 3.10)
22

33
# Set the project name and version
44
project(TestApps VERSION 1.0)
5-
# Include directories
6-
include_directories(Inc)
75

8-
set(SRC src/input.c src/mcm.c src/mcm_mock.c)
6+
# Find the threading library
7+
find_package(Threads REQUIRED)
98

9+
# Find the BSD library
10+
find_library(BSD_LIB bsd REQUIRED)
1011

12+
execute_process(
13+
COMMAND git rev-parse --show-toplevel
14+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
15+
OUTPUT_VARIABLE GIT_REPO_ROOT
16+
OUTPUT_STRIP_TRAILING_WHITESPACE
17+
)
18+
message(STATUS "************* root project dir: ${GIT_REPO_ROOT} *************")
19+
20+
set(INC ${GIT_REPO_ROOT}/sdk/include Inc)
21+
set(SRC src/input.c src/mcm.c)
22+
23+
include_directories(${INC})
1124

1225
# Add the executable
1326
add_executable(TxApp tx_app.c ${SRC})
1427
add_executable(RxApp rx_app.c ${SRC})
28+
29+
30+
target_link_libraries(TxApp PRIVATE memif ${CMAKE_THREAD_LIBS_INIT} ${BSD_LIB} mcm_dp)
31+
target_link_libraries(RxApp PRIVATE memif ${CMAKE_THREAD_LIBS_INIT} ${BSD_LIB} mcm_dp)
32+

tests/tools/TestApp/Inc/input.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
/*
2+
* SPDX-FileCopyrightText: Copyright (c) 2025 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
17
#ifndef _INPUT_H_
28
#define _INPUT_H_
39

4-
const char* parse_json_to_string(const char* file_name);
5-
int is_mock_enabled();
6-
10+
char *parse_json_to_string(const char *file_name);
711

8-
#endif /* _INPUT_H_*/
12+
#endif /* _INPUT_H_ */

tests/tools/TestApp/Inc/mcm.h

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1+
2+
/*
3+
* SPDX-FileCopyrightText: Copyright (c) 2025 Intel Corporation
4+
*
5+
* SPDX-License-Identifier: BSD-3-Clause
6+
*/
7+
18
#ifndef _MCM_H_
29
#define _MCM_H_
3-
#include "mcm_mock.h"
4-
5-
#define DUMMY_LEN 1
6-
typedef struct mcm_ts{
7-
MeshConnection *connection;
8-
MeshClient *client;
9-
}mcm_ts;
1010

11+
#include <stdio.h>
12+
#include "mesh_dp.h"
1113

12-
int mcm_init_client(mcm_ts* mcm, const char* cfg);
13-
int mcm_create_tx_connection(mcm_ts* mcm, const char* cfg);
14-
int mcm_create_rx_connection(mcm_ts* mcm, const char* cfg);
15-
int mcm_send_video_frame(mcm_ts* mcm, const char* frame, int frame_len);
16-
int mcm_receive_video_frames(mcm_ts* mcm);
17-
int file_to_buffer(FILE* fp, MeshBuffer* buf, int frame_size);
14+
int mcm_init_client(MeshConnection **connection, MeshClient *client, const char *cfg);
15+
int mcm_create_tx_connection(MeshConnection *connection, MeshClient *client, const char *cfg);
16+
int mcm_create_rx_connection(MeshConnection *connection, MeshClient *client, const char *cfg);
17+
int mcm_send_video_frames(MeshConnection *connection, const char *filename);
18+
void read_data_in_loop(MeshConnection *connection, const char *filename);
19+
int is_root();
1820

19-
#endif /* _MCM_H_*/
21+
#endif /* _MCM_H_ */

tests/tools/TestApp/Inc/mcm_mock.h

Lines changed: 0 additions & 35 deletions
This file was deleted.

tests/tools/TestApp/README.md

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,46 @@
11
# TestApp
22

3-
Application for utilizing MCM api,
3+
Application for utilizing Media Communications Mesh SDK API.
44

5-
*Disclaimer*
6-
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.
5+
## Prerequisities
6+
before building this code following libreries need to be build and installed on host system:
7+
* [grpc](grpcMedia-Communications-Mesh/sdk/README.md)
8+
* [memif](Media-Communications-Mesh/sdk/3rdparty/libmemif/docs/buildinstructions_doc.rst)
9+
10+
test apps use them as shared libraries during linking stage, without them, compilation will fail.
711

812
## Usage
9-
1. Create directory:
10-
```shell
11-
mkdir /tmp/MCM_MOCK
12-
```
1313
1. Build binaries:
14-
```shell
15-
mkdir build && cd build
16-
cmake ..
17-
make
18-
touch client.json
19-
touch connection.json
20-
```
14+
```shell
15+
mkdir build && cd build
16+
cmake ..
17+
make
18+
```
2119

22-
1. Run RxApp:
23-
```shell
24-
$ ./RxApp
25-
launching RX App
26-
RX App PID: 956656
27-
reading client configuration...
28-
reading connection configuration...
29-
waiting for frames..
20+
2. Prepare client and conneciton files for sender (TxApp) and receiver (RxApp)
21+
```shell
22+
touch client_tx.json
23+
touch connection_tx.json
24+
touch client_rx.json
25+
touch connection_rx.json
26+
```
27+
> 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.
28+
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).
3029

31-
```
30+
3. Run RxApp:
31+
```shell
32+
./RxApp <client_cfg.json> <connection_cfg.json> <path_to_output_file>
33+
```
34+
For example:
35+
```shell
36+
./RxApp client_rx.json connection_rx.json output_video.yuv
37+
```
3238

33-
1. Run TxApp:
34-
```shell
35-
./TxApp <abs path to file to transmit> <RX App PID>
36-
```
39+
4. Run TxApp:
40+
```shell
41+
./TxApp <client_cfg.json> <connection_cfg.json> <path_to_input_file>
42+
```
43+
For example:
44+
```shell
45+
./RxApp client_tx.json connection_tx.json input_video.yuv
46+
```
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"apiVersion": "v1",
3+
"apiConnectionString": "Server=127.0.0.1; Port=8002",
4+
"apiDefaultTimeoutMicroseconds": 100000,
5+
"maxMediaConnections": 32
6+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"connection": {
3+
"multipointGroup": {
4+
"urn": "ipv4:192.168.123.123"
5+
}
6+
},
7+
"payload": {
8+
"video": {
9+
"width": 1920,
10+
"height": 1080,
11+
"fps": 60.0,
12+
"pixelFormat": "yuv422p10rfc4175"
13+
}
14+
}
15+
}

tests/tools/TestApp/rx_app.c

Lines changed: 55 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,59 @@
11
#include <stdio.h>
2+
#include <unistd.h>
3+
#include <stdlib.h>
24
#include "Inc/input.h"
35
#include "Inc/mcm.h"
4-
#include <unistd.h>
56

6-
const char* client_cfg;
7-
const char* conn_cfg;
8-
9-
int main(int argc, char* argv[]){
10-
11-
printf("launching RX App \n");
12-
printf("RX App PID: %d\n", getpid());
13-
printf("reading client configuration... \n");
14-
client_cfg = parse_json_to_string("client.json");
15-
printf("reading connection configuration... \n");
16-
conn_cfg = parse_json_to_string("connection.json");
17-
mcm_ts mcm;
18-
mcm_init_client(&mcm, client_cfg);
19-
mcm_create_rx_connection(&mcm, conn_cfg);
20-
printf("waiting for frames... \n");
21-
while(1){
22-
// mcm_create_rx_connection(&mcm, conn_cfg);
23-
// mcm_receive_video_frames(&mcm);
24-
}
25-
return 0;
26-
}
7+
char *client_cfg;
8+
char *conn_cfg;
9+
10+
int main(int argc, char *argv[]) {
11+
if (!is_root()) {
12+
fprintf(stderr, "This program must be run as root. Exiting.\n");
13+
exit(EXIT_FAILURE);
14+
}
15+
if (argc != 4) {
16+
fprintf(stderr, "Usage: %s <client_cfg.json> <connection_cfg.json> <path_to_output_file>\n",
17+
argv[0]);
18+
exit(EXIT_FAILURE);
19+
}
20+
21+
char *client_cfg_file = argv[1];
22+
char *conn_cfg_file = argv[2];
23+
char *out_filename = argv[3];
24+
25+
MeshConnection *connection = NULL;
26+
MeshClient *client = NULL;
27+
28+
printf("[RX] Launching RX App \n");
29+
printf("[RX] Reading client configuration... \n");
30+
client_cfg = parse_json_to_string(client_cfg_file);
31+
printf("[RX] Reading connection configuration... \n");
32+
conn_cfg = parse_json_to_string(conn_cfg_file);
33+
34+
/* Initialize mcm client */
35+
int err = mesh_create_client_json(&client, client_cfg);
36+
if (err) {
37+
printf("[RX] Failed to create mesh client: %s (%d)\n", mesh_err2str(err), err);
38+
goto safe_exit;
39+
}
40+
41+
/* Create mesh connection */
42+
err = mesh_create_rx_connection(client, &connection, conn_cfg);
43+
if (err) {
44+
printf("[RX] Failed to create connection: %s (%d)\n", mesh_err2str(err), err);
45+
mesh_delete_client(&client);
46+
goto safe_exit;
47+
}
48+
printf("[RX] Waiting for frames... \n");
49+
read_data_in_loop(connection, out_filename);
50+
printf("[RX] Shuting down connection and client\n");
51+
mesh_delete_connection(&connection);
52+
mesh_delete_client(&client);
53+
printf("[RX] Shutdown completed exiting\n");
54+
55+
safe_exit:
56+
free(client_cfg);
57+
free(conn_cfg);
58+
return err;
59+
}

tests/tools/TestApp/src/input.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
#include "input.h"
1+
/*
2+
* SPDX-FileCopyrightText: Copyright (c) 2025 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
26

37
#include <stdio.h>
48
#include <stdlib.h>
59
#include <getopt.h>
610
#include <string.h>
11+
#include "input.h"
712

8-
9-
const char* parse_json_to_string(const char* file_name) {
13+
char *parse_json_to_string(const char *file_name) {
1014
FILE *input_fp = fopen(file_name, "rb");
1115
if (input_fp == NULL) {
1216
perror("Failed to open a file");
@@ -19,7 +23,7 @@ const char* parse_json_to_string(const char* file_name) {
1923
fseek(input_fp, 0, SEEK_SET); // Rewind to the beginning of the file
2024

2125
// Allocate memory to hold the file contents plus a null terminator
22-
char *buffer = (char*)malloc(file_size + 1);
26+
char *buffer = (char *)malloc(file_size + 1);
2327
if (buffer == NULL) {
2428
perror("Failed to allocate memory");
2529
fclose(input_fp);
@@ -44,8 +48,3 @@ const char* parse_json_to_string(const char* file_name) {
4448
// Return the buffer as a const char*
4549
return buffer;
4650
}
47-
48-
int is_mock_enabled(int argc, char *argv[]){
49-
return (argc == 2 && strcmp("mock", argv[1]) == 0) ? 1 : 0;
50-
}
51-

0 commit comments

Comments
 (0)