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