Skip to content

Commit aa6a7e8

Browse files
committed
Better organization, make paths consistent
1 parent 7317c8d commit aa6a7e8

File tree

1 file changed

+36
-10
lines changed

1 file changed

+36
-10
lines changed

scripts/tests/local.py

+36-10
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@ def execute_str(self, path: str):
255255
return f"valgrind {path}"
256256
elif self == BinaryRunner.COVERAGE:
257257
# Expected path is like "out/<target>/<binary>"
258-
rawname = path[: path.rindex("/")] + ".profraw"
259-
return f'LLVM_PROFILE_FILE="{rawname}" {path}'
258+
rawname = os.path.basename(path[: path.rindex("/")] + ".profraw")
259+
return f'LLVM_PROFILE_FILE="out/profiling/{rawname}" {path}'
260260

261261

262262
__RUNNERS__ = {
@@ -552,13 +552,13 @@ def gen_coverage():
552552

553553
trace_files = []
554554
for t in _get_targets(coverage=True):
555-
path = os.path.join("./out", f"{t.target}.profraw")
555+
path = os.path.join("./out", "profiling", f"{t.target}.profraw")
556556

557557
if not os.path.exists(path):
558558
logging.warning("No profile file '%s'. Skipping.", path)
559559
continue
560560

561-
data_path = os.path.join("./out", f"{t.target}.profdata")
561+
data_path = os.path.join("./out", "profiling", f"{t.target}.profdata")
562562
cmd = [
563563
"llvm-profdata",
564564
"merge",
@@ -581,11 +581,34 @@ def gen_coverage():
581581
cmd.append("-ignore-filename-regex")
582582
cmd.append(p)
583583

584-
info_path = os.path.join("./out", f"{t.target}.info")
584+
info_path = os.path.join("./out", "profiling", f"{t.target}.info")
585585
subprocess.run(_with_activate(cmd, output_path=info_path), check=True)
586586
trace_files.append(info_path)
587587
logging.info("Generated %s", info_path)
588588

589+
# !!!!! HACK ALERT !!!!!
590+
#
591+
# The paths for our examples are generally including CHIP as
592+
# examples/<name>/third_party/connectedhomeip/....
593+
# So we will replace every occurence of these to remove the extra indirection into third_party
594+
#
595+
# Generally we will replace every path (Shown as SF:...) with the corresponding item
596+
#
597+
# We assume that the info lines fit in RAM
598+
lines = []
599+
with open(info_path, 'rt') as f:
600+
for line in f.readlines():
601+
if line.startswith("SF:"):
602+
# This is a source file line: "SF:..."
603+
path = line[3:]
604+
lines.append(f"SF:{os.path.realpath(path)}")
605+
lines.append(line)
606+
607+
# re-write it.
608+
with open(info_path, 'wt') as f:
609+
f.write("\n".join(lines))
610+
611+
589612
if not trace_files:
590613
logging.error(
591614
"Could not find any trace files. Did you run tests with coverage enabled?"
@@ -602,13 +625,13 @@ def gen_coverage():
602625
]
603626

604627
cmd.append("--output-file")
605-
cmd.append("out/merged.info")
628+
cmd.append("out/profiling/merged.info")
606629
for e in errors_to_ignore:
607630
cmd.append("--ignore-errors")
608631
cmd.append(e)
609632

610-
if os.path.exists("out/merged.info"):
611-
os.unlink("out/merged.info")
633+
if os.path.exists("out/profiling/merged.info"):
634+
os.unlink("out/profiling/merged.info")
612635

613636
subprocess.run(cmd, check=True)
614637

@@ -620,7 +643,7 @@ def gen_coverage():
620643

621644
cmd.append("--output-directory")
622645
cmd.append("out/coverage")
623-
cmd.append("out/merged.info")
646+
cmd.append("out/profiling/merged.info")
624647

625648
subprocess.run(cmd, check=True)
626649
logging.info("Coverage HTML should be available in out/coverage/index.html")
@@ -673,7 +696,7 @@ def gen_coverage():
673696
"--fail-log-dir",
674697
default=None,
675698
help="Save failure logs into the specified directory instead of logging (as logging can be noisy/slow)",
676-
type=click.Path(exists=True, file_okay=False, dir_okay=True),
699+
type=click.Path(file_okay=False, dir_okay=True),
677700
)
678701
@click.option("--coverage/--no-coverage", default=None)
679702
@click.option(
@@ -749,6 +772,9 @@ def as_runner(path):
749772
if not os.path.exists("out/trace_data"):
750773
os.mkdir("out/trace_data")
751774

775+
if not os.path.exists(fail_log_dir):
776+
os.mkdir(fail_log_dir)
777+
752778
metadata = yaml.full_load(open("src/python_testing/test_metadata.yaml"))
753779
excluded_patterns = set([item["name"] for item in metadata["not_automated"]])
754780

0 commit comments

Comments
 (0)