Update TODO
[rainbows.git] / t / GNUmakefile
blobec04607d0019a95b3faf0aaac6acf47792602135
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 = ThreadPool ThreadSpawn Rev EventMachine NeverBlock
26 rp := )
27 ONENINE := $(shell case $(RUBY_VERSION) in 1.9.*$(rp) echo true;;esac)
28 ifeq ($(ONENINE),true)
29 models += Revactor
30 models += FiberSpawn
31 models += FiberPool
33 # technically this works under 1.8, but wait until rev 0.3.2
34 models += RevThreadSpawn
35 models += RevThreadPool
36 endif
37 all_models := $(models) Base
39 T = $(wildcard t[0-9][0-9][0-9][0-9]-*.sh)
41 MODEL_T := $(foreach m,$(all_models),$(addprefix $(m).,$(T)))
42 $(T): MODELS = $(models)
44 # some tests can be run with all models
45 t0000-simple-http.sh: MODELS = $(all_models)
46 t0001-unix-http.sh: MODELS = $(all_models)
47 t0002-graceful.sh: MODELS = $(all_models)
48 t0002-parser-error.sh: MODELS = $(all_models)
49 t0003-reopen-logs.sh: MODELS = $(all_models)
51 # recursively run per-model tests
52 # haven't figured out a good way to make make non-recursive here, yet...
53 $(T):
54 $(MAKE) $(foreach m,$(MODELS),$(addprefix $(m).,$@))
56 $(all_models):
57 $(MAKE) $(filter $@.%,$(MODEL_T))
59 all:: $(T)
61 # can't rely on "set -o pipefail" since we don't require bash or ksh93 :<
62 t_pfx = trash/$@-$(RUBY_VERSION)
63 TEST_OPTS =
64 # TRACER = strace -f -o $(t_pfx).strace -s 100000
65 # TRACER = /usr/bin/time -o $(t_pfx).time
67 ifdef V
68 ifeq ($(V),2)
69 TEST_OPTS += --trace
70 else
71 TEST_OPTS += --verbose
72 endif
73 endif
75 test-bin-$(RUBY_VERSION)/rainbows: ruby_bin = $(shell which $(RUBY))
76 test-bin-$(RUBY_VERSION)/rainbows: ../bin/rainbows
77 mkdir -p $(@D)
78 install -m 755 $^ $@.$(pid)
79 $(RUBY) -i -p -e '$$_.gsub!(%r{^#!.*$$},"#!$(ruby_bin)")' $@.$(pid)
80 mv $@.$(pid) $@
82 random_blob:
83 dd if=/dev/urandom bs=1M count=30 of=$@.$(pid)
84 mv $@.$(pid) $@
86 $(T): random_blob
88 dependencies := socat curl
89 deps := $(addprefix .dep+,$(dependencies))
90 $(deps): dep_bin = $(lastword $(subst +, ,$@))
91 $(deps):
92 @which $(dep_bin) > $@.$(pid) 2>/dev/null || :
93 @test -s $@.$(pid) || \
94 { echo >&2 "E '$(dep_bin)' not found in PATH=$(PATH)"; exit 1; }
95 @mv $@.$(pid) $@
96 dep: $(deps)
98 $(MODEL_T): export model = $(firstword $(subst ., ,$@))
99 $(MODEL_T): script = $(subst $(model).,,$@)
100 $(MODEL_T): trash/.gitignore
101 $(MODEL_T): export RUBY := $(RUBY)
102 $(MODEL_T): export PATH := $(CURDIR)/test-bin-$(RUBY_VERSION):$(PATH)
103 $(MODEL_T): test-bin-$(RUBY_VERSION)/rainbows dep
104 $(TRACER) $(SHELL) $(SH_TEST_OPTS) $(script) $(TEST_OPTS)
106 trash/.gitignore:
107 mkdir -p $(@D)
108 echo '*' > $@
110 clean:
111 $(RM) -r trash/*.log trash/*.code test-bin-$(RUBY_VERSION)
113 .PHONY: $(T) clean