depend on Isolate ~> 2.0.2 for development
[rainbows.git] / t / GNUmakefile
blob81484a7977e0dd918d39c1aff9bc604f3f95d414
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 ($(RUBY_VERSION),)
15 $(error unable to detect RUBY_VERSION)
16 endif
18 ifeq ($(RUBYLIB),)
19 RUBYLIB := $(rainbows_lib)
20 else
21 RUBYLIB := $(rainbows_lib):$(RUBYLIB)
22 endif
23 export RUBYLIB RUBY_VERSION
25 models += WriterThreadPool
26 models += WriterThreadSpawn
27 models += ThreadPool
28 models += ThreadSpawn
29 models += Rev
30 models += EventMachine
31 models += NeverBlock
32 models += RevThreadSpawn
33 models += RevThreadPool
35 rp := )
36 ONENINE := $(shell case $(RUBY_VERSION) in 1.9.*$(rp) echo true;;esac)
37 ifeq ($(ONENINE),true)
38 models += Revactor
39 models += FiberSpawn
40 models += RevFiberSpawn
41 models += FiberPool
42 endif
43 all_models := $(models) Base
45 T = $(wildcard t[0-9][0-9][0-9][0-9]-*.sh)
47 MODEL_T := $(foreach m,$(all_models),$(addprefix $(m).,$(T)))
48 $(T): MODELS = $(models)
50 # some tests can be run with all models
51 t0000-simple-http.sh: MODELS = $(all_models)
52 t0001-unix-http.sh: MODELS = $(all_models)
53 t0002-graceful.sh: MODELS = $(all_models)
54 t0002-parser-error.sh: MODELS = $(all_models)
55 t0003-reopen-logs.sh: MODELS = $(all_models)
57 # recursively run per-model tests
58 # haven't figured out a good way to make make non-recursive here, yet...
59 $(T):
60 $(MAKE) $(foreach m,$(MODELS),$(addprefix $(m).,$@))
62 $(all_models):
63 $(MAKE) $(filter $@.%,$(MODEL_T))
65 all:: $(T)
67 # can't rely on "set -o pipefail" since we don't require bash or ksh93 :<
68 t_pfx = trash/$@-$(RUBY_VERSION)
69 TEST_OPTS =
70 # TRACER = strace -f -o $(t_pfx).strace -s 100000
71 # TRACER = /usr/bin/time -o $(t_pfx).time
73 ifdef V
74 ifeq ($(V),2)
75 TEST_OPTS += --trace
76 else
77 TEST_OPTS += --verbose
78 endif
79 endif
81 test-bin-$(RUBY_VERSION)/rainbows: ruby_bin = $(shell which $(RUBY))
82 test-bin-$(RUBY_VERSION)/rainbows: ../bin/rainbows
83 mkdir -p $(@D)
84 install -m 755 $^ $@.$(pid)
85 $(RUBY) -i -p -e '$$_.gsub!(%r{^#!.*$$},"#!$(ruby_bin)")' $@.$(pid)
86 mv $@.$(pid) $@
88 random_blob:
89 dd if=/dev/urandom bs=1M count=30 of=$@.$(pid)
90 mv $@.$(pid) $@
92 $(T): random_blob
94 dependencies := socat curl
95 deps := $(addprefix .dep+,$(dependencies))
96 $(deps): dep_bin = $(lastword $(subst +, ,$@))
97 $(deps):
98 @which $(dep_bin) > $@.$(pid) 2>/dev/null || :
99 @test -s $@.$(pid) || \
100 { echo >&2 "E '$(dep_bin)' not found in PATH=$(PATH)"; exit 1; }
101 @mv $@.$(pid) $@
102 dep: $(deps)
103 $(MAKE) -C .. isolate
105 $(MODEL_T): export model = $(firstword $(subst ., ,$@))
106 $(MODEL_T): script = $(subst $(model).,,$@)
107 $(MODEL_T): trash/.gitignore
108 $(MODEL_T): export RUBY := $(RUBY)
109 $(MODEL_T): export PATH := $(CURDIR)/test-bin-$(RUBY_VERSION):$(PATH)
110 $(MODEL_T): test-bin-$(RUBY_VERSION)/rainbows dep
111 $(TRACER) $(SHELL) $(SH_TEST_OPTS) $(script) $(TEST_OPTS)
113 trash/.gitignore:
114 mkdir -p $(@D)
115 echo '*' > $@
117 clean:
118 $(RM) -r trash/*.log trash/*.code test-bin-$(RUBY_VERSION)
120 .PHONY: $(T) clean