tests: update checks for Ruby 2.0.0
[rainbows.git] / t / GNUmakefile
blob19aacbe3a490b1381442ed2551906a2a68a44245
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 ifeq (Linux,$(shell uname -s))
23 models += XEpoll
24 models += XEpollThreadSpawn
25 models += XEpollThreadPool
26 models += Epoll
27 endif
28 models += WriterThreadPool
29 models += WriterThreadSpawn
30 models += ThreadPool
31 models += ThreadSpawn
32 models += Coolio
34 models += StreamResponseEpoll
36 ifeq ($(RUBY_ENGINE),ruby)
37 rp := )
38 ONENINE := $(shell case $(RUBY_VERSION) in 1.9.*|2.0.*$(rp) echo true;;esac)
39 ifeq ($(ONENINE),true)
40 ifeq ($(RUBY_VERSION),1.9.2)
41 models += Revactor
42 endif
43 models += FiberSpawn
44 models += FiberPool
45 models += CoolioThreadPool
46 models += CoolioThreadSpawn
47 models += CoolioFiberSpawn
49 # EventMachine 1.0.0 currently does not build on Ruby 2.0.0
50 # NeverBlock depends on 2.0.0
51 RBTWO := $(shell case $(RUBY_VERSION) in 2.0.*$(rp) echo true;;esac)
52 ifeq ($(RBTWO),)
53 models += EventMachine
54 models += NeverBlock
55 endif
56 endif
57 endif
59 ifeq ($(RUBY_ENGINE),rbx)
60 models += ActorSpawn
61 endif
62 all_models := $(models) Base
64 T = $(wildcard t[0-9][0-9][0-9][0-9]-*.sh)
66 MODEL_T := $(foreach m,$(all_models),$(addprefix $(m).,$(T)))
67 $(T): MODELS = $(models)
69 # some tests can be run with all models
70 t0000-simple-http.sh: MODELS = $(all_models)
71 t0001-unix-http.sh: MODELS = $(all_models)
72 t0002-graceful.sh: MODELS = $(all_models)
73 t0002-parser-error.sh: MODELS = $(all_models)
74 t0003-reopen-logs.sh: MODELS = $(all_models)
76 # recursively run per-model tests
77 # haven't figured out a good way to make make non-recursive here, yet...
78 $(T):
79 $(MAKE) $(foreach m,$(MODELS),$(addprefix $(m).,$@))
81 $(all_models):
82 $(MAKE) $(filter $@.%,$(MODEL_T))
84 all:: $(T)
86 # can't rely on "set -o pipefail" since we don't require bash or ksh93 :<
87 t_pfx = trash/$@-$(RUBY_ENGINE)-$(RUBY_VERSION)
88 TEST_OPTS =
89 # TRACER = strace -f -o $(t_pfx).strace -s 100000
90 # TRACER = /usr/bin/time -o $(t_pfx).time
92 ifdef V
93 ifeq ($(V),2)
94 TEST_OPTS += --trace
95 else
96 TEST_OPTS += --verbose
97 endif
98 endif
100 bindir := $(CURDIR)/bin-$(RUBY_ENGINE)-$(RUBY_VERSION)
101 bin_rainbows := $(bindir)/rainbows
102 $(bin_rainbows): ruby_bin = $(shell which $(RUBY))
103 $(bin_rainbows): ../bin/rainbows
104 mkdir -p $(@D)
105 install -m 755 $^ $@.$(pid)
106 $(MRI) -i -p -e '$$_.gsub!(%r{^#!.*$$},"#!$(ruby_bin)")' $@.$(pid)
107 mv $@.$(pid) $@
109 random_blob:
110 dd if=/dev/urandom bs=1M count=30 of=$@.$(pid)
111 mv $@.$(pid) $@
113 dependencies := socat curl
114 deps := $(addprefix .dep+,$(dependencies))
115 $(deps): dep_bin = $(lastword $(subst +, ,$@))
116 $(deps):
117 @which $(dep_bin) > $@.$(pid) 2>/dev/null || :
118 @test -s $@.$(pid) || \
119 { echo >&2 "E '$(dep_bin)' not found in PATH=$(PATH)"; exit 1; }
120 @mv $@.$(pid) $@
122 libs := tmp/isolate/$(RUBY_ENGINE)-$(RUBY_VERSION)/.libs
123 $(libs): test_isolate.rb
124 mkdir -p $(@D)
125 $(RUBY) $< > $@+
126 mv $@+ $@
127 t_deps := random_blob $(libs) $(deps) $(bin_rainbows) trash/.gitignore
128 $(T): $(t_deps)
130 $(MODEL_T): export model = $(firstword $(subst ., ,$@))
131 $(MODEL_T): script = $(subst $(model).,,$@)
132 $(MODEL_T): export RUBY := $(RUBY)
133 $(MODEL_T): export PATH := $(bindir):$(PATH)
134 $(MODEL_T): $(t_deps)
135 RUBYLIB=$(rainbows_lib):$$(cat $(libs)):$(RUBYLIB) \
136 $(TRACER) $(SHELL) $(SH_TEST_OPTS) $(script) $(TEST_OPTS)
138 trash/.gitignore:
139 mkdir -p $(@D)
140 echo '*' > $@
142 clean:
143 $(RM) -r trash/*.log trash/*.code $(bindir)
145 .PHONY: $(T) clean