Ian Rogers | afd9acc | 2014-06-17 08:21:54 -0700 | [diff] [blame] | 1 | # |
| 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 Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 17 | ifndef ART_ANDROID_COMMON_TEST_MK |
| 18 | ART_ANDROID_COMMON_TEST_MK = true |
Ian Rogers | afd9acc | 2014-06-17 08:21:54 -0700 | [diff] [blame] | 19 | |
| 20 | include art/build/Android.common_path.mk |
| 21 | |
Dan Willemsen | cd8a057 | 2016-09-16 17:11:36 -0700 | [diff] [blame] | 22 | # Directory used for temporary test files on the host. |
Elliott Hughes | d566b08 | 2018-10-04 13:36:24 -0700 | [diff] [blame] | 23 | # Use a hash calculated from CWD and USER as one of the path |
Alex Light | dfee52f | 2018-01-04 06:44:27 -0800 | [diff] [blame] | 24 | # components for the test output. This should allow us to run tests from |
| 25 | # multiple repositories at the same time. |
Elliott Hughes | d566b08 | 2018-10-04 13:36:24 -0700 | [diff] [blame] | 26 | # We only take the first few characters to keep paths short. |
Colin Cross | 25accea | 2018-02-26 15:43:11 -0800 | [diff] [blame] | 27 | ART_TMPDIR := $(if $(TMPDIR),$(TMPDIR),/tmp) |
Elliott Hughes | d566b08 | 2018-10-04 13:36:24 -0700 | [diff] [blame] | 28 | ART_HOST_TEST_DIR := $(ART_TMPDIR)/test-art-$(shell echo $$CWD-${USER} | $(MD5SUM) | cut -c-5) |
Dan Willemsen | cd8a057 | 2016-09-16 17:11:36 -0700 | [diff] [blame] | 29 | |
Ian Rogers | afd9acc | 2014-06-17 08:21:54 -0700 | [diff] [blame] | 30 | # List of known broken tests that we won't attempt to execute. The test name must be the full |
| 31 | # rule name such as test-art-host-oat-optimizing-HelloWorld64. |
Mathieu Chartier | bdeb9b7 | 2015-01-07 17:42:07 -0800 | [diff] [blame] | 32 | ART_TEST_KNOWN_BROKEN := |
Ian Rogers | afd9acc | 2014-06-17 08:21:54 -0700 | [diff] [blame] | 33 | |
Nicolas Geoffray | f61b537 | 2014-06-25 14:35:34 +0100 | [diff] [blame] | 34 | # List of known failing tests that when executed won't cause test execution to not finish. |
| 35 | # The test name must be the full rule name such as test-art-host-oat-optimizing-HelloWorld64. |
| 36 | ART_TEST_KNOWN_FAILING := |
Ian Rogers | afd9acc | 2014-06-17 08:21:54 -0700 | [diff] [blame] | 37 | |
| 38 | # Keep going after encountering a test failure? |
Andreas Gampe | e7655c5 | 2014-07-24 21:41:06 -0700 | [diff] [blame] | 39 | ART_TEST_KEEP_GOING ?= true |
Ian Rogers | afd9acc | 2014-06-17 08:21:54 -0700 | [diff] [blame] | 40 | |
Alex Light | 91de25f | 2015-10-28 17:00:06 -0700 | [diff] [blame] | 41 | # Do you want run-test to be quieter? run-tests will only show output if they fail. |
| 42 | ART_TEST_QUIET ?= true |
| 43 | |
Ian Rogers | afd9acc | 2014-06-17 08:21:54 -0700 | [diff] [blame] | 44 | # Define the command run on test failure. $(1) is the name of the test. Executed by the shell. |
Roland Levillain | 984b081 | 2016-11-09 16:38:42 +0000 | [diff] [blame] | 45 | # If the test was a top-level make target (e.g. `test-art-host-gtest-codegen_test64`), the command |
| 46 | # fails with exit status 1 (returned by the last `grep` statement below). |
| 47 | # Otherwise (e.g., if the test was run as a prerequisite of a compound test command, such as |
| 48 | # `test-art-host-gtest-codegen_test`), the command does not fail, as this would break rules running |
| 49 | # ART_TEST_PREREQ_FINISHED as one of their actions, which expects *all* prerequisites *not* to fail. |
Ian Rogers | afd9acc | 2014-06-17 08:21:54 -0700 | [diff] [blame] | 50 | define ART_TEST_FAILED |
| 51 | ( [ -f $(ART_HOST_TEST_DIR)/skipped/$(1) ] || \ |
| 52 | (mkdir -p $(ART_HOST_TEST_DIR)/failed/ && touch $(ART_HOST_TEST_DIR)/failed/$(1) && \ |
| 53 | echo $(ART_TEST_KNOWN_FAILING) | grep -q $(1) \ |
| 54 | && (echo -e "$(1) \e[91mKNOWN FAILURE\e[0m") \ |
Roland Levillain | 984b081 | 2016-11-09 16:38:42 +0000 | [diff] [blame] | 55 | || (echo -e "$(1) \e[91mFAILED\e[0m" >&2; echo $(MAKECMDGOALS) | grep -q -v $(1)))) |
Ian Rogers | afd9acc | 2014-06-17 08:21:54 -0700 | [diff] [blame] | 56 | endef |
| 57 | |
Alex Light | 91de25f | 2015-10-28 17:00:06 -0700 | [diff] [blame] | 58 | ifeq ($(ART_TEST_QUIET),true) |
| 59 | ART_TEST_ANNOUNCE_PASS := ( true ) |
| 60 | ART_TEST_ANNOUNCE_RUN := ( true ) |
| 61 | ART_TEST_ANNOUNCE_SKIP_FAILURE := ( true ) |
| 62 | ART_TEST_ANNOUNCE_SKIP_BROKEN := ( true ) |
| 63 | else |
| 64 | # Note the use of '=' and not ':=' is intentional since these are actually functions. |
| 65 | ART_TEST_ANNOUNCE_PASS = ( echo -e "$(1) \e[92mPASSED\e[0m" ) |
| 66 | ART_TEST_ANNOUNCE_RUN = ( echo -e "$(1) \e[95mRUNNING\e[0m") |
| 67 | ART_TEST_ANNOUNCE_SKIP_FAILURE = ( echo -e "$(1) \e[93mSKIPPING DUE TO EARLIER FAILURE\e[0m" ) |
| 68 | ART_TEST_ANNOUNCE_SKIP_BROKEN = ( echo -e "$(1) \e[93mSKIPPING BROKEN TEST\e[0m" ) |
| 69 | endif |
| 70 | |
Ian Rogers | afd9acc | 2014-06-17 08:21:54 -0700 | [diff] [blame] | 71 | # Define the command run on test success. $(1) is the name of the test. Executed by the shell. |
| 72 | # The command checks prints "PASSED" then checks to see if this was a top-level make target (e.g. |
| 73 | # "mm test-art-host-oat-HelloWorld32"), if it was then it does nothing, otherwise it creates a file |
| 74 | # to be printed in the passing test summary. |
| 75 | define ART_TEST_PASSED |
Alex Light | 91de25f | 2015-10-28 17:00:06 -0700 | [diff] [blame] | 76 | ( $(call ART_TEST_ANNOUNCE_PASS,$(1)) && \ |
Ian Rogers | afd9acc | 2014-06-17 08:21:54 -0700 | [diff] [blame] | 77 | (echo $(MAKECMDGOALS) | grep -q $(1) || \ |
| 78 | (mkdir -p $(ART_HOST_TEST_DIR)/passed/ && touch $(ART_HOST_TEST_DIR)/passed/$(1)))) |
| 79 | endef |
| 80 | |
| 81 | # Define the command run on test success of multiple prerequisites. $(1) is the name of the test. |
| 82 | # When the test is a top-level make target then a summary of the ran tests is produced. Executed by |
| 83 | # the shell. |
| 84 | define ART_TEST_PREREQ_FINISHED |
| 85 | (echo -e "$(1) \e[32mCOMPLETE\e[0m" && \ |
| 86 | (echo $(MAKECMDGOALS) | grep -q -v $(1) || \ |
| 87 | (([ -d $(ART_HOST_TEST_DIR)/passed/ ] \ |
| 88 | && (echo -e "\e[92mPASSING TESTS\e[0m" && ls -1 $(ART_HOST_TEST_DIR)/passed/) \ |
| 89 | || (echo -e "\e[91mNO TESTS PASSED\e[0m")) && \ |
| 90 | ([ -d $(ART_HOST_TEST_DIR)/skipped/ ] \ |
| 91 | && (echo -e "\e[93mSKIPPED TESTS\e[0m" && ls -1 $(ART_HOST_TEST_DIR)/skipped/) \ |
| 92 | || (echo -e "\e[92mNO TESTS SKIPPED\e[0m")) && \ |
| 93 | ([ -d $(ART_HOST_TEST_DIR)/failed/ ] \ |
Ian Rogers | 5182915 | 2014-07-21 20:28:31 -0700 | [diff] [blame] | 94 | && (echo -e "\e[91mFAILING TESTS\e[0m" >&2 && ls -1 $(ART_HOST_TEST_DIR)/failed/ >&2) \ |
Ian Rogers | afd9acc | 2014-06-17 08:21:54 -0700 | [diff] [blame] | 95 | || (echo -e "\e[92mNO TESTS FAILED\e[0m")) \ |
| 96 | && ([ ! -d $(ART_HOST_TEST_DIR)/failed/ ] && rm -r $(ART_HOST_TEST_DIR) \ |
| 97 | || (rm -r $(ART_HOST_TEST_DIR) && false))))) |
| 98 | endef |
| 99 | |
| 100 | # Define the command executed by the shell ahead of running an art test. $(1) is the name of the |
| 101 | # test. |
| 102 | define ART_TEST_SKIP |
| 103 | ((echo $(ART_TEST_KNOWN_BROKEN) | grep -q -v $(1) \ |
| 104 | && ([ ! -d $(ART_HOST_TEST_DIR)/failed/ ] || [ $(ART_TEST_KEEP_GOING) = true ])\ |
Alex Light | 91de25f | 2015-10-28 17:00:06 -0700 | [diff] [blame] | 105 | && $(call ART_TEST_ANNOUNCE_RUN,$(1)) ) \ |
Ian Rogers | afd9acc | 2014-06-17 08:21:54 -0700 | [diff] [blame] | 106 | || ((mkdir -p $(ART_HOST_TEST_DIR)/skipped/ && touch $(ART_HOST_TEST_DIR)/skipped/$(1) \ |
| 107 | && ([ -d $(ART_HOST_TEST_DIR)/failed/ ] \ |
Alex Light | 91de25f | 2015-10-28 17:00:06 -0700 | [diff] [blame] | 108 | && $(call ART_TEST_ANNOUNCE_SKIP_FAILURE,$(1)) ) \ |
| 109 | || $(call ART_TEST_ANNOUNCE_SKIP_BROKEN,$(1)) ) && false)) |
Ian Rogers | afd9acc | 2014-06-17 08:21:54 -0700 | [diff] [blame] | 110 | endef |
| 111 | |
| 112 | # Create a build rule to create the dex file for a test. |
| 113 | # $(1): module prefix, e.g. art-test-dex |
| 114 | # $(2): input test directory in art/test, e.g. HelloWorld |
| 115 | # $(3): target output module path (default module path is used on host) |
| 116 | # $(4): additional dependencies |
Ian Rogers | 1a2f84e | 2014-07-07 16:05:18 -0700 | [diff] [blame] | 117 | # $(5): a make variable used to collate target dependencies, e.g ART_TEST_TARGET_OAT_HelloWorld_DEX |
| 118 | # $(6): a make variable used to collate host dependencies, e.g ART_TEST_HOST_OAT_HelloWorld_DEX |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 119 | # |
Colin Cross | 822cf6a | 2017-10-02 13:35:15 -0700 | [diff] [blame] | 120 | # If the input test directory contains a file called main.list, |
Richard Uhler | 4d57ecf | 2015-03-11 12:36:24 -0700 | [diff] [blame] | 121 | # then a multi-dex file is created passing main.list as the --main-dex-list |
Colin Cross | 822cf6a | 2017-10-02 13:35:15 -0700 | [diff] [blame] | 122 | # argument to dx. |
Ian Rogers | afd9acc | 2014-06-17 08:21:54 -0700 | [diff] [blame] | 123 | define build-art-test-dex |
| 124 | ifeq ($(ART_BUILD_TARGET),true) |
| 125 | include $(CLEAR_VARS) |
| 126 | LOCAL_MODULE := $(1)-$(2) |
| 127 | LOCAL_SRC_FILES := $(call all-java-files-under, $(2)) |
| 128 | LOCAL_NO_STANDARD_LIBRARIES := true |
| 129 | LOCAL_DEX_PREOPT := false |
| 130 | LOCAL_ADDITIONAL_DEPENDENCIES := art/build/Android.common_test.mk $(4) |
| 131 | LOCAL_MODULE_TAGS := tests |
| 132 | LOCAL_JAVA_LIBRARIES := $(TARGET_CORE_JARS) |
| 133 | LOCAL_MODULE_PATH := $(3) |
| 134 | LOCAL_DEX_PREOPT_IMAGE_LOCATION := $(TARGET_CORE_IMG_OUT) |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 135 | ifneq ($(wildcard $(LOCAL_PATH)/$(2)/main.list),) |
Colin Cross | 1c5143e | 2017-03-15 21:29:02 -0700 | [diff] [blame] | 136 | LOCAL_DX_FLAGS := --multi-dex --main-dex-list=$(LOCAL_PATH)/$(2)/main.list --minimal-main-dex |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 137 | endif |
Ian Rogers | afd9acc | 2014-06-17 08:21:54 -0700 | [diff] [blame] | 138 | include $(BUILD_JAVA_LIBRARY) |
Brian Carlstrom | 532714a | 2014-06-25 02:15:31 -0700 | [diff] [blame] | 139 | $(5) := $$(LOCAL_INSTALLED_MODULE) |
Ian Rogers | afd9acc | 2014-06-17 08:21:54 -0700 | [diff] [blame] | 140 | endif |
| 141 | ifeq ($(ART_BUILD_HOST),true) |
| 142 | include $(CLEAR_VARS) |
| 143 | LOCAL_MODULE := $(1)-$(2) |
| 144 | LOCAL_SRC_FILES := $(call all-java-files-under, $(2)) |
| 145 | LOCAL_NO_STANDARD_LIBRARIES := true |
| 146 | LOCAL_DEX_PREOPT := false |
| 147 | LOCAL_ADDITIONAL_DEPENDENCIES := art/build/Android.common_test.mk $(4) |
| 148 | LOCAL_JAVA_LIBRARIES := $(HOST_CORE_JARS) |
| 149 | LOCAL_DEX_PREOPT_IMAGE := $(HOST_CORE_IMG_LOCATION) |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 150 | ifneq ($(wildcard $(LOCAL_PATH)/$(2)/main.list),) |
Colin Cross | 1c5143e | 2017-03-15 21:29:02 -0700 | [diff] [blame] | 151 | LOCAL_DX_FLAGS := --multi-dex --main-dex-list=$(LOCAL_PATH)/$(2)/main.list --minimal-main-dex |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 152 | endif |
Ian Rogers | afd9acc | 2014-06-17 08:21:54 -0700 | [diff] [blame] | 153 | include $(BUILD_HOST_DALVIK_JAVA_LIBRARY) |
Ian Rogers | 1a2f84e | 2014-07-07 16:05:18 -0700 | [diff] [blame] | 154 | $(6) := $$(LOCAL_INSTALLED_MODULE) |
Ian Rogers | afd9acc | 2014-06-17 08:21:54 -0700 | [diff] [blame] | 155 | endif |
Ian Rogers | afd9acc | 2014-06-17 08:21:54 -0700 | [diff] [blame] | 156 | endef |
| 157 | |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 158 | endif # ART_ANDROID_COMMON_TEST_MK |