Skip to content

Commit dfb5ebd

Browse files
Reformated
1 parent 6daf5d8 commit dfb5ebd

File tree

2 files changed

+63
-38
lines changed

2 files changed

+63
-38
lines changed

tests/validation/common/integrity/test_audio_integrity.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ SAMPLE_NUM=480 # 480 samples per frame
1919
CHANNEL_NUM=2 # stereo
2020
FRAME_SIZE=$((SAMPLE_SIZE * SAMPLE_NUM * CHANNEL_NUM))
2121
FRAME_COUNT=100 # generate 100 frames
22-
SEGMENT_COUNT=3 # for stream test, use 3 segments
2322

2423
echo "Creating test audio files..."
2524
echo "Frame size: $FRAME_SIZE bytes"

tests/validation/common/integrity/test_audio_runner.py

Lines changed: 63 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,29 @@
44
# Copyright(c) 2024-2025 Intel Corporation
55
# Media Communications Mesh
66

7-
import argparse
87
import logging
9-
import os
108
import subprocess
119
import sys
1210
import tempfile
1311
from pathlib import Path
1412

13+
1514
# Create mock runner classes for testing
1615
class FileAudioIntegrityRunner:
17-
def __init__(self, host, test_repo_path, src_url, out_name, sample_size=2, sample_num=480,
18-
channel_num=2, out_path="/mnt/ramdisk", python_path=None, integrity_path=None, delete_file=True):
16+
def __init__(
17+
self,
18+
host,
19+
test_repo_path,
20+
src_url,
21+
out_name,
22+
sample_size=2,
23+
sample_num=480,
24+
channel_num=2,
25+
out_path="/mnt/ramdisk",
26+
python_path=None,
27+
integrity_path=None,
28+
delete_file=True,
29+
):
1930
self.host = host
2031
self.test_repo_path = test_repo_path
2132
self.src_url = src_url
@@ -33,10 +44,12 @@ def __init__(self, host, test_repo_path, src_url, out_name, sample_size=2, sampl
3344
# Get the directory where this script is located
3445
script_dir = Path(__file__).parent
3546
self.integrity_path = str(script_dir / "audio_integrity.py")
36-
47+
3748
def setup(self):
38-
logging.info(f"Setting up audio integrity check on {self.host.name} for {self.out_name}")
39-
49+
logging.info(
50+
f"Setting up audio integrity check on {self.host.name} for {self.out_name}"
51+
)
52+
4053
def run(self):
4154
cmd = " ".join(
4255
[
@@ -56,15 +69,22 @@ def run(self):
5669
"--delete_file" if self.delete_file else "--no_delete_file",
5770
]
5871
)
59-
logging.debug(f"Running audio integrity check on {self.host.name} for {self.out_name} with command: {cmd}")
60-
result = self.host.connection.execute_command(cmd, shell=True, stderr_to_stdout=True, expected_return_codes=(0, 1))
72+
logging.debug(
73+
f"Running audio integrity check on {self.host.name} for {self.out_name} with command: {cmd}"
74+
)
75+
result = self.host.connection.execute_command(
76+
cmd, shell=True, stderr_to_stdout=True, expected_return_codes=(0, 1)
77+
)
6178
if result.return_code > 0:
6279
logging.error(f"Audio integrity check failed on {self.host.name}: {self.out_name}")
6380
logging.error(result.stdout)
6481
return False
65-
logging.info(f"Audio integrity check completed successfully on {self.host.name} for {self.out_name}")
82+
logging.info(
83+
f"Audio integrity check completed successfully on {self.host.name} for {self.out_name}"
84+
)
6685
return True
6786

87+
6888
# Set up logging
6989
logging.basicConfig(
7090
level=logging.INFO,
@@ -75,14 +95,17 @@ def run(self):
7595

7696
class LocalHost:
7797
"""Simple host class for testing that mimics the expected interface"""
98+
7899
def __init__(self, name="localhost"):
79100
self.name = name
80101
self.connection = self
81102

82103
def path(self, *args):
83104
return Path(*args)
84105

85-
def execute_command(self, cmd, shell=False, stderr_to_stdout=False, expected_return_codes=None):
106+
def execute_command(
107+
self, cmd, shell=False, stderr_to_stdout=False, expected_return_codes=None
108+
):
86109
class CommandResult:
87110
def __init__(self, return_code, stdout):
88111
self.return_code = return_code
@@ -91,20 +114,19 @@ def __init__(self, return_code, stdout):
91114
logger.info(f"Executing command: {cmd}")
92115
try:
93116
result = subprocess.run(
94-
cmd,
95-
shell=shell,
96-
check=False,
97-
text=True,
98-
capture_output=True
117+
cmd, shell=shell, check=False, text=True, capture_output=True
99118
)
100119
logger.info(f"Command output: {result.stdout}")
101120
if result.stderr:
102121
logger.error(f"Command error: {result.stderr}")
103-
122+
104123
if expected_return_codes and result.returncode not in expected_return_codes:
105124
logger.error(f"Command failed with return code {result.returncode}")
106-
107-
return CommandResult(result.returncode, result.stdout + result.stderr if stderr_to_stdout else result.stdout)
125+
126+
return CommandResult(
127+
result.returncode,
128+
result.stdout + result.stderr if stderr_to_stdout else result.stdout,
129+
)
108130
except Exception as e:
109131
logger.error(f"Exception running command: {e}")
110132
return CommandResult(1, str(e))
@@ -113,7 +135,7 @@ def __init__(self, return_code, stdout):
113135
def create_test_files(test_dir, sample_size, sample_num, channel_num, frame_count):
114136
"""Create test PCM files for the integrity test"""
115137
frame_size = sample_size * sample_num * channel_num
116-
138+
117139
# Create source file
118140
source_file = test_dir / "source.pcm"
119141
with open(source_file, "wb") as f:
@@ -122,12 +144,12 @@ def create_test_files(test_dir, sample_size, sample_num, channel_num, frame_coun
122144
# This example creates a pattern based on the frame number
123145
pattern = bytes([(i + j) % 256 for j in range(frame_size)])
124146
f.write(pattern)
125-
147+
126148
# Create a matching destination file
127149
dest_file = test_dir / "dest.pcm"
128150
with open(source_file, "rb") as src, open(dest_file, "wb") as dst:
129151
dst.write(src.read())
130-
152+
131153
# Create a corrupted file for additional testing (optional)
132154
corrupt_file = test_dir / "corrupt.pcm"
133155
with open(source_file, "rb") as src, open(corrupt_file, "wb") as dst:
@@ -139,36 +161,36 @@ def create_test_files(test_dir, sample_size, sample_num, channel_num, frame_coun
139161
for i in range(min(10, frame_size)):
140162
corrupt_data[corrupt_pos + i] = (corrupt_data[corrupt_pos + i] + 123) % 256
141163
dst.write(corrupt_data)
142-
164+
143165
return source_file, dest_file
144166

145167

146168
def main():
147169
# Create temporary directory for test files
148170
with tempfile.TemporaryDirectory() as temp_dir:
149171
test_dir = Path(temp_dir)
150-
172+
151173
# Parameters for audio frames
152174
sample_size = 2 # 16-bit samples (2 bytes)
153175
sample_num = 480 # 480 samples per frame
154176
channel_num = 2 # stereo
155177
frame_count = 100 # generate 100 frames
156-
178+
157179
# Get the path to the repo
158180
repo_path = Path(__file__).parent.parent.parent
159-
181+
160182
# Create test files
161183
source_file, dest_file = create_test_files(
162184
test_dir, sample_size, sample_num, channel_num, frame_count
163185
)
164-
186+
165187
logger.info(f"Created test files in {test_dir}")
166188
logger.info(f"Source file: {source_file}")
167189
logger.info(f"Destination file: {dest_file}")
168-
190+
169191
# Create local host for testing
170192
host = LocalHost()
171-
193+
172194
# Test 1: Test the file audio integrity runner with valid file
173195
logger.info("Test 1: Testing FileAudioIntegrityRunner with valid file...")
174196
file_runner = FileAudioIntegrityRunner(
@@ -182,16 +204,16 @@ def main():
182204
out_path=str(test_dir),
183205
delete_file=False,
184206
)
185-
207+
186208
file_runner.setup()
187209
result = file_runner.run()
188-
210+
189211
if result:
190212
logger.info("✅ Test 1: FileAudioIntegrityRunner with valid file - PASSED")
191213
else:
192214
logger.error("❌ Test 1: FileAudioIntegrityRunner with valid file - FAILED")
193215
return 1
194-
216+
195217
# Test 2: Test with corrupted file (should fail)
196218
logger.info("Test 2: Testing FileAudioIntegrityRunner with corrupted file...")
197219
corrupt_runner = FileAudioIntegrityRunner(
@@ -205,16 +227,20 @@ def main():
205227
out_path=str(test_dir),
206228
delete_file=False,
207229
)
208-
230+
209231
corrupt_runner.setup()
210232
corrupt_result = corrupt_runner.run()
211-
233+
212234
if not corrupt_result:
213-
logger.info("✅ Test 2: FileAudioIntegrityRunner with corrupted file - PASSED (correctly detected corruption)")
235+
logger.info(
236+
"✅ Test 2: FileAudioIntegrityRunner with corrupted file - PASSED (correctly detected corruption)"
237+
)
214238
else:
215-
logger.error("❌ Test 2: FileAudioIntegrityRunner with corrupted file - FAILED (did not detect corruption)")
239+
logger.error(
240+
"❌ Test 2: FileAudioIntegrityRunner with corrupted file - FAILED (did not detect corruption)"
241+
)
216242
return 1
217-
243+
218244
return 0
219245

220246

0 commit comments

Comments
 (0)