-
Notifications
You must be signed in to change notification settings - Fork 684
/
GlowTestSupport.cmake
108 lines (98 loc) · 3.91 KB
/
GlowTestSupport.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# Copyright (c) Glow Contributors. See CONTRIBUTORS file.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# A function to add a test to be driven through the 'check' target.
# Unlike the 'test' target, the 'check' target rebuilds the executables
# before invoking the tests.
function(add_glow_test)
set(options OPTIONAL EXPENSIVE STRESS)
set(oneValueArgs NAME)
set(multiValueArgs COMMAND DEPENDS)
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}"
"${multiValueArgs}" ${ARGN})
if (NOT ARG_NAME)
list(GET ARG_UNPARSED_ARGUMENTS 0 ARG_NAME)
list(REMOVE_AT ARG_UNPARSED_ARGUMENTS 0)
endif()
if (NOT ARG_NAME)
message(FATAL_ERROR "Name mandatory")
endif()
if (NOT ARG_COMMAND)
set(ARG_COMMAND ${ARG_UNPARSED_ARGUMENTS})
endif()
if (NOT ARG_COMMAND)
message(FATAL_ERROR "Command mandatory")
endif()
list(GET ARG_COMMAND 0 TEST_EXEC)
list(APPEND ARG_DEPENDS ${TEST_EXEC})
set_property(GLOBAL APPEND PROPERTY GLOW_TEST_DEPENDS ${ARG_DEPENDS})
# Produce the specific test rule using the default built-in.
add_test(NAME ${ARG_NAME} COMMAND ${ARG_COMMAND})
# If the EXPENSIVE argument is passed, add the EXPENSIVE label to the test
# so that it will only be run with the other expensive tests with the
# ninja check_expensive command
if (ARG_EXPENSIVE)
set_property(TEST ${ARG_NAME} PROPERTY LABELS EXPENSIVE)
endif()
# If the STRESS argument is passed, add the STRESS label to the test so that
# it will only be run with the other expensive and stress tests with the ninja
# check_expensive_stress command
if (ARG_STRESS)
set_property(TEST ${ARG_NAME} PROPERTY LABELS STRESS)
endif()
endfunction()
# Adds a backend-parameterized test. These tests can be instantiated for any
# backend present in lib/Backends, and allow similar functionality to easily be
# tested across all defined backends.
function(add_backend_test)
set(options UNOPT EXPENSIVE STRESS)
set(oneValueArgs BACKEND TEST)
set(multiValueArgs PRIVATE)
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
set(test "${ARG_BACKEND}${ARG_TEST}")
set(SOURCES "${ARG_TEST}.cpp")
set(BLACKLIST_SOURCE "${GLOW_BACKENDS_DIR}/${ARG_BACKEND}/tests/${test}.cpp")
if(NOT EXISTS ${BLACKLIST_SOURCE})
return()
endif()
if (DEFINED "${ARG_BACKEND}_MAJOR_VERSION")
add_definitions(-D${ARG_BACKEND}_MAJOR_VERSION=${${ARG_BACKEND}_MAJOR_VERSION})
endif()
if (DEFINED "${ARG_BACKEND}_MINOR_VERSION")
add_definitions(-D${ARG_BACKEND}_MINOR_VERSION=${${ARG_BACKEND}_MINOR_VERSION})
endif()
list(APPEND SOURCES ${BLACKLIST_SOURCE})
add_executable("${test}" ${SOURCES})
target_compile_definitions("${test}" PRIVATE -DGLOW_TEST_BACKEND=${ARG_BACKEND})
target_link_libraries("${test}"
PRIVATE BackendTestUtils TestMain ${ARG_PRIVATE})
if(${ARG_EXPENSIVE})
set(ARG_EXPENSIVE EXPENSIVE)
else()
set(ARG_EXPENSIVE)
endif()
if(${ARG_STRESS})
set(ARG_STRESS STRESS)
set(STRESS_PREFIX "stress/")
else()
set(ARG_STRESS)
set(STRESS_PREFIX)
endif()
add_glow_test("${test}" ${ARG_EXPENSIVE} ${ARG_STRESS} ${GLOW_BINARY_DIR}/tests/${STRESS_PREFIX}${test} --gtest_output=xml:${test}.xml )
if (DEFINED "${ARG_BACKEND}_API_DIR")
target_include_directories("${test}" PRIVATE ${${ARG_BACKEND}_API_DIR})
endif()
if(${ARG_UNOPT})
list(APPEND UNOPT_TESTS ./tests/${STRESS_PREFIX}${test} -optimize-ir=false &&)
endif()
endfunction()