()
| 238 | |
| 239 | |
| 240 | def main(): |
| 241 | parser = argparse.ArgumentParser(description="Build the per-test coverage map.") |
| 242 | parser.add_argument("--runner", required=True, help="instrumented test runner") |
| 243 | parser.add_argument("--out", required=True, help="output directory") |
| 244 | parser.add_argument("--suite", action="append", default=[], help="suite to run (repeatable)") |
| 245 | parser.add_argument("--llvm-bin", default=os.environ.get("COV_LLVM_BIN", ""), |
| 246 | help="directory holding llvm-profdata and llvm-cov of the compiler that " |
| 247 | "built the runner") |
| 248 | parser.add_argument("--root", default="", |
| 249 | help="repository root the source files are named relative to " |
| 250 | "(default: the repository this script is in)") |
| 251 | parser.add_argument("--keep-raw", action="store_true", help="keep the raw profiles") |
| 252 | parser.add_argument("--timeout", type=int, default=3600, help="seconds per suite") |
| 253 | add_v2_arguments(parser) |
| 254 | args = parser.parse_args() |
| 255 | if args.format == 2: |
| 256 | from coverage_live_v2 import collect |
| 257 | return collect(args) |
| 258 | |
| 259 | runner = os.path.abspath(args.runner) |
| 260 | if not os.access(runner, os.X_OK): |
| 261 | fail(f"runner is not executable: {runner}") |
| 262 | profdata = os.path.join(args.llvm_bin, "llvm-profdata") if args.llvm_bin else "llvm-profdata" |
| 263 | llvm_cov = os.path.join(args.llvm_bin, "llvm-cov") if args.llvm_bin else "llvm-cov" |
| 264 | for tool in (profdata, llvm_cov): |
| 265 | if not shutil.which(tool): |
| 266 | fail(f"not found: {tool}") |
| 267 | root = args.root or os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
| 268 | |
| 269 | out = os.path.abspath(args.out) |
| 270 | raw = os.path.join(out, "raw") |
| 271 | os.makedirs(raw, exist_ok=True) |
| 272 | |
| 273 | # Listing the suites is also the cheapest run of the runner: the profile it |
| 274 | # leaves is the one llvm-cov needs to print the coverage mapping. |
| 275 | listing_profile = os.path.join(out, "listing.profraw") |
| 276 | listed = subprocess.run([runner, "--list-suites"], capture_output=True, text=True, |
| 277 | env=dict(os.environ, LLVM_PROFILE_FILE=listing_profile)) |
| 278 | if listed.returncode != 0: |
| 279 | fail("the runner could not list its suites") |
| 280 | if not os.path.exists(listing_profile): |
| 281 | fail("the runner wrote no profile: is it the instrumented build (make test-runner-cov)?") |
| 282 | table = source_table(llvm_cov, profdata, runner, listing_profile, root, out) |
| 283 | os.remove(listing_profile) |
| 284 | suites = args.suite or [line.strip() for line in listed.stdout.splitlines() if line.strip()] |
| 285 | if not suites: |
| 286 | fail("no suites to run") |
| 287 | |
| 288 | functions = Functions(table) |
| 289 | test_rows = [] |
| 290 | suite_meta = [] |
| 291 | failed = False |
| 292 | env = dict(os.environ) |
| 293 | # A plain name: a runner built for continuous profiles would otherwise start |
| 294 | # in that mode and ignore every per-test name (tests/test_main.c). |
| 295 | env["LLVM_PROFILE_FILE"] = os.devnull |
| 296 | env["CBM_TEST_COVERAGE_DIR"] = raw |
| 297 | for suite in suites: |
no test coverage detected