initial cool.io support
[rainbows.git] / t / GNUmakefile
blob0084f3d79f1f17a3d6008782ea0d85ac1579b2dd
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 += Rev
27 models += Coolio
28 models += EventMachine
29 models += NeverBlock
31 ifeq ($(RUBY_ENGINE),ruby)
32 rp := )
33 ONENINE := $(shell case $(RUBY_VERSION) in 1.9.*$(rp) echo true;;esac)
34 ifeq ($(ONENINE),true)
35 models += Revactor
36 models += FiberSpawn
37 models += FiberPool
38 models += RevThreadPool
39 models += RevThreadSpawn
40 models += RevFiberSpawn
41 models += CoolioThreadPool
42 models += CoolioThreadSpawn
43 models += CoolioFiberSpawn
44 endif
45 endif
47 ifeq ($(RUBY_ENGINE),rbx)
48 models += ActorSpawn
49 endif
50 all_models := $(models) Base
52 T = $(wildcard t[0-9][0-9][0-9][0-9]-*.sh)
54 MODEL_T := $(foreach m,$(all_models),$(addprefix $(m).,$(T)))
55 $(T): MODELS = $(models)
57 # some tests can be run with all models
58 t0000-simple-http.sh: MODELS = $(all_models)
59 t0001-unix-http.sh: MODELS = $(all_models)
60 t0002-graceful.sh: MODELS = $(all_models)
61 t0002-parser-error.sh: MODELS = $(all_models)
62 t0003-reopen-logs.sh: MODELS = $(all_models)
64 # recursively run per-model tests
65 # haven't figured out a good way to make make non-recursive here, yet...
66 $(T):
67 $(MAKE) $(foreach m,$(MODELS),$(addprefix $(m).,$@))
69 $(all_models):
70 $(MAKE) $(filter $@.%,$(MODEL_T))
72 all:: $(T)
74 # can't rely on "set -o pipefail" since we don't require bash or ksh93 :<
75 t_pfx = trash/$@-$(RUBY_ENGINE)-$(RUBY_VERSION)
76 TEST_OPTS =
77 # TRACER = strace -f -o $(t_pfx).strace -s 100000
78 # TRACER = /usr/bin/time -o $(t_pfx).time
80 ifdef V
81 ifeq ($(V),2)
82 TEST_OPTS += --trace
83 else
84 TEST_OPTS += --verbose
85 endif
86 endif
88 bindir := $(CURDIR)/bin-$(RUBY_ENGINE)-$(RUBY_VERSION)
89 bin_rainbows := $(bindir)/rainbows
90 $(bin_rainbows): ruby_bin = $(shell which $(RUBY))
91 $(bin_rainbows): ../bin/rainbows
92 mkdir -p $(@D)
93 install -m 755 $^ $@.$(pid)
94 $(MRI) -i -p -e '$$_.gsub!(%r{^#!.*$$},"#!$(ruby_bin)")' $@.$(pid)
95 mv $@.$(pid) $@
97 random_blob:
98 dd if=/dev/urandom bs=1M count=30 of=$@.$(pid)
99 mv $@.$(pid) $@
101 $(T): random_blob
103 dependencies := socat curl
104 deps := $(addprefix .dep+,$(dependencies))
105 $(deps): dep_bin = $(lastword $(subst +, ,$@))
106 $(deps):
107 @which $(dep_bin) > $@.$(pid) 2>/dev/null || :
108 @test -s $@.$(pid) || \
109 { echo >&2 "E '$(dep_bin)' not found in PATH=$(PATH)"; exit 1; }
110 @mv $@.$(pid) $@
112 libs := tmp/isolate/$(RUBY_ENGINE)-$(RUBY_VERSION)/.libs
113 $(libs): test_isolate.rb
114 mkdir -p $(@D)
115 $(RUBY) $< > $@+
116 mv $@+ $@
117 t_deps := $(libs) $(deps) $(bin_rainbows) trash/.gitignore
118 $(T): $(t_deps)
120 $(MODEL_T): export model = $(firstword $(subst ., ,$@))
121 $(MODEL_T): script = $(subst $(model).,,$@)
122 $(MODEL_T): export RUBY := $(RUBY)
123 $(MODEL_T): export PATH := $(bindir):$(PATH)
124 $(MODEL_T): $(t_deps)
125 RUBYLIB=$(rainbows_lib):$$(cat $(libs)):$(RUBYLIB) \
126 $(TRACER) $(SHELL) $(SH_TEST_OPTS) $(script) $(TEST_OPTS)
128 trash/.gitignore:
129 mkdir -p $(@D)
130 echo '*' > $@
132 clean:
133 $(RM) -r trash/*.log trash/*.code $(bindir)
135 .PHONY: $(T) clean