Skip to content

Commit

Permalink
encapp: add mode to split test according to sources
Browse files Browse the repository at this point in the history
The options "--separate_sources" will run the tests using same sources
separatly, pushing and cleaning data as it progress.
This will enable large testsets for limited DUTs.

Signed-off-by: JohanBlome <[email protected]>
  • Loading branch information
JohanBlome committed Oct 30, 2024
1 parent ba11219 commit 91e670b
Show file tree
Hide file tree
Showing 2 changed files with 143 additions and 36 deletions.
159 changes: 124 additions & 35 deletions scripts/encapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,35 +683,113 @@ def run_codec_tests_file(
if debug > 0:
print("Remove other pbtxt files")
files_to_push = {fl for fl in files_to_push if not fl.endswith(".pbtxt")}
# If we are using the id - we need to replace characters that are problematic in
# a filepath (i.e. space)
protobuf_txt_filepath = (
f"{local_workdir}/{valid_path(test.common.id)}_aggr.pbtxt"
)
with open(protobuf_txt_filepath, "w") as f:
f.write(text_format.MessageToString(test_suite))
if debug > 0:
print(f"add {protobuf_txt_filepath}")
files_to_push |= {protobuf_txt_filepath}
if options.dry_run:
# Do nothing here
if debug:
print("Dry run - do nothing")
return None, None

if options.separate_sources:
# create test(s) for each source
# dictionary with source as key
test_collection = {}
for test in test_suite.test:
source = test.input.filepath
tests = []
if source in test_collection:
tests = test_collection[source]
else:
test_collection[source] = tests
tests.append(test)

counter = 0
# Clear target and run test, collect result and iterate
encapp_tool.adb_cmds.remove_files_using_regex(
serial, "encapp_.*", options.device_workdir, options.debug
)
encapp_tool.adb_cmds.remove_files_using_regex(
serial, ".*pbtxt$", options.device_workdir, options.debug
)
encapp_tool.adb_cmds.remove_files_using_regex(
serial, ".*[yuv|raw]$", options.device_workdir, options.debug
)
success = True
result_files = []
for testsource in test_collection:
files = []
# find file
basename = os.path.basename(testsource)
for file in files_to_push:
if basename in file:
files.append(file)
break

test_suite = tests_definitions.TestSuite()
for test in test_collection[testsource]:
# Add tests to the test suite
test_suite.test.append(test)
counter += 1
protobuf_txt_filepath = (
f"{local_workdir}/{valid_path(test.common.id)}_{counter}.pbtxt"
)
with open(protobuf_txt_filepath, "w") as f:
f.write(text_format.MessageToString(test_suite))
if debug > 0:
print(f"add {protobuf_txt_filepath}")
files.append(protobuf_txt_filepath)

results = run_codec_tests(
test_suite,
files,
model,
serial,
options.mediastore,
local_workdir,
options.device_workdir,
options.ignore_results,
options.fast_copy,
options.split,
debug,
)

# Remove test files
for file in files:
basename = os.path.basename(file)
encapp_tool.adb_cmds.remove_file(
serial, f"{options.device_workdir}/{basename}", options.debug
)

if not results[0]:
success = False
result_files += results[1]

return success, result_files

else:
return run_codec_tests(
test_suite,
files_to_push,
model,
serial,
options.mediastore,
local_workdir,
options.device_workdir,
options.ignore_results,
options.fast_copy,
options.split,
debug,
# If we are using the id - we need to replace characters that are problematic in
# a filepath (i.e. space)
protobuf_txt_filepath = (
f"{local_workdir}/{valid_path(test.common.id)}_aggr.pbtxt"
)
with open(protobuf_txt_filepath, "w") as f:
f.write(text_format.MessageToString(test_suite))
if debug > 0:
print(f"add {protobuf_txt_filepath}")
files_to_push |= {protobuf_txt_filepath}
if options.dry_run:
# Do nothing here
if debug:
print("Dry run - do nothing")
return None, None
else:
return run_codec_tests(
test_suite,
files_to_push,
model,
serial,
options.mediastore,
local_workdir,
options.device_workdir,
options.ignore_results,
options.fast_copy,
options.split,
debug,
)
else:
print(
f"Apparently something is not quite right, check the test definition: {test_suite=}"
Expand Down Expand Up @@ -966,8 +1044,10 @@ def update_media(test, options):
or out_pix_fmt == PIX_FMT_TYPES_VALUES["rgba"]
)
and test.configure.surface
and not encapp_tool.ffutils.video_is_y4m(test.input.filepath)
or test.input.device_decode
and not (
encapp_tool.ffutils.video_is_y4m(test.input.filepath)
or test.input.device_decode
)
):
if options.debug > 0:
print("Skip raw transcoding.")
Expand Down Expand Up @@ -1841,6 +1921,14 @@ def __call__(self, parser, options, values, option_string=None):
default=False,
help="Run serial test individually",
)
parser.add_argument(
"--separate_sources",
action="store_true",
dest="separate_sources",
default=False,
help="Run each source separatly clearing space inbetween",
)

parser.add_argument(
"--mediastore",
type=str,
Expand Down Expand Up @@ -2084,12 +2172,13 @@ def process_input_path(input_filepath, replace, test_input, debug=0):
)

else:
encapp_tool.ffutils.ffmpeg_convert_to_raw(
input_filepath,
output_filepath,
replace,
debug,
)
if not os.path.exists(output_filepath):
encapp_tool.ffutils.ffmpeg_convert_to_raw(
input_filepath,
output_filepath,
replace,
debug,
)
# replace input and other derived values
return {
"filepath": output_filepath,
Expand Down
20 changes: 19 additions & 1 deletion scripts/encapp_tool/adb_cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,25 @@ def get_device_info(
return model, serial


def remove_file(serial: str, file: str, debug: int) -> None:
"""Remove files from a device specific file (path).
Args:
serial (str): device serial no.
location (str): Path/directory to analyze and remove files from
debug (int): Debug level
"""
if USE_IDB:
# remove the output
print(f"Removing {counter}/{len(output_files)}", end="\r")
cmd = f"idb file rm {location}/{file} --udid {serial} --bundle-id {IDB_BUNDLE_ID}"
run_cmd(cmd, debug)
else:
# remove the output
adb_cmd = f"adb -s {serial} shell rm {file}"
run_cmd(adb_cmd, debug)


def remove_files_using_regex(
serial: str, regex_str: str, location: str, debug: int
) -> None:
Expand Down Expand Up @@ -659,7 +678,6 @@ def push_file_to_device_android(
def pull_files_from_device(
serial: str, regex_str: str, location: str, debug: int
) -> None:

if USE_IDB:
cmd = f"idb file ls {location} --udid {serial} --bundle-id {IDB_BUNDLE_ID}"
_, stdout, _ = run_cmd(cmd, debug)
Expand Down

0 comments on commit 91e670b

Please sign in to comment.