diff options
-rw-r--r-- | Makefile | 83 | ||||
-rw-r--r-- | deps.mk | 30 | ||||
-rwxr-xr-x | mkdeps.sh | 27 | ||||
-rw-r--r-- | src/untls.go | 4 | ||||
-rwxr-xr-x | tests/cli-opts.sh | 2 | ||||
-rw-r--r-- | tests/untls.go | 2 |
6 files changed, 110 insertions, 38 deletions
@@ -17,7 +17,7 @@ MANDIR = $(SHAREDIR)/man EXEC = ./ ## Where to store the installation. Empty by default. DESTDIR = -LDLIBS = +LDLIBS = --static GOCFLAGS = -I $(GOLIBDIR) GOLDFLAGS = -L $(GOLIBDIR) @@ -26,17 +26,26 @@ GOLDFLAGS = -L $(GOLIBDIR) .SUFFIXES: .SUFFIXES: .go .a .bin .bin-check +.go.a: + go tool compile $(GOCFLAGS) -I $(@D) -o $@ -p $(*F) \ + `find $< $$(if [ $(*F) != main ]; then \ + echo src/$(NAME).go src/version.go; fi) | uniq` + +.a.bin: + go tool link $(GOLDFLAGS) -L $(@D) -o $@ --extldflags '$(LDLIBS)' $< + all: include deps.mk -objects = \ - src/$(NAME).a \ - src/main.a \ - tests/$(NAME).a \ - tests/main.a \ +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 \ @@ -46,14 +55,16 @@ sources = \ derived-assets = \ src/version.go \ - $(objects) \ - src/main.bin \ - tests/main.bin \ + $(libs.a) \ + $(mains.a) \ + $(mains.bin) \ $(NAME).bin \ side-assets = \ - $(NAME).socket \ glaze.socket \ + $(NAME).socket \ + tests/fuzz/corpus/ \ + tests/benchmarks/*/main.txt \ @@ -62,36 +73,26 @@ side-assets = \ all: $(derived-assets) -$(objects): Makefile - -src/$(NAME).a: src/$(NAME).go src/version.go - go tool compile $(GOCFLAGS) -o $@ -p $(*F) -I $(@D) $*.go src/version.go +$(libs.a): Makefile deps.mk +$(libs.a): src/$(NAME).go src/version.go -src/main.a: src/main.go src/$(NAME).a -tests/main.a: tests/main.go tests/$(NAME).a -src/main.a tests/main.a: - go tool compile $(GOCFLAGS) -o $@ -p $(*F) -I $(@D) $*.go -tests/$(NAME).a: tests/$(NAME).go src/$(NAME).go src/version.go - go tool compile $(GOCFLAGS) -o $@ -p $(*F) $*.go src/$(*F).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/main.bin: src/main.a -tests/main.bin: tests/main.a -src/main.bin tests/main.bin: - go tool link $(GOLDFLAGS) -o $@ -L $(@D) --extldflags '$(LDLIBS)' $*.a +src/version.go: Makefile + echo 'package $(NAME); const Version = "$(VERSION)"' > $@ $(NAME).bin: src/main.bin ln -fs $? $@ -src/version.go: Makefile - echo 'package $(NAME); const Version = "$(VERSION)"' > $@ - tests.bin-check = \ - tests/main.bin-check \ + tests/main.bin-check \ + $(functional-tests/main.go:.go=.bin-check) \ -tests/main.bin-check: tests/main.bin $(tests.bin-check): $(EXEC)$*.bin @@ -108,6 +109,7 @@ $(integration-tests): ALWAYS sh $@ check-integration: $(integration-tests) +check-integration: fuzz ## Run all tests. Each test suite is isolated, so that a parallel @@ -117,6 +119,27 @@ 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): + rm -f $*.txt + 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: @@ -150,7 +173,7 @@ uninstall: run: all rm -f $(NAME).socket rm -f glaze.socket - ./$(NAME).bin cert.pem key.pem tls.socket glaze.socket + ./$(NAME).bin cert.pem privkey.pem tls.socket glaze.socket ALWAYS: @@ -0,0 +1,30 @@ +libs.go = \ + src/untls.go \ + tests/untls.go \ + +mains.go = \ + src/main.go \ + tests/main.go \ + +functional-tests/libs.go = \ + +functional-tests/main.go = \ + +fuzz-targets/lib.go = \ + +fuzz-targets/main.go = \ + +benchmarks/lib.go = \ + +benchmarks/main.go = \ + +src/main.a: src/main.go +src/untls.a: src/untls.go +tests/main.a: tests/main.go +tests/untls.a: tests/untls.go +src/main.bin: src/main.a +tests/main.bin: tests/main.a +src/main.bin-check: src/main.bin +tests/main.bin-check: tests/main.bin +src/main.a: src/$(NAME).a +tests/main.a: tests/$(NAME).a @@ -3,8 +3,27 @@ set -eu export LANG=POSIX.UTF-8 -varlist() { - printf '%s = \\\n' "$1" - sed 's|^\(.*\)$|\t\1 \\|' - printf '\n' + +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/libs.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/untls.go b/src/untls.go index e61f2e9..fedb6bf 100644 --- a/src/untls.go +++ b/src/untls.go @@ -32,7 +32,7 @@ func parseArgs(args []string) _CLIArgs { if len(args) != 5 { fmt.Fprintf( os.Stderr, - "Usage: %s CERT.pem KEY.pem FROM.socket TO.socket\n", + "Usage: %s CERT.pem PRIVKEY.pem FROM.socket TO.socket\n", args[0], ) os.Exit(2) @@ -106,7 +106,7 @@ func start(toAddr string, listener net.Listener) { func Main() { - g.Init(slog.Group("versions", "gobang", g.Version, "this", version)) + g.Init(slog.Group("versions", "gobang", g.Version, "this", Version)) args := parseArgs(os.Args) listener := listen(args.certFile, args.keyFile, args.fromAddr) start(args.toAddr, listener) diff --git a/tests/cli-opts.sh b/tests/cli-opts.sh index bcceaa2..87698fd 100755 --- a/tests/cli-opts.sh +++ b/tests/cli-opts.sh @@ -34,7 +34,7 @@ test_needs_4_arguments() { ERR="$(mkstemp)" trap 'rm -f "$OUT" "$ERR"' EXIT STATUS=0 - ./untls.bin cert.pem key.pem TO-ADDR 1>"$OUT" 2>"$ERR" || STATUS=$? + ./untls.bin cert.pem privkey.pem TO-ADDR 1>"$OUT" 2>"$ERR" || STATUS=$? assert_status 2 assert_empty_stdout assert_usage "$ERR" diff --git a/tests/untls.go b/tests/untls.go index 767ad31..7b50546 100644 --- a/tests/untls.go +++ b/tests/untls.go @@ -7,7 +7,7 @@ import ( func test_Stub() { - g.AssertEqual(X, 1) + g.TAssertEqual(X, 1) } |