tests: fix bugs with dash in GNUmakefile
[rainbows.git] / t / GNUmakefile
blob52f59df21b4d094ea151d34af6306cc1c1be6002
1 # we can run tests in parallel with GNU make
3 all::
5 pid := $(shell echo $$PPID)
7 RUBY = ruby
8 rainbows_lib := $(shell cd ../lib && pwd)
9 -include ../local.mk
10 ifeq ($(RUBY_VERSION),)
11 RUBY_VERSION := $(shell $(RUBY) -e 'puts RUBY_VERSION')
12 endif
14 ifeq ($(RUBY_VERSION),)
15 $(error unable to detect RUBY_VERSION)
16 endif
18 ifeq ($(RUBYLIB),)
19 RUBYLIB := $(rainbows_lib)
20 else
21 RUBYLIB := $(rainbows_lib):$(RUBYLIB)
22 endif
23 export RUBYLIB RUBY_VERSION
25 models = ThreadPool ThreadSpawn Rev EventMachine
26 rp := )
27 ONENINE := $(shell case $(RUBY_VERSION) in 1.9.*$(rp) echo true;;esac)
28 ifeq ($(ONENINE),true)
29 models += Revactor
30 models += FiberSpawn
31 models += FiberPool
33 # technically this works under 1.8, too, it's just slow
34 models += RevThreadSpawn
35 endif
36 all_models := $(models) Base
38 T = $(wildcard t[0-9][0-9][0-9][0-9]-*.sh)
40 MODEL_T := $(foreach m,$(all_models),$(addprefix $(m).,$(T)))
41 $(T): MODELS = $(models)
43 # some tests can be run with all models
44 t0000-simple-http.sh: MODELS = $(all_models)
45 t0001-unix-http.sh: MODELS = $(all_models)
46 t0002-graceful.sh: MODELS = $(all_models)
47 t0002-parser-error.sh: MODELS = $(all_models)
48 t0003-reopen-logs.sh: MODELS = $(all_models)
50 # recursively run per-model tests
51 # haven't figured out a good way to make make non-recursive here, yet...
52 $(T):
53 $(MAKE) $(foreach m,$(MODELS),$(addprefix $(m).,$@))
55 $(all_models):
56 $(MAKE) $(filter $@.%,$(MODEL_T))
58 all:: $(T)
60 # can't rely on "set -o pipefail" since we don't require bash or ksh93 :<
61 t_pfx = trash/$@-$(RUBY_VERSION)
62 TEST_OPTS =
63 # TRACER = strace -f -o $(t_pfx).strace -s 100000
64 # TRACER = /usr/bin/time -o $(t_pfx).time
66 ifdef V
67 ifeq ($(V),2)
68 TEST_OPTS += --trace
69 else
70 TEST_OPTS += --verbose
71 endif
72 endif
74 test-bin-$(RUBY_VERSION)/rainbows: ruby_bin = $(shell which $(RUBY))
75 test-bin-$(RUBY_VERSION)/rainbows: ../bin/rainbows
76 mkdir -p $(@D)
77 install -m 755 $^ $@.$(pid)
78 $(RUBY) -i -p -e '$$_.gsub!(%r{^#!.*$$},"#!$(ruby_bin)")' $@.$(pid)
79 mv $@.$(pid) $@
81 random_blob:
82 dd if=/dev/urandom bs=1M count=30 of=$@.$(pid)
83 mv $@.$(pid) $@
85 $(T): random_blob
87 dependencies := socat curl
88 deps := $(addprefix .dep+,$(dependencies))
89 $(deps): dep_bin = $(lastword $(subst +, ,$@))
90 $(deps):
91 @which $(dep_bin) > $@.$(pid) 2>/dev/null || :
92 @test -s $@.$(pid) || \
93 { echo >&2 "E '$(dep_bin)' not found in PATH=$(PATH)"; exit 1; }
94 @mv $@.$(pid) $@
95 dep: $(deps)
97 $(MODEL_T): export model = $(firstword $(subst ., ,$@))
98 $(MODEL_T): script = $(subst $(model).,,$@)
99 $(MODEL_T): trash/.gitignore
100 $(MODEL_T): export RUBY := $(RUBY)
101 $(MODEL_T): export PATH := $(CURDIR)/test-bin-$(RUBY_VERSION):$(PATH)
102 $(MODEL_T): test-bin-$(RUBY_VERSION)/rainbows dep
103 $(TRACER) $(SHELL) $(SH_TEST_OPTS) $(script) $(TEST_OPTS)
105 trash/.gitignore:
106 mkdir -p $(@D)
107 echo '*' > $@
109 clean:
110 $(RM) -r trash/*.log trash/*.code test-bin-$(RUBY_VERSION)
112 .PHONY: $(T) clean