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