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