diff options
-rw-r--r-- | .gitignore | 15 | ||||
-rw-r--r-- | Makefile | 159 | ||||
-rw-r--r-- | deps.mk | 25 | ||||
-rwxr-xr-x | mkdeps.sh | 29 | ||||
-rw-r--r-- | src/stm.go | 9 | ||||
-rw-r--r-- | tests/main.go | 7 | ||||
-rw-r--r-- | tests/stm.go | 9 |
7 files changed, 253 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..094db69 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +/src/version.go +/*.bin +/src/*.a +/src/*.bin +/src/*cgo* +/tests/*.a +/tests/*.bin +/tests/functional/*/*.a +/tests/functional/*/*.bin +/tests/fuzz/*/*.a +/tests/fuzz/*/*.bin +/tests/benchmarks/*/*.a +/tests/benchmarks/*/*.bin +/tests/benchmarks/*/*.txt +/tests/fuzz/corpus/ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..eb78d0e --- /dev/null +++ b/Makefile @@ -0,0 +1,159 @@ +.POSIX: +DATE = 1970-01-01 +VERSION = 0.1.0 +NAME = stm +NAME_UC = $(NAME) +LANGUAGES = en +## Installation prefix. Defaults to "/usr". +PREFIX = /usr +BINDIR = $(PREFIX)/bin +LIBDIR = $(PREFIX)/lib +GOLIBDIR = $(LIBDIR)/go +INCLUDEDIR = $(PREFIX)/include +SRCDIR = $(PREFIX)/src/$(NAME) +SHAREDIR = $(PREFIX)/share +LOCALEDIR = $(SHAREDIR)/locale +MANDIR = $(SHAREDIR)/man +EXEC = ./ +## Where to store the installation. Empty by default. +DESTDIR = +LDLIBS = --static +GOCFLAGS = -I $(GOLIBDIR) +GOLDFLAGS = -L $(GOLIBDIR) + + + +.SUFFIXES: +.SUFFIXES: .go .a .bin .bin-check + +.go.a: + go tool compile -I $(@D) $(GOCFLAGS) -o $@ -p $(*F) \ + `find $< $$(if [ $(*F) != main ]; then \ + echo src/$(NAME).go src/version.go; fi) | uniq` + +.a.bin: + go tool link -L $(@D) $(GOLDFLAGS) -o $@ --extldflags '$(LDLIBS)' $< + + + +all: +include deps.mk + + +libs.a = $(libs.go:.go=.a) +mains.a = $(mains.go:.go=.a) +mains.bin = $(mains.go:.go=.bin) +functional-tests/lib.a = $(functional-tests/lib.go:.go=.a) +fuzz-targets/lib.a = $(fuzz-targets/lib.go:.go=.a) +benchmarks/lib.a = $(benchmarks/lib.go:.go=.a) + +sources = \ + src/$(NAME).go \ + src/version.go \ + + +derived-assets = \ + src/version.go \ + $(libs.a) \ + $(mains.a) \ + $(mains.bin) \ + +side-assets = \ + tests/fuzz/corpus/ \ + tests/benchmarks/*/main.txt \ + + + +## Default target. Builds all artifacts required for testing +## and installation. +all: $(derived-assets) + + +$(libs.a): Makefile deps.mk +$(libs.a): src/$(NAME).go src/version.go + + +$(fuzz-targets/lib.a): + go tool compile $(GOCFLAGS) -o $@ -p $(NAME) -d=libfuzzer \ + $*.go src/$(NAME).go src/version.go + +src/version.go: Makefile + echo 'package $(NAME); const Version = "$(VERSION)"' > $@ + + + +tests.bin-check = \ + tests/main.bin-check \ + $(functional-tests/main.go:.go=.bin-check) \ + +$(tests.bin-check): + $(EXEC)$*.bin + +check-unit: $(tests.bin-check) + + +integration-tests = \ + +.PRECIOUS: $(integration-tests) +$(integration-tests): $(NAME).bin +$(integration-tests): ALWAYS + sh $@ + +check-integration: $(integration-tests) +check-integration: fuzz + + +## Run all tests. Each test suite is isolated, so that a parallel +## build can run tests at the same time. The required artifacts +## are created if missing. +check: check-unit check-integration + + + +FUZZSEC=1 +fuzz-targets/main.bin-check = $(fuzz-targets/main.go:.go=.bin-check) +$(fuzz-targets/main.bin-check): + $(EXEC)$*.bin --test.fuzztime=$(FUZZSEC)s \ + --test.fuzz='.*' --test.fuzzcachedir=tests/fuzz/corpus + +fuzz: $(fuzz-targets/main.bin-check) + + + +benchmarks/main.bin-check = $(benchmarks/main.go:.go=.bin-check) +$(benchmarks/main.bin-check): + printf '%s\n' '$(EXEC)$*.bin' > $*.txt + LANG=POSIX.UTF-8 time -p $(EXEC)$*.bin 2>> $*.txt + printf '%s\n' '$*.txt' + +bench: $(benchmarks/main.bin-check) + + + +## Remove *all* derived artifacts produced during the build. +## A dedicated test asserts that this is always true. +clean: + rm -rf $(derived-assets) $(side-assets) + + +## Installs into $(DESTDIR)$(PREFIX). Its dependency target +## ensures that all installable artifacts are crafted beforehand. +install: all + mkdir -p \ + '$(DESTDIR)$(GOLIBDIR)' \ + '$(DESTDIR)$(SRCDIR)' \ + + cp src/$(NAME).a '$(DESTDIR)$(GOLIBDIR)' + cp $(sources) '$(DESTDIR)$(SRCDIR)' + +## Uninstalls from $(DESTDIR)$(PREFIX). This is a perfect mirror +## of the "install" target, and removes *all* that was installed. +## A dedicated test asserts that this is always true. +uninstall: + rm -rf \ + '$(DESTDIR)$(GOLIBDIR)'/$(NAME).a \ + '$(DESTDIR)$(SRCDIR)' \ + + + +ALWAYS: @@ -0,0 +1,25 @@ +libs.go = \ + src/stm.go \ + tests/stm.go \ + +mains.go = \ + tests/main.go \ + +functional-tests/lib.go = \ + +functional-tests/main.go = \ + +fuzz-targets/lib.go = \ + +fuzz-targets/main.go = \ + +benchmarks/lib.go = \ + +benchmarks/main.go = \ + +src/stm.a: src/stm.go +tests/main.a: tests/main.go +tests/stm.a: tests/stm.go +tests/main.bin: tests/main.a +tests/main.bin-check: tests/main.bin +tests/main.a: tests/$(NAME).a diff --git a/mkdeps.sh b/mkdeps.sh new file mode 100755 index 0000000..e8da8a4 --- /dev/null +++ b/mkdeps.sh @@ -0,0 +1,29 @@ +#!/bin/sh +set -eu + +export LANG=POSIX.UTF-8 + + +libs() { + find src tests -name '*.go' | grep -v '/main\.go$' | + grep -v '/version\.go$' +} + +mains() { + find src tests -name '*.go' | grep '/main\.go$' +} + +libs | varlist 'libs.go' +mains | varlist 'mains.go' + +find tests/functional/*/*.go -not -name main.go | varlist 'functional-tests/lib.go' +find tests/functional/*/main.go | varlist 'functional-tests/main.go' +find tests/fuzz/*/*.go -not -name main.go | varlist 'fuzz-targets/lib.go' +find tests/fuzz/*/main.go | varlist 'fuzz-targets/main.go' +find tests/benchmarks/*/*.go -not -name main.go | varlist 'benchmarks/lib.go' +find tests/benchmarks/*/main.go | varlist 'benchmarks/main.go' + +{ libs; mains; } | sort | sed 's/^\(.*\)\.go$/\1.a:\t\1.go/' +mains | sort | sed 's/^\(.*\)\.go$/\1.bin:\t\1.a/' +mains | sort | sed 's/^\(.*\)\.go$/\1.bin-check:\t\1.bin/' +mains | sort | sed 's|^\(.*\)/main\.go$|\1/main.a:\t\1/$(NAME).a|' diff --git a/src/stm.go b/src/stm.go new file mode 100644 index 0000000..53b4fe1 --- /dev/null +++ b/src/stm.go @@ -0,0 +1,9 @@ +package stm + +import ( +) + + + +func F() { +} diff --git a/tests/main.go b/tests/main.go new file mode 100644 index 0000000..1ff3662 --- /dev/null +++ b/tests/main.go @@ -0,0 +1,7 @@ +package main + +import "stm" + +func main() { + stm.MainTest() +} diff --git a/tests/stm.go b/tests/stm.go new file mode 100644 index 0000000..a30ac1a --- /dev/null +++ b/tests/stm.go @@ -0,0 +1,9 @@ +package stm + +import ( +) + + + +func MainTest() { +} |