Skip to content

Commit 0a68995

Browse files
Reformated
1 parent 6daf5d8 commit 0a68995

File tree

3 files changed

+94
-67
lines changed

3 files changed

+94
-67
lines changed

tests/validation/common/integrity/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pip install -r requirements.txt
2222

2323
### Audio Integrity
2424

25-
#### File Mode
25+
#### Audio File Mode
2626

2727
Compares a single audio file against a reference source file:
2828

@@ -32,7 +32,7 @@ python audio_integrity.py file <source_file> <output_file> \
3232
--output_path /path/to/output/dir
3333
```
3434

35-
#### Stream Mode
35+
#### Audio Stream Mode
3636

3737
Checks the integrity of segmented audio files from a stream:
3838

@@ -44,7 +44,7 @@ python audio_integrity.py stream <source_file> <segment_prefix> \
4444

4545
### Video Integrity
4646

47-
#### File Mode
47+
#### Video File Mode
4848

4949
Compares a single video file against a reference source file:
5050

@@ -53,7 +53,7 @@ python video_integrity.py file <source_file> <output_file> <resolution> <format>
5353
--output_path /path/to/output/dir
5454
```
5555

56-
#### Stream Mode
56+
#### Video Stream Mode
5757

5858
Checks the integrity of segmented video files from a stream:
5959

tests/validation/common/integrity/test_audio_integrity.sh

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ TEST_DIR="/tmp/mtl_audio_integrity_test"
1414
mkdir -p $TEST_DIR
1515

1616
# Define parameters for our test
17-
SAMPLE_SIZE=2 # 16-bit samples (2 bytes)
18-
SAMPLE_NUM=480 # 480 samples per frame
19-
CHANNEL_NUM=2 # stereo
17+
SAMPLE_SIZE=2 # 16-bit samples (2 bytes)
18+
SAMPLE_NUM=480 # 480 samples per frame
19+
CHANNEL_NUM=2 # stereo
2020
FRAME_SIZE=$((SAMPLE_SIZE * SAMPLE_NUM * CHANNEL_NUM))
21-
FRAME_COUNT=100 # generate 100 frames
22-
SEGMENT_COUNT=3 # for stream test, use 3 segments
21+
FRAME_COUNT=100 # generate 100 frames
2322

2423
echo "Creating test audio files..."
2524
echo "Frame size: $FRAME_SIZE bytes"
@@ -54,49 +53,49 @@ cp $SOURCE_FILE $SEGMENT_FILE
5453
# Test file integrity - should pass
5554
echo -e "\n\n### TEST 1: File integrity check (should pass) ###"
5655
python3 "$SCRIPT_DIR/audio_integrity.py" file \
57-
$SOURCE_FILE $DEST_FILE \
58-
--sample_size $SAMPLE_SIZE --sample_num $SAMPLE_NUM --channel_num $CHANNEL_NUM \
59-
--output_path $TEST_DIR --no_delete_file
56+
$SOURCE_FILE $DEST_FILE \
57+
--sample_size $SAMPLE_SIZE --sample_num $SAMPLE_NUM --channel_num $CHANNEL_NUM \
58+
--output_path $TEST_DIR --no_delete_file
6059
RESULT=$?
6160
if [ $RESULT -eq 0 ]; then
62-
echo "✅ File integrity check passed as expected"
61+
echo "✅ File integrity check passed as expected"
6362
else
64-
echo "❌ File integrity check failed unexpectedly"
65-
exit 1
63+
echo "❌ File integrity check failed unexpectedly"
64+
exit 1
6665
fi
6766

6867
# Test file integrity with corrupt file - should fail
6968
echo -e "\n\n### TEST 2: File integrity check with corrupt file (should fail) ###"
7069
# Temporarily disable exit on error for this test since we expect it to fail
7170
set +e
7271
python3 "$SCRIPT_DIR/audio_integrity.py" file \
73-
$SOURCE_FILE $CORRUPT_FILE \
74-
--sample_size $SAMPLE_SIZE --sample_num $SAMPLE_NUM --channel_num $CHANNEL_NUM \
75-
--output_path $TEST_DIR --no_delete_file
72+
$SOURCE_FILE $CORRUPT_FILE \
73+
--sample_size $SAMPLE_SIZE --sample_num $SAMPLE_NUM --channel_num $CHANNEL_NUM \
74+
--output_path $TEST_DIR --no_delete_file
7675
RESULT=$?
77-
set -e # Re-enable exit on error
76+
set -e # Re-enable exit on error
7877
if [ $RESULT -eq 1 ]; then
79-
echo "✅ Corrupt file check correctly failed"
78+
echo "✅ Corrupt file check correctly failed"
8079
else
81-
echo "❌ Corrupt file check incorrectly passed"
82-
exit 1
80+
echo "❌ Corrupt file check incorrectly passed"
81+
exit 1
8382
fi
8483

