initial cut of the RevThreadSpawn model
[rainbows.git] / t / GNUmakefile
blobda4dfd2267569b9bf42f9905c1ca37b039563e79
1 # we can run tests in parallel with GNU make
3 all::
5 pid := $(shell echo $$PPID)
7 RUBY = $(ruby)
8 rainbows_lib := $(shell cd ../lib && pwd)
9 -include ../local.mk
10 ifeq ($(RUBY_VERSION),)
11 RUBY_VERSION := $(shell $(RUBY) -e 'puts RUBY_VERSION')
12 endif
14 ifeq ($(RUBYLIB),)
15 RUBYLIB := $(rainbows_lib)
16 else
17 RUBYLIB := $(rainbows_lib):$(RUBYLIB)
18 endif
19 export RUBYLIB RUBY_VERSION
21 models := ThreadPool ThreadSpawn Rev EventMachine
22 models += RevThreadSpawn
23 ifeq ($(RUBY_VERSION),1.9.1) # 1.9.2-preview1 was broken
24 models += Revactor
25 endif
26 all_models := $(models) Base
28 T = $(wildcard t[0-9][0-9][0-9][0-9]-*.sh)
30 MODEL_T := $(foreach m,$(all_models),$(addprefix $(m).,$(T)))
31 $(T): MODELS = $(models)
33 # some tests can be run with all models
34 t0000-simple-http.sh: MODELS = $(all_models)
35 t0001-unix-http.sh: MODELS = $(all_models)
36 t0002-graceful.sh: MODELS = $(all_models)
37 t0002-parser-error.sh: MODELS = $(all_models)
38 t0003-reopen-logs.sh: MODELS = $(all_models)
40 # this test is not compatible with non-Thread models yet
41 t9000-rack-app-pool.sh: MODELS = ThreadPool ThreadSpawn
43 # recursively run per-model tests
44 # haven't figured out a good way to make make non-recursive here, yet...
45 $(T):
46 $(MAKE) $(foreach m,$(MODELS),$(addprefix $(m).,$@))
48 $(all_models):
49 $(MAKE) $(filter $@.%,$(MODEL_T))
51 all:: $(T)
53 # can't rely on "set -o pipefail" since we don't require bash or ksh93 :<
54 t_pfx = trash/$@-$(RUBY_VERSION)
55 TEST_OPTS =
56 # TRACER = strace -f -o $(t_pfx).strace -s 100000
57 # TRACER = /usr/bin/time -o $(t_pfx).time
59 ifdef V
60 ifeq ($(V),2)
61 TEST_OPTS += --trace
62 else
63 TEST_OPTS += --verbose
64 endif
65 endif
67 test-bin-$(RUBY_VERSION)/rainbows: ruby_bin = $(shell which $(RUBY))
68 test-bin-$(RUBY_VERSION)/rainbows: ../bin/rainbows
69 mkdir -p $(@D)
70 install -m 755 $^ $@.$(pid)
71 $(RUBY) -i -p -e '$$_.gsub!(%r{^#!.*$$},"#!$(ruby_bin)")' $@.$(pid)
72 mv $@.$(pid) $@
74 random_blob:
75 dd if=/dev/urandom bs=1M count=30 of=$@.$(pid)
76 mv $@.$(pid) $@
78 $(T): random_blob
80 dependencies := socat curl
81 deps := $(addprefix .dep+,$(dependencies))
82 $(deps): dep_bin = $(lastword $(subst +, ,$@))
83 $(deps):
84 @which $(dep_bin) > $@.$(pid) 2>/dev/null || :
85 @test -s $@.$(pid) || \
86 { echo >&2 "E '$(dep_bin)' not found in PATH=$(PATH)"; exit 1; }
87 @mv $@.$(pid) $@
88 dep: $(deps)
90 $(MODEL_T): export model = $(firstword $(subst ., ,$@))
91 $(MODEL_T): script = $(subst $(model).,,$@)
92 $(MODEL_T): trash/.gitignore
93 $(MODEL_T): export RUBY := $(RUBY)
94 $(MODEL_T): export PATH := $(CURDIR)/test-bin-$(RUBY_VERSION):$(PATH)
95 $(MODEL_T): test-bin-$(RUBY_VERSION)/rainbows dep
96 $(TRACER) $(SHELL) $(SH_TEST_OPTS) $(script) $(TEST_OPTS)
98 trash/.gitignore:
99 mkdir -p $(@D)
100 echo '*' > $@
102 clean:
103 $(RM) -r trash/*.log trash/*.code test-bin-$(RUBY_VERSION)
105 .PHONY: $(T) clean