| 1 |
.PHONY: test bench-simple clean update-golang-test fuzz fuzz-json |
| 2 |
|
| 3 |
golang.version ?= 1.21 |
| 4 |
golang.tmp.root := /tmp/golang$(golang.version) |
| 5 |
golang.tmp.json.root := $(golang.tmp.root)/go-go$(golang.version)/src/encoding/json |
| 6 |
golang.test.files := $(wildcard json/golang_*_test.go) |
| 7 |
benchstat := ${GOPATH}/bin/benchstat |
| 8 |
go-fuzz := ${GOPATH}/bin/go-fuzz |
| 9 |
go-fuzz-build := ${GOPATH}/bin/go-fuzz-build |
| 10 |
go-fuzz-corpus := ${GOPATH}/src/github.com/dvyukov/go-fuzz-corpus |
| 11 |
go-fuzz-dep := ${GOPATH}/src/github.com/dvyukov/go-fuzz/go-fuzz-dep |
| 12 |
|
| 13 |
test: test-ascii test-json test-json-bugs test-proto test-iso8601 test-thrift test-purego |
| 14 |
|
| 15 |
test-ascii: |
| 16 |
go test -cover -race ./ascii |
| 17 |
|
| 18 |
test-json: |
| 19 |
go test -cover -race ./json |
| 20 |
|
| 21 |
test-json-bugs: |
| 22 |
go test -race ./json/bugs/... |
| 23 |
|
| 24 |
test-proto: |
| 25 |
go test -cover -race ./proto |
| 26 |
|
| 27 |
test-iso8601: |
| 28 |
go test -cover -race ./iso8601 |
| 29 |
|
| 30 |
test-thrift: |
| 31 |
go test -cover -race ./thrift |
| 32 |
|
| 33 |
test-purego: |
| 34 |
go test -race -tags purego ./... |
| 35 |
|
| 36 |
$(benchstat): |
| 37 |
GO111MODULE=off go get -u golang.org/x/perf/cmd/benchstat |
| 38 |
|
| 39 |
# This compares segmentio/encoding/json to the standard golang encoding/json; |
| 40 |
# for more in-depth benchmarks, see the `benchmarks` directory. |
| 41 |
count ?= 5 |
| 42 |
bench-simple: $(benchstat) |
| 43 |
@go test -v -run '^$$' -bench '(Marshal|Unmarshal)$$/codeResponse' -benchmem -cpu 1 -count $(count) ./json -package encoding/json | tee /tmp/encoding-json.txt |
| 44 |
@go test -v -run '^$$' -bench '(Marshal|Unmarshal)$$/codeResponse' -benchmem -cpu 1 -count $(count) ./json | tee /tmp/segmentio-encoding-json.txt |
| 45 |
benchstat /tmp/encoding-json.txt /tmp/segmentio-encoding-json.txt |
| 46 |
|
| 47 |
bench-master: $(benchstat) |
| 48 |
git stash |
| 49 |
git checkout master |
| 50 |
@go test -v -run '^$$' -bench /codeResponse -benchmem -benchtime 3s -cpu 1 ./json -count 8 | tee /tmp/segmentio-encoding-json-master.txt |
| 51 |
git checkout - |
| 52 |
git stash pop |
| 53 |
@go test -v -run '^$$' -bench /codeResponse -benchmem -benchtime 3s -cpu 1 ./json -count 8 | tee /tmp/segmentio-encoding-json.txt |
| 54 |
benchstat /tmp/segmentio-encoding-json-master.txt /tmp/segmentio-encoding-json.txt |
| 55 |
|
| 56 |
update-golang-test: $(golang.test.files) |
| 57 |
@echo "updated golang tests to $(golang.version)" |
| 58 |
|
| 59 |
json/golang_%_test.go: $(golang.tmp.json.root)/%_test.go $(golang.tmp.json.root) |
| 60 |
@echo "updating $@ with $<" |
| 61 |
cp $< $@ |
| 62 |
sed -i '' -E '/(import)?[ \t]*"internal\/.*".*/d' $@ |
| 63 |
|
| 64 |
$(golang.tmp.json.root): $(golang.tmp.root) |
| 65 |
curl -L "https://github.com/golang/go/archive/go${golang.version}.tar.gz" | tar xz -C "$</" |
| 66 |
|
| 67 |
$(golang.tmp.root): |
| 68 |
mkdir -p "$@" |
| 69 |
|
| 70 |
$(go-fuzz): |
| 71 |
GO111MODULE=off go install github.com/dvyukov/go-fuzz/go-fuzz |
| 72 |
|
| 73 |
$(go-fuzz-build): |
| 74 |
GO111MODULE=off go install github.com/dvyukov/go-fuzz/go-fuzz-build |
| 75 |
|
| 76 |
$(go-fuzz-corpus): |
| 77 |
GO111MODULE=off go get github.com/dvyukov/go-fuzz-corpus |
| 78 |
|
| 79 |
$(go-fuzz-dep): |
| 80 |
GO111MODULE=off go get github.com/dvyukov/go-fuzz/go-fuzz-dep |
| 81 |
|
| 82 |
json/fuzz/corpus: $(go-fuzz-corpus) |
| 83 |
cp -r $(go-fuzz-corpus)/json/corpus json/fuzz/corpus |
| 84 |
|
| 85 |
json/fuzz/json-fuzz.zip: $(go-fuzz-build) $(go-fuzz-corpus) $(go-fuzz-dep) $(wildcard ./json/fuzz/corpus/*) |
| 86 |
cd json/fuzz && GO111MODULE=off go-fuzz-build -o json-fuzz.zip |
| 87 |
|
| 88 |
fuzz: fuzz-json |
| 89 |
|
| 90 |
fuzz-json: $(go-fuzz) $(wildcard json/fuzz/*.go) json/fuzz/json-fuzz.zip |
| 91 |
cd json/fuzz && GO111MODULE=off go-fuzz -bin json-fuzz.zip |
| 92 |
|
| 93 |
clean: |
| 94 |
rm -rf $(golang.tmp.root) json/fuzz/{crashers,corpus,suppressions,json-fuzz.zip} *json.txt |