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