| 227 | return {"native": native, "runner_owned": owned} |
| 228 | |
| 229 | def case(self, mode, source_seed=None): |
| 230 | case = self.root / mode |
| 231 | case.mkdir(mode=0o700) |
| 232 | coverage = case / "coverage" |
| 233 | directory = coverage / SUITE |
| 234 | directory.mkdir(mode=0o700, parents=True) |
| 235 | terminal = directory / "_setup.1.profraw" |
| 236 | result = {"mode": mode, "coverage_root": str(coverage), "controls_passed": False} |
| 237 | self.receipt["cases"].append(result) |
| 238 | if source_seed is not None: |
| 239 | self.seed = terminal |
| 240 | result["seed_source"] = self.common.identity(source_seed) |
| 241 | with source_seed.open("rb") as source, terminal.open("xb") as output: |
| 242 | os.fchmod(output.fileno(), 0o600) |
| 243 | for block in iter(lambda: source.read(1024 * 1024), b""): |
| 244 | output.write(block) |
| 245 | output.flush() |
| 246 | os.fchmod(output.fileno(), 0o400) |
| 247 | self.admit(terminal) |
| 248 | self.seed_identity = self.fingerprint(terminal) |
| 249 | require(self.seed_identity["mode"] == 0o400, "seed did not retain the read-only mode") |
| 250 | require(self.seed_identity["sha256"] == result["seed_source"]["sha256"], |
| 251 | "seed copy differs from genuine successful initial profile") |
| 252 | result["seed_before"] = self.seed_identity |
| 253 | environment = self.environment.copy() |
| 254 | environment["CBM_TEST_COVERAGE_DIR"] = str(coverage) |
| 255 | environment["CBM_TEST_ONLY"] = SUITE + ":" + TEST |
| 256 | result["input_environment"] = {"LLVM_PROFILE_FILE": "/dev/null", |
| 257 | "CBM_TEST_COVERAGE_DIR": str(coverage), |
| 258 | "CBM_TEST_ONLY": SUITE + ":" + TEST, |
| 259 | "CBM_TEST_ONLY_FILE": "absent"} |
| 260 | process = self.run(case, "runner", [self.runner, SUITE], environment) |
| 261 | result["runner"] = process |
| 262 | code = process["returncode"] |
| 263 | result["summary"] = self.body(self.log(case, process, "stdout"), code) |
| 264 | result["errors"] = self.errors(self.log(case, process, "stderr"), terminal, source_seed is not None) |
| 265 | if source_seed is not None: |
| 266 | result["seed_after_quiescence"] = self.fingerprint(terminal) |
| 267 | require(result["seed_after_quiescence"] == self.seed_identity, |
| 268 | "native run replaced/changed seeded terminal artifact; precondition unmet") |
| 269 | result["inventory"] = self.inventory(directory) |
| 270 | result["initial"] = self.count(case, "initial", directory / "_setup.0.profraw", FINAL_FUNCTION) |
| 271 | result["terminal"] = self.count(case, "terminal", terminal, FINAL_FUNCTION) |
| 272 | result["body"] = self.count(case, "body", directory / (TEST + ".parent.profraw"), "test_" + TEST) |
| 273 | require(result["initial"]["count"] == 0 and result["body"]["count"] > 0, |
| 274 | "current initial/body profile controls failed") |
| 275 | require((result["terminal"]["count"] > 0) if source_seed is None |
| 276 | else (result["terminal"]["count"] == 0), "terminal native count precondition failed") |
| 277 | rows = self.reduce(case, directory, code) |
| 278 | result["rows"] = rows |
| 279 | require(all(row["reason"] in ("", "suite did not exit 0") for row in rows.values()), |
| 280 | "actual reduction reports unrelated unreadable/missing-profile evidence") |
| 281 | complete = all(row["status"] == "complete" and row["reason"] == "" for row in rows.values()) |
| 282 | conservative = all(row["status"] == "incomplete" |
| 283 | and "suite did not exit 0" in row["reason"].split("; ") for row in rows.values()) |
| 284 | if source_seed is None: |
| 285 | require(code == 0 and complete, "successful control failed") |
| 286 | result["feature_passed"] = True |