| 62 | |
| 63 | |
| 64 | class Proof: |
| 65 | def __init__(self, args, root, receipt): |
| 66 | self.common = guarded_import(args.helper, HELPER_SHA, "terminal_verified_helpers") |
| 67 | require((self.common.DEADLINE, self.common.GRACE, self.common.LOG_CAP) == (60, 5, 1048576), |
| 68 | "reviewed process-helper bounds differ") |
| 69 | self.root, self.receipt = root, receipt |
| 70 | self.work, self.admitted = [], set() |
| 71 | receipt["work"] = self.work |
| 72 | receipt["processes"] = self.common.PROCESS_RECORDS |
| 73 | self.inputs = {} |
| 74 | for name, path, executable in ( |
| 75 | ("runner", args.runner, True), ("profdata", args.llvm_profdata, True), |
| 76 | ("reducer", args.reducer, False), ("helper", args.helper, False), |
| 77 | ("driver", __file__, False)): |
| 78 | self.admit(Path(path).resolve(strict=True)) |
| 79 | self.inputs[name] = self.common.identity(path, executable) |
| 80 | require(self.inputs["helper"]["sha256"] == HELPER_SHA, "helper identity differs") |
| 81 | require(self.inputs["reducer"]["sha256"] == REDUCER_SHA, "reducer identity differs") |
| 82 | receipt["inputs"] = self.inputs |
| 83 | self.runner = self.inputs["runner"]["path"] |
| 84 | self.tool = self.inputs["profdata"]["path"] |
| 85 | self.environment = os.environ.copy() |
| 86 | self.environment["LLVM_PROFILE_FILE"] = "/dev/null" |
| 87 | self.environment.pop("CBM_TEST_COVERAGE_DIR", None) |
| 88 | self.environment.pop("CBM_TEST_ONLY", None) |
| 89 | self.environment.pop("CBM_TEST_ONLY_FILE", None) |
| 90 | self.seed = None |
| 91 | self.seed_identity = None |
| 92 | |
| 93 | def charge(self, kind, detail): |
| 94 | require(len(self.work) < WORK_CAP, "combined finite work cap exhausted") |
| 95 | self.work.append({"kind": kind, "detail": detail}) |
| 96 | |
| 97 | def admit(self, path): |
| 98 | key = str(path) |
| 99 | if key not in self.admitted: |
| 100 | self.charge("input_file", key) |
| 101 | self.admitted.add(key) |
| 102 | |
| 103 | def run(self, directory, label, argv, environment, success=False): |
| 104 | self.charge("process", label) |
| 105 | record = self.common.run_process(directory, label, argv, environment) |
| 106 | record["evidence_directory"] = str(directory) |
| 107 | record["process_receipt"] = str(directory / (label + ".process.json")) |
| 108 | require(not record["failure"] and record["quiescent"] |
| 109 | and type(record["returncode"]) is int and record["returncode"] >= 0, |
| 110 | "process infrastructure failure: " + label) |
| 111 | if success: |
| 112 | require(record["returncode"] == 0, "native tool/control failed: " + label) |
| 113 | return record |
| 114 | |
| 115 | def log(self, directory, record, kind): |
| 116 | return self.common.ANSI.sub("", self.common.read_log(directory, record, kind)) |
| 117 | |
| 118 | def fingerprint(self, path): |
| 119 | value = path.lstat() |
| 120 | require(stat.S_ISREG(value.st_mode) and value.st_nlink == 1 and value.st_uid == os.geteuid(), |
| 121 | "owned seed/profile is not a private regular file") |