1
1
# SPDX-License-Identifier: BSD-3-Clause
2
2
# Copyright(c) 2024-2025 Intel Corporation
3
3
4
- import hashlib
5
4
import logging
6
5
import os
7
- import time
8
6
import re
7
+ import time
9
8
10
9
from mtl_engine .RxTxApp import prepare_tcpdump
11
10
@@ -54,20 +53,20 @@ def fract_format(framerate: str) -> str:
54
53
# If already in fractional format, return as-is
55
54
if "/" in framerate :
56
55
return framerate
57
-
56
+
58
57
# Convert specific decimal framerates to fractional format
59
58
framerate_map = {
60
59
"23.98" : "2398/100" ,
61
- "23.976" : "2398/100" ,
60
+ "23.976" : "2398/100" ,
62
61
"29.97" : "2997/100" ,
63
62
"59.94" : "5994/100" ,
64
- "119.88" : "11988/100"
63
+ "119.88" : "11988/100" ,
65
64
}
66
-
65
+
67
66
# Check if it's one of the special decimal framerates
68
67
if framerate in framerate_map :
69
68
return framerate_map [framerate ]
70
-
69
+
71
70
# For integer framerates, add /1
72
71
try :
73
72
int (framerate ) # Validate it's a number
@@ -324,6 +323,7 @@ def setup_gstreamer_st40p_rx_pipeline(
324
323
325
324
return pipeline_command
326
325
326
+
327
327
def execute_test (
328
328
build : str ,
329
329
tx_command : dict ,
@@ -357,15 +357,15 @@ def execute_test(
357
357
:return: True if test passed, False otherwise
358
358
"""
359
359
is_dual = tx_host is not None and rx_host is not None
360
-
360
+
361
361
if is_dual :
362
362
logger .info ("Executing dual host GStreamer test" )
363
363
tx_remote_host = tx_host
364
364
rx_remote_host = rx_host
365
365
else :
366
366
logger .info ("Executing single host GStreamer test" )
367
367
tx_remote_host = rx_remote_host = host
368
-
368
+
369
369
case_id = os .environ .get ("PYTEST_CURRENT_TEST" , "gstreamer_test" )
370
370
case_id = case_id [: case_id .rfind ("(" ) - 1 ] if "(" in case_id else case_id
371
371
@@ -374,10 +374,10 @@ def execute_test(
374
374
375
375
tx_process = None
376
376
rx_process = None
377
-
377
+
378
378
if is_dual :
379
379
tx_tcpdump = prepare_tcpdump (capture_cfg , tx_host ) if capture_cfg else None
380
- rx_tcpdump = prepare_tcpdump (capture_cfg , rx_host ) if capture_cfg else None
380
+ # rx_tcpdump = prepare_tcpdump(capture_cfg, rx_host) if capture_cfg else None # Unused
381
381
tcpdump = tx_tcpdump
382
382
else :
383
383
tcpdump = prepare_tcpdump (capture_cfg , host )
@@ -492,15 +492,20 @@ def execute_test(
492
492
# Compare files for validation
493
493
if is_dual :
494
494
# For dual host tests, files are on different hosts
495
- file_compare = compare_files (input_file , output_file , tx_remote_host , rx_remote_host )
495
+ file_compare = compare_files (
496
+ input_file , output_file , tx_remote_host , rx_remote_host
497
+ )
496
498
else :
497
499
# For single host tests, both files are on the same host
498
- file_compare = compare_files (input_file , output_file , tx_remote_host , rx_remote_host )
499
-
500
+ file_compare = compare_files (
501
+ input_file , output_file , tx_remote_host , rx_remote_host
502
+ )
503
+
500
504
logger .info (f"File comparison: { file_compare } " )
501
505
502
506
return file_compare
503
507
508
+
504
509
def compare_files (input_file , output_file , input_host = None , output_host = None ):
505
510
"""
506
511
Compare files on remote hosts.
@@ -513,13 +518,15 @@ def compare_files(input_file, output_file, input_host=None, output_host=None):
513
518
# Check if input file exists (for cases where input file might not be created)
514
519
input_stat_proc = run (f"stat -c '%s' { input_file } " , host = input_host )
515
520
input_file_exists = input_stat_proc .return_code == 0
516
-
521
+
517
522
if input_file_exists :
518
523
input_file_size = int (input_stat_proc .stdout_text .strip ())
519
524
logger .info (f"Input file size: { input_file_size } " )
520
525
else :
521
- logger .info (f"Input file { input_file } does not exist - skipping input validation" )
522
-
526
+ logger .info (
527
+ f"Input file { input_file } does not exist - skipping input validation"
528
+ )
529
+
523
530
# Check output file size (always remote)
524
531
output_stat_proc = run (f"stat -c '%s' { output_file } " , host = output_host )
525
532
if output_stat_proc .return_code != 0 :
@@ -536,7 +543,7 @@ def compare_files(input_file, output_file, input_host=None, output_host=None):
536
543
else :
537
544
log_fail ("Output file is empty" )
538
545
return False
539
-
546
+
540
547
# If input file exists, do full comparison
541
548
if input_file_size != output_file_size :
542
549
log_fail ("File size is different" )
@@ -546,20 +553,28 @@ def compare_files(input_file, output_file, input_host=None, output_host=None):
546
553
if input_hash_proc .return_code != 0 :
547
554
log_fail (f"Could not calculate hash for input file { input_file } " )
548
555
return False
549
- i_hash = input_hash_proc .stdout_text .split ()[0 ] if input_hash_proc .stdout_text .strip () else ""
556
+ i_hash = (
557
+ input_hash_proc .stdout_text .split ()[0 ] if
558
+ input_hash_proc .stdout_text .strip ()
559
+ else ""
560
+ )
550
561
551
562
output_hash_proc = run (f"md5sum { output_file } " , host = output_host )
552
563
if output_hash_proc .return_code != 0 :
553
564
log_fail (f"Could not calculate hash for output file { output_file } " )
554
565
return False
555
- o_hash = output_hash_proc .stdout_text .split ()[0 ] if output_hash_proc .stdout_text .strip () else ""
566
+ o_hash = (
567
+ output_hash_proc .stdout_text .split ()[0 ]
568
+ if output_hash_proc .stdout_text .strip ()
569
+ else ""
570
+ )
556
571
557
572
logger .info (f"Input file hash: { i_hash } " )
558
573
logger .info (f"Output file hash: { o_hash } " )
559
-
574
+
560
575
if i_hash and o_hash and i_hash == o_hash :
561
576
return True
562
-
577
+
563
578
except Exception as e :
564
579
log_fail (f"Error during file comparison: { e } " )
565
580
return False
@@ -604,5 +619,4 @@ def get_case_id() -> str:
604
619
605
620
def sanitize_filename (name : str ) -> str :
606
621
"""Replace unsafe characters with underscores"""
607
- import re
608
622
return re .sub (r"[^A-Za-z0-9_.-]" , "_" , name )
0 commit comments