Skip to content

Commit

Permalink
Renamed coverage.py -> cov.py
Browse files Browse the repository at this point in the history
  • Loading branch information
geky committed Nov 15, 2022
1 parent df283ae commit 29cbafe
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 49 deletions.
36 changes: 18 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,20 @@ override CFLAGS += -I.
override CFLAGS += -std=c99 -Wall -pedantic
override CFLAGS += -Wextra -Wshadow -Wjump-misses-init -Wundef
override CFLAGS += -ftrack-macro-expansion=0
ifdef YES_COVERAGE
ifdef YES_COV
override CFLAGS += --coverage
endif
ifdef YES_PERF
override CFLAGS += -fno-omit-frame-pointer
endif

ifdef VERBOSE
override CODEFLAGS += -v
override DATAFLAGS += -v
override STACKFLAGS += -v
override STRUCTFLAGS += -v
override COVERAGEFLAGS += -v
override PERFFLAGS += -v
override CODEFLAGS += -v
override DATAFLAGS += -v
override STACKFLAGS += -v
override STRUCTFLAGS += -v
override COVFLAGS += -v
override PERFFLAGS += -v
endif
ifneq ($(NM),nm)
override CODEFLAGS += --nm-tool="$(NM)"
Expand Down Expand Up @@ -159,14 +159,14 @@ tags:
$(CTAGS) --totals --c-types=+p $(shell find -H -name '*.h') $(SRC)

.PHONY: test-runner build-test
ifndef NO_COVERAGE
ifndef NO_COV
test-runner build-test: override CFLAGS+=--coverage
endif
ifdef YES_PERF
bench-runner build-bench: override CFLAGS+=-fno-omit-frame-pointer
endif
test-runner build-test: $(TEST_RUNNER)
ifndef NO_COVERAGE
ifndef NO_COV
rm -f $(TEST_GCDA)
endif
ifdef YES_PERF
Expand All @@ -182,14 +182,14 @@ test-list: test-runner
./scripts/test.py $(TEST_RUNNER) $(TESTFLAGS) -l

.PHONY: bench-runner build-bench
ifdef YES_COVERAGE
ifdef YES_COV
bench-runner build-bench: override CFLAGS+=--coverage
endif
ifndef NO_PERF
bench-runner build-bench: override CFLAGS+=-fno-omit-frame-pointer
endif
bench-runner build-bench: $(BENCH_RUNNER)
ifdef YES_COVERAGE
ifdef YES_COV
rm -f $(BENCH_GCDA)
endif
ifndef NO_PERF
Expand Down Expand Up @@ -220,12 +220,12 @@ stack: $(CI)
struct: $(OBJ)
./scripts/struct_.py $^ -Ssize $(STRUCTFLAGS)

.PHONY: coverage
coverage: $(GCDA)
$(strip ./scripts/coverage.py \
.PHONY: cov
cov: $(GCDA)
$(strip ./scripts/cov.py \
$^ $(patsubst %,-F%,$(SRC)) \
-slines -sbranches \
$(COVERAGEFLAGS))
$(COVFLAGS))

.PHONY: perf
perf: $(BENCH_PERF)
Expand Down Expand Up @@ -269,8 +269,8 @@ $(BUILDDIR)lfs.stack.csv: $(CI)
$(BUILDDIR)lfs.struct.csv: $(OBJ)
./scripts/struct_.py $^ -q $(CODEFLAGS) -o $@

$(BUILDDIR)lfs.coverage.csv: $(GCDA)
./scripts/coverage.py $^ $(patsubst %,-F%,$(SRC)) -q $(COVERAGEFLAGS) -o $@
$(BUILDDIR)lfs.cov.csv: $(GCDA)
./scripts/cov.py $^ $(patsubst %,-F%,$(SRC)) -q $(COVFLAGS) -o $@

$(BUILDDIR)lfs.perf.csv: $(BENCH_PERF)
./scripts/perf.py $^ $(patsubst %,-F%,$(SRC)) -q $(PERFFLAGS) -o $@
Expand Down Expand Up @@ -325,7 +325,7 @@ clean:
$(BUILDDIR)lfs.data.csv \
$(BUILDDIR)lfs.stack.csv \
$(BUILDDIR)lfs.struct.csv \
$(BUILDDIR)lfs.coverage.csv \
$(BUILDDIR)lfs.cov.csv \
$(BUILDDIR)lfs.perf.csv)
rm -f $(OBJ)
rm -f $(DEP)
Expand Down
62 changes: 31 additions & 31 deletions scripts/coverage.py → scripts/cov.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Script to find coverage info after running tests.
#
# Example:
# ./scripts/coverage.py \
# ./scripts/cov.py \
# lfs.t.a.gcda lfs_util.t.a.gcda \
# -Flfs.c -Flfs_util.c -slines
#
Expand Down Expand Up @@ -178,7 +178,7 @@ def __ge__(self, other):
return not self.__lt__(other)

