From f898a826ab24e03019323ade6a8785e2bf463a41 Mon Sep 17 00:00:00 2001 From: "Joe Richey joerichey@google.com" Date: Tue, 18 Jul 2017 11:04:50 -0700 Subject: Travis.yml and Makefile now run integration tests. --- Makefile | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 61 insertions(+), 15 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 5adec6e..aa943a9 100644 --- a/Makefile +++ b/Makefile @@ -24,9 +24,24 @@ CMD_PKG = github.com/google/$(NAME)/cmd/$(NAME) SRC_FILES = $(shell find . -type f -name '*.go' -o -name "*.h" -o -name "*.c") GO_FILES = $(shell find . -type f -name '*.go' -not -path "./vendor/*") +PROTO_FILES = $(shell find . -type f -name '*.proto' -not -path "./vendor/*") C_FILES = $(shell find . -type f -name "*.h" -o -name "*.c" -not -path "./vendor/*") GO_PKGS = $(shell go list ./... | grep -v /vendor/) +# IMAGE will be the path to our test ext4 image file. +IMAGE ?= $(NAME)_image + +# MOUNT will be the path to the filesystem where our tests are run. +# +# Running "make test-setup MOUNT=/foo/bar" creates a test filesystem at that +# location. Be sure to also run "make test-teardown MOUNT=/foo/bar". +# Running "make all MOUNT=/foo/bar" (or "make go") will run all tests on that +# filesystem. By default, it is the one created with "make test-setup". +MOUNT ?= /mnt/$(NAME)_mount +# Only run the integration tests if our root exists. +ifneq ("$(wildcard $(MOUNT))","") +export TEST_FILESYSTEM_ROOT = $(MOUNT) +endif # The flags code below lets the caller of the makefile change the build flags # for fscrypt in a familiar manner. # CFLAGS @@ -67,22 +82,25 @@ override GO_FLAGS += --ldflags '$(GO_LINK_FLAGS)' .PHONY: default all default: $(NAME) -all: update go format lint default +all: gen update format lint default test $(NAME): $(SRC_FILES) go build $(GO_FLAGS) -o $(NAME) $(CMD_PKG) .PHONY: clean clean: - rm -rf $(NAME) + rm -rf $(NAME) $(IMAGE) # Make sure go files build and tests pass. -.PHONY: go -go: - @go generate $(GO_FLAGS) $(GO_PKGS) - @go build $(GO_FLAGS) $(GO_PKGS) +.PHONY: test +test: @go test -p 1 $(GO_FLAGS) $(GO_PKGS) +# Make sure the protocol buffers are generated +.PHONY: gen +gen: + protoc --go_out=. $(PROTO_FILES) + # Update the vendored dependencies. .PHONY: update update: @@ -91,6 +109,7 @@ update: @govendor add +external @govendor remove +unused +# Format all the Go and C code .PHONY: format format: @gofmt -l -s -w $(GO_FILES) @@ -103,15 +122,6 @@ lint: @golint $(GO_PKGS) | grep -v "pb.go" | ./input_fail.py @megacheck -unused.exported $(GO_PKGS) -# Check all files -.PHONY: check -check: all - @govendor list +missing +external +unused \ - | ./input_fail.py "Incorrect vendored dependencies. Run \"make update\"" - @git diff - @git status -s \ - | ./input_fail.py "Files have changed unexpectedly. Run \"make all\"" - .PHONY: install install: $(NAME) $(INSTALL) -d $(DESTDIR) @@ -120,3 +130,39 @@ install: $(NAME) .PHONY: uninstall uninstall: rm -rf $(DESTDIR)/$(NAME) + +# Install the go tools used for checking/generating the code +.PHONY: go-tools +go-tools: + go get -u github.com/golang/protobuf/protoc-gen-go + go get -u github.com/golang/lint/golint + go get -u github.com/kardianos/govendor + go get -u honnef.co/go/tools/cmd/megacheck + +##### Setup/Teardown for integration tests (need root permissions) ##### +.PHONY: test-setup test-teardown +test-setup: + dd if=/dev/zero of=$(IMAGE) bs=1M count=20 + mkfs.ext4 -b 4096 -O encrypt $(IMAGE) -F + sudo mkdir -p $(MOUNT) + sudo mount -o rw,loop $(IMAGE) $(MOUNT) + sudo chmod +777 $(MOUNT) + # Add UUID to BLKID cache + sudo blkid $$(df $(MOUNT) --output=source | grep /dev/) + +test-teardown: + sudo umount $(MOUNT) + sudo rmdir $(MOUNT) + rm -f $(IMAGE) + +##### Commands for Travis CI ##### + +.PHONY: check +check: lint default test + @govendor list +missing +external +unused \ + | ./input_fail.py "Incorrect vendored dependencies. Run \"make update\"." + @gofmt -s -d $(GO_FILES) \ + | ./input_fail.py "Incorrectly formatted Go files. Run \"make format\"." + @clang-format -i -style=Google -output-replacements-xml $(C_FILES) \ + | grep " Date: Tue, 18 Jul 2017 21:18:22 -0700 Subject: Makefile: typo --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index aa943a9..e2f0bd9 100644 --- a/Makefile +++ b/Makefile @@ -164,5 +164,5 @@ check: lint default test @gofmt -s -d $(GO_FILES) \ | ./input_fail.py "Incorrectly formatted Go files. Run \"make format\"." @clang-format -i -style=Google -output-replacements-xml $(C_FILES) \ - | grep "