Skip to content

Commit 7bccbac

Browse files
committed
Use context manager to handle test file's download and deletion
1 parent 9124198 commit 7bccbac

4 files changed

Lines changed: 123 additions & 123 deletions

File tree

contrib/checkbox-ce-oem/checkbox-provider-ce-oem/bin/gst_encoder_psnr.py

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@
3030
GStreamerMuxerType,
3131
GStreamerEncodePlugins,
3232
MetadataValidator,
33-
get_big_bug_bunny_golden_sample,
3433
generate_artifact_name,
3534
compare_psnr,
3635
delete_file,
3736
execute_command,
37+
get_test_file_path_by_params,
38+
manage_test_file_by_params,
3839
)
3940

4041
logging.basicConfig(level=logging.INFO)
@@ -200,8 +201,8 @@ def __init__(
200201
}
201202
# This sample video file will be consumed by any gstreamer piple as
202203
# input video.
203-
self._golden_sample = get_big_bug_bunny_golden_sample(
204-
width=self._width, height=self._height, framerate=self._framerate
204+
self._golden_sample = get_test_file_path_by_params(
205+
self._width, self._height, self._framerate
205206
)
206207
self._artifact_file = ""
207208

@@ -332,9 +333,8 @@ def __init__(
332333
}
333334
# This sample video file will be consumed by any gstreamer piple as
334335
# input video.
335-
self._golden_sample = os.path.join(
336-
VIDEO_CODEC_TESTING_DATA,
337-
"{}p_{}fps_h264.mp4".format(self._height, self._framerate),
336+
self._golden_sample = get_test_file_path_by_params(
337+
self._width, self._height, self._framerate, "h264"
338338
)
339339
self._artifact_file = ""
340340

@@ -427,9 +427,8 @@ def _h264_pipeline_builder(self) -> str:
427427
"""
428428
# This sample video file will be consumed by any gstreamer piple as
429429
# input video.
430-
self._golden_sample = os.path.join(
431-
VIDEO_CODEC_TESTING_DATA,
432-
"{}p_{}fps_h264.mp4".format(self._height, self._framerate),
430+
self._golden_sample = get_test_file_path_by_params(
431+
self._width, self._height, self._framerate, "h264"
433432
)
434433
pipeline = (
435434
"{} filesrc location={} ! qtdemux ! decodebin !"
@@ -452,9 +451,8 @@ def _h265_pipeline_builder(self) -> str:
452451
"""
453452
# This sample video file will be consumed by any gstreamer piple as
454453
# input video.
455-
self._golden_sample = os.path.join(
456-
VIDEO_CODEC_TESTING_DATA,
457-
"{}p_{}fps_h265.mp4".format(self._height, self._framerate),
454+
self._golden_sample = get_test_file_path_by_params(
455+
self._width, self._height, self._framerate, "h265"
458456
)
459457
pipeline = (
460458
"{} filesrc location={} ! qtdemux ! decodebin !"
@@ -475,9 +473,8 @@ def _vp8_pipeline_builder(self) -> str:
475473
"""
476474
# This sample video file will be consumed by any gstreamer piple as
477475
# input video.
478-
self._golden_sample = os.path.join(
479-
VIDEO_CODEC_TESTING_DATA,
480-
"{}p_{}fps_vp8.webm".format(self._height, self._framerate),
476+
self._golden_sample = get_test_file_path_by_params(
477+
self._width, self._height, self._framerate, "vp8"
481478
)
482479
pipeline = (
483480
"{} filesrc location={} ! qtdemux ! decodebin !"
@@ -546,9 +543,8 @@ def _omxh264_pipeline_builder(self) -> str:
546543
"""
547544
Build gstreamer pipeline for omxh264enc
548545
"""
549-
self._golden_sample = os.path.join(
550-
VIDEO_CODEC_TESTING_DATA,
551-
"{}p_{}fps_h264.mp4".format(self._height, self._framerate),
546+
self._golden_sample = get_test_file_path_by_params(
547+
self._width, self._height, self._framerate, "h264"
552548
)
553549
pipeline = (
554550
"{} filesrc location={} ! qtdemux ! h264parse !"
@@ -585,22 +581,27 @@ def build_pipeline(self) -> str:
585581

586582
def main() -> None:
587583
args = register_arguments()
588-
p = project_factory(args)
589-
logging.info("Step 1: Generating artifact...")
590-
cmd = p.build_pipeline()
591-
# execute command
592-
execute_command(cmd=cmd)
593-
logging.info("\nStep 2: Checking metadata...")
594-
mv = MetadataValidator(file_path=p.artifact_file)
595-
mv.validate("width", args.width).validate("height", args.height).validate(
596-
"frame_rate", args.framerate
597-
).validate("codec", args.encoder_plugin).is_valid()
598-
logging.info("\nStep 3: Comparing PSNR...")
599-
compare_psnr(
600-
golden_reference_file=p.psnr_reference_file,
601-
artifact_file=p.artifact_file,
602-
)
603-
delete_file(file_path=p.artifact_file)
584+
with manage_test_file_by_params(
585+
args.width, args.height, args.framerate, args.encoder_plugin
586+
):
587+
p = project_factory(args)
588+
logging.info("Step 1: Generating artifact...")
589+
cmd = p.build_pipeline()
590+
# execute command
591+
execute_command(cmd=cmd)
592+
logging.info("\nStep 2: Checking metadata...")
593+
mv = MetadataValidator(file_path=p.artifact_file)
594+
mv.validate("width", args.width).validate(
595+
"height", args.height
596+
).validate("frame_rate", args.framerate).validate(
597+
"codec", args.encoder_plugin
598+
).is_valid()
599+
logging.info("\nStep 3: Comparing PSNR...")
600+
compare_psnr(
601+
golden_reference_file=p.psnr_reference_file,
602+
artifact_file=p.artifact_file,
603+
)
604+
delete_file(file_path=p.artifact_file)
604605

605606

606607
if __name__ == "__main__":

contrib/checkbox-ce-oem/checkbox-provider-ce-oem/bin/gst_transform_resize.py

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,15 @@
2525

2626
from gst_utils import (
2727
GST_LAUNCH_BIN,
28-
VIDEO_CODEC_TESTING_DATA,
29-
SAMPLE_2_FOLDER,
3028
PipelineInterface,
3129
GStreamerEncodePlugins,
3230
MetadataValidator,
33-
get_big_bug_bunny_golden_sample,
3431
generate_artifact_name,
3532
compare_psnr,
3633
delete_file,
3734
execute_command,
35+
get_test_file_path_by_params,
36+
manage_test_file_by_params,
3837
)
3938

4039
logging.basicConfig(level=logging.INFO)
@@ -169,10 +168,8 @@ def __init__(
169168
}
170169
# This sample video file will be consumed by any gstreamer piple as
171170
# input video.
172-
self._golden_sample = get_big_bug_bunny_golden_sample(
173-
width=self._width_from,
174-
height=self._height_from,
175-
framerate=self._framerate,
171+
self._golden_sample = get_test_file_path_by_params(
172+
self._width_from, self._height_from, self._framerate
176173
)
177174
self._artifact_file = ""
178175

@@ -188,17 +185,13 @@ def psnr_reference_file(self) -> str:
188185
A golden reference which has been transformed in advance. It's used to
189186
be the compared reference file for PSNR.
190187
"""
191-
golden_reference = get_big_bug_bunny_golden_sample(
188+
golden_reference = get_test_file_path_by_params(
192189
self._width_to, self._height_to, self._framerate
193190
)
194-
195-
full_path = os.path.join(
196-
VIDEO_CODEC_TESTING_DATA, SAMPLE_2_FOLDER, golden_reference
197-
)
198-
if not os.path.exists(full_path):
191+
if not os.path.exists(golden_reference):
199192
raise SystemExit(
200193
"Error: Golden PSNR reference '{}' doesn't exist".format(
201-
full_path
194+
golden_reference
202195
)
203196
)
204197

@@ -229,24 +222,30 @@ def build_pipeline(self) -> str:
229222

230223
def main() -> None:
231224
args = register_arguments()
232-
p = project_factory(args)
233-
logging.info("Step 1: Generating artifact...")
234-
cmd = p.build_pipeline()
235-
# execute command
236-
execute_command(cmd=cmd)
237-
logging.info("\nStep 2: Checking metadata...")
238-
mv = MetadataValidator(file_path=p.artifact_file)
239-
mv.validate("width", args.width_to).validate(
240-
"height", args.height_to
241-
).validate("frame_rate", args.framerate).validate(
242-
"codec", args.encoder_plugin
243-
).is_valid()
244-
logging.info("\nStep 3: Comparing PSNR...")
245-
compare_psnr(
246-
golden_reference_file=p.psnr_reference_file,
247-
artifact_file=p.artifact_file,
248-
)
249-
delete_file(file_path=p.artifact_file)
225+
with manage_test_file_by_params(
226+
args.width_from, args.height_from, args.framerate, args.encoder_plugin
227+
):
228+
with manage_test_file_by_params(
229+
args.width_to, args.height_to, args.framerate, args.encoder_plugin
230+
):
231+
p = project_factory(args)
232+
logging.info("Step 1: Generating artifact...")
233+
cmd = p.build_pipeline()
234+
# execute command
235+
execute_command(cmd=cmd)
236+
logging.info("\nStep 2: Checking metadata...")
237+
mv = MetadataValidator(file_path=p.artifact_file)
238+
mv.validate("width", args.width_to).validate(
239+
"height", args.height_to
240+
).validate("frame_rate", args.framerate).validate(
241+
"codec", args.encoder_plugin
242+
).is_valid()
243+
logging.info("\nStep 3: Comparing PSNR...")
244+
compare_psnr(
245+
golden_reference_file=p.psnr_reference_file,
246+
artifact_file=p.artifact_file,
247+
)
248+
delete_file(file_path=p.artifact_file)
250249

251250

252251
if __name__ == "__main__":

contrib/checkbox-ce-oem/checkbox-provider-ce-oem/bin/gst_v4l2_audio_video_synchronization.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import shlex
2424
import subprocess
2525
from typing import Any
26+
from gst_utils import manage_test_file_by_name
2627

2728
logging.basicConfig(level=logging.INFO)
2829

@@ -169,21 +170,20 @@ def play_video_for_av_synchronization_test(args: Any) -> None:
169170
exist, or if the extracted MD5 checksum does not match the golden MD5
170171
checksum.
171172
"""
172-
# Check the golden sample exists
173-
if not os.path.exists(args.golden_sample_path):
174-
raise SystemExit(
175-
"Golden Sample '{}' doesn't exist".format(args.golden_sample_path)
173+
with manage_test_file_by_name(
174+
file_name=os.path.basename(args.golden_sample_path),
175+
target_dir=os.path.dirname(args.golden_sample_path),
176+
):
177+
gst_launch_bin = os.getenv("GST_LAUNCH_BIN", "gst-launch-1.0")
178+
cmd = build_gst_command(
179+
gst_bin=gst_launch_bin,
180+
golden_sample_path=args.golden_sample_path,
181+
decoder=args.decoder_plugin,
182+
video_sink=args.video_sink,
183+
capssetter_pipeline=args.capssetter_pipeline,
176184
)
177-
gst_launch_bin = os.getenv("GST_LAUNCH_BIN", "gst-launch-1.0")
178-
cmd = build_gst_command(
179-
gst_bin=gst_launch_bin,
180-
golden_sample_path=args.golden_sample_path,
181-
decoder=args.decoder_plugin,
182-
video_sink=args.video_sink,
183-
capssetter_pipeline=args.capssetter_pipeline,
184-
)
185-
# The video will be displayed on the real display
186-
execute_command(cmd)
185+
# The video will be displayed on the real display
186+
execute_command(cmd)
187187

188188

189189
def main() -> None:

contrib/checkbox-ce-oem/checkbox-provider-ce-oem/bin/gst_video_decoder_performance.py

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import re
2424

2525
from performance_mode_controller import get_performance_ctx_function
26-
from gst_utils import execute_command
26+
from gst_utils import execute_command, manage_test_file_by_name
2727

2828
logging.basicConfig(level=logging.INFO)
2929

@@ -304,50 +304,50 @@ def main() -> None:
304304
),
305305
args.minimum_fps,
306306
)
307-
# Check the golden sample exixt
308-
if not os.path.exists(args.golden_sample_path):
309-
raise SystemExit(
310-
"Golden Sample '{}' doesn't exist".format(args.golden_sample_path)
311-
)
312-
gst_launch_bin = os.getenv("GST_LAUNCH_BIN", "gst-launch-1.0")
313-
if "imx8m" in args.platform:
314-
cmd = build_imx_gst_command(
315-
gst_bin=gst_launch_bin,
316-
golden_sample_path=args.golden_sample_path,
317-
decoder=args.decoder_plugin,
318-
sink=args.sink,
319-
fpsdisplaysink_sync=args.fpsdisplaysink_sync,
320-
)
321-
elif "rz" in args.platform:
322-
cmd = build_renesas_gst_command(
323-
gst_bin=gst_launch_bin,
324-
golden_sample_path=args.golden_sample_path,
325-
decoder=args.decoder_plugin,
326-
sink=args.sink,
327-
fpsdisplaysink_sync=args.fpsdisplaysink_sync,
328-
platform=args.platform,
329-
)
330-
else:
331-
cmd = build_gst_command(
332-
gst_bin=gst_launch_bin,
333-
golden_sample_path=args.golden_sample_path,
334-
decoder=args.decoder_plugin,
335-
sink=args.sink,
336-
fpsdisplaysink_sync=args.fpsdisplaysink_sync,
337-
)
338-
339-
output = ""
340-
341-
if args.performance_mode_target:
342-
performance_mode_ctx = get_performance_ctx_function()
343-
with performance_mode_ctx(platform=args.performance_mode_target):
307+
with manage_test_file_by_name(
308+
file_name=os.path.basename(args.golden_sample_path),
309+
target_dir=os.path.dirname(args.golden_sample_path),
310+
):
311+
gst_launch_bin = os.getenv("GST_LAUNCH_BIN", "gst-launch-1.0")
312+
if "imx8m" in args.platform:
313+
cmd = build_imx_gst_command(
314+
gst_bin=gst_launch_bin,
315+
golden_sample_path=args.golden_sample_path,
316+
decoder=args.decoder_plugin,
317+
sink=args.sink,
318+
fpsdisplaysink_sync=args.fpsdisplaysink_sync,
319+
)
320+
elif "rz" in args.platform:
321+
cmd = build_renesas_gst_command(
322+
gst_bin=gst_launch_bin,
323+
golden_sample_path=args.golden_sample_path,
324+
decoder=args.decoder_plugin,
325+
sink=args.sink,
326+
fpsdisplaysink_sync=args.fpsdisplaysink_sync,
327+
platform=args.platform,
328+
)
329+
else:
330+
cmd = build_gst_command(
331+
gst_bin=gst_launch_bin,
332+
golden_sample_path=args.golden_sample_path,
333+
decoder=args.decoder_plugin,
334+
sink=args.sink,
335+
fpsdisplaysink_sync=args.fpsdisplaysink_sync,
336+
)
337+
338+
output = ""
339+
340+
if args.performance_mode_target:
341+
performance_mode_ctx = get_performance_ctx_function()
342+
with performance_mode_ctx(platform=args.performance_mode_target):
343+
output = execute_command(cmd).rstrip(os.linesep)
344+
else:
344345
output = execute_command(cmd).rstrip(os.linesep)
345-
else:
346-
output = execute_command(cmd).rstrip(os.linesep)
347346

348-
if not is_valid_result(output, args.minimum_fps):
349-
raise SystemExit(1)
350-
logging.info("Pass")
347+
is_valid = is_valid_result(output, args.minimum_fps)
348+
if not is_valid:
349+
raise SystemExit(1)
350+
logging.info("Pass")
351351

352352

353353
if __name__ == "__main__":

0 commit comments

Comments
 (0)