-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
123 lines (104 loc) · 3.67 KB
/
Makefile
File metadata and controls
123 lines (104 loc) · 3.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# roughtime - https://github.com/tannerryan/roughtime
BINARIES = roughtime roughtime-client roughtime-debug roughtime-bench roughtime-stamp
# name:pkg — split on ':' by the fuzz rule
FUZZ_TARGETS = \
FuzzParseEcosystem:./ \
FuzzDecodePublicKey:./ \
FuzzVersionsForScheme:./ \
FuzzParseProof:./ \
FuzzDecode:./protocol/ \
FuzzParsePacketHeader:./protocol/ \
FuzzParseRequest:./protocol/ \
FuzzParseShortVersion:./protocol/ \
FuzzVerifyReply:./protocol/ \
FuzzVerifyReplyAllVersions:./protocol/ \
FuzzPQVerifyReply:./protocol/ \
FuzzCreateReplies:./protocol/ \
FuzzCreateRepliesBatch:./protocol/ \
FuzzCreateRequestWithNonce:./protocol/ \
FuzzNonceOffsetInRequest:./protocol/ \
FuzzDecodeTimestamp:./protocol/ \
FuzzEncode:./protocol/ \
FuzzExtractVersion:./protocol/ \
FuzzSelectVersion:./protocol/ \
FuzzGrease:./protocol/ \
FuzzParseMalfeasanceReport:./protocol/ \
FuzzChainNonce:./protocol/ \
FuzzChainVerify:./protocol/ \
FuzzValidateRequest:./server/ \
FuzzServeOnce:./server/ \
FuzzReadTCPFrame:./server/
FUZZ_TIME ?= 30s
.PHONY: all deps build test test-verbose test-race test-cover test-race-cover \
test-all fuzz lint vet fmt verify coverage-report check clean
# Default: fmt, vet, build, race tests
all: fmt vet build test-race
# Install dev tools
deps:
go install golang.org/x/tools/cmd/goimports@latest
go install honnef.co/go/tools/cmd/staticcheck@latest
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
go install golang.org/x/tools/gopls@latest
go install github.com/gojp/goreportcard/cmd/goreportcard-cli@latest
# Build binaries
build:
go build -o roughtime ./server
go build -o roughtime-client ./client
go build -o roughtime-debug ./debug
go build -o roughtime-bench ./bench
go build -o roughtime-stamp ./stamp
# Unit tests
test:
go test ./...
# Unit tests, verbose
test-verbose:
go test -v ./...
# Unit tests with race detector
test-race:
go test -race ./...
# Unit tests with coverage
test-cover:
go test -cover ./ ./protocol/ ./server/
# Race + coverage profile (CI)
test-race-cover:
go test -race -covermode=atomic -coverprofile=coverage.out ./ ./protocol/ ./server/
# Verify module checksums
verify:
go mod download
go mod verify
# Per-function summary + HTML coverage report
coverage-report: test-race-cover
go tool cover -func=coverage.out > coverage.txt
cat coverage.txt
go tool cover -html=coverage.out -o coverage.html
# All test variants
test-all: test-verbose test-race test-cover
# Run all fuzz targets sequentially. Up to 3 attempts absorb the upstream
# go-fuzz coordinator deadline-race flake; real crashes replay from
# testdata/fuzz.
fuzz:
@for entry in $(FUZZ_TARGETS); do \
name=$${entry%%:*}; pkg=$${entry#*:}; \
echo "=== fuzzing $$name ($$pkg, $(FUZZ_TIME)) ==="; \
for _ in 1 2 3; do \
go test -run='^$$' -fuzz="^$${name}$$" -fuzztime=$(FUZZ_TIME) $$pkg && break; \
done || exit 1; \
done
# gofmt + goimports
fmt:
gofmt -w .
goimports -w .
# go vet
vet:
go vet ./...
# All linters (staticcheck, golangci-lint, gopls, vet)
lint: vet
staticcheck ./...
golangci-lint run ./...
gopls check ./protocol/protocol.go ./protocol/chain.go ./protocol/sigscheme.go ./protocol/transport.go ./server/main.go ./server/listen_linux.go ./server/listen_other.go ./server/listen_tcp.go ./server/listen_unix.go ./debug/main.go ./client/main.go ./bench/main.go ./stamp/main.go ./roughtime.go
# Full check: verify, fmt, vet, lint, build, race+cover, report card
check: verify fmt vet lint build test-race-cover
goreportcard-cli -v
# Remove binaries and coverage artifacts
clean:
rm -f $(BINARIES) coverage.out coverage.txt coverage.html