README: reference yahns
[zbatery.git] / t / GNUmakefile
blob0035d9a2db6a13e1fb53954c088952f05a173a62
1 # we can run tests in parallel with GNU make
3 all::
5 pid := $(shell echo $$PPID)
7 MRI = ruby
8 RUBY = ruby
9 zbatery_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 += XEpollThreadPool
26 models += Epoll
27 endif
28 models += WriterThreadPool
29 models += WriterThreadSpawn
30 models += ThreadPool
31 models += ThreadSpawn
32 models += Coolio
33 models += EventMachine
34 models += NeverBlock
36 ifeq ($(RUBY_ENGINE),ruby)
37 rp := )
38 ONENINE := $(shell case $(RUBY_VERSION) in 1.9.*$(rp) echo true;;esac)
39 ifeq ($(ONENINE),true)
40 models += Revactor
41 models += FiberSpawn
42 models += CoolioFiberSpawn
43 models += FiberPool
44 models += CoolioThreadSpawn
45 models += CoolioThreadPool
46 endif
47 endif
49 ifeq ($(RUBY_ENGINE),rbx)
50 models += ActorSpawn
51 endif
52 all_models := $(models) Base
54 T = $(wildcard t[0-9][0-9][0-9][0-9]-*.sh)
56 MODEL_T := $(foreach m,$(all_models),$(addprefix $(m).,$(T)))
57 $(T): MODELS = $(models)
59 # some tests can be run with all models
60 t0000-simple-http.sh: MODELS = $(all_models)
61 t0001-unix-http.sh: MODELS = $(all_models)
62 t0002-graceful.sh: MODELS = $(all_models)
63 t0002-parser-error.sh: MODELS = $(all_models)
64 t0003-reopen-logs.sh: MODELS = $(all_models)
66 # recursively run per-model tests
67 # haven't figured out a good way to make make non-recursive here, yet...
68 $(T):
69 $(MAKE) $(foreach m,$(MODELS),$(addprefix $(m).,$@))
71 $(all_models):
72 $(MAKE) $(filter $@.%,$(MODEL_T))
74 all:: $(T)
76 # can't rely on "set -o pipefail" since we don't require bash or ksh93 :<
77 t_pfx = trash/$@-$(RUBY_ENGINE)-$(RUBY_VERSION)
78 TEST_OPTS =
79 # TRACER = strace -f -o $(t_pfx).strace -s 100000
80 # TRACER = /usr/bin/time -o $(t_pfx).time
82 ifdef V
83 ifeq ($(V),2)
84 TEST_OPTS += --trace
85 else
86 TEST_OPTS += --verbose
87 endif
88 endif
90 bindir := $(CURDIR)/bin-$(RUBY_ENGINE)-$(RUBY_VERSION)
91 bin_zbatery := $(bindir)/zbatery
92 $(bin_zbatery): ruby_bin = $(shell which $(RUBY))
93 $(bin_zbatery): ../bin/zbatery
94 mkdir -p $(@D)
95 install -m 755 $^ $@.$(pid)
96 $(MRI) -i -p -e '$$_.gsub!(%r{^#!.*$$},"#!$(ruby_bin)")' $@.$(pid)
97 mv $@.$(pid) $@
99 random_blob:
100 dd if=/dev/urandom bs=1M count=30 of=$@.$(pid)
101 mv $@.$(pid) $@
103 $(T): random_blob
105 dependencies := socat curl
106 deps := $(addprefix .dep+,$(dependencies))
107 $(deps): dep_bin = $(lastword $(subst +, ,$@))
108 $(deps):
109 @which $(dep_bin) > $@.$(pid) 2>/dev/null || :
110 @test -s $@.$(pid) || \
111 { echo >&2 "E '$(dep_bin)' not found in PATH=$(PATH)"; exit 1; }
112 @mv $@.$(pid) $@
114 libs := tmp/isolate/$(RUBY_ENGINE)-$(RUBY_VERSION)/.libs
115 $(libs): test_isolate.rb
116 mkdir -p $(@D)
117 $(RUBY) $< > $@+
118 mv $@+ $@
119 t_deps := $(libs) $(deps) $(bin_zbatery) trash/.gitignore
120 $(T): $(t_deps)
122 $(MODEL_T): export model = $(firstword $(subst ., ,$@))
123 $(MODEL_T): script = $(subst $(model).,,$@)
124 $(MODEL_T): export RUBY := $(RUBY)
125 $(MODEL_T): export PATH := $(bindir):$(PATH)
126 $(MODEL_T): $(t_deps)
127 RUBYLIB=$(zbatery_lib):$$(cat $(libs)) \
128 $(TRACER) $(SHELL) $(SH_TEST_OPTS) $(script) $(TEST_OPTS)
130 trash/.gitignore:
131 mkdir -p $(@D)
132 echo '*' > $@
134 clean:
135 $(RM) -r trash/*.log trash/*.code $(bindir)
137 .PHONY: $(T) clean