Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package-Level Makefiles for Testing #587

Merged
merged 1 commit into from
Jul 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
185 changes: 48 additions & 137 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -713,73 +713,6 @@ GO_CLEAN += $$(PKG_A_$1)-clean
endif
endif


################################################################################
## PROJECT TESTS ##
################################################################################
ifneq (,$$(strip $$(TEST_SRCS_$1)))
ifneq (1,$$(TEST_C_$1))

TEST_DEPS_SRCS_$1 := $$(foreach d,$$(TEST_INT_DEPS_$1),$$(SRCS_.$$(subst $$(ROOT_IMPORT_PATH),,$$(d))))

$$(PKG_TD_$1): $$(filter-out %_generated.go,$$(TEST_SRCS_$1))
$$(file >$$@,$$(PKG_TA_$1) $$(PKG_TD_$1): $$(filter-out %_generated.go,$$(TEST_DEPS_SRCS_$1)))

$$(PKG_TD_$1)-clean:
rm -f $$(PKG_TD_$1)
GO_CLEAN += $$(PKG_TD_$1)-clean

-include $$(PKG_TD_$1)

ifneq (,$$(strip $$(PKG_A_$1)))
$$(PKG_TA_$1): $$(PKG_A_$1)
ifeq (true,$$(STALE_$1))
GO_PHONY += $$(PKG_TA_$1)
endif
endif
ifneq (,$$(strip $$(SRCS_$1)))
$$(PKG_TA_$1): $$(SRCS_$1)
endif

$$(PKG_TA_$1): $$(TEST_SRCS_$1) $$(TEST_EXT_DEPS_SRCS_$1) | $$(TEST_DEPS_ARKS_$1)
ifeq (,$$(BUILD_TAGS))
ifeq (1,$(COVERAGE_ENABLED))
go test -cover -coverpkg '$$(TEST_COVERPKG_$1)' -c -o $$@ $1
else
go test -c -o $$@ $1
endif
else
ifeq (1,$(COVERAGE_ENABLED))
go test -cover -coverpkg '$$(TEST_COVERPKG_$1)' -tags "$$(BUILD_TAGS)" -c -o $$@ $1
else
go test -tags "$$(BUILD_TAGS)" -c -o $$@ $1
endif
endif

$$(PKG_TA_$1)-clean:
rm -f $$(PKG_TA_$1)
GO_PHONY += $$(PKG_TA_$1)-clean
GO_CLEAN += $$(PKG_TA_$1)-clean

$$(PKG_TC_$1): $$(PKG_TA_$1)
ifeq (1,$(COVERAGE_ENABLED))
$$(PKG_TA_$1) -test.coverprofile $$@ $$(GO_TEST_FLAGS)
else
$$(PKG_TA_$1) $$(GO_TEST_FLAGS) && touch $$@
endif
TEST_PROFILES += $$(PKG_TC_$1)

$$(PKG_TC_$1)-clean:
rm -f $$(PKG_TC_$1)
GO_PHONY += $$(PKG_TC_$1)-clean

GO_TEST += $$(PKG_TC_$1)
GO_BUILD_TESTS += $$(PKG_TA_$1)
GO_CLEAN += $$(PKG_TC_$1)-clean

endif
endif

