From 6c4eb1aa31b670d32910d4881b0801eac8265057 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Sun, 3 Nov 2024 10:15:49 -0300 Subject: Setup Makefile project structure with empty src/urubu.go source --- .gitignore | 20 +++ Makefile | 169 +++++++++++++++++++++++++ deps.mk | 75 +++++++++++ mkdeps.sh | 29 +++++ src/main.go | 7 + src/urubu.go | 6 + tests/benchmarks/never-matching-lexer/main.go | 1 + tests/benchmarks/never-matching-lexer/urubu.go | 24 ++++ tests/cli-opts.sh | 0 tests/functional/json/main.go | 1 + tests/functional/json/urubu.go | 5 + tests/fuzz/api-check/main.go | 1 + tests/fuzz/api-check/urubu.go | 35 +++++ tests/fuzz/generated-lexer-check/main.go | 1 + tests/fuzz/generated-lexer-check/urubu.go | 35 +++++ tests/fuzz/generated-parser-check/main.go | 1 + tests/fuzz/generated-parser-check/urubu.go | 35 +++++ tests/integration.sh | 0 tests/main.go | 7 + tests/urubu.go | 6 + 20 files changed, 458 insertions(+) create mode 100644 Makefile create mode 100644 deps.mk create mode 100644 mkdeps.sh create mode 100644 src/main.go create mode 100644 src/urubu.go create mode 120000 tests/benchmarks/never-matching-lexer/main.go create mode 100644 tests/benchmarks/never-matching-lexer/urubu.go create mode 100755 tests/cli-opts.sh create mode 120000 tests/functional/json/main.go create mode 100644 tests/functional/json/urubu.go create mode 120000 tests/fuzz/api-check/main.go create mode 100644 tests/fuzz/api-check/urubu.go create mode 120000 tests/fuzz/generated-lexer-check/main.go create mode 100644 tests/fuzz/generated-lexer-check/urubu.go create mode 120000 tests/fuzz/generated-parser-check/main.go create mode 100644 tests/fuzz/generated-parser-check/urubu.go create mode 100755 tests/integration.sh create mode 100644 tests/main.go create mode 100644 tests/urubu.go diff --git a/.gitignore b/.gitignore index 47b3d13..fb07bbc 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,21 @@ +/src/version.go +/*.bin +/*.db* +/src/*.a +/src/*.bin +/src/*cgo* +/tests/*.a +/tests/*.bin +/tests/functional/*/*.a +/tests/functional/*/*.bin +/tests/functional/*/*.go.db* +/tests/fuzz/*/*.a +/tests/fuzz/*/*.bin +/tests/benchmarks/*/*.a +/tests/benchmarks/*/*.bin +/tests/benchmarks/*/*.txt +/tests/fuzz/corpus/ + + + spec/grammar/clexspec.json diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..11096d1 --- /dev/null +++ b/Makefile @@ -0,0 +1,169 @@ +.POSIX: +DATE = 1970-01-01 +VERSION = 0.1.0 +NAME = urubu +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 \ + src/main.go \ + + +derived-assets = \ + src/version.go \ + $(libs.a) \ + $(mains.a) \ + $(mains.bin) \ + $(NAME).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)"' > $@ + +$(NAME).bin: src/main.bin + ln -fs $? $@ + + + +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 = \ + tests/cli-opts.sh \ + tests/integration.sh \ + +.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)$(BINDIR)' \ + '$(DESTDIR)$(GOLIBDIR)' \ + '$(DESTDIR)$(SRCDIR)' \ + + cp $(NAME).bin '$(DESTDIR)$(BINDIR)'/$(NAME) + 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)$(BINDIR)'/$(NAME) \ + '$(DESTDIR)$(GOLIBDIR)'/$(NAME).a \ + '$(DESTDIR)$(SRCDIR)' \ + + + +ALWAYS: diff --git a/deps.mk b/deps.mk new file mode 100644 index 0000000..5cace88 --- /dev/null +++ b/deps.mk @@ -0,0 +1,75 @@ +libs.go = \ + src/urubu.go \ + tests/benchmarks/never-matching-lexer/urubu.go \ + tests/functional/json/urubu.go \ + tests/fuzz/api-check/urubu.go \ + tests/fuzz/generated-lexer-check/urubu.go \ + tests/fuzz/generated-parser-check/urubu.go \ + tests/urubu.go \ + +mains.go = \ + src/main.go \ + tests/benchmarks/never-matching-lexer/main.go \ + tests/functional/json/main.go \ + tests/fuzz/api-check/main.go \ + tests/fuzz/generated-lexer-check/main.go \ + tests/fuzz/generated-parser-check/main.go \ + tests/main.go \ + +functional-tests/lib.go = \ + tests/functional/json/urubu.go \ + +functional-tests/main.go = \ + tests/functional/json/main.go \ + +fuzz-targets/lib.go = \ + tests/fuzz/api-check/urubu.go \ + tests/fuzz/generated-lexer-check/urubu.go \ + tests/fuzz/generated-parser-check/urubu.go \ + +fuzz-targets/main.go = \ + tests/fuzz/api-check/main.go \ + tests/fuzz/generated-lexer-check/main.go \ + tests/fuzz/generated-parser-check/main.go \ + +benchmarks/lib.go = \ + tests/benchmarks/never-matching-lexer/urubu.go \ + +benchmarks/main.go = \ + tests/benchmarks/never-matching-lexer/main.go \ + +src/main.a: src/main.go +src/urubu.a: src/urubu.go +tests/benchmarks/never-matching-lexer/main.a: tests/benchmarks/never-matching-lexer/main.go +tests/benchmarks/never-matching-lexer/urubu.a: tests/benchmarks/never-matching-lexer/urubu.go +tests/functional/json/main.a: tests/functional/json/main.go +tests/functional/json/urubu.a: tests/functional/json/urubu.go +tests/fuzz/api-check/main.a: tests/fuzz/api-check/main.go +tests/fuzz/api-check/urubu.a: tests/fuzz/api-check/urubu.go +tests/fuzz/generated-lexer-check/main.a: tests/fuzz/generated-lexer-check/main.go +tests/fuzz/generated-lexer-check/urubu.a: tests/fuzz/generated-lexer-check/urubu.go +tests/fuzz/generated-parser-check/main.a: tests/fuzz/generated-parser-check/main.go +tests/fuzz/generated-parser-check/urubu.a: tests/fuzz/generated-parser-check/urubu.go +tests/main.a: tests/main.go +tests/urubu.a: tests/urubu.go +src/main.bin: src/main.a +tests/benchmarks/never-matching-lexer/main.bin: tests/benchmarks/never-matching-lexer/main.a +tests/functional/json/main.bin: tests/functional/json/main.a +tests/fuzz/api-check/main.bin: tests/fuzz/api-check/main.a +tests/fuzz/generated-lexer-check/main.bin: tests/fuzz/generated-lexer-check/main.a +tests/fuzz/generated-parser-check/main.bin: tests/fuzz/generated-parser-check/main.a +tests/main.bin: tests/main.a +src/main.bin-check: src/main.bin +tests/benchmarks/never-matching-lexer/main.bin-check: tests/benchmarks/never-matching-lexer/main.bin +tests/functional/json/main.bin-check: tests/functional/json/main.bin +tests/fuzz/api-check/main.bin-check: tests/fuzz/api-check/main.bin +tests/fuzz/generated-lexer-check/main.bin-check: tests/fuzz/generated-lexer-check/main.bin +tests/fuzz/generated-parser-check/main.bin-check: tests/fuzz/generated-parser-check/main.bin +tests/main.bin-check: tests/main.bin +src/main.a: src/$(NAME).a +tests/benchmarks/never-matching-lexer/main.a: tests/benchmarks/never-matching-lexer/$(NAME).a +tests/functional/json/main.a: tests/functional/json/$(NAME).a +tests/fuzz/api-check/main.a: tests/fuzz/api-check/$(NAME).a +tests/fuzz/generated-lexer-check/main.a: tests/fuzz/generated-lexer-check/$(NAME).a +tests/fuzz/generated-parser-check/main.a: tests/fuzz/generated-parser-check/$(NAME).a +tests/main.a: tests/$(NAME).a diff --git a/mkdeps.sh b/mkdeps.sh new file mode 100644 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/main.go b/src/main.go new file mode 100644 index 0000000..d9c9b31 --- /dev/null +++ b/src/main.go @@ -0,0 +1,7 @@ +package main + +import "urubu" + +func main() { + urubu.Main() +} diff --git a/src/urubu.go b/src/urubu.go new file mode 100644 index 0000000..024989a --- /dev/null +++ b/src/urubu.go @@ -0,0 +1,6 @@ +package urubu + + + +func Main() { +} diff --git a/tests/benchmarks/never-matching-lexer/main.go b/tests/benchmarks/never-matching-lexer/main.go new file mode 120000 index 0000000..f67563d --- /dev/null +++ b/tests/benchmarks/never-matching-lexer/main.go @@ -0,0 +1 @@ +../../main.go \ No newline at end of file diff --git a/tests/benchmarks/never-matching-lexer/urubu.go b/tests/benchmarks/never-matching-lexer/urubu.go new file mode 100644 index 0000000..9186769 --- /dev/null +++ b/tests/benchmarks/never-matching-lexer/urubu.go @@ -0,0 +1,24 @@ +package urubu + +import ( + "flag" + "time" +) + + + +var nFlag = flag.Int( + "n", + 1_000, + "The number of iterations to execute", +) + +func MainTest() { + // FIXME + flag.Parse() + n := *nFlag + + for i := 0; i < n; i++ { + time.Sleep(time.Millisecond * 1) + } +} diff --git a/tests/cli-opts.sh b/tests/cli-opts.sh new file mode 100755 index 0000000..e69de29 diff --git a/tests/functional/json/main.go b/tests/functional/json/main.go new file mode 120000 index 0000000..f67563d --- /dev/null +++ b/tests/functional/json/main.go @@ -0,0 +1 @@ +../../main.go \ No newline at end of file diff --git a/tests/functional/json/urubu.go b/tests/functional/json/urubu.go new file mode 100644 index 0000000..7a40ac0 --- /dev/null +++ b/tests/functional/json/urubu.go @@ -0,0 +1,5 @@ +package urubu + +func MainTest() { + // FIXME +} diff --git a/tests/fuzz/api-check/main.go b/tests/fuzz/api-check/main.go new file mode 120000 index 0000000..f67563d --- /dev/null +++ b/tests/fuzz/api-check/main.go @@ -0,0 +1 @@ +../../main.go \ No newline at end of file diff --git a/tests/fuzz/api-check/urubu.go b/tests/fuzz/api-check/urubu.go new file mode 100644 index 0000000..7ba1c2f --- /dev/null +++ b/tests/fuzz/api-check/urubu.go @@ -0,0 +1,35 @@ +package urubu + +import ( + "os" + "testing" + "testing/internal/testdeps" +) + + + +func api(f *testing.F) { + f.Fuzz(func(t *testing.T, n int) { + // FIXME + if n > 1 { + if n < 2 { + t.Errorf("Failed n: %v\n", n) + } + } + }) +} + + + +func MainTest() { + fuzzTargets := []testing.InternalFuzzTarget{ + { "api", api }, + } + + deps := testdeps.TestDeps{} + tests := []testing.InternalTest {} + benchmarks := []testing.InternalBenchmark{} + examples := []testing.InternalExample {} + m := testing.MainStart(deps, tests, benchmarks, fuzzTargets, examples) + os.Exit(m.Run()) +} diff --git a/tests/fuzz/generated-lexer-check/main.go b/tests/fuzz/generated-lexer-check/main.go new file mode 120000 index 0000000..f67563d --- /dev/null +++ b/tests/fuzz/generated-lexer-check/main.go @@ -0,0 +1 @@ +../../main.go \ No newline at end of file diff --git a/tests/fuzz/generated-lexer-check/urubu.go b/tests/fuzz/generated-lexer-check/urubu.go new file mode 100644 index 0000000..7ba1c2f --- /dev/null +++ b/tests/fuzz/generated-lexer-check/urubu.go @@ -0,0 +1,35 @@ +package urubu + +import ( + "os" + "testing" + "testing/internal/testdeps" +) + + + +func api(f *testing.F) { + f.Fuzz(func(t *testing.T, n int) { + // FIXME + if n > 1 { + if n < 2 { + t.Errorf("Failed n: %v\n", n) + } + } + }) +} + + + +func MainTest() { + fuzzTargets := []testing.InternalFuzzTarget{ + { "api", api }, + } + + deps := testdeps.TestDeps{} + tests := []testing.InternalTest {} + benchmarks := []testing.InternalBenchmark{} + examples := []testing.InternalExample {} + m := testing.MainStart(deps, tests, benchmarks, fuzzTargets, examples) + os.Exit(m.Run()) +} diff --git a/tests/fuzz/generated-parser-check/main.go b/tests/fuzz/generated-parser-check/main.go new file mode 120000 index 0000000..f67563d --- /dev/null +++ b/tests/fuzz/generated-parser-check/main.go @@ -0,0 +1 @@ +../../main.go \ No newline at end of file diff --git a/tests/fuzz/generated-parser-check/urubu.go b/tests/fuzz/generated-parser-check/urubu.go new file mode 100644 index 0000000..7ba1c2f --- /dev/null +++ b/tests/fuzz/generated-parser-check/urubu.go @@ -0,0 +1,35 @@ +package urubu + +import ( + "os" + "testing" + "testing/internal/testdeps" +) + + + +func api(f *testing.F) { + f.Fuzz(func(t *testing.T, n int) { + // FIXME + if n > 1 { + if n < 2 { + t.Errorf("Failed n: %v\n", n) + } + } + }) +} + + + +func MainTest() { + fuzzTargets := []testing.InternalFuzzTarget{ + { "api", api }, + } + + deps := testdeps.TestDeps{} + tests := []testing.InternalTest {} + benchmarks := []testing.InternalBenchmark{} + examples := []testing.InternalExample {} + m := testing.MainStart(deps, tests, benchmarks, fuzzTargets, examples) + os.Exit(m.Run()) +} diff --git a/tests/integration.sh b/tests/integration.sh new file mode 100755 index 0000000..e69de29 diff --git a/tests/main.go b/tests/main.go new file mode 100644 index 0000000..02c3642 --- /dev/null +++ b/tests/main.go @@ -0,0 +1,7 @@ +package main + +import "urubu" + +func main() { + urubu.MainTest() +} diff --git a/tests/urubu.go b/tests/urubu.go new file mode 100644 index 0000000..e36fe88 --- /dev/null +++ b/tests/urubu.go @@ -0,0 +1,6 @@ +package urubu + + + +func MainTest() { +} -- cgit v1.2.3