@@ -27,9 +27,11 @@ GIT_COMMIT = $(shell git rev-parse HEAD)
2727BUILD_DATE = $(shell date -u +"% Y-% m-% dT% H:% M:% SZ")
2828GIT_BRANCH ?= $(shell git branch --show-current)
2929
30+ TEST_IMAGE ?= gaudi-dra-driver-test-image:latest
31+
3032EXT_LDFLAGS = -static
3133LDFLAGS = \
32- -s -w -extldflags $( EXT_LDFLAGS ) \
34+ -s -w \
3335 -X ${PKG}/pkg/version.gitCommit=${GIT_COMMIT} \
3436 -X ${PKG}/pkg/version.buildDate=${BUILD_DATE}
3537
@@ -69,13 +71,16 @@ include $(CURDIR)/qat.mk
6971build : gpu gaudi qat bin/intel-cdi-specs-generator bin/device-faker
7072
7173
74+
7275bin/intel-cdi-specs-generator : cmd/cdi-specs-generator/* .go $(GPU_COMMON_SRC )
7376 CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} \
74- go build -a -ldflags " ${LDFLAGS} " -mod vendor -o $@ ./cmd/cdi-specs-generator
77+ go build -a -ldflags " ${LDFLAGS} -extldflags $( EXT_LDFLAGS) " \
78+ -mod vendor -o $@ ./cmd/cdi-specs-generator
7579
7680bin/device-faker : cmd/device-faker/* .go
7781 CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} \
78- go build -a -ldflags " ${LDFLAGS} " -mod vendor -o $@ ./cmd/device-faker
82+ go build -a -ldflags " ${LDFLAGS} -extldflags ${EXT_LDFLAGS} " \
83+ -mod vendor -o $@ ./cmd/device-faker
7984
8085
8186.PHONY : branch-build
@@ -109,9 +114,6 @@ cleanall: clean
109114.PHONY : rm-clientsets
110115rm-clientsets : rm-gpu-clientset rm-gaudi-clientset
111116
112- .PHONY : generate
113- generate : generate-gpu-crd generate-gaudi-crd
114-
115117.PHONY : generate-deepcopy
116118generate-deepcopy : generate-gpu-deepcopy generate-gaudi-deepcopy
117119
@@ -159,7 +161,7 @@ licenses: clean-licenses
159161# linting targets for Go and other code
160162.PHONY : lint format cilint vet shellcheck yamllint
161163
162- lint : format cilint vet klogformat shellcheck yamllint
164+ lint : vendor format cilint vet klogformat shellcheck yamllint
163165
164166format :
165167 gofmt -w -s -l ./
@@ -187,18 +189,62 @@ yamllint:
187189 @echo -e " \nyamllint: lint non-templated YAML files:"
188190 git ls-files ' *.yaml' | xargs grep -L ' ^ *{{-' | xargs yamllint -d relaxed --no-warnings
189191
192+ .PHONE : test-image test-image-push
193+ test-image : vendor
194+ @echo " Building container image with fake HLML for Gaudi tests with user $( shell id -u) :$( shell id -g) "
195+ $(DOCKER ) build \
196+ --build-arg UID=$(shell id -u) --build-arg GID=$(shell id -g) \
197+ --platform=" linux/$( ARCH) " \
198+ -t " $( TEST_IMAGE) " -f Dockerfile.gaudi-test .
199+
200+ test-image-push : test-image
201+ $(DOCKER ) push " $( TEST_IMAGE) "
190202
191- .PHONY : test coverage
203+ .PHONY : test html- coverage test-containerized
192204COVERAGE_FILE := coverage.out
205+ # Gaudi tests expect fake HLML library to be present at /usr/lib/habanalabs/libhlml.so
206+ # Dependency comes from gohlml package hardcoded LD_LIBRARY_PATH pointing to it.
193207test :
194- go test -v -coverprofile=$(COVERAGE_FILE ) $(shell go list ./... | grep -v "test/e2e")
208+ ifeq ("$(container ) ","yes")
209+ @echo setting safe directory
210+ go test -buildvcs=false -v -coverprofile=$(COVERAGE_FILE) $(shell go list ./... | grep -v "test/e2e")
211+ else
212+ @echo running tests
213+ go test -v -coverprofile=$(COVERAGE_FILE) $(shell go list ./... | grep -v "test/e2e")
214+ endif
215+
216+ test-containerized :
217+ $(DOCKER ) run \
218+ -it -e container=yes \
219+ --user 1000:1000 \
220+ -v " $( shell pwd) " :/home/ubuntu/src:rw \
221+ " $( TEST_IMAGE) " \
222+ bash -c " cd src && make test"
195223
196- coverage : test
224+ html- coverage : $( COVERAGE_FILE )
197225 go tool cover -html=$(COVERAGE_FILE ) -o coverage.html
198226 @echo coverage file: coverage.html
199- @echo " average coverage (except main.go files)"
200- grep ' <option value=' coverage.html | grep -v ' main.go' | grep -o ' (.*)' | tr -d ' ()%' | awk ' BEGIN{s=0;}{s+=$$1;}END{print s/NR;}'
201227
202- .PHONY : e2e-qat
203- e2e-qat :
204- go test -v ./test/e2e/... --clean-start=true -ginkgo.v -ginkgo.trace -ginkgo.show-node-events
228+ $(COVERAGE_FILE ) : $(shell find cmd pkg -name '* .go')
229+ go test -v -coverprofile=$(COVERAGE_FILE ) $(shell go list ./... | grep -v "test/e2e")
230+
231+ .PHONY : gpu-coverage gaudi-coverage qat-coverage cdispecsgen-coverage excluded-coverage
232+
233+ gpu-coverage : COVERAGE_EXCLUDE="cdi-specs-generator|device-faker|kubelet-gaudi-plugin|kubelet-qat-plugin|qat-showdevice|pkg/qat|pkg/gaudi|pkg/fakesysfs|plugintesthelpers"
234+ gpu-coverage : excluded-coverage
235+ # See: https://www.gnu.org/software/make/manual/html_node/Target_002dspecific.html
236+
237+ gaudi-coverage : COVERAGE_EXCLUDE="cdi-specs-generator|device-faker|kubelet-gpu-plugin|kubelet-qat-plugin|qat-showdevice|pkg/qat|pkg/gpu|pkg/fakesysfs|plugintesthelpers"
238+ gaudi-coverage : excluded-coverage
239+
240+ qat-coverage : COVERAGE_EXCLUDE="cdi-specs-generator|device-faker|kubelet-gpu-plugin|kubelet-gaudi-plugin|pkg/gpu|pkg/gaudi|pkg/fakesysfs|plugintesthelpers"
241+ qat-coverage : excluded-coverage
242+
243+ cdispecsgen-coverage : COVERAGE_EXCLUDE="device-faker|kubelet-gpu-plugin|kubelet-gaudi-plugin|kubelet-qat-plugin|qat-showdevice|pkg/qat|pkg/gpu|pkg/gaudi|pkg/fakesysfs|plugintesthelpers"
244+ cdispecsgen-coverage : excluded-coverage
245+
246+ COVERAGE_EXCLUDE ?= "$^ "
247+ excluded-coverage : $(COVERAGE_FILE )
248+ @grep -v -E $(COVERAGE_EXCLUDE ) $(COVERAGE_FILE ) > $(COVERAGE_FILE ) .tmp && \
249+ go tool cover -func=$(COVERAGE_FILE ) .tmp && \
250+ rm $(COVERAGE_FILE ) .tmp
0 commit comments