blob: 3d1f4343f1dcab9b2388166f283978f76ac3f411 [file] [log] [blame]
Ian Rogersafd9acc2014-06-17 08:21:54 -07001#
2# Copyright (C) 2011 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
Igor Murashkin37743352014-11-13 14:38:00 -080017ifndef ART_ANDROID_COMMON_TEST_MK
18ART_ANDROID_COMMON_TEST_MK = true
Ian Rogersafd9acc2014-06-17 08:21:54 -070019
20include art/build/Android.common_path.mk
21
Dan Willemsencd8a0572016-09-16 17:11:36 -070022# Directory used for temporary test files on the host.
23ifneq ($(TMPDIR),)
Colin Crossa82a1ac2016-10-04 23:06:16 +000024ART_HOST_TEST_DIR := $(TMPDIR)/test-art-$(shell echo $$PPID)
Dan Willemsencd8a0572016-09-16 17:11:36 -070025else
Alex Lightdfee52f2018-01-04 06:44:27 -080026# Use a BSD checksum calculated from PPID and USER as one of the path
27# components for the test output. This should allow us to run tests from
28# multiple repositories at the same time.
29ART_HOST_TEST_DIR := /tmp/test-art-$(shell echo $$PPID-${USER} | sum | cut -d ' ' -f1)
Dan Willemsencd8a0572016-09-16 17:11:36 -070030endif
31
Ian Rogersafd9acc2014-06-17 08:21:54 -070032# List of known broken tests that we won't attempt to execute. The test name must be the full
33# rule name such as test-art-host-oat-optimizing-HelloWorld64.
Mathieu Chartierbdeb9b72015-01-07 17:42:07 -080034ART_TEST_KNOWN_BROKEN :=
Ian Rogersafd9acc2014-06-17 08:21:54 -070035
Nicolas Geoffrayf61b5372014-06-25 14:35:34 +010036# List of known failing tests that when executed won't cause test execution to not finish.
37# The test name must be the full rule name such as test-art-host-oat-optimizing-HelloWorld64.
38ART_TEST_KNOWN_FAILING :=
Ian Rogersafd9acc2014-06-17 08:21:54 -070039
40# Keep going after encountering a test failure?
Andreas Gampee7655c52014-07-24 21:41:06 -070041ART_TEST_KEEP_GOING ?= true
Ian Rogersafd9acc2014-06-17 08:21:54 -070042
Alex Light91de25f2015-10-28 17:00:06 -070043# Do you want run-test to be quieter? run-tests will only show output if they fail.
44ART_TEST_QUIET ?= true
45
Ian Rogersafd9acc2014-06-17 08:21:54 -070046# Define the command run on test failure. $(1) is the name of the test. Executed by the shell.
Roland Levillain984b0812016-11-09 16:38:42 +000047# If the test was a top-level make target (e.g. `test-art-host-gtest-codegen_test64`), the command
48# fails with exit status 1 (returned by the last `grep` statement below).
49# Otherwise (e.g., if the test was run as a prerequisite of a compound test command, such as
50# `test-art-host-gtest-codegen_test`), the command does not fail, as this would break rules running
51# ART_TEST_PREREQ_FINISHED as one of their actions, which expects *all* prerequisites *not* to fail.
Ian Rogersafd9acc2014-06-17 08:21:54 -070052define ART_TEST_FAILED
53 ( [ -f $(ART_HOST_TEST_DIR)/skipped/$(1) ] || \
54 (mkdir -p $(ART_HOST_TEST_DIR)/failed/ && touch $(ART_HOST_TEST_DIR)/failed/$(1) && \
55 echo $(ART_TEST_KNOWN_FAILING) | grep -q $(1) \
56 && (echo -e "$(1) \e[91mKNOWN FAILURE\e[0m") \
Roland Levillain984b0812016-11-09 16:38:42 +000057 || (echo -e "$(1) \e[91mFAILED\e[0m" >&2; echo $(MAKECMDGOALS) | grep -q -v $(1))))
Ian Rogersafd9acc2014-06-17 08:21:54 -070058endef
59
Alex Light91de25f2015-10-28 17:00:06 -070060ifeq ($(ART_TEST_QUIET),true)
61 ART_TEST_ANNOUNCE_PASS := ( true )
62 ART_TEST_ANNOUNCE_RUN := ( true )
63 ART_TEST_ANNOUNCE_SKIP_FAILURE := ( true )
64 ART_TEST_ANNOUNCE_SKIP_BROKEN := ( true )
65else
66 # Note the use of '=' and not ':=' is intentional since these are actually functions.
67 ART_TEST_ANNOUNCE_PASS = ( echo -e "$(1) \e[92mPASSED\e[0m" )
68 ART_TEST_ANNOUNCE_RUN = ( echo -e "$(1) \e[95mRUNNING\e[0m")
69 ART_TEST_ANNOUNCE_SKIP_FAILURE = ( echo -e "$(1) \e[93mSKIPPING DUE TO EARLIER FAILURE\e[0m" )
70 ART_TEST_ANNOUNCE_SKIP_BROKEN = ( echo -e "$(1) \e[93mSKIPPING BROKEN TEST\e[0m" )
71endif
72
Ian Rogersafd9acc2014-06-17 08:21:54 -070073# Define the command run on test success. $(1) is the name of the test. Executed by the shell.
74# The command checks prints "PASSED" then checks to see if this was a top-level make target (e.g.
75# "mm test-art-host-oat-HelloWorld32"), if it was then it does nothing, otherwise it creates a file
76# to be printed in the passing test summary.
77define ART_TEST_PASSED
Alex Light91de25f2015-10-28 17:00:06 -070078 ( $(call ART_TEST_ANNOUNCE_PASS,$(1)) && \
Ian Rogersafd9acc2014-06-17 08:21:54 -070079 (echo $(MAKECMDGOALS) | grep -q $(1) || \
80 (mkdir -p $(ART_HOST_TEST_DIR)/passed/ && touch $(ART_HOST_TEST_DIR)/passed/$(1))))
81endef
82
83# Define the command run on test success of multiple prerequisites. $(1) is the name of the test.
84# When the test is a top-level make target then a summary of the ran tests is produced. Executed by
85# the shell.
86define ART_TEST_PREREQ_FINISHED
87 (echo -e "$(1) \e[32mCOMPLETE\e[0m" && \
88 (echo $(MAKECMDGOALS) | grep -q -v $(1) || \
89 (([ -d $(ART_HOST_TEST_DIR)/passed/ ] \
90 && (echo -e "\e[92mPASSING TESTS\e[0m" && ls -1 $(ART_HOST_TEST_DIR)/passed/) \
91 || (echo -e "\e[91mNO TESTS PASSED\e[0m")) && \
92 ([ -d $(ART_HOST_TEST_DIR)/skipped/ ] \
93 && (echo -e "\e[93mSKIPPED TESTS\e[0m" && ls -1 $(ART_HOST_TEST_DIR)/skipped/) \
94 || (echo -e "\e[92mNO TESTS SKIPPED\e[0m")) && \
95 ([ -d $(ART_HOST_TEST_DIR)/failed/ ] \
Ian Rogers51829152014-07-21 20:28:31 -070096 && (echo -e "\e[91mFAILING TESTS\e[0m" >&2 && ls -1 $(ART_HOST_TEST_DIR)/failed/ >&2) \
Ian Rogersafd9acc2014-06-17 08:21:54 -070097 || (echo -e "\e[92mNO TESTS FAILED\e[0m")) \
98 && ([ ! -d $(ART_HOST_TEST_DIR)/failed/ ] && rm -r $(ART_HOST_TEST_DIR) \
99 || (rm -r $(ART_HOST_TEST_DIR) && false)))))
100endef
101
102# Define the command executed by the shell ahead of running an art test. $(1) is the name of the
103# test.
104define ART_TEST_SKIP
105 ((echo $(ART_TEST_KNOWN_BROKEN) | grep -q -v $(1) \
106 && ([ ! -d $(ART_HOST_TEST_DIR)/failed/ ] || [ $(ART_TEST_KEEP_GOING) = true ])\
Alex Light91de25f2015-10-28 17:00:06 -0700107 && $(call ART_TEST_ANNOUNCE_RUN,$(1)) ) \
Ian Rogersafd9acc2014-06-17 08:21:54 -0700108 || ((mkdir -p $(ART_HOST_TEST_DIR)/skipped/ && touch $(ART_HOST_TEST_DIR)/skipped/$(1) \
109 && ([ -d $(ART_HOST_TEST_DIR)/failed/ ] \
Alex Light91de25f2015-10-28 17:00:06 -0700110 && $(call ART_TEST_ANNOUNCE_SKIP_FAILURE,$(1)) ) \
111 || $(call ART_TEST_ANNOUNCE_SKIP_BROKEN,$(1)) ) && false))
Ian Rogersafd9acc2014-06-17 08:21:54 -0700112endef
113
114# Create a build rule to create the dex file for a test.
115# $(1): module prefix, e.g. art-test-dex
116# $(2): input test directory in art/test, e.g. HelloWorld
117# $(3): target output module path (default module path is used on host)
118# $(4): additional dependencies
Ian Rogers1a2f84e2014-07-07 16:05:18 -0700119# $(5): a make variable used to collate target dependencies, e.g ART_TEST_TARGET_OAT_HelloWorld_DEX
120# $(6): a make variable used to collate host dependencies, e.g ART_TEST_HOST_OAT_HelloWorld_DEX
Richard Uhler66d874d2015-01-15 09:37:19 -0800121#
Colin Cross822cf6a2017-10-02 13:35:15 -0700122# If the input test directory contains a file called main.list,
Richard Uhler4d57ecf2015-03-11 12:36:24 -0700123# then a multi-dex file is created passing main.list as the --main-dex-list
Colin Cross822cf6a2017-10-02 13:35:15 -0700124# argument to dx.
Ian Rogersafd9acc2014-06-17 08:21:54 -0700125define build-art-test-dex
126 ifeq ($(ART_BUILD_TARGET),true)
127 include $(CLEAR_VARS)
128 LOCAL_MODULE := $(1)-$(2)
129 LOCAL_SRC_FILES := $(call all-java-files-under, $(2))
130 LOCAL_NO_STANDARD_LIBRARIES := true
131 LOCAL_DEX_PREOPT := false
132 LOCAL_ADDITIONAL_DEPENDENCIES := art/build/Android.common_test.mk $(4)
133 LOCAL_MODULE_TAGS := tests
134 LOCAL_JAVA_LIBRARIES := $(TARGET_CORE_JARS)
135 LOCAL_MODULE_PATH := $(3)
136 LOCAL_DEX_PREOPT_IMAGE_LOCATION := $(TARGET_CORE_IMG_OUT)
Richard Uhler66d874d2015-01-15 09:37:19 -0800137 ifneq ($(wildcard $(LOCAL_PATH)/$(2)/main.list),)
Colin Cross1c5143e2017-03-15 21:29:02 -0700138 LOCAL_DX_FLAGS := --multi-dex --main-dex-list=$(LOCAL_PATH)/$(2)/main.list --minimal-main-dex
Richard Uhler66d874d2015-01-15 09:37:19 -0800139 endif
Ian Rogersafd9acc2014-06-17 08:21:54 -0700140 include $(BUILD_JAVA_LIBRARY)
Brian Carlstrom532714a2014-06-25 02:15:31 -0700141 $(5) := $$(LOCAL_INSTALLED_MODULE)
Ian Rogersafd9acc2014-06-17 08:21:54 -0700142 endif
143 ifeq ($(ART_BUILD_HOST),true)
144 include $(CLEAR_VARS)
145 LOCAL_MODULE := $(1)-$(2)
146 LOCAL_SRC_FILES := $(call all-java-files-under, $(2))
147 LOCAL_NO_STANDARD_LIBRARIES := true
148 LOCAL_DEX_PREOPT := false
149 LOCAL_ADDITIONAL_DEPENDENCIES := art/build/Android.common_test.mk $(4)
150 LOCAL_JAVA_LIBRARIES := $(HOST_CORE_JARS)
151 LOCAL_DEX_PREOPT_IMAGE := $(HOST_CORE_IMG_LOCATION)
Richard Uhler66d874d2015-01-15 09:37:19 -0800152 ifneq ($(wildcard $(LOCAL_PATH)/$(2)/main.list),)
Colin Cross1c5143e2017-03-15 21:29:02 -0700153 LOCAL_DX_FLAGS := --multi-dex --main-dex-list=$(LOCAL_PATH)/$(2)/main.list --minimal-main-dex
Richard Uhler66d874d2015-01-15 09:37:19 -0800154 endif
Ian Rogersafd9acc2014-06-17 08:21:54 -0700155 include $(BUILD_HOST_DALVIK_JAVA_LIBRARY)
Ian Rogers1a2f84e2014-07-07 16:05:18 -0700156 $(6) := $$(LOCAL_INSTALLED_MODULE)
Ian Rogersafd9acc2014-06-17 08:21:54 -0700157 endif
Ian Rogersafd9acc2014-06-17 08:21:54 -0700158endef
159
Igor Murashkin37743352014-11-13 14:38:00 -0800160endif # ART_ANDROID_COMMON_TEST_MK