blob: 269f5d58ddbc1c9e425d7afd772b182694e5e6eb [file] [log] [blame]
Magnus Ihse Bursieb826ae72017-03-03 12:57:57 +01001#
2# Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
3# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4#
5# This code is free software; you can redistribute it and/or modify it
6# under the terms of the GNU General Public License version 2 only, as
7# published by the Free Software Foundation. Oracle designates this
8# particular file as subject to the "Classpath" exception as provided
9# by Oracle in the LICENSE file that accompanied this code.
10#
11# This code is distributed in the hope that it will be useful, but WITHOUT
12# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14# version 2 for more details (a copy is included in the LICENSE file that
15# accompanied this code).
16#
17# You should have received a copy of the GNU General Public License version
18# 2 along with this work; if not, write to the Free Software Foundation,
19# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20#
21# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22# or visit www.oracle.com if you need additional information or have any
23# questions.
24#
25
26default: all
27
28include $(SPEC)
29include MakeBase.gmk
30include FindTests.gmk
31
32# We will always run multiple tests serially
33.NOTPARALLEL:
34
35# Hook to include the corresponding custom file, if present.
Magnus Ihse Bursie5f7dcca2017-10-05 12:41:06 +020036$(eval $(call IncludeCustomExtension, RunTests.gmk))
Magnus Ihse Bursieb826ae72017-03-03 12:57:57 +010037
Magnus Ihse Bursiee84be602017-09-25 10:32:00 +020038TEST_RESULTS_DIR := $(OUTPUTDIR)/test-results
39TEST_SUPPORT_DIR := $(OUTPUTDIR)/test-support
Magnus Ihse Bursieb826ae72017-03-03 12:57:57 +010040
Magnus Ihse Bursie2add8092017-11-27 19:11:45 +010041ifeq ($(CUSTOM_ROOT), )
42 JTREG_TOPDIR := $(TOPDIR)
43else
44 JTREG_TOPDIR := $(CUSTOM_ROOT)
45endif
Magnus Ihse Bursieb826ae72017-03-03 12:57:57 +010046
47################################################################################
48# Parse control variables
49################################################################################
50
51$(eval $(call ParseKeywordVariable, JTREG, \
52 KEYWORDS := JOBS TIMEOUT TEST_MODE ASSERT VERBOSE RETAIN MAX_MEM, \
53 STRING_KEYWORDS := OPTIONS JAVA_OPTIONS VM_OPTIONS, \
54))
55
56ifneq ($(JTREG), )
57 # Inform the user
58 $(info Running tests using JTREG control variable '$(JTREG)')
59endif
60
61$(eval $(call ParseKeywordVariable, GTEST, \
62 KEYWORDS := REPEAT, \
63 STRING_KEYWORDS := OPTIONS, \
64))
65
66ifneq ($(GTEST), )
67 # Inform the user
68 $(info Running tests using GTEST control variable '$(GTEST)')
69endif
70
71
72################################################################################
73# Component-specific Jtreg settings
74################################################################################
75
76ifeq ($(TEST_JOBS), 0)
77 # If TEST_JOBS is not specified, hotspot fallback default is
78 # min(num_cores / 2, 12).
79 hotspot_JTREG_JOBS := $(shell $(EXPR) $(NUM_CORES) / 2)
80 ifeq ($(hotspot_JTREG_JOBS), 0)
81 hotspot_JTREG_JOBS := 1
82 else ifeq ($(shell $(EXPR) $(hotspot_JTREG_JOBS) \> 12), 1)
83 hotspot_JTREG_JOBS := 12
84 endif
85endif
86
87hotspot_JTREG_MAX_MEM := 0
88hotspot_JTREG_ASSERT := false
89hotspot_JTREG_NATIVEPATH := $(TEST_IMAGE_DIR)/hotspot/jtreg/native
90jdk_JTREG_NATIVEPATH := $(TEST_IMAGE_DIR)/jdk/jtreg/native
91
92
93################################################################################
94# Parse test selection
95#
96# The user has given a test selection in the TEST variable. We must parse it
97# and determine what that means in terms of actual calls to the test framework.
98#
99# The parse functions take as argument a test specification as given by the
100# user, and returns a fully qualified test descriptor if it was a match, or
101# nothing if not. A single test specification can result in multiple test
102# descriptors being returned. A valid test descriptor must always be accepted
103# and returned identically.
104################################################################################
105
106# Helper function to determine if a test specification is a Gtest test
107#
108# It is a Gtest test if it is either "gtest", or "gtest:" followed by an optional
109# test filter string.
110define ParseGtestTestSelection
111 $(if $(filter gtest%, $1), \
112 $(if $(filter gtest, $1), \
113 gtest:all \
114 , \
115 $(if $(filter gtest:, $1), \
116 gtest:all \
117 , \
118 $1 \
119 ) \
120 ) \
121 )
122endef
123
Magnus Ihse Bursie2add8092017-11-27 19:11:45 +0100124# Helper function that removes the TOPDIR part
125CleanupJtregPath = \
126 $(strip $(patsubst %/, %, $(subst $(JTREG_TOPDIR)/,, $1)))
127
Magnus Ihse Bursie97325142017-11-24 09:21:38 +0100128# Take a partial Jtreg root path and return a full, absolute path to that Jtreg
129# root. Also support having "hotspot" as an alias for "hotspot/jtreg".
130ExpandJtregRoot = \
Magnus Ihse Bursie2add8092017-11-27 19:11:45 +0100131 $(call CleanupJtregPath, $(wildcard \
Magnus Ihse Bursie97325142017-11-24 09:21:38 +0100132 $(if $(filter /%, $1), \
Magnus Ihse Bursie2add8092017-11-27 19:11:45 +0100133 $(if $(wildcard $(strip $1)/TEST.ROOT), \
134 $1 \
135 ) \
Magnus Ihse Bursie97325142017-11-24 09:21:38 +0100136 , \
137 $(filter $(addprefix %, $1), $(JTREG_TESTROOTS) $(addsuffix /, $(JTREG_TESTROOTS))) \
138 $(filter $(addprefix %, $(strip $1)/jtreg), $(JTREG_TESTROOTS) $(addsuffix /, $(JTREG_TESTROOTS))) \
139 ) \
Magnus Ihse Bursie2add8092017-11-27 19:11:45 +0100140 ))
Magnus Ihse Bursie97325142017-11-24 09:21:38 +0100141
142# Take a partial Jtreg test path and return a full, absolute path to that Jtreg
143# test. Also support having "hotspot" as an alias for "hotspot/jtreg".
144ExpandJtregPath = \
145 $(if $(call ExpandJtregRoot, $1), \
146 $(call ExpandJtregRoot, $1) \
147 , \
Magnus Ihse Bursie2add8092017-11-27 19:11:45 +0100148 $(call CleanupJtregPath, $(wildcard \
Magnus Ihse Bursie97325142017-11-24 09:21:38 +0100149 $(if $(filter /%, $1), \
150 $1 \
151 , \
152 $(addsuffix /$(strip $1), $(JTREG_TESTROOTS) $(TEST_BASEDIRS)) \
153 $(addsuffix $(strip $(patsubst hotspot/%, /hotspot/jtreg/%, $1)), $(JTREG_TESTROOTS) $(TEST_BASEDIRS)) \
154 ) \
Magnus Ihse Bursie2add8092017-11-27 19:11:45 +0100155 )) \
Magnus Ihse Bursie97325142017-11-24 09:21:38 +0100156 )
157
Magnus Ihse Bursieb826ae72017-03-03 12:57:57 +0100158# Helper function to determine if a test specification is a Jtreg test
159#
160# It is a Jtreg test if it optionally begins with jtreg:, and then is either
161# an unspecified group name (possibly prefixed by :), or a group in a
Magnus Ihse Bursie97325142017-11-24 09:21:38 +0100162# specified test root, or a path to a test or test directory,
163# either absolute or relative to any of the TEST_BASEDIRS or test roots.
Magnus Ihse Bursieb826ae72017-03-03 12:57:57 +0100164define ParseJtregTestSelection
165 $(eval TEST_NAME := $(strip $(patsubst jtreg:%, %, $1))) \
166 $(if $(or $(findstring :, $(TEST_NAME)), $(findstring /, $(TEST_NAME))), , \
167 $(eval TEST_NAME := :$(TEST_NAME)) \
168 ) \
169 $(if $(findstring :, $(TEST_NAME)), \
170 $(if $(filter :%, $(TEST_NAME)), \
Magnus Ihse Bursie97325142017-11-24 09:21:38 +0100171 $(eval TEST_GROUP := $(patsubst :%, %, $(TEST_NAME))) \
172 $(eval TEST_ROOTS := $(JTREG_TESTROOTS)) \
Magnus Ihse Bursieb826ae72017-03-03 12:57:57 +0100173 , \
Magnus Ihse Bursie97325142017-11-24 09:21:38 +0100174 $(eval TEST_PATH := $(word 1, $(subst :, $(SPACE), $(TEST_NAME)))) \
175 $(eval TEST_GROUP := $(word 2, $(subst :, $(SPACE), $(TEST_NAME)))) \
176 $(eval TEST_ROOTS := $(call ExpandJtregRoot, $(TEST_PATH))) \
177 ) \
178 $(foreach test_root, $(TEST_ROOTS), \
Magnus Ihse Bursie2add8092017-11-27 19:11:45 +0100179 $(if $(filter /%, $(test_root)), \
Magnus Ihse Bursie97325142017-11-24 09:21:38 +0100180 jtreg:$(test_root):$(TEST_GROUP) \
Magnus Ihse Bursie2add8092017-11-27 19:11:45 +0100181 , \
182 $(if $(filter $(TEST_GROUP), $($(JTREG_TOPDIR)/$(test_root)_JTREG_TEST_GROUPS)), \
183 jtreg:$(test_root):$(TEST_GROUP) \
184 ) \
Magnus Ihse Bursieb826ae72017-03-03 12:57:57 +0100185 ) \
186 ) \
187 , \
Magnus Ihse Bursie2add8092017-11-27 19:11:45 +0100188 $(eval TEST_PATHS := $(call ExpandJtregPath, $(TEST_NAME))) \
189 $(foreach test_path, $(TEST_PATHS), \
190 jtreg:$(test_path) \
Magnus Ihse Bursieb826ae72017-03-03 12:57:57 +0100191 ) \
192 )
193endef
194
195ifeq ($(TEST), )
196 $(info No test selection given in TEST!)
197 $(info Please use e.g. 'run-test TEST=tier1' or 'run-test-tier1')
Magnus Ihse Bursie7e434552017-11-23 13:24:40 +0100198 $(info See doc/testing.[md|html] for help)
Magnus Ihse Bursieb826ae72017-03-03 12:57:57 +0100199 $(error Cannot continue)
200endif
201
202# Now intelligently convert the test selection given by the user in TEST
203# into a list of fully qualified test descriptors of the tests to run.
204TESTS_TO_RUN :=
205$(foreach test, $(TEST), \
206 $(eval PARSED_TESTS := $(call ParseCustomTestSelection, $(test))) \
207 $(if $(strip $(PARSED_TESTS)), , \
208 $(eval PARSED_TESTS += $(call ParseGtestTestSelection, $(test))) \
209 ) \
210 $(if $(strip $(PARSED_TESTS)), , \
211 $(eval PARSED_TESTS += $(call ParseJtregTestSelection, $(test))) \
212 ) \
213 $(if $(strip $(PARSED_TESTS)), , \
214 $(eval UNKNOWN_TEST := $(test)) \
215 ) \
216 $(eval TESTS_TO_RUN += $(PARSED_TESTS)) \
217)
218
219ifneq ($(UNKNOWN_TEST), )
220 $(info Unknown test selection: '$(UNKNOWN_TEST)')
Magnus Ihse Bursie7e434552017-11-23 13:24:40 +0100221 $(info See doc/testing.[md|html] for help)
Magnus Ihse Bursieb826ae72017-03-03 12:57:57 +0100222 $(error Cannot continue)
223endif
224
225TESTS_TO_RUN := $(strip $(TESTS_TO_RUN))
226
227
228# Present the result of our parsing to the user
229$(info Test selection '$(TEST)', will run:)
230$(foreach test, $(TESTS_TO_RUN), $(info * $(test)))
231
232
233################################################################################
234# Functions for setting up rules for running the selected tests
235#
236# The SetupRun*Test functions all have the same interface:
237#
238# Parameter 1 is the name of the rule. This is the test id, based on the test
239# descriptor, and this is also used as variable prefix, and the targets
240# generated are listed in a variable by that name.
241#
242# Remaining parameters are named arguments. Currently this is only:
243# TEST -- The properly formatted fully qualified test descriptor
244#
245# After the rule named by the test id has been executed, the following
246# variables will be available:
247# testid_TOTAL - the total number of tests run
248# testid_PASSED - the number of successful tests
249# testid_FAILED - the number of failed tests
250# testid_ERROR - the number of tests was neither successful or failed
251#
252################################################################################
253
254### Rules for Gtest
255
256SetupRunGtestTest = $(NamedParamsMacroTemplate)
257define SetupRunGtestTestBody
258 $1_TEST_RESULTS_DIR := $$(TEST_RESULTS_DIR)/$1
259 $1_TEST_SUPPORT_DIR := $$(TEST_SUPPORT_DIR)/$1
260
261 $1_TEST_NAME := $$(strip $$(patsubst gtest:%, %, $$($1_TEST)))
262 ifneq ($$($1_TEST_NAME), all)
263 $1_GTEST_FILTER := --gtest_filter=$$($1_TEST_NAME)*
264 endif
265
266 ifneq ($$(GTEST_REPEAT), )
267 $1_GTEST_REPEAT :=--gtest_repeat=$$(GTEST_REPEAT)
268 endif
269
270 run-test-$1:
271 $$(call LogWarn)
272 $$(call LogWarn, Running test '$$($1_TEST)')
273 $$(call MakeDir, $$($1_TEST_RESULTS_DIR) $$($1_TEST_SUPPORT_DIR))
274 $$(call ExecuteWithLog, $$($1_TEST_SUPPORT_DIR)/gtest, \
275 $$(FIXPATH) $$(TEST_IMAGE_DIR)/hotspot/gtest/server/gtestLauncher \
276 -jdk $(JDK_IMAGE_DIR) $$($1_GTEST_FILTER) \
277 --gtest_output=xml:$$($1_TEST_RESULTS_DIR)/gtest.xml \
278 $$($1_GTEST_REPEAT) $$(GTEST_OPTIONS) \
279 > >($(TEE) $$($1_TEST_RESULTS_DIR)/gtest.txt) || true )
280
281 $1_RESULT_FILE := $$($1_TEST_RESULTS_DIR)/gtest.txt
282
283 parse-test-$1: run-test-$1
284 $$(call LogWarn, Finished running test '$$($1_TEST)')
285 $$(call LogWarn, Test report is stored in $$(strip \
286 $$(subst $$(TOPDIR)/, , $$($1_TEST_RESULTS_DIR))))
287 $$(eval $1_TOTAL := $$(shell $$(AWK) '/==========.* tests? from .* \
288 test cases? ran/ { print $$$$2 }' $$($1_RESULT_FILE)))
289 $$(eval $1_PASSED := $$(shell $$(AWK) '/\[ PASSED \] .* tests?./ \
290 { print $$$$4 }' $$($1_RESULT_FILE)))
291 $$(eval $1_FAILED := $$(shell $$(AWK) '/\[ FAILED \] .* tests?, \
292 listed below/ { print $$$$4 }' $$($1_RESULT_FILE)))
293 $$(if $$($1_FAILED), , $$(eval $1_FAILED := 0))
294 $$(eval $1_ERROR := $$(shell \
295 $$(EXPR) $$($1_TOTAL) - $$($1_PASSED) - $$($1_FAILED)))
296
297 $1: run-test-$1 parse-test-$1
298
299 TARGETS += $1
300endef
301
302################################################################################
303
304### Rules for Jtreg
305
306# Helper function for SetupRunJtregTest. Set a JTREG_* variable from, in order:
307# 1) Specified by user on command line
308# 2) Component-specific default
309# 3) Generic default
310#
311# Note: No spaces are allowed around the arguments.
312# Arg $1 The test ID (i.e. $1 in SetupRunJtregTest)
313# Arg $2 Base variable, e.g. JTREG_JOBS
314# Arg $3 The default value (optional)
315define SetJtregValue
316 ifneq ($$($2), )
317 $1_$2 := $$($2)
318 else
319 ifneq ($$($$($1_COMPONENT)_$2), )
320 $1_$2 := $$($$($1_COMPONENT)_$2)
321 else
322 ifneq ($3, )
323 $1_$2 := $3
324 endif
325 endif
326 endif
327endef
328
329SetupRunJtregTest = $(NamedParamsMacroTemplate)
330define SetupRunJtregTestBody
331 $1_TEST_RESULTS_DIR := $$(TEST_RESULTS_DIR)/$1
332 $1_TEST_SUPPORT_DIR := $$(TEST_SUPPORT_DIR)/$1
333
334 $1_TEST_NAME := $$(strip $$(patsubst jtreg:%, %, $$($1_TEST)))
Magnus Ihse Bursie97325142017-11-24 09:21:38 +0100335
336 $1_COMPONENT := \
337 $$(strip $$(foreach root, $$(JTREG_TESTROOTS), \
Magnus Ihse Bursie2add8092017-11-27 19:11:45 +0100338 $$(if $$(filter $$(root)%, $$(JTREG_TOPDIR)/$$($1_TEST_NAME)), \
Magnus Ihse Bursie97325142017-11-24 09:21:38 +0100339 $$(lastword $$(subst /, $$(SPACE), $$(root))) \
340 ) \
341 ))
342 # This will work only as long as just hotspot has the additional "jtreg" directory
343 ifeq ($$($1_COMPONENT), jtreg)
344 $1_COMPONENT := hotspot
345 endif
Magnus Ihse Bursieb826ae72017-03-03 12:57:57 +0100346
Magnus Ihse Bursie3cd66ee2017-05-12 19:11:14 +0200347 ifeq ($$(JT_HOME), )
348 $$(info Error: jtreg framework is not found.)
349 $$(info Please run configure using --with-jtreg.)
350 $$(error Cannot continue)
351 endif
352
Magnus Ihse Bursieb826ae72017-03-03 12:57:57 +0100353 # Unfortunately, we need different defaults for some JTREG values,
354 # depending on what component we're running.
355
356 # Convert JTREG_foo into $1_JTREG_foo with a suitable value.
357 $$(eval $$(call SetJtregValue,$1,JTREG_TEST_MODE,agentvm))
358 $$(eval $$(call SetJtregValue,$1,JTREG_ASSERT,true))
359 $$(eval $$(call SetJtregValue,$1,JTREG_MAX_MEM,512m))
360 $$(eval $$(call SetJtregValue,$1,JTREG_NATIVEPATH))
361 $$(eval $$(call SetJtregValue,$1,JTREG_BASIC_OPTIONS))
362
363 ifneq ($(TEST_JOBS), 0)
364 # User has specified TEST_JOBS, use that as fallback default
365 $$(eval $$(call SetJtregValue,$1,JTREG_JOBS,$$(TEST_JOBS)))
366 else
367 # Use JOBS as default (except for hotspot)
368 $$(eval $$(call SetJtregValue,$1,JTREG_JOBS,$$(JOBS)))
369 endif
370
Bob Vandetted74f4e62017-08-29 15:52:59 -0400371 # Make sure MaxRAMPercentage is high enough to not cause OOM or swapping since
Magnus Ihse Bursieb826ae72017-03-03 12:57:57 +0100372 # we may end up with a lot of JVM's
Bob Vandetted74f4e62017-08-29 15:52:59 -0400373 $1_JTREG_MAX_RAM_PERCENTAGE := $$(shell $$(EXPR) 25 / $$($1_JTREG_JOBS))
Magnus Ihse Bursieb826ae72017-03-03 12:57:57 +0100374
375 JTREG_TIMEOUT ?= 4
376 JTREG_VERBOSE ?= fail,error,summary
377 JTREG_RETAIN ?= fail,error
378
379 ifneq ($$($1_JTREG_MAX_MEM), 0)
380 $1_JTREG_BASIC_OPTIONS += -vmoption:-Xmx$$($1_JTREG_MAX_MEM)
381 $1_JTREG_LAUNCHER_OPTIONS += -Xmx$$($1_JTREG_MAX_MEM)
382 endif
383
384 $1_JTREG_BASIC_OPTIONS += -$$($1_JTREG_TEST_MODE) \
385 -verbose:$$(JTREG_VERBOSE) -retain:$$(JTREG_RETAIN) \
386 -concurrency:$$($1_JTREG_JOBS) -timeoutFactor:$$(JTREG_TIMEOUT) \
Bob Vandetted74f4e62017-08-29 15:52:59 -0400387 -vmoption:-XX:MaxRAMPercentage=$$($1_JTREG_MAX_RAM_PERCENTAGE)
Magnus Ihse Bursieb826ae72017-03-03 12:57:57 +0100388
389 $1_JTREG_BASIC_OPTIONS += -automatic -keywords:\!ignore -ignore:quiet
390
Christian Tornqvist269a6e72017-10-11 16:14:47 -0400391 # Make it possible to specify the JIB_DATA_DIR for tests using the
392 # JIB Artifact resolver
393 $1_JTREG_BASIC_OPTIONS += -e:JIB_DATA_DIR
Magnus Ihse Bursieb826ae72017-03-03 12:57:57 +0100394 # Some tests needs to find a boot JDK using the JDK8_HOME variable.
395 $1_JTREG_BASIC_OPTIONS += -e:JDK8_HOME=$$(BOOT_JDK)
396
397 $1_JTREG_BASIC_OPTIONS += \
398 $$(addprefix -javaoption:, $$(JTREG_JAVA_OPTIONS)) \
399 $$(addprefix -vmoption:, $$(JTREG_VM_OPTIONS)) \
400 #
401
402 ifeq ($$($1_JTREG_ASSERT), true)
403 $1_JTREG_BASIC_OPTIONS += -ea -esa
404 endif
405
406 ifneq ($$($1_JTREG_NATIVEPATH), )
407 $1_JTREG_BASIC_OPTIONS += -nativepath:$$($1_JTREG_NATIVEPATH)
408 endif
409
Erik Joelsson3a52bbe2017-06-15 10:27:28 +0200410 ifneq ($$(JIB_JAR), )
411 $1_JTREG_BASIC_OPTIONS += -cpa:$$(JIB_JAR)
412 endif
413
Magnus Ihse Bursieb826ae72017-03-03 12:57:57 +0100414 run-test-$1:
415 $$(call LogWarn)
416 $$(call LogWarn, Running test '$$($1_TEST)')
417 $$(call MakeDir, $$($1_TEST_RESULTS_DIR) $$($1_TEST_SUPPORT_DIR))
418 $$(call ExecuteWithLog, $$($1_TEST_SUPPORT_DIR)/jtreg, \
419 $$(JAVA) $$($1_JTREG_LAUNCHER_OPTIONS) \
420 -Dprogram=jtreg -jar $$(JT_HOME)/lib/jtreg.jar \
421 $$($1_JTREG_BASIC_OPTIONS) \
422 -testjdk:$$(JDK_IMAGE_DIR) \
Magnus Ihse Bursie2add8092017-11-27 19:11:45 +0100423 -dir:$$(JTREG_TOPDIR) \
Magnus Ihse Bursieb826ae72017-03-03 12:57:57 +0100424 -reportDir:$$($1_TEST_RESULTS_DIR) \
425 -workDir:$$($1_TEST_SUPPORT_DIR) \
426 $$(JTREG_OPTIONS) \
427 $$($1_TEST_NAME) || true )
428
429 $1_RESULT_FILE := $$($1_TEST_RESULTS_DIR)/text/stats.txt
430
431 parse-test-$1: run-test-$1
432 $$(call LogWarn, Finished running test '$$($1_TEST)')
433 $$(call LogWarn, Test report is stored in $$(strip \
434 $$(subst $$(TOPDIR)/, , $$($1_TEST_RESULTS_DIR))))
Magnus Ihse Bursie6beed6f2017-09-25 11:52:40 +0200435 $$(if $$(wildcard $$($1_RESULT_FILE)), \
436 $$(eval $1_PASSED := $$(shell $$(AWK) '{ gsub(/[,;]/, ""); \
437 for (i=1; i<=NF; i++) { if ($$$$i == "passed:") \
438 print $$$$(i+1) } }' $$($1_RESULT_FILE))) \
439 $$(if $$($1_PASSED), , $$(eval $1_PASSED := 0)) \
440 $$(eval $1_FAILED := $$(shell $$(AWK) '{gsub(/[,;]/, ""); \
441 for (i=1; i<=NF; i++) { if ($$$$i == "failed:") \
442 print $$$$(i+1) } }' $$($1_RESULT_FILE))) \
443 $$(if $$($1_FAILED), , $$(eval $1_FAILED := 0)) \
444 $$(eval $1_ERROR := $$(shell $$(AWK) '{gsub(/[,;]/, ""); \
445 for (i=1; i<=NF; i++) { if ($$$$i == "error:") \
446 print $$$$(i+1) } }' $$($1_RESULT_FILE))) \
447 $$(if $$($1_ERROR), , $$(eval $1_ERROR := 0)) \
448 $$(eval $1_TOTAL := $$(shell \
449 $$(EXPR) $$($1_PASSED) + $$($1_FAILED) + $$($1_ERROR))) \
450 , \
451 $$(eval $1_PASSED := 0) \
452 $$(eval $1_FAILED := 0) \
453 $$(eval $1_ERROR := 1) \
454 $$(eval $1_TOTAL := 1) \
455 )
Magnus Ihse Bursieb826ae72017-03-03 12:57:57 +0100456
457 $1: run-test-$1 parse-test-$1
458
459 TARGETS += $1
460endef
461
462
463################################################################################
464# Setup and execute make rules for all selected tests
465################################################################################
466
467# Helper function to determine which handler to use for the given test
468UseGtestTestHandler = \
469 $(if $(filter gtest:%, $1), true)
470
471UseJtregTestHandler = \
472 $(if $(filter jtreg:%, $1), true)
473
474# Now process each test to run and setup a proper make rule
475$(foreach test, $(TESTS_TO_RUN), \
476 $(eval TEST_ID := $(shell $(ECHO) $(strip $(test)) | \
477 $(TR) -cs '[a-z][A-Z][0-9]\n' '_')) \
478 $(eval ALL_TEST_IDS += $(TEST_ID)) \
479 $(if $(call UseCustomTestHandler, $(test)), \
480 $(eval $(call SetupRunCustomTest, $(TEST_ID), \
481 TEST := $(test), \
482 )) \
483 ) \
484 $(if $(call UseGtestTestHandler, $(test)), \
485 $(eval $(call SetupRunGtestTest, $(TEST_ID), \
486 TEST := $(test), \
487 )) \
488 ) \
489 $(if $(call UseJtregTestHandler, $(test)), \
490 $(eval $(call SetupRunJtregTest, $(TEST_ID), \
491 TEST := $(test), \
492 )) \
493 ) \
494)
495
496# Sort also removes duplicates, so if there is any we'll get fewer words.
497ifneq ($(words $(ALL_TEST_IDS)), $(words $(sort $(ALL_TEST_IDS))))
498 $(error Duplicate test specification)
499endif
500
501
502################################################################################
503# The main target for RunTests.gmk
504################################################################################
505
506# The SetupRun*Test functions have populated TARGETS.
507
508TEST_FAILURE := false
509
510run-test: $(TARGETS)
511 # Print a table of the result of all tests run and their result
512 $(ECHO)
513 $(ECHO) ==============================
514 $(ECHO) Test summary
515 $(ECHO) ==============================
516 $(PRINTF) "%2s %-49s %5s %5s %5s %5s %2s\n" " " TEST \
517 TOTAL PASS FAIL ERROR " "
518 $(foreach test, $(TESTS_TO_RUN), \
519 $(eval TEST_ID := $(shell $(ECHO) $(strip $(test)) | \
520 $(TR) -cs '[a-z][A-Z][0-9]\n' '_')) \
Magnus Ihse Bursie2add8092017-11-27 19:11:45 +0100521 $(eval NAME_PATTERN := $(shell $(ECHO) $(test) | $(TR) -c \\n _)) \
522 $(if $(filter __________________________________________________%, $(NAME_PATTERN)), \
523 $(eval TEST_NAME := ) \
524 $(PRINTF) "%2s %-49s\n" " " "$(test)" $(NEWLINE) \
525 , \
526 $(eval TEST_NAME := $(test)) \
527 ) \
Magnus Ihse Bursieb826ae72017-03-03 12:57:57 +0100528 $(if $(filter $($(TEST_ID)_PASSED), $($(TEST_ID)_TOTAL)), \
Magnus Ihse Bursie2add8092017-11-27 19:11:45 +0100529 $(PRINTF) "%2s %-49s %5d %5d %5d %5d %2s\n" " " "$(TEST_NAME)" \
Magnus Ihse Bursieb826ae72017-03-03 12:57:57 +0100530 $($(TEST_ID)_TOTAL) $($(TEST_ID)_PASSED) $($(TEST_ID)_FAILED) \
531 $($(TEST_ID)_ERROR) " " $(NEWLINE) \
532 , \
Magnus Ihse Bursie2add8092017-11-27 19:11:45 +0100533 $(PRINTF) "%2s %-49s %5d %5d %5d %5d %2s\n" ">>" "$(TEST_NAME)" \
Magnus Ihse Bursieb826ae72017-03-03 12:57:57 +0100534 $($(TEST_ID)_TOTAL) $($(TEST_ID)_PASSED) $($(TEST_ID)_FAILED) \
535 $($(TEST_ID)_ERROR) "<<" $(NEWLINE) \
536 $(eval TEST_FAILURE := true) \
537 ) \
538 )
539 $(ECHO) ==============================
540 $(if $(filter true, $(TEST_FAILURE)), \
541 $(ECHO) TEST FAILURE $(NEWLINE) \
542 $(TOUCH) $(MAKESUPPORT_OUTPUTDIR)/exit-with-error \
543 , \
544 $(ECHO) TEST SUCCESS \
545 )
546 $(ECHO)
547
548################################################################################
549
550all: run-test
551
552.PHONY: default all run-test $(TARGETS)