8584
# Test stream integrity - should pass
8685
echo -e "\n\n### TEST 3: Stream integrity check (should pass) ###"
8786
# Temporarily disable exit on error for this test
8887
set +e
8988
python3 "$SCRIPT_DIR/audio_integrity.py" stream \
90-
$SOURCE_FILE segment \
91-
--sample_size $SAMPLE_SIZE --sample_num $SAMPLE_NUM --channel_num $CHANNEL_NUM \
92-
--output_path $TEST_DIR/segments --no_delete_file
89+
$SOURCE_FILE segment \
90+
--sample_size $SAMPLE_SIZE --sample_num $SAMPLE_NUM --channel_num $CHANNEL_NUM \
91+
--output_path $TEST_DIR/segments --no_delete_file
9392
RESULT=$?
94-
set -e # Re-enable exit on error
93+
set -e # Re-enable exit on error
9594
if [ $RESULT -eq 0 ]; then
96-
echo "✅ Stream integrity check passed as expected"
95+
echo "✅ Stream integrity check passed as expected"
9796
else
98-
echo "❌ Stream integrity check failed unexpectedly"
99-
exit 1
97+
echo "❌ Stream integrity check failed unexpectedly"
98+
exit 1
10099
fi
101100

102101
# Clean up test files

tests/validation/common/integrity/test_audio_runner.py

Lines changed: 66 additions & 38 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,24 @@ 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:
62-
logging.error(f"Audio integrity check failed on {self.host.name}: {self.out_name}")
79+
logging.error(
80+
f"Audio integrity check failed on {self.host.name}: {self.out_name}"
81+
)
6382
logging.error(result.stdout)
6483
return False
65-
logging.info(f"Audio integrity check completed successfully on {self.host.name} for {self.out_name}")
84+
logging.info(
85+
f"Audio integrity check completed successfully on {self.host.name} for {self.out_name}"
86+
)
6687
return True
6788

