Skip to content

Commit 334cfad

Browse files
committed
tests: add download-only to video_test_framework
Add download-only to the three main testing apps
1 parent 8dd1532 commit 334cfad

5 files changed

Lines changed: 95 additions & 3 deletions

File tree

tests/libs/video_test_config_base.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,36 @@ def download_sample_assets(samples, asset_type: str = "test") -> bool:
460460
return False
461461

462462

463+
def load_and_download_samples(sample_class, json_file: str,
464+
test_type: str) -> bool:
465+
"""Load samples from JSON and download their assets.
466+
467+
Args:
468+
sample_class: Sample class with a from_dict() classmethod
469+
json_file: Path to JSON file containing sample definitions
470+
test_type: Type of test ("decode" or "encode")
471+
472+
Returns:
473+
True if download succeeded or no samples found.
474+
"""
475+
samples_data = load_samples_from_json(json_file, test_type=test_type)
476+
if not samples_data:
477+
print(f"No {test_type} samples found")
478+
return True
479+
480+
samples = []
481+
for data in samples_data:
482+
try:
483+
samples.append(sample_class.from_dict(data))
484+
except (KeyError, ValueError, TypeError) as e:
485+
print(f" Warning: failed to load {test_type} sample "
486+
f"{data.get('name', 'unknown')}: {e}")
487+
488+
if not samples:
489+
return True
490+
return download_sample_assets(samples, f"{test_type} test")
491+
492+
463493
def _validate_zip_member(member_name: str, extract_dir: Path) -> Path:
464494
"""
465495
Validate a zip member path to prevent zip slip attacks.

tests/libs/video_test_utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ def add_common_arguments(parser, codec_choices=None):
162162
action="store_true",
163163
help="Show skipped tests in summary output",
164164
)
165+
parser.add_argument(
166+
"--download-only",
167+
action="store_true",
168+
help="Download test resources and exit without running tests",
169+
)
165170
return parser
166171

167172

tests/video_test_framework_codec.py

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
VideoTestStatus,
4040
load_samples_from_json,
4141
download_sample_assets,
42+
load_and_download_samples,
4243
load_skip_list,
4344
is_test_skipped,
4445
SkipFilter,
@@ -49,8 +50,14 @@
4950
)
5051

5152
from tests.libs.video_test_utils import safe_main_wrapper, DEFAULT_TEST_TIMEOUT
52-
from tests.video_test_framework_encode import VulkanVideoEncodeTestFramework
53-
from tests.video_test_framework_decode import VulkanVideoDecodeTestFramework
53+
from tests.video_test_framework_encode import (
54+
VulkanVideoEncodeTestFramework,
55+
EncodeTestSample,
56+
)
57+
from tests.video_test_framework_decode import (
58+
VulkanVideoDecodeTestFramework,
59+
DecodeTestSample,
60+
)
5461

5562

5663
@dataclass
@@ -598,6 +605,10 @@ def create_argument_parser() -> argparse.ArgumentParser:
598605
parser.add_argument(
599606
"--no-auto-download", action="store_true",
600607
help="Skip automatic download of missing/corrupt sample files")
608+
parser.add_argument(
609+
"--download-only", action="store_true",
610+
help="Download all test resources (encode and decode) and exit "
611+
"without running tests")
601612
parser.add_argument(
602613
"--deviceID",
603614
help="Vulkan device ID to use for testing "
@@ -655,6 +666,29 @@ def find_executables(args: argparse.Namespace) -> Tuple[str, str]:
655666
return encoder_path, decoder_path
656667

657668

669+
def download_all_resources(args: argparse.Namespace) -> bool:
670+
"""Download all test resources (encode and decode) without running tests"""
671+
print("=== Downloading All Test Resources ===\n")
672+
673+
decode_json = args.decode_test_suite or "decode_samples.json"
674+
encode_json = args.encode_test_suite or "encode_samples.json"
675+
676+
decode_ok = load_and_download_samples(
677+
DecodeTestSample, decode_json, "decode"
678+
)
679+
encode_ok = load_and_download_samples(
680+
EncodeTestSample, encode_json, "encode"
681+
)
682+
683+
success = decode_ok and encode_ok
684+
if success:
685+
print("\n✓ All resources downloaded successfully")
686+
else:
687+
print("\n✗ Some resources failed to download")
688+
689+
return success
690+
691+
658692
def run_framework_tests(args: argparse.Namespace, encoder_path: str,
659693
decoder_path: str) -> bool:
660694
"""Run the actual test framework"""
@@ -725,6 +759,11 @@ def main() -> int:
725759
list_all_samples(skip_list_path)
726760
return 0
727761

762+
# Handle --download-only option
763+
if args.download_only:
764+
success = download_all_resources(args)
765+
return 0 if success else 1
766+
728767
# Find executable paths
729768
encoder_path, decoder_path = find_executables(args)
730769

tests/video_test_framework_decode.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
VideoTestStatus,
3838
check_sample_resources,
3939
create_error_result,
40+
load_and_download_samples,
4041
load_samples_from_json,
4142
)
4243
from tests.libs.video_test_framework_base import ( # noqa: E402
@@ -341,6 +342,14 @@ def main() -> int:
341342
list_decoder_samples()
342343
return 0
343344

345+
# Handle --download-only option
346+
if args.download_only:
347+
json_file = args.decode_test_suite or "decode_samples.json"
348+
success = load_and_download_samples(
349+
DecodeTestSample, json_file, "decode"
350+
)
351+
return 0 if success else 1
352+
344353
# Find and resolve decoder executable path
345354
args.decoder = PlatformUtils.resolve_executable_path(
346355
args.decoder, args.verbose

tests/video_test_framework_encode.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@
3636
CodecType,
3737
TestResult,
3838
VideoTestStatus,
39+
check_sample_resources,
3940
create_error_result,
41+
load_and_download_samples,
4042
load_samples_from_json,
41-
check_sample_resources,
4243
)
4344
from tests.libs.video_test_framework_base import ( # noqa: E402
4445
VulkanVideoTestFrameworkBase,
@@ -497,6 +498,14 @@ def main() -> int:
497498
list_encoder_samples(test_suite)
498499
return 0
499500

501+
# Handle --download-only option
502+
if args.download_only:
503+
json_file = args.encode_test_suite or "encode_samples.json"
504+
success = load_and_download_samples(
505+
EncodeTestSample, json_file, "encode"
506+
)
507+
return 0 if success else 1
508+
500509
# Find and resolve encoder executable path
501510
args.encoder = PlatformUtils.resolve_executable_path(
502511
args.encoder, args.verbose

0 commit comments

Comments
 (0)