ev_core: ensure quit is triggered on all errors
[rainbows.git] / t / GNUmakefile
blob8c8ed84c2c4bd9d58add6b9d5b7259e2ae7fc4b6
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 ($(RUBYLIB),)
15 RUBYLIB := $(rainbows_lib)
16 else
17 RUBYLIB := $(rainbows_lib):$(RUBYLIB)
18 endif
19 export RUBYLIB RUBY_VERSION
21 models := ThreadPool ThreadSpawn Rev EventMachine
22 ifeq ($(RUBY_VERSION),1.9.1) # 1.9.2-preview1 was broken
23 models += Revactor
24 endif
25 all_models := $(models) Base
27 T = $(wildcard t[0-9][0-9][0-9][0-9]-*.sh)
29 MODEL_T := $(foreach m,$(all_models),$(addprefix $(m).,$(T)))
30 $(T): MODELS = $(models)
32 # some tests can be run with all models
33 t0000-simple-http.sh: MODELS = $(all_models)
34 t0001-unix-http.sh: MODELS = $(all_models)
35 t0002-graceful.sh: MODELS = $(all_models)
36 t0002-parser-error.sh: MODELS = $(all_models)
37 t0003-reopen-logs.sh: MODELS = $(all_models)
39 # this test is not compatible with non-Thread models yet
40 t9000-rack-app-pool.sh: MODELS = ThreadPool ThreadSpawn
42 # recursively run per-model tests
43 # haven't figured out a good way to make make non-recursive here, yet...
44 $(T):
45 $(MAKE) $(foreach m,$(MODELS),$(addprefix $(m).,$@))
47 $(all_models):
48 $(MAKE) $(filter $@.%,$(MODEL_T))
50 all:: $(T)
52 # can't rely on "set -o pipefail" since we don't require bash or ksh93 :<
53 t_pfx = trash/$@-$(RUBY_VERSION)
54 TEST_OPTS =
55 # TRACER = strace -f -o $(t_pfx).strace -s 100000
56 # TRACER = /usr/bin/time -o $(t_pfx).time
58 ifdef V
59 ifeq ($(V),2)
60 TEST_OPTS += --trace
61 else
62 TEST_OPTS += --verbose
63 endif
64 endif
66 test-bin-$(RUBY_VERSION)/rainbows: ruby_bin = $(shell which $(RUBY))
67 test-bin-$(RUBY_VERSION)/rainbows: ../bin/rainbows
68 mkdir -p $(@D)
69 install -m 755 $^ $@.$(pid)
70 $(RUBY) -i -p -e '$$_.gsub!(%r{^#!.*$$},"#!$(ruby_bin)")' $@.$(pid)
71 mv $@.$(pid) $@
73 random_blob:
74 dd if=/dev/urandom bs=1M count=30 of=$@.$(pid)
75 mv $@.$(pid) $@
77 $(T): random_blob
79 dependencies := socat curl
80 deps := $(addprefix .dep+,$(dependencies))
81 $(deps): dep_bin = $(lastword $(subst +, ,$@))
82 $(deps):
83 @which $(dep_bin) > $@.$(pid) 2>/dev/null || :
84 @test -s $@.$(pid) || \
85 { echo >&2 "E '$(dep_bin)' not found in PATH=$(PATH)"; exit 1; }
86 @mv $@.$(pid) $@
87 dep: $(deps)
89 $(MODEL_T): export model = $(firstword $(subst ., ,$@))
90 $(MODEL_T): script = $(subst $(model).,,$@)
91 $(MODEL_T): trash/.gitignore
92 $(MODEL_T): export RUBY := $(RUBY)
93 $(MODEL_T): export PATH := $(CURDIR)/test-bin-$(RUBY_VERSION):$(PATH)
94 $(MODEL_T): test-bin-$(RUBY_VERSION)/rainbows dep
95 $(TRACER) $(SHELL) $(SH_TEST_OPTS) $(script) $(TEST_OPTS)
97 trash/.gitignore:
98 mkdir -p $(@D)
99 echo '*' > $@
101 clean:
102 $(RM) -r trash/*.log trash/*.code test-bin-$(RUBY_VERSION)
104 .PHONY: $(T) clean