# coverage results
class CoverageResult(co.namedtuple('CoverageResult', [
class CovResult(co.namedtuple('CovResult', [
'file', 'function', 'line',
'calls', 'hits', 'funcs', 'lines', 'branches'])):
_by = ['file', 'function', 'line']
Expand All @@ -194,7 +194,7 @@ def __new__(cls, file='', function='', line=0,
Int(calls), Int(hits), Frac(funcs), Frac(lines), Frac(branches))

def __add__(self, other):
return CoverageResult(self.file, self.function, self.line,
return CovResult(self.file, self.function, self.line,
max(self.calls, other.calls),
max(self.hits, other.hits),
self.funcs + other.funcs,
Expand Down Expand Up @@ -269,7 +269,7 @@ def collect(gcda_paths, *,

# go ahead and add functions, later folding will merge this if
# there are other hits on this line
results.append(CoverageResult(
results.append(CovResult(
file_name, func_name, func['start_line'],
func['execution_count'], 0,
Frac(1 if func['execution_count'] > 0 else 0, 1),
Expand All @@ -285,7 +285,7 @@ def collect(gcda_paths, *,

# go ahead and add lines, later folding will merge this if
# there are other hits on this line
results.append(CoverageResult(
results.append(CovResult(
file_name, func_name, line['line_number'],
0, line['count'],
0,
Expand Down Expand Up @@ -612,40 +612,40 @@ def main(gcda_paths, *,
reader = csv.DictReader(f, restval='')
for r in reader:
try:
results.append(CoverageResult(
**{k: r[k] for k in CoverageResult._by
results.append(CovResult(
**{k: r[k] for k in CovResult._by
if k in r and r[k].strip()},
**{k: r['coverage_'+k]
for k in CoverageResult._fields
if 'coverage_'+k in r
and r['coverage_'+k].strip()}))
**{k: r['cov_'+k]
for k in CovResult._fields
if 'cov_'+k in r
and r['cov_'+k].strip()}))
except TypeError:
pass

# fold
results = fold(CoverageResult, results, by=by, defines=defines)
results = fold(CovResult, results, by=by, defines=defines)

# sort, note that python's sort is stable
results.sort()
if sort:
for k, reverse in reversed(sort):
results.sort(key=lambda r: (getattr(r, k),)
if getattr(r, k) is not None else (),
reverse=reverse ^ (not k or k in CoverageResult._fields))
reverse=reverse ^ (not k or k in CovResult._fields))

# write results to CSV
if args.get('output'):
with openio(args['output'], 'w') as f:
writer = csv.DictWriter(f,
(by if by is not None else CoverageResult._by)
+ ['coverage_'+k for k in CoverageResult._fields])
(by if by is not None else CovResult._by)
+ ['cov_'+k for k in CovResult._fields])
writer.writeheader()
for r in results:
writer.writerow(
{k: getattr(r, k)
for k in (by if by is not None else CoverageResult._by)}
| {'coverage_'+k: getattr(r, k)
for k in CoverageResult._fields})
for k in (by if by is not None else CovResult._by)}
| {'cov_'+k: getattr(r, k)
for k in CovResult._fields})

# find previous results?
if args.get('diff'):
Expand All @@ -655,20 +655,20 @@ def main(gcda_paths, *,
reader = csv.DictReader(f, restval='')
for r in reader:
try:
diff_results.append(CoverageResult(
**{k: r[k] for k in CoverageResult._by
diff_results.append(CovResult(
**{k: r[k] for k in CovResult._by
if k in r and r[k].strip()},
**{k: r['coverage_'+k]
for k in CoverageResult._fields
if 'coverage_'+k in r
and r['coverage_'+k].strip()}))
**{k: r['cov_'+k]
for k in CovResult._fields
if 'cov_'+k in r
and r['cov_'+k].strip()}))
except TypeError:
pass
except FileNotFoundError:
pass

# fold
diff_results = fold(CoverageResult, diff_results,
diff_results = fold(CovResult, diff_results,
by=by, defines=defines)

# print table
Expand All @@ -677,10 +677,10 @@ def main(gcda_paths, *,
or args.get('lines')
or args.get('branches')):
# annotate sources
annotate(CoverageResult, results, **args)
annotate(CovResult, results, **args)
else:
# print table
table(CoverageResult, results,
table(CovResult, results,
diff_results if args.get('diff') else None,
by=by if by is not None else ['function'],
fields=fields if fields is not None
Expand All @@ -691,10 +691,10 @@ def main(gcda_paths, *,

# catch lack of coverage
if args.get('error_on_lines') and any(
r.coverage_lines.a < r.coverage_lines.b for r in results):
r.lines.a < r.lines.b for r in results):
sys.exit(2)
elif args.get('error_on_branches') and any(
r.coverage_branches.a < r.coverage_branches.b for r in results):
r.branches.a < r.branches.b for r in results):
sys.exit(3)


Expand Down Expand Up @@ -738,13 +738,13 @@ def main(gcda_paths, *,
parser.add_argument(
'-b', '--by',
action='append',
choices=CoverageResult._by,
choices=CovResult._by,
help="Group by this field.")
parser.add_argument(
'-f', '--field',
dest='fields',
action='append',
choices=CoverageResult._fields,
choices=CovResult._fields,
help="Show this field.")
parser.add_argument(
'-D', '--define',
Expand Down

0 comments on commit 29cbafe

Please sign in to comment.