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