endef
$(foreach i,\
$(IMPORT_PATH_INFO),\
Expand Down Expand Up @@ -972,12 +905,59 @@ endef
#$(eval $(call LSS_RULES,$(LSS_WINDOWS),windows,amd64))


################################################################################
## TESTS ##
################################################################################

# test all of the drivers that have a Makefile that match the pattern
# ./drivers/storage/%/tests/Makefile. The % is extracted as the name
# of the driver
TEST_DRIVERS := $(strip $(patsubst ./drivers/storage/%/tests/Makefile,\
%,\
$(wildcard ./drivers/storage/*/tests/Makefile)))

# a list of the framework packages to test
TEST_FRAMEWORK_PKGS := ./api/context \
./api/server/auth \
./api/types \
./api/utils/filters \
./api/utils/schema \
./api/utils

# a list of the driver packages to test
TEST_DRIVER_PKGS := $(foreach d,$(TEST_DRIVERS),./drivers/storage/$d/tests)

# a list of the packages to test
TEST_PKGS := $(TEST_FRAMEWORK_PKGS) $(TEST_DRIVER_PKGS)

# the recipe for building the pkgs' test binaries
$(foreach d,$(TEST_PKGS),build-$d-test):
$(MAKE) -C $(patsubst build-%-test,%,$@) build

# the recipe for executing the pkgs' test binaries
$(foreach d,$(TEST_PKGS),$d-test): %-test: build-./%-test
$(MAKE) -C $(patsubst %-test,%,$@) test

# the recipe for cleaning the pkgs' test output
$(foreach d,$(TEST_PKGS),clean-$d-test):
$(MAKE) -C $(patsubst clean-%-test,%,$@) clean

# builds all the tests
build-tests: $(foreach p,$(TEST_PKGS),build-$p-test)

# executes the framework test binaries and the vfs test binary
test: $(addsuffix -test,$(TEST_FRAMEWORK_PKGS))
$(MAKE) -C ./drivers/storage/vfs/tests test

clean-tests: $(foreach p,$(TEST_PKGS),clean-$p-test)

################################################################################
## COVERAGE ##
################################################################################
COVERAGE := coverage.out
GO_COVERAGE := $(COVERAGE)
$(COVERAGE): $(TEST_PROFILES)
$(COVERAGE): $(foreach p,$(TEST_FRAMEWORK_PKGS),$p/$(notdir $p).test.out) \
./drivers/storage/vfs/tests/vfs.test.out
printf "mode: set\n" > $@
$(foreach f,$?,grep -v "mode: set" $(f) >> $@ &&) true

Expand Down Expand Up @@ -1035,75 +1015,6 @@ ifeq ($(GOOS)_$(GOARCH),$(GOHOSTOS)_$(GOHOSTARCH))
endif
$(MAKE) build-lss

build-tests:$(filter-out ./drivers/storage/%,$(GO_BUILD_TESTS)) \
$(filter ./drivers/storage/vfs/%,$(GO_BUILD_TESTS))

test: build-tests
$(MAKE) -j $(filter-out ./drivers/storage/%,$(GO_TEST))
DRIVERS=vfs $(MAKE) $(filter ./drivers/storage/vfs/%,$(GO_TEST))

test-debug:
LIBSTORAGE_DEBUG=true $(MAKE) test

test-azureud:
DRIVERS=azureud $(MAKE) deps
DRIVERS=azureud $(MAKE) ./drivers/storage/azureud/tests/azureud.test

test-azureud-clean:
DRIVERS=azureud $(MAKE) clean

test-dobs:
DRIVERS=dobs $(MAKE) deps
DRIVERS=dobs $(MAKE) ./drivers/storage/dobs/tests/dobs.test

test-dobs-clean:
DRIVERS=dobs $(MAKE) clean

test-ebs:
DRIVERS=ebs $(MAKE) deps
DRIVERS=ebs $(MAKE) ./drivers/storage/ebs/tests/ebs.test

test-ebs-clean:
DRIVERS=ebs $(MAKE) clean

test-efs:
DRIVERS=efs $(MAKE) deps
DRIVERS=efs $(MAKE) ./drivers/storage/efs/tests/efs.test

test-efs-clean:
DRIVERS=efs $(MAKE) clean

test-fittedcloud:
DRIVERS=fittedcloud $(MAKE) deps
DRIVERS=fittedcloud $(MAKE) ./drivers/storage/fittedcloud/tests/fittedcloud.test

test-fittedcloud-clean:
DRIVERS=fittedcloud $(MAKE) clean

test-gcepd:
DRIVERS=gcepd $(MAKE) deps
DRIVERS=gcepd $(MAKE) ./drivers/storage/gcepd/tests/gcepd.test

test-gcepd-clean:
DRIVERS=gcepd $(MAKE) clean

test-rbd:
DRIVERS=rbd $(MAKE) deps
DRIVERS=rbd $(MAKE) ./drivers/storage/rbd/tests/rbd.test

test-rbd-clean:
DRIVERS=rbd $(MAKE) clean

test-vfs:
DRIVERS=vfs $(MAKE) ./drivers/storage/vfs/tests/vfs.test

test-cinder:
DRIVERS=cinder $(MAKE) deps
DRIVERS=cinder $(MAKE) ./drivers/storage/cinder/tests/cinder.test

test-cinder-clean:
DRIVERS=cinder $(MAKE) clean

clean: $(GO_CLEAN)

clobber: clean $(GO_CLOBBER)
Expand Down
1 change: 1 addition & 0 deletions api/context/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../test-framework-pkg.mk
1 change: 1 addition & 0 deletions api/server/auth/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../../test-framework-pkg.mk
1 change: 1 addition & 0 deletions api/types/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../test-framework-pkg.mk
1 change: 1 addition & 0 deletions api/utils/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../test-framework-pkg.mk
1 change: 1 addition & 0 deletions api/utils/filters/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../../test-framework-pkg.mk
1 change: 1 addition & 0 deletions api/utils/schema/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../../test-framework-pkg.mk
1 change: 1 addition & 0 deletions drivers/storage/azureud/tests/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../../../test-driver-pkg.mk
2 changes: 0 additions & 2 deletions drivers/storage/azureud/tests/coverage.mk

This file was deleted.

1 change: 1 addition & 0 deletions drivers/storage/cinder/tests/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../../../test-driver-pkg.mk
2 changes: 0 additions & 2 deletions drivers/storage/cinder/tests/coverage.mk

This file was deleted.

1 change: 1 addition & 0 deletions drivers/storage/dobs/tests/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../../../test-driver-pkg.mk
2 changes: 0 additions & 2 deletions drivers/storage/dobs/tests/coverage.mk

This file was deleted.

1 change: 1 addition & 0 deletions drivers/storage/ebs/tests/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../../../test-driver-pkg.mk
2 changes: 0 additions & 2 deletions drivers/storage/ebs/tests/coverage.mk

This file was deleted.

1 change: 1 addition & 0 deletions drivers/storage/efs/tests/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../../../test-driver-pkg.mk
2 changes: 0 additions & 2 deletions drivers/storage/efs/tests/coverage.mk

This file was deleted.

1 change: 1 addition & 0 deletions drivers/storage/fittedcloud/tests/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../../../test-driver-pkg.mk
2 changes: 0 additions & 2 deletions drivers/storage/fittedcloud/tests/coverage.mk

This file was deleted.

1 change: 1 addition & 0 deletions drivers/storage/gcepd/tests/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../../../test-driver-pkg.mk
2 changes: 0 additions & 2 deletions drivers/storage/gcepd/tests/coverage.mk

This file was deleted.

1 change: 1 addition & 0 deletions drivers/storage/isilon/tests/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../../../test-driver-pkg.mk
2 changes: 0 additions & 2 deletions drivers/storage/isilon/tests/coverage.mk

This file was deleted.

2 changes: 0 additions & 2 deletions drivers/storage/mock/tests/coverage.mk

This file was deleted.

1 change: 1 addition & 0 deletions drivers/storage/rbd/tests/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../../../test-driver-pkg.mk
2 changes: 0 additions & 2 deletions drivers/storage/rbd/tests/coverage.mk

This file was deleted.

1 change: 1 addition & 0 deletions drivers/storage/s3fs/tests/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../../../test-driver-pkg.mk
2 changes: 0 additions & 2 deletions drivers/storage/s3fs/tests/coverage.mk

This file was deleted.

1 change: 1 addition & 0 deletions drivers/storage/scaleio/tests/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../../../test-driver-pkg.mk
2 changes: 0 additions & 2 deletions drivers/storage/scaleio/tests/coverage.mk

This file was deleted.

1 change: 1 addition & 0 deletions drivers/storage/vbox/tests/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../../../test-driver-pkg.mk
2 changes: 0 additions & 2 deletions drivers/storage/vbox/tests/coverage.mk

This file was deleted.

1 change: 1 addition & 0 deletions drivers/storage/vfs/tests/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../../../test-driver-pkg.mk
2 changes: 0 additions & 2 deletions drivers/storage/vfs/tests/coverage.mk

This file was deleted.

37 changes: 37 additions & 0 deletions test-driver-pkg.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# this Makefile can be reused by driver packages for testing

SHELL := $(shell env which bash)

# the name of the driver is grok'd from the basename
# of the parent directory
DRIVER := $(shell basename $$(dirname $$(pwd)))

# a list of this package's Go sources, Go test sources, Go Xtest sources
# (test sources in this directory but belonging to a different package)
#, and Go sources for packages on which this package depends
SRCS := $(shell \
go list -tags $(DRIVER) -f \
'{{join .GoFiles "\n"}}{{"\n"}}{{join .TestGoFiles "\n"}}{{"\n"}}{{join .XTestGoFiles "\n"}}' \
&& \
go list -tags $(DRIVER) -f \
'{{with $$p := .}}{{if not $$p.Standard}}{{range $$f := $$p.GoFiles}}{{printf "%s/%s\n" $$p.Dir $$f }}{{end}}{{end}}{{end}}' \
$$(go list -tags $(DRIVER) -f '{{if not .Standard}}{{join .Deps "\n"}}{{end}}' \
. \
$$(go list -tags $(DRIVER) -f '{{join .TestImports "\n"}}{{"\n"}}{{join .XTestImports "\n"}}') | sort -u))

# the test binary
$(DRIVER).test: $(SRCS)
go test -tags $(patsubst %.test,%,$@) -cover -c -o $@ .

# the coverage file
$(DRIVER).test.out: $(DRIVER).test
./$< -test.coverprofile $@

build: $(DRIVER).test

test: $(DRIVER).test.out

clean:
rm -f $(DRIVER).test $(DRIVER).test.out

.PHONY: clean
36 changes: 36 additions & 0 deletions test-framework-pkg.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# this Makefile can be reused by framework packages for testing

SHELL := $(shell env which bash)

# the name of the directory that contains this Makefile
PKG := $(shell basename $$(pwd))

# a list of this package's Go sources, Go test sources, Go Xtest sources
# (test sources in this directory but belonging to a different package)
#, and Go sources for packages on which this package depends
SRCS := $(shell \
go list -f \
'{{join .GoFiles "\n"}}{{"\n"}}{{join .TestGoFiles "\n"}}{{"\n"}}{{join .XTestGoFiles "\n"}}' \
&& \
go list -f \
'{{with $$p := .}}{{if not $$p.Standard}}{{range $$f := $$p.GoFiles}}{{printf "%s/%s\n" $$p.Dir $$f }}{{end}}{{end}}{{end}}' \
$$(go list -f '{{if not .Standard}}{{join .Deps "\n"}}{{end}}' \
. \
$$(go list -f '{{join .TestImports "\n"}}{{"\n"}}{{join .XTestImports "\n"}}') | sort -u))

# the test binary
$(PKG).test: $(SRCS)
go test -cover -c -o $@ .

# the coverage file
$(PKG).test.out: $(PKG).test
./$< -test.coverprofile $@

build: $(PKG).test

test: $(PKG).test.out

clean:
rm -f $(PKG).test $(PKG).test.out

.PHONY: clean