This repository has been archived by the owner on Apr 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
makefile
188 lines (153 loc) · 6.75 KB
/
makefile
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
GOTOOLS = github.com/golangci/golangci-lint/cmd/golangci-lint
PACKAGES=$(shell go list ./...)
INCLUDE = -I=. -I=${GOPATH}/src -I=${GOPATH}/src/github.com/gogo/protobuf/protobuf
# Setup
# See: LevelDB: https://github.com/jmhodges/levigo/blob/master/README.md
# See: RocksDB: https://github.com/line/gorocksdb/blob/main/README.md
CLEVELDB_DIR=$(shell pwd)/leveldb
ROCKSDB_DIR=$(shell pwd)/rocksdb
CGO_CFLAGS=-I$(CLEVELDB_DIR)/include -I$(ROCKSDB_DIR)/include
CGO_LDFLAGS=-L$(CLEVELDB_DIR) -L$(ROCKSDB_DIR) -lleveldb -lrocksdb -lm -lstdc++ $(shell awk '/PLATFORM_LDFLAGS/ {sub("PLATFORM_LDFLAGS=", ""); print}' < $(ROCKSDB_DIR)/make_config.mk)
DOCKER_NAME=tm-db-testing
DOCKER_IMAGE=line/$(DOCKER_NAME)
export GO111MODULE = on
all: lint test
### go tests
## By default this will only test memdb & goleveldb
test:
@echo "--> Running go test"
@go test $(PACKAGES) -v
test-cleveldb: build-cleveldb
@echo "--> Running go test"
@CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" \
go test $(PACKAGES) -tags cleveldb -v
test-rocksdb: build-rocksdb
@echo "--> Running go test"
@CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" \
go test $(PACKAGES) -tags rocksdb -v
test-boltdb:
@echo "--> Running go test"
@go test $(PACKAGES) -tags boltdb -v
test-badgerdb:
@echo "--> Running go test"
@go test $(PACKAGES) -tags badgerdb -v
test-all: build-cleveldb build-rocksdb
@echo "--> Running go test"
@CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" \
go test $(PACKAGES) -tags cleveldb,rocksdb,boltdb,badgerdb -v
test-all-docker:
@echo "--> Running go test"
@docker run --rm -e CGO_LDFLAGS="-lrocksdb" -v $(CURDIR):/workspace --workdir /workspace $(DOCKER_IMAGE) \
go test $(PACKAGES) -tags cleveldb,rocksdb,boltdb,badgerdb -v
.PHONY: test-all-docker
bench:
@go test -bench=. -run=^$ $(PACKAGES)
bench-cleveldb: build-cleveldb
@CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" \
go test -bench=. -run=^$ $(PACKAGES) -tags cleveldb
bench-rocksdb: build-rocksdb
@CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" \
go test -bench=. -run=^$ $(PACKAGES) -tags rocksdb
bench-boltdb:
@go test -bench=. -run=^$ $(PACKAGES) -tags boltdb
bench-badgerdb:
@go test -bench=. -run=^$ $(PACKAGES) -tags badgerdb
bench-all: build-cleveldb build-rocksdb
@CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" \
go test -bench=. -run=^$ $(PACKAGES) -timeout 20m -tags cleveldb,rocksdb,boltdb,badgerdb
bench-all-docker:
@docker run --rm -e CGO_LDFLAGS="-lrocksdb" -v $(CURDIR):/workspace --workdir /workspace $(DOCKER_IMAGE) \
go test -bench=. -run=^$ $(PACKAGES) -timeout 20m -tags cleveldb,rocksdb,boltdb,badgerdb
.PHONY: bench-all-docker
bench-rw-all: build-cleveldb build-rocksdb
@CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" \
go test -bench=DBRandomReadsWrites -run=^$ github.com/line/tm-db/v2 -benchtime 10s -count 5 -timeout 20m \
-tags cleveldb,rocksdb,boltdb,badgerdb
bench-parallel-rw-all: build-cleveldb build-rocksdb
@CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" \
go test -bench=DBParallelRandomReadsWrites -run=^$ github.com/line/tm-db/v2 -benchtime 10s -count 5 -timeout 20m \
-tags cleveldb,rocksdb,boltdb,badgerdb
bench-scan1m-all: build-cleveldb build-rocksdb
@CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" \
go test -bench=DBRangeScans1M -run=^$ github.com/line/tm-db/v2 -benchtime 1s -count 1 \
-tags cleveldb,rocksdb,boltdb,badgerdb
bench-scan10m-all: build-cleveldb build-rocksdb
@CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" \
go test -bench=DBRangeScans10M -run=^$ github.com/line/tm-db/v2 -benchtime 1s -count 1 -timeout 20m \
-tags cleveldb,rocksdb,boltdb,badgerdb
lint:
@echo "--> Running linter"
@golangci-lint run
@go mod verify
.PHONY: lint
lint-all: build-cleveldb build-rocksdb
@echo "--> Running linter"
@CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" \
golangci-lint run --build-tags "cleveldb,rocksdb,boltdb,badgerdb"
@go mod verify
.PHONY: lint-all
lint-all-docker:
@echo "--> Running go lint"
@docker run --rm -e CGO_LDFLAGS="-lrocksdb" -v $(CURDIR):/workspace --workdir /workspace $(DOCKER_IMAGE) \
golangci-lint run --build-tags "cleveldb,rocksdb,boltdb,badgerdb"
.PHONY: test-all-docker
format:
find . -name '*.go' -type f -not -path "*.git*" -not -name '*.pb.go' -not -name '*pb_test.go' | xargs gofmt -w -s
find . -name '*.go' -type f -not -path "*.git*" -not -name '*.pb.go' -not -name '*pb_test.go' | xargs goimports -w
.PHONY: format
tools:
go get -v $(GOTOOLS)
build-cleveldb:
@if [ ! -e $(CLEVELDB_DIR) ]; then \
sh ./contrib/get_cleveldb.sh; \
fi
@if [ ! -e $(CLEVELDB_DIR)/libcleveldb.a ]; then \
cd $(CLEVELDB_DIR) && make; \
fi
.PHONY: build-cleveldb
build-rocksdb:
@if [ ! -e $(ROCKSDB_DIR) ]; then \
sh ./contrib/get_rocksdb.sh; \
fi
@if [ ! -e $(ROCKSDB_DIR)/librocksdb.a ]; then \
cd $(ROCKSDB_DIR) && make -j4 static_lib; \
fi
.PHONY: build-rocksdb
# generates certificates for TLS testing in remotedb
gen_certs: clean_certs
certstrap init --common-name "tendermint.com" --passphrase ""
certstrap request-cert --common-name "remotedb" -ip "127.0.0.1" --passphrase ""
certstrap sign "remotedb" --CA "tendermint.com" --passphrase ""
mv out/remotedb.crt remotedb/test.crt
mv out/remotedb.key remotedb/test.key
rm -rf out
clean_certs:
rm -f db/remotedb/test.crt
rm -f db/remotedb/test.key
%.pb.go: %.proto
## If you get the following error,
## "error while loading shared libraries: libprotobuf.so.14: cannot open shared object file: No such file or directory"
## See https://stackoverflow.com/a/25518702
## Note the $< here is substituted for the %.proto
## Note the $@ here is substituted for the %.pb.go
protoc $(INCLUDE) $< --gogo_out=Mgoogle/protobuf/timestamp.proto=github.com/golang/protobuf/ptypes/timestamp,plugins=grpc:.
protoc_remotedb: remotedb/proto/defs.pb.go
build-local-docker:
## If you met the compile error, it might be the shortage of memory on docker with your machine
## Please check your Docker Desktop and its settings of resources
## for mac: https://docs.docker.com/desktop/mac/#resources
## for windows: https://docs.docker.com/desktop/windows/#resources
@docker build --rm --progress plain --tag="$(DOCKER_IMAGE)" -f ./tools/Dockerfile .
.PHONY: build-local-docker
bash-local-docker:
## If you want to `golangci-lint` in Docker,
## should install `golangci-lint` after Docker container start with bash and
## should be the same version of lint.yml.
## See: .github/lint.yml
##
## example: golangci-lint
##
## curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.42.1
## golangci-lint run --build-tags "cleveldb,rocksdb,boltdb,badgerdb"
@docker run --rm -it -e CGO_LDFLAGS="-lrocksdb" -v $(CURDIR):/workspace --workdir /workspace $(DOCKER_IMAGE) bash
.PHONY: bash-local-docker