Skip to content

Commit

Permalink
Val: video test stubs and media-proxy related fixtures (#304)
Browse files Browse the repository at this point in the history
* Add: stub for fixtures relating to media_proxy process lifecycle (spawning, killing)
* Add: removal of sent file at the end of test to avoid disk full errors
* Add: tests of mock for cluster and st2110 video transfers
* Fix: wrong connection.st2110.transport value
* Add: todos for further code extension
* in tests/validation: Extending copyright with 2024-2025
* in tests/validation: Removing 'Intel(R)' from Media Communications Mesh
  • Loading branch information
MateuszGrabuszynski authored Jan 28, 2025
1 parent 498b832 commit 8935e44
Show file tree
Hide file tree
Showing 20 changed files with 168 additions and 50 deletions.
4 changes: 2 additions & 2 deletions tests/validation/Engine/client_json.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2024 Intel Corporation
# Intel® Media Communications Mesh
# Copyright 2024-2025 Intel Corporation
# Media Communications Mesh

import json

Expand Down
6 changes: 3 additions & 3 deletions tests/validation/Engine/connection.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2024 Intel Corporation
# Intel® Media Communications Mesh
# Copyright 2024-2025 Intel Corporation
# Media Communications Mesh

from enum import Enum

Expand Down Expand Up @@ -72,7 +72,7 @@ def to_dict(self) -> dict:
return {
"connection": {
"st2110": {
"transport": self.transport.value[0],
"transport": self.transport.value,
"remoteIpAddr": self.remoteIpAddr,
"remotePort": self.remotePort,
"pacing": self.pacing,
Expand Down
4 changes: 2 additions & 2 deletions tests/validation/Engine/connection_json.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2024 Intel Corporation
# Intel® Media Communications Mesh
# Copyright 2024-2025 Intel Corporation
# Media Communications Mesh

import json

Expand Down
4 changes: 2 additions & 2 deletions tests/validation/Engine/connection_json_usage_example.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2024 Intel Corporation
# Intel® Media Communications Mesh
# Copyright 2024-2025 Intel Corporation
# Media Communications Mesh

from connection import ConnectionMode, Rdma, St2110, TransportType
from connection_json import ConnectionJson
Expand Down
4 changes: 2 additions & 2 deletions tests/validation/Engine/connection_usage_example.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2024 Intel Corporation
# Intel® Media Communications Mesh
# Copyright 2024-2025 Intel Corporation
# Media Communications Mesh

from connection import ConnectionMode, Rdma, St2110, TransportType

Expand Down
4 changes: 2 additions & 2 deletions tests/validation/Engine/const.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2024 Intel Corporation
# Intel® Media Communications Mesh
# Copyright 2024-2025 Intel Corporation
# Media Communications Mesh

LOG_FOLDER = "logs"
4 changes: 2 additions & 2 deletions tests/validation/Engine/csv_report.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2024 Intel Corporation
# Intel® Media Communications Mesh
# Copyright 2024-2025 Intel Corporation
# Media Communications Mesh

import csv

Expand Down
27 changes: 21 additions & 6 deletions tests/validation/Engine/engine_mcm.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2024 Intel Corporation
# Intel® Media Communications Mesh
# Copyright 2024-2025 Intel Corporation
# Media Communications Mesh

import logging
import os
import signal
import subprocess

from pathlib import Path

import Engine.client_json
import Engine.connection
import Engine.connection_json
Expand All @@ -18,7 +19,7 @@ def create_client_json(build: str, client: Engine.client_json.ClientJson):
logging.debug("Client JSON:")
for line in client.to_json().splitlines():
logging.debug(line)
output_path = os.path.join(build, "tests", "tools", "TestApp", "build", "client.json")
output_path = Path(build, "tests", "tools", "TestApp", "build", "client.json")
logging.debug(f"Client JSON path: {output_path}")
client.prepare_and_save_json(output_path=output_path)

Expand All @@ -27,7 +28,7 @@ def create_connection_json(build: str, connection: Engine.connection_json.Connec
logging.debug("Connection JSON:")
for line in connection.to_json().splitlines():
logging.debug(line)
output_path = os.path.join(build, "tests", "tools", "TestApp", "build", "connection.json")
output_path = Path(build, "tests", "tools", "TestApp", "build", "connection.json")
logging.debug(f"Connection JSON path: {output_path}")
connection.prepare_and_save_json(output_path=output_path)

Expand All @@ -50,12 +51,26 @@ def stop_rx_app(rx: Engine.execute.AsyncProcess):
rx.process.wait()


def remove_sent_file(file_path: str, app_path: str) -> None:
# filepath "/x/y/z.yuv", app_path "/a/b/"
# removes /a/b/z.yuv
removal_path = Path(app_path, Path(file_path).name)
try:
removal_path.unlink()
logging.debug(f"Removed: {removal_path}")
# except makes the test pass if there's no file to remove
except (FileNotFoundError, NotADirectoryError):
logging.debug(f"Cannot remove. File does not exist: {removal_path}")


def run_rx_tx_with_file(file_path: str, build: str):
app_path = os.path.join(build, "tests", "tools", "TestApp", "build")
app_path = Path(build, "tests", "tools", "TestApp", "build")

try:
rx = run_rx_app(cwd=app_path)
tx = run_tx_app(file_path=file_path, rx_pid=rx.process.pid, cwd=app_path)
handle_tx_failure(tx)
finally:
stop_rx_app(rx)
# TODO: Add checks for transmission errors
remove_sent_file(file_path, app_path)
4 changes: 2 additions & 2 deletions tests/validation/Engine/execute.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2024 Intel Corporation
# Intel® Media Communications Mesh
# Copyright 2024-2025 Intel Corporation
# Media Communications Mesh

import logging
import os
Expand Down
4 changes: 2 additions & 2 deletions tests/validation/Engine/fixtures.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2024 Intel Corporation
# Intel® Media Communications Mesh
# Copyright 2024-2025 Intel Corporation
# Media Communications Mesh

import os
from typing import Dict
Expand Down
42 changes: 34 additions & 8 deletions tests/validation/Engine/fixtures_mcm.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2024 Intel Corporation
# Intel® Media Communications Mesh
# Copyright 2024-2025 Intel Corporation
# Media Communications Mesh
import os
import subprocess

Expand All @@ -10,16 +10,42 @@
@pytest.fixture(scope="session")
def build_TestApp(build):
path = os.path.join(build, "tests", "tools", "TestApp", "build")
subprocess.run(f"rm -rf {path}", shell=True, timeout=10)
subprocess.run(f"mkdir -p {path}", shell=True, timeout=10)
subprocess.run(f'rm -rf "{path}"', shell=True, timeout=10)
subprocess.run(f'mkdir -p "{path}"', shell=True, timeout=10)
subprocess.run("cmake ..", cwd=path, shell=True, timeout=10)
subprocess.run("make", cwd=path, shell=True, timeout=10)


@pytest.fixture(scope="package")
def media_proxy_single():
# Run single media proxy
pass
def kill_all_existing_media_proxies():
# TODO: This assumes the way previous media_proxy worked will not change in the new version, which is unlikely
"Kills all existing media_proxy processes using their PIDs found with px -aux"
existing_mps = subprocess.run("ps -aux | awk '/media_proxy/{print($2)}'", shell=True, capture_output=True)
mp_pids = existing_mps.stdout.decode("utf-8").split() # returns an array of PIDs
(subprocess.run(f"kill -9 {mp_pid}", shell=True) for mp_pid in mp_pids)


@pytest.fixture(scope="package", autouse=False)
def media_proxy_single(sender_mp_port: int, receiver_mp_port: int, kill_existing: bool = True):
# TODO: This assumes the way previous media_proxy worked will not change in the new version, which is unlikely
"""Opens new media_proxies for sender and receiver.
May optionally kill the already-running media_proxies first.
Arguments:
sender_mp_port(int): specifies the port number for sender
receiver_mp_port(int): specifies the port number for receiver
Keyword arguments:
kill_existing(bool, optional): if use kill_all_existing_media_proxies() function to kill -9 all existing
media_proxies before running new instances
"""
if kill_existing:
kill_all_existing_media_proxies()
# create new media_proxy processes for sender and receiver
sender_mp_proc = subprocess.Popen(f"media_proxy -t {sender_mp_port}") # sender's media_proxy
receiver_mp_proc = subprocess.Popen(f"media_proxy -t {receiver_mp_port}") # receiver media_proxy
yield
sender_mp_proc.terminate()
receiver_mp_proc.terminate()


@pytest.fixture(scope="package")
Expand Down
4 changes: 2 additions & 2 deletions tests/validation/Engine/logging.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2024 Intel Corporation
# Intel® Media Communications Mesh
# Copyright 2024-2025 Intel Corporation
# Media Communications Mesh

import datetime
import logging
Expand Down
4 changes: 2 additions & 2 deletions tests/validation/Engine/media_files.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2024 Intel Corporation
# Intel® Media Communications Mesh
# Copyright 2024-2025 Intel Corporation
# Media Communications Mesh

# This file is a copy retreived from an MTL project

Expand Down
4 changes: 2 additions & 2 deletions tests/validation/Engine/payload.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2024 Intel Corporation
# Intel® Media Communications Mesh
# Copyright 2024-2025 Intel Corporation
# Media Communications Mesh

from enum import Enum

Expand Down
4 changes: 2 additions & 2 deletions tests/validation/Engine/payload_usage_example.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2024 Intel Corporation
# Intel® Media Communications Mesh
# Copyright 2024-2025 Intel Corporation
# Media Communications Mesh

from payload import Audio, Video

Expand Down
4 changes: 2 additions & 2 deletions tests/validation/Engine/stash.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2024 Intel Corporation
# Intel® Media Communications Mesh
# Copyright 2024-2025 Intel Corporation
# Media Communications Mesh

import os
from typing import List
Expand Down
4 changes: 2 additions & 2 deletions tests/validation/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2024 Intel Corporation
# Intel® Media Communications Mesh
# Copyright 2024-2025 Intel Corporation
# Media Communications Mesh

pytest_plugins = ["Engine.fixtures", "Engine.logging", "Engine.fixtures_mcm"]

Expand Down
35 changes: 35 additions & 0 deletions tests/validation/functional/cluster/video/test_video.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2024-2025 Intel Corporation
# Media Communications Mesh
import os
import pytest

import Engine.client_json
import Engine.connection
import Engine.connection_json
import Engine.engine_mcm as utils
import Engine.execute
import Engine.payload
from Engine.media_files import yuv_files


@pytest.mark.parametrize("video_type", [k for k in yuv_files.keys()])
def test_video(build_TestApp, build: str, media: str, video_type):
client = Engine.client_json.ClientJson()
conn_mpg = Engine.connection.Rdma()
payload = Engine.payload.Video(
width=yuv_files[video_type]["width"],
height=yuv_files[video_type]["height"],
fps=yuv_files[video_type]["fps"],
pixelFormat=yuv_files[video_type]["format"],
)
connection = Engine.connection_json.ConnectionJson(connection=conn_mpg, payload=payload)

utils.create_client_json(build, client)
utils.create_connection_json(build, connection)

# Use a specified file from media_files.py
media_file = yuv_files[video_type]["filename"]
media_file_path = os.path.join(media, media_file)

utils.run_rx_tx_with_file(file_path=media_file_path, build=build)
17 changes: 12 additions & 5 deletions tests/validation/functional/local/video/test_video.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2024 Intel Corporation
# Intel® Media Communications Mesh
# Copyright 2024-2025 Intel Corporation
# Media Communications Mesh
import os
import pytest

import Engine.client_json
import Engine.connection
Expand All @@ -12,17 +13,23 @@
from Engine.media_files import yuv_files


def test_video(build_TestApp, build: str, media: str):
@pytest.mark.parametrize("video_type", [k for k in yuv_files.keys()])
def test_video(build_TestApp, build: str, media: str, video_type):
client = Engine.client_json.ClientJson()
conn_mpg = Engine.connection.MultipointGroup()
payload = Engine.payload.Video(width=3840, height=2160)
payload = Engine.payload.Video(
width=yuv_files[video_type]["width"],
height=yuv_files[video_type]["height"],
fps=yuv_files[video_type]["fps"],
pixelFormat=yuv_files[video_type]["format"],
)
connection = Engine.connection_json.ConnectionJson(connection=conn_mpg, payload=payload)

utils.create_client_json(build, client)
utils.create_connection_json(build, connection)

# Use a specified file from media_files.py
media_file = yuv_files["i2160p25"]["filename"]
media_file = yuv_files[video_type]["filename"]
media_file_path = os.path.join(media, media_file)

utils.run_rx_tx_with_file(file_path=media_file_path, build=build)
35 changes: 35 additions & 0 deletions tests/validation/functional/st2110/st20/test_video.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2024-2025 Intel Corporation
# Media Communications Mesh
import os
import pytest

import Engine.client_json
import Engine.connection
import Engine.connection_json
import Engine.engine_mcm as utils
import Engine.execute
import Engine.payload
from Engine.media_files import yuv_files


@pytest.mark.parametrize("video_type", [k for k in yuv_files.keys()])
def test_video(build_TestApp, build: str, media: str, video_type):
client = Engine.client_json.ClientJson()
conn_mpg = Engine.connection.St2110()
payload = Engine.payload.Video(
width=yuv_files[video_type]["width"],
height=yuv_files[video_type]["height"],
fps=yuv_files[video_type]["fps"],
pixelFormat=yuv_files[video_type]["format"],
)
connection = Engine.connection_json.ConnectionJson(connection=conn_mpg, payload=payload)

utils.create_client_json(build, client)
utils.create_connection_json(build, connection)

# Use a specified file from media_files.py
media_file = yuv_files[video_type]["filename"]
media_file_path = os.path.join(media, media_file)

utils.run_rx_tx_with_file(file_path=media_file_path, build=build)

0 comments on commit 8935e44

Please sign in to comment.