blob: 3a557b6d6501cbb2eb76250db3ee9b70812b1b9e [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.
Dan Willemsen01046062019-01-02 13:39:29 -080023# TMPDIR is always provided by the build system as $OUT_DIR-unique temporary directory.
24ART_HOST_TEST_DIR := $(TMPDIR)/test-art
Dan Willemsencd8a0572016-09-16 17:11:36 -070025
Ian Rogersafd9acc2014-06-17 08:21:54 -070026# List of known broken tests that we won't attempt to execute. The test name must be the full
27# rule name such as test-art-host-oat-optimizing-HelloWorld64.
Mathieu Chartierbdeb9b72015-01-07 17:42:07 -080028ART_TEST_KNOWN_BROKEN :=
Ian Rogersafd9acc2014-06-17 08:21:54 -070029
Nicolas Geoffrayf61b5372014-06-25 14:35:34 +010030# List of known failing tests that when executed won't cause test execution to not finish.
31# The test name must be the full rule name such as test-art-host-oat-optimizing-HelloWorld64.
32ART_TEST_KNOWN_FAILING :=
Ian Rogersafd9acc2014-06-17 08:21:54 -070033
34# Keep going after encountering a test failure?
Andreas Gampee7655c52014-07-24 21:41:06 -070035ART_TEST_KEEP_GOING ?= true
Ian Rogersafd9acc2014-06-17 08:21:54 -070036
Alex Light91de25f2015-10-28 17:00:06 -070037# Do you want run-test to be quieter? run-tests will only show output if they fail.
38ART_TEST_QUIET ?= true
39
Ian Rogersafd9acc2014-06-17 08:21:54 -070040# 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 +000041# If the test was a top-level make target (e.g. `test-art-host-gtest-codegen_test64`), the command
42# fails with exit status 1 (returned by the last `grep` statement below).
43# Otherwise (e.g., if the test was run as a prerequisite of a compound test command, such as
44# `test-art-host-gtest-codegen_test`), the command does not fail, as this would break rules running
45# ART_TEST_PREREQ_FINISHED as one of their actions, which expects *all* prerequisites *not* to fail.
Ian Rogersafd9acc2014-06-17 08:21:54 -070046define ART_TEST_FAILED
47 ( [ -f $(ART_HOST_TEST_DIR)/skipped/$(1) ] || \
48 (mkdir -p $(ART_HOST_TEST_DIR)/failed/ && touch $(ART_HOST_TEST_DIR)/failed/$(1) && \
49 echo $(ART_TEST_KNOWN_FAILING) | grep -q $(1) \
50 && (echo -e "$(1) \e[91mKNOWN FAILURE\e[0m") \
Roland Levillain984b0812016-11-09 16:38:42 +000051 || (echo -e "$(1) \e[91mFAILED\e[0m" >&2; echo $(MAKECMDGOALS) | grep -q -v $(1))))
Ian Rogersafd9acc2014-06-17 08:21:54 -070052endef
53
Alex Light91de25f2015-10-28 17:00:06 -070054ifeq ($(ART_TEST_QUIET),true)
55 ART_TEST_ANNOUNCE_PASS := ( true )
56 ART_TEST_ANNOUNCE_RUN := ( true )
57 ART_TEST_ANNOUNCE_SKIP_FAILURE := ( true )
58 ART_TEST_ANNOUNCE_SKIP_BROKEN := ( true )
59else
60 # Note the use of '=' and not ':=' is intentional since these are actually functions.
61 ART_TEST_ANNOUNCE_PASS = ( echo -e "$(1) \e[92mPASSED\e[0m" )
62 ART_TEST_ANNOUNCE_RUN = ( echo -e "$(1) \e[95mRUNNING\e[0m")
63 ART_TEST_ANNOUNCE_SKIP_FAILURE = ( echo -e "$(1) \e[93mSKIPPING DUE TO EARLIER FAILURE\e[0m" )
64 ART_TEST_ANNOUNCE_SKIP_BROKEN = ( echo -e "$(1) \e[93mSKIPPING BROKEN TEST\e[0m" )
65endif
66
Ian Rogersafd9acc2014-06-17 08:21:54 -070067# Define the command run on test success. $(1) is the name of the test. Executed by the shell.
68# The command checks prints "PASSED" then checks to see if this was a top-level make target (e.g.
69# "mm test-art-host-oat-HelloWorld32"), if it was then it does nothing, otherwise it creates a file
70# to be printed in the passing test summary.
71define ART_TEST_PASSED
Alex Light91de25f2015-10-28 17:00:06 -070072 ( $(call ART_TEST_ANNOUNCE_PASS,$(1)) && \
Ian Rogersafd9acc2014-06-17 08:21:54 -070073 (echo $(MAKECMDGOALS) | grep -q $(1) || \
74 (mkdir -p $(ART_HOST_TEST_DIR)/passed/ && touch $(ART_HOST_TEST_DIR)/passed/$(1))))
75endef
76
77# Define the command run on test success of multiple prerequisites. $(1) is the name of the test.
78# When the test is a top-level make target then a summary of the ran tests is produced. Executed by
79# the shell.
80define ART_TEST_PREREQ_FINISHED
81 (echo -e "$(1) \e[32mCOMPLETE\e[0m" && \
82 (echo $(MAKECMDGOALS) | grep -q -v $(1) || \
83 (([ -d $(ART_HOST_TEST_DIR)/passed/ ] \
84 && (echo -e "\e[92mPASSING TESTS\e[0m" && ls -1 $(ART_HOST_TEST_DIR)/passed/) \
85 || (echo -e "\e[91mNO TESTS PASSED\e[0m")) && \
86 ([ -d $(ART_HOST_TEST_DIR)/skipped/ ] \
87 && (echo -e "\e[93mSKIPPED TESTS\e[0m" && ls -1 $(ART_HOST_TEST_DIR)/skipped/) \
88 || (echo -e "\e[92mNO TESTS SKIPPED\e[0m")) && \
89 ([ -d $(ART_HOST_TEST_DIR)/failed/ ] \
Ian Rogers51829152014-07-21 20:28:31 -070090 && (echo -e "\e[91mFAILING TESTS\e[0m" >&2 && ls -1 $(ART_HOST_TEST_DIR)/failed/ >&2) \
Ian Rogersafd9acc2014-06-17 08:21:54 -070091 || (echo -e "\e[92mNO TESTS FAILED\e[0m")) \
92 && ([ ! -d $(ART_HOST_TEST_DIR)/failed/ ] && rm -r $(ART_HOST_TEST_DIR) \
93 || (rm -r $(ART_HOST_TEST_DIR) && false)))))
94endef
95
96# Define the command executed by the shell ahead of running an art test. $(1) is the name of the
97# test.
98define ART_TEST_SKIP
99 ((echo $(ART_TEST_KNOWN_BROKEN) | grep -q -v $(1) \
100 && ([ ! -d $(ART_HOST_TEST_DIR)/failed/ ] || [ $(ART_TEST_KEEP_GOING) = true ])\
Alex Light91de25f2015-10-28 17:00:06 -0700101 && $(call ART_TEST_ANNOUNCE_RUN,$(1)) ) \
Ian Rogersafd9acc2014-06-17 08:21:54 -0700102 || ((mkdir -p $(ART_HOST_TEST_DIR)/skipped/ && touch $(ART_HOST_TEST_DIR)/skipped/$(1) \
103 && ([ -d $(ART_HOST_TEST_DIR)/failed/ ] \
Alex Light91de25f2015-10-28 17:00:06 -0700104 && $(call ART_TEST_ANNOUNCE_SKIP_FAILURE,$(1)) ) \
105 || $(call ART_TEST_ANNOUNCE_SKIP_BROKEN,$(1)) ) && false))
Ian Rogersafd9acc2014-06-17 08:21:54 -0700106endef
107
Igor Murashkin37743352014-11-13 14:38:00 -0800108endif # ART_ANDROID_COMMON_TEST_MK