aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--.travis.yml24
-rw-r--r--Makefile76
-rw-r--r--metadata/metadata.proto1
4 files changed, 87 insertions, 16 deletions
diff --git a/.gitignore b/.gitignore
index 01f4f15..2491d40 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,2 @@
/fscrypt
-fscrypt.*
+fscrypt_image
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..2a186aa
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,24 @@
+language: go
+sudo: required
+go:
+ - 1.8.x
+dist: trusty
+
+addons:
+ apt:
+ sources:
+ - sourceline: 'deb http://en.archive.ubuntu.com/ubuntu/ artful main universe'
+ packages:
+ - libargon2-0-dev
+ - libblkid-dev
+ - libpam0g-dev
+ - e2fsprogs
+ - protobuf-compiler
+ - git # Needed to stop git from getting deleted
+
+install:
+ - make go-tools
+ - make test-setup
+
+script:
+ - make check
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 "<replacement "
+ | ./input_fail.py "Incorrectly formatted C files. Run \"make format\"."
diff --git a/metadata/metadata.proto b/metadata/metadata.proto
index 395cdff..1bec64f 100644
--- a/metadata/metadata.proto
+++ b/metadata/metadata.proto
@@ -19,6 +19,7 @@
* the License.
*/
+// If you modify this file, be sure to run "go generate" on this package.
syntax = "proto3";
package metadata;