Skip to content

Commit fc77790

Browse files
committed
coverage
1 parent ce7c84f commit fc77790

9 files changed

Lines changed: 603 additions & 28 deletions

File tree

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ test-validation: test-zem-diag-ret-trunc-ld32s64
245245
test-validation: test-zem-coverage-smoke
246246
test-validation: test-zem-coverage-blackholes
247247
test-validation: test-zem-rep-scan
248+
test-validation: test-zem-rep-render-from-report
248249
test-validation: test-zem-strip-uncovered-ret
249250
test-validation: test-zem-strip-uncovered-delete
250251

@@ -294,6 +295,9 @@ test-zem-coverage-blackholes: zas zem
294295
test-zem-rep-scan: zem
295296
sh test/zem_rep_scan.sh
296297

298+
test-zem-rep-render-from-report:
299+
sh test/zem_rep_render_from_report.sh
300+
297301
test-zem-caps: zem
298302
sh test/zem_caps.sh
299303

src/zem/DEBLOAT.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,24 @@ The coverage report is line-delimited JSON (JSONL). Record keys:
137137

138138
- `k == "zem_rep_cov"` (optional repetition/coverage enrichment)
139139
- `v`: schema version (currently `1`)
140+
- `module_hash`: from coverage summary (string)
140141
- `total_instr`: from coverage summary
141142
- `covered_instr`: from coverage summary
143+
- `total_labels`: number of labels seen in coverage
142144
- `blackhole_labels`: number of labels with uncovered instructions
143145

146+
- `k == "zem_rep_blackhole"` (optional top blackhole labels; emitted when `--rep-max-report N` is non-zero)
147+
- `v`: schema version (currently `1`)
148+
- `label`: label name (string)
149+
- `uncovered_instr`: uncovered instruction records under this label
150+
- `covered_instr`: covered instruction records under this label
151+
- `total_instr`: total instruction records under this label
152+
- `first_pc`: first IR record index where this label appears
153+
144154
Notes:
145155

146156
- This is a C implementation intended to eventually replace the Python repetition scan for CI/one-binary workflows.
147-
- The detailed “top repeated n-grams” report (`zem_rep_ngram`) is not emitted yet.
157+
- The detailed “top repeated n-grams” report (`k == "zem_rep_ngram"`) is emitted when `--rep-max-report N` is non-zero.
148158

149159
### Requirements
150160

src/zem/main.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ static void print_help(FILE *out) {
106106
" --rep-n N N-gram length (e.g. 8)\n",
107107
" --rep-mode MODE MODE: exact | shape\n",
108108
" --rep-out PATH Write repetition report JSONL to PATH (or '-' for stdout)\n",
109+
" --rep-max-report N Emit up to N zem_rep_ngram records (top repeated n-grams)\n",
109110
" --rep-coverage-jsonl PATH Optional coverage JSONL to enrich bloat score\n",
110111
" --rep-diag Print one-line bloat_diag summary to stdout\n",
111112
" -- Stop option parsing; remaining args become guest argv\n",
@@ -224,6 +225,7 @@ int main(int argc, char **argv) {
224225
const char *rep_mode = "shape";
225226
const char *rep_out = NULL;
226227
const char *rep_cov = NULL;
228+
int rep_max_report = 0;
227229

228230
zem_proc_t proc;
229231
memset(&proc, 0, sizeof(proc));
@@ -321,6 +323,16 @@ int main(int argc, char **argv) {
321323
rep_out = argv[++i];
322324
continue;
323325
}
326+
if (strcmp(argv[i], "--rep-max-report") == 0) {
327+
if (i + 1 >= argc) {
328+
return zem_failf("--rep-max-report requires a number");
329+
}
330+
char *end = NULL;
331+
long v = strtol(argv[++i], &end, 10);
332+
if (!end || end == argv[i]) return zem_failf("bad --rep-max-report value");
333+
rep_max_report = (int)v;
334+
continue;
335+
}
324336
if (strcmp(argv[i], "--rep-coverage-jsonl") == 0) {
325337
if (i + 1 >= argc) {
326338
return zem_failf("--rep-coverage-jsonl requires a path");
@@ -621,7 +633,7 @@ int main(int argc, char **argv) {
621633
return zem_failf("cannot read program IR from stdin while --debug-script - uses stdin");
622634
}
623635
return zem_rep_scan_program(inputs, ninputs, rep_n, rep_mode, rep_cov, rep_out,
624-
rep_diag);
636+
rep_max_report, rep_diag);
625637
}
626638

627639
if (!dbg.debug_events_only) {

0 commit comments

Comments
 (0)