coolio*: favor Coolio over Rev
[rainbows.git] / t / GNUmakefile
blob91e05f5e1feac7db0c34f0677593a7728eb8e56b
1 # we can run tests in parallel with GNU make
3 all::
5 pid := $(shell echo $$PPID)
7 MRI = ruby
8 RUBY = ruby
9 rainbows_lib := $(shell cd ../lib && pwd)
10 -include ../local.mk
11 ifeq ($(RUBY_VERSION),)
12 RUBY_VERSION := $(shell $(RUBY) -e 'puts RUBY_VERSION')
13 endif
15 ifeq ($(RUBY_VERSION),)
16 $(error unable to detect RUBY_VERSION)
17 endif
19 RUBY_ENGINE := $(shell $(RUBY) -e 'puts((RUBY_ENGINE rescue "ruby"))')
20 export RUBY_VERSION RUBY_ENGINE
22 models += WriterThreadPool
23 models += WriterThreadSpawn
24 models += ThreadPool
25 models += ThreadSpawn
26 models += Coolio
27 models += EventMachine
28 models += NeverBlock
30 ifeq ($(RUBY_ENGINE),ruby)
31 rp := )
32 ONENINE := $(shell case $(RUBY_VERSION) in 1.9.*$(rp) echo true;;esac)
33 ifeq ($(ONENINE),true)
34 models += Revactor
35 models += FiberSpawn
36 models += FiberPool
37 models += CoolioThreadPool
38 models += CoolioThreadSpawn
39 models += CoolioFiberSpawn
40 endif
41 endif
43 ifeq ($(RUBY_ENGINE),rbx)
44 models += ActorSpawn
45 endif
46 all_models := $(models) Base
48 T = $(wildcard t[0-9][0-9][0-9][0-9]-*.sh)
50 MODEL_T := $(foreach m,$(all_models),$(addprefix $(m).,$(T)))
51 $(T): MODELS = $(models)
53 # some tests can be run with all models
54 t0000-simple-http.sh: MODELS = $(all_models)
55 t0001-unix-http.sh: MODELS = $(all_models)
56 t0002-graceful.sh: MODELS = $(all_models)
57 t0002-parser-error.sh: MODELS = $(all_models)
58 t0003-reopen-logs.sh: MODELS = $(all_models)
60 # recursively run per-model tests
61 # haven't figured out a good way to make make non-recursive here, yet...
62 $(T):
63 $(MAKE) $(foreach m,$(MODELS),$(addprefix $(m).,$@))
65 $(all_models):
66 $(MAKE) $(filter $@.%,$(MODEL_T))
68 all:: $(T)
70 # can't rely on "set -o pipefail" since we don't require bash or ksh93 :<
71 t_pfx = trash/$@-$(RUBY_ENGINE)-$(RUBY_VERSION)
72 TEST_OPTS =
73 # TRACER = strace -f -o $(t_pfx).strace -s 100000
74 # TRACER = /usr/bin/time -o $(t_pfx).time
76 ifdef V
77 ifeq ($(V),2)
78 TEST_OPTS += --trace
79 else
80 TEST_OPTS += --verbose
81 endif
82 endif
84 bindir := $(CURDIR)/bin-$(RUBY_ENGINE)-$(RUBY_VERSION)
85 bin_rainbows := $(bindir)/rainbows
86 $(bin_rainbows): ruby_bin = $(shell which $(RUBY))
87 $(bin_rainbows): ../bin/rainbows
88 mkdir -p $(@D)
89 install -m 755 $^ $@.$(pid)
90 $(MRI) -i -p -e '$$_.gsub!(%r{^#!.*$$},"#!$(ruby_bin)")' $@.$(pid)
91 mv $@.$(pid) $@
93 random_blob:
94 dd if=/dev/urandom bs=1M count=30 of=$@.$(pid)
95 mv $@.$(pid) $@
97 $(T): random_blob
99 dependencies := socat curl
100 deps := $(addprefix .dep+,$(dependencies))
101 $(deps): dep_bin = $(lastword $(subst +, ,$@))
102 $(deps):
103 @which $(dep_bin) > $@.$(pid) 2>/dev/null || :
104 @test -s $@.$(pid) || \
105 { echo >&2 "E '$(dep_bin)' not found in PATH=$(PATH)"; exit 1; }
106 @mv $@.$(pid) $@
108 libs := tmp/isolate/$(RUBY_ENGINE)-$(RUBY_VERSION)/.libs
109 $(libs): test_isolate.rb
110 mkdir -p $(@D)
111 $(RUBY) $< > $@+
112 mv $@+ $@
113 t_deps := $(libs) $(deps) $(bin_rainbows) trash/.gitignore
114 $(T): $(t_deps)
116 $(MODEL_T): export model = $(firstword $(subst ., ,$@))
117 $(MODEL_T): script = $(subst $(model).,,$@)
118 $(MODEL_T): export RUBY := $(RUBY)
119 $(MODEL_T): export PATH := $(bindir):$(PATH)
120 $(MODEL_T): $(t_deps)
121 RUBYLIB=$(rainbows_lib):$$(cat $(libs)):$(RUBYLIB) \
122 $(TRACER) $(SHELL) $(SH_TEST_OPTS) $(script) $(TEST_OPTS)
124 trash/.gitignore:
125 mkdir -p $(@D)
126 echo '*' > $@
128 clean:
129 $(RM) -r trash/*.log trash/*.code $(bindir)
131 .PHONY: $(T) clean