Skip to content

Commit 8d6c0ba

Browse files
committed
feat: support multi file write
1 parent 733b4a6 commit 8d6c0ba

File tree

1 file changed

+56
-43
lines changed

1 file changed

+56
-43
lines changed

Tools/PC/c3-submission-helpers/parse-suspend-30-logs.py

Lines changed: 56 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828

2929
class Input:
30-
filename: str
30+
filenames: list[str]
3131
write_individual_files: bool
3232
write_dir: str
3333
verbose: bool
@@ -121,7 +121,8 @@ def parse_args() -> Input:
121121
),
122122
)
123123
p.add_argument(
124-
"filename",
124+
"filenames",
125+
nargs="+",
125126
help="The path to the suspend logs or the stress test submission .tar",
126127
)
127128
p.add_argument(
@@ -143,7 +144,7 @@ def parse_args() -> Input:
143144
"Where to write the individual logs. "
144145
"If not specified and the -w flag is true, "
145146
"it will create a new local directory called "
146-
"{your original file name}-split"
147+
"{your original file name}-split."
147148
),
148149
)
149150
p.add_argument(
@@ -190,7 +191,7 @@ def parse_args() -> Input:
190191

191192
out = p.parse_args()
192193
# have to wait until out.filename is populated
193-
out.write_dir = out.write_dir or f"{out.filename}-split"
194+
# out.write_dir = out.write_dir or f"{out.filename}-split"
194195
return cast(Input, out)
195196

196197

@@ -262,6 +263,7 @@ def open_log_file(filename: str, num_boots: int, num_suspends: int) -> tuple[
262263
"test_output/com.canonical.certification__stress-tests_"
263264
+ f"suspend_cycles_{suspend_i}_reboot{boot_i}"
264265
)
266+
265267
try:
266268
extracted = tarball.extractfile(individual_file_name)
267269
assert extracted, f"Failed to extract {individual_file_name}"
@@ -418,50 +420,27 @@ def write_suspend_output(
418420
f.writelines(lines)
419421

420422

421-
def main():
422-
args = parse_args()
423-
C.no_color = args.no_color
424-
425-
if args.no_transform:
426-
# idk why tox doesn't like this, this is super common
427-
transform_err_msg: Callable[[str], str] = lambda msg: msg.strip()
428-
else:
429-
transform_err_msg = default_err_msg_transform
430-
431-
print(
432-
C.medium("[ WARN ]"),
433-
"The summary file might not match",
434-
"the number of failures found by this script.",
435-
)
436-
print(
437-
C.medium("[ WARN ]"),
438-
"Please double check since the original test case",
439-
"may consider some failures to be not worth reporting",
440-
)
441-
423+
def print_summary_for_1_submission(
424+
args: Input, filename: str, transform_err_msg: Callable[[str], str]
425+
) -> None:
442426
expected_num_results = args.num_boots * args.num_suspends # noqa: N806
443-
444-
print(
445-
C.low("[ INFO ]"),
446-
f"Expecting ({args.num_boots} boots * {args.num_suspends} suspends) = "
447-
f"{expected_num_results} results",
448-
)
427+
write_dir = f"{args.write_dir}/{filename.replace("/", '-')}-split"
449428

450429
if args.write_individual_files:
451430
print(
452431
C.low("[ INFO ]"),
453-
f'Individual results will be in "{args.write_dir}"',
432+
f'Individual results will be in "{write_dir}"',
454433
)
455-
if not os.path.exists(args.write_dir):
456-
os.mkdir(args.write_dir)
457-
434+
if not os.path.exists(write_dir):
435+
os.makedirs(write_dir, exist_ok=True)
458436
log_files, summary_file, missing_runs = open_log_file(
459-
args.filename, args.num_boots, args.num_suspends
437+
filename, args.num_boots, args.num_suspends
460438
)
461439

462440
if not args.no_summary:
463441
if summary_file:
464-
print(f"\n{C.gray(' Begin Summary File '.center(80, '-'))}\n")
442+
print(C.gray(" Begin Summary File ".center(80, "-")))
443+
print(C.gray(f"In {filename}\n"))
465444

466445
for line in summary_file.readlines():
467446
clean_line = line.strip()
@@ -478,16 +457,16 @@ def main():
478457

479458
# failed_runs[fail_type][boot_i][suspend_i] = set of messages
480459
failed_runs: RunsGroupedByIndex = {
481-
k: defaultdict(lambda: defaultdict(set)) for k in FAIL_TYPES
460+
ft: defaultdict(lambda: defaultdict(set)) for ft in FAIL_TYPES
482461
}
483462
# actual_suspend_counts[boot_i] = num files actually found
484463
actual_suspend_counts: dict[int, int] = {}
485464

486465
for boot_i in log_files:
487466
actual_suspend_counts[boot_i] = len(log_files[boot_i])
488467
for suspend_i in log_files[boot_i]:
489-
log_file_lines = log_files[boot_i][suspend_i].readlines()
490-
log_files[boot_i][suspend_i].close()
468+
with log_files[boot_i][suspend_i] as f:
469+
log_file_lines = f.readlines()
491470

492471
curr_meta: Meta | None = None
493472
for i, line in enumerate(log_file_lines):
@@ -531,7 +510,7 @@ def main():
531510
end="\r",
532511
)
533512
write_suspend_output(
534-
args.write_dir,
513+
write_dir,
535514
boot_i,
536515
suspend_i,
537516
curr_meta,
@@ -546,7 +525,7 @@ def main():
546525
print(
547526
C.ok("[ OK ]"),
548527
f"Found all {expected_num_results}",
549-
"expected log files!",
528+
f"expected log files in {filename}!",
550529
)
551530
if n_failed_runs == 0:
552531
print(
@@ -565,12 +544,46 @@ def main():
565544
for boot_i, suspend_indicies in missing_runs.items():
566545
print(f"- Reboot {boot_i}, suspend {str(suspend_indicies)}")
567546

568-
print(f"\n{C.gray(' Begin Parsed Output '.center(80, '-'))}\n")
547+
print(f"\n{C.gray(' Begin Parsed Output '.center(80, '-'))}")
548+
print(C.gray(f"In {filename}\n"))
569549

570550
print_by_err(
571551
group_by_err(failed_runs), actual_suspend_counts, args.num_suspends
572552
)
573553

574554

555+
def main():
556+
args = parse_args()
557+
C.no_color = args.no_color
558+
559+
expected_num_results = args.num_boots * args.num_suspends # noqa: N806
560+
print(
561+
C.low("[ INFO ]"),
562+
f"Expecting ({args.num_boots} boots * {args.num_suspends} suspends) = "
563+
f"{expected_num_results} results",
564+
)
565+
566+
if args.no_transform:
567+
# idk why tox doesn't like this, this is super common
568+
transform_err_msg: Callable[[str], str] = lambda msg: msg.strip()
569+
else:
570+
transform_err_msg = default_err_msg_transform
571+
572+
print(
573+
C.medium("[ WARN ]"),
574+
"The summary file might not match",
575+
"the number of failures found by this script.",
576+
)
577+
print(
578+
C.medium("[ WARN ]"),
579+
"Please double check since the original test case",
580+
"may consider some failures to be not worth reporting",
581+
)
582+
print()
583+
584+
for filename in args.filenames:
585+
print_summary_for_1_submission(args, filename, transform_err_msg)
586+
587+
575588
if __name__ == "__main__":
576589
main()

0 commit comments

Comments
 (0)