89+
6890
# Set up logging
6991
logging.basicConfig(
7092
level=logging.INFO,
@@ -75,14 +97,17 @@ def run(self):
7597

7698
class LocalHost:
7799
"""Simple host class for testing that mimics the expected interface"""
100+
78101
def __init__(self, name="localhost"):
79102
self.name = name
80103
self.connection = self
81104

82105
def path(self, *args):
83106
return Path(*args)
84107

85-
def execute_command(self, cmd, shell=False, stderr_to_stdout=False, expected_return_codes=None):
108+
def execute_command(
109+
self, cmd, shell=False, stderr_to_stdout=False, expected_return_codes=None
110+
):
86111
class CommandResult:
87112
def __init__(self, return_code, stdout):
88113
self.return_code = return_code
@@ -91,20 +116,19 @@ def __init__(self, return_code, stdout):
91116
logger.info(f"Executing command: {cmd}")
92117
try:
93118
result = subprocess.run(
94-
cmd,
95-
shell=shell,
96-
check=False,
97-
text=True,
98-
capture_output=True
119+
cmd, shell=shell, check=False, text=True, capture_output=True
99120
)
100121
logger.info(f"Command output: {result.stdout}")
101122
if result.stderr:
102123
logger.error(f"Command error: {result.stderr}")
103-
124+
104125
if expected_return_codes and result.returncode not in expected_return_codes:
105126
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)
127+
128+
return CommandResult(
129+
result.returncode,
130+
result.stdout + result.stderr if stderr_to_stdout else result.stdout,
131+
)
108132
except Exception as e:
109133
logger.error(f"Exception running command: {e}")
110134
return CommandResult(1, str(e))
@@ -113,7 +137,7 @@ def __init__(self, return_code, stdout):
113137
def create_test_files(test_dir, sample_size, sample_num, channel_num, frame_count):
114138
"""Create test PCM files for the integrity test"""
115139
frame_size = sample_size * sample_num * channel_num
116-
140+
117141
# Create source file
118142
source_file = test_dir / "source.pcm"
119143
with open(source_file, "wb") as f:
@@ -122,12 +146,12 @@ def create_test_files(test_dir, sample_size, sample_num, channel_num, frame_coun
122146
# This example creates a pattern based on the frame number
123147
pattern = bytes([(i + j) % 256 for j in range(frame_size)])
124148
f.write(pattern)
125-
149+
126150
# Create a matching destination file
127151
dest_file = test_dir / "dest.pcm"
128152
with open(source_file, "rb") as src, open(dest_file, "wb") as dst:
129153
dst.write(src.read())
130-
154+
131155
# Create a corrupted file for additional testing (optional)
132156
corrupt_file = test_dir / "corrupt.pcm"
133157
with open(source_file, "rb") as src, open(corrupt_file, "wb") as dst:
@@ -139,36 +163,36 @@ def create_test_files(test_dir, sample_size, sample_num, channel_num, frame_coun
139163
for i in range(min(10, frame_size)):
140164
corrupt_data[corrupt_pos + i] = (corrupt_data[corrupt_pos + i] + 123) % 256
141165
dst.write(corrupt_data)
142-
166+
143167
return source_file, dest_file
144168

145169

146170
def main():
147171
# Create temporary directory for test files
148172
with tempfile.TemporaryDirectory() as temp_dir:
149173
test_dir = Path(temp_dir)
150-
174+
151175
# Parameters for audio frames
152176
sample_size = 2 # 16-bit samples (2 bytes)
153177
sample_num = 480 # 480 samples per frame
154178
channel_num = 2 # stereo
155179
frame_count = 100 # generate 100 frames
156-
180+
157181
# Get the path to the repo
158182
repo_path = Path(__file__).parent.parent.parent
159-
183+
160184
# Create test files
161185
source_file, dest_file = create_test_files(
162186
test_dir, sample_size, sample_num, channel_num, frame_count
163187
)
164-
188+
165189
logger.info(f"Created test files in {test_dir}")
166190
logger.info(f"Source file: {source_file}")
167191
logger.info(f"Destination file: {dest_file}")
168-
192+
169193
# Create local host for testing
170194
host = LocalHost()
171-
195+
172196
# Test 1: Test the file audio integrity runner with valid file
173197
logger.info("Test 1: Testing FileAudioIntegrityRunner with valid file...")
174198
file_runner = FileAudioIntegrityRunner(
@@ -182,16 +206,16 @@ def main():
182206
out_path=str(test_dir),
183207
delete_file=False,
184208
)
185-
209+
186210
file_runner.setup()
187211
result = file_runner.run()
188-
212+
189213
if result:
190214
logger.info("✅ Test 1: FileAudioIntegrityRunner with valid file - PASSED")
191215
else:
192216
logger.error("❌ Test 1: FileAudioIntegrityRunner with valid file - FAILED")
193217
return 1
194-
218+
195219
# Test 2: Test with corrupted file (should fail)
196220
logger.info("Test 2: Testing FileAudioIntegrityRunner with corrupted file...")
197221
corrupt_runner = FileAudioIntegrityRunner(
@@ -205,16 +229,20 @@ def main():
205229
out_path=str(test_dir),
206230
delete_file=False,
207231
)
208-
232+
209233
corrupt_runner.setup()
210234
corrupt_result = corrupt_runner.run()
211-
235+
212236
if not corrupt_result:
213-
logger.info("✅ Test 2: FileAudioIntegrityRunner with corrupted file - PASSED (correctly detected corruption)")
237+
logger.info(
238+
"✅ Test 2: FileAudioIntegrityRunner with corrupted file - PASSED (correctly detected corruption)"
239+
)
214240
else:
215-
logger.error("❌ Test 2: FileAudioIntegrityRunner with corrupted file - FAILED (did not detect corruption)")
241+
logger.error(
242+
"❌ Test 2: FileAudioIntegrityRunner with corrupted file - FAILED (did not detect corruption)"
243+
)
216244
return 1
217-
245+
218246
return 0
219247

220248

0 commit comments

Comments
 (0)