Skip to content

Commit

Permalink
Merge pull request #357 from frasercrmck/check-targets
Browse files Browse the repository at this point in the history
Conditionally rename check targets in an LLVM tree
  • Loading branch information
frasercrmck authored Feb 13, 2024
2 parents e4b39ac + 46c1295 commit 9b0922b
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 61 deletions.
23 changes: 15 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -318,17 +318,24 @@ add_to_group(ComputeAorta
UnitCL UnitCargo UnitCore UnitMux UnitCompiler UnitVK UnitMD FuzzCL
clVectorAddition vkVectorAddition veczc UnitUR urVectorAddition)

# Create a check-ComputeAorta target to build+test.
add_ca_check_group(ComputeAorta DEPENDS ComputeAorta check)
# Create a ComputeAorta check target to alias the global build+test check
# target.
add_ca_check_group(ComputeAorta NOGLOBAL
DEPENDS ${OCK_CHECK_TARGET} ComputeAorta)

# Create a check-tidy-ComputeAorta target to build+test+tidy.
add_ca_check_group(tidy-ComputeAorta DEPENDS check-ComputeAorta tidy)
# Create a tidy-ComputeAorta check target to build+test+tidy.
get_ock_check_name(check_ComputeAorta_name ComputeAorta)
add_ca_check_group(tidy-ComputeAorta NOGLOBAL
DEPENDS ${check_ComputeAorta_name} tidy)

if(CMAKE_CROSSCOMPILING)
# Create a check-cross-ComputeAorta target to build+test fast subset of checks.
add_ca_check_group(cross-ComputeAorta DEPENDS ComputeAorta
check-host-lit check-spirv-ll-lit check-vecz-lit check-UnitCargo
check-UnitMux check-UnitCL-offline)
# Create a cross-ComputeAorta check target to build+test fast subset of checks.
set(check_deps ComputeAorta)
foreach(target host-lit;spirv-ll-lit;vecz-lit;UnitCargo;UnitMux;UnitCL-offline)
get_ock_check_name(check_name ${target})
list(APPEND check_deps ${check_name})
endforeach()
add_ca_check_group(cross-ComputeAorta DEPENDS ${check_deps})
endif()

if(CA_ENABLE_TESTS)
Expand Down
115 changes: 79 additions & 36 deletions cmake/AddCA.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,23 @@ set(CA_CL_STANDARD_INTERNAL 300)
set(CA_CL_PLATFORM_VERSION_MAJOR 3)
set(CA_CL_PLATFORM_VERSION_MINOR 0)

# Set up a variable which both defines the global check target *and* the prefix
# with which all of our sub-check targets are named.
#
# This variable is usually `check` - `check`, `check-UnitCL`, etc., as that is
# familiar to most developers.
#
# However, if we build inside an LLVM tree, we define `check-ock` -
# `check-ock`, `check-ock-UnitCL`, etc. While we may wish to add our tests to
# the global set in an ideal world, LLVM calls into our code and then tries to
# unconditionally define a 'check' target. This errors if we have already
# created one.
if (NOT OCK_IN_LLVM_TREE)
set(OCK_CHECK_TARGET check)
else()
set(OCK_CHECK_TARGET check-ock)
endif()

if(NOT MSVC AND (CA_BUILD_32_BITS OR CMAKE_SIZEOF_VOID_P EQUAL 4) AND
(CMAKE_SYSTEM_PROCESSOR STREQUAL x86 OR
CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64 OR
Expand Down Expand Up @@ -689,24 +706,42 @@ endmacro()
# Add the check target to run all registered checks, see add_ca_check() below, if
# cmake:variable:`CA_ENABLE_TESTS` is enabled.
if (CA_ENABLE_TESTS)
add_custom_target(check COMMENT "ComputeAorta checks.")
add_custom_target(${OCK_CHECK_TARGET} COMMENT "ComputeAorta checks.")
endif()

if(CMAKE_CROSSCOMPILING AND NOT CMAKE_CROSSCOMPILING_EMULATOR)
message(WARNING "ComputeAorta check targets disabled as "
"CMAKE_CROSSCOMPILING_EMULATOR was not specified")
endif()

#[=======================================================================[.rst:
.. cmake:command:: get_ock_check_name
The ``get_ock_check_name`` function returns the name of a check target or
group defined with the provided ``$name`` component. This naming scheme is
used internally for naming all such targets and thus the final targets that
users can 'build' to run tests.
Arguments:
* ``check_name``: The name of the output variable to set the check name.
* ``name``: The check name component
#]=======================================================================]
function(get_ock_check_name check_name name)
set(${check_name} ${OCK_CHECK_TARGET}-${name} PARENT_SCOPE)
endfunction()

#[=======================================================================[.rst:
.. cmake:command:: add_ca_check
The ``add_ca_check()`` macro takes a list of arguments which form a command
to run a check. A new target called ``check-${name}`` is created and a
dependency for ``check-${name}`` is added to the check target. To run an
individual check build the ``check-${name}`` target and to run all checks
build the ``check`` target. All checks are executed with a working directory
of ``${PROJECT_SOURCE_DIR}`` and a comment of the form "Running ${name}
checks" is displayed by the build system during execution.
to run a check. A new target is created and a
dependency for that target is added to the project-level check target. The
name of the new target is determined by calling the ``get_ock_check_name``
function on the parameter ``${name}``. To run an individual check build the
specific target and to run all checks build the global check target. All
checks are executed with a working directory of ``${PROJECT_SOURCE_DIR}`` and
a comment of the form "Running ${name} checks" is displayed by the build
system during execution.
.. note::
Expand All @@ -715,14 +750,14 @@ endif()
Arguments:
* ``name`` - Target name suffix for the check, this will create a target
called ``check-${name}``.
named via ``get_ock_check_name(target ${name})``.
Keyword Arguments:
* ``NOEMULATE`` - Flag to specify that the first argument of the
``COMMAND`` should not be emulated using
:cmake-variable:`CMAKE_CROSSCOMPILING_EMULATOR`, this should be set if
the executable driving the check is not cross-compiled.
* ``NOGLOBAL`` - Flag to specify that ``check-${name}`` should not be added
* ``NOGLOBAL`` - Flag to specify that the target check should not be added
to the global check target.
* ``GTEST`` - Flag to specify that this check uses GoogleTest and that
:cmake-variable:`CA_GTEST_LAUNCHER` should be used, if set, to launch the
Expand Down Expand Up @@ -796,18 +831,19 @@ function(add_ca_check name)
# Add a custom target, which runs the test, to the test target, if
# cmake:variable:`CA_ENABLE_TESTS` is enabled.
if (CA_ENABLE_TESTS)
get_ock_check_name(check_name ${name})
if(args_USES_TERMINAL)
add_custom_target(check-${name}
add_custom_target(${check_name}
COMMAND ${command} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
USES_TERMINAL
DEPENDS ${args_DEPENDS} COMMENT "Running ${name} checks")
else()
add_custom_target(check-${name}
add_custom_target(${check_name}
COMMAND ${command} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
DEPENDS ${args_DEPENDS} COMMENT "Running ${name} checks")
endif()
if(NOT args_NOGLOBAL)
add_dependencies(check check-${name})
add_dependencies(${OCK_CHECK_TARGET} ${check_name})
endif()
endif()
if(CA_ENABLE_COVERAGE AND (CA_RUNTIME_COMPILER_ENABLED OR
Expand All @@ -824,8 +860,8 @@ endfunction()
The ``add_ca_check_group()`` function creates a named target for a group of
targets and/or checks, this is useful to setup check dependencies and for
having a single named check for a set of disparate test suites. As with
:cmake:command:`add_ca_check` the name is used to generate a target called
``check-${name}``.
:cmake:command:`add_ca_check` the name is used to generate a target named by
calling ``get_ock_check_name(target ${name})``.
.. note::
Expand All @@ -834,17 +870,19 @@ endfunction()
Arguments:
* ``name`` - Target name suffix for the check group, this will create a
target called ``check-${name}``.
target named by calling ``get_ock_check_name(target ${name})``.
Keyword Arguments:
* ``NOGLOBAL`` - Flag to specify that the new target should not be
added to the global check target.
* ``DEPENDS`` - A list of targets this check group will depends on, any
CMake target can be specified.
.. note::
The full target name including the ``check-`` prefix should be
The full target name including the global check prefix should be
specified for dependent check targets.
Here's an example:
Example:
.. code:: CMake
Expand All @@ -854,15 +892,19 @@ function(add_ca_check_group name)
if (NOT CA_ENABLE_TESTS)
return()
endif()
cmake_parse_arguments(args "" "" "DEPENDS" ${ARGN})
cmake_parse_arguments(args "NOGLOBAL" "" "DEPENDS" ${ARGN})
if(args_UNPARSED_ARGUMENTS)
message(FATAL_ERROR
"add_ca_check_group invalid arguments: ${args_UNPARSED_ARGUMENTS}")
endif()
# Add a custom target, which depends on all listed targets.
add_custom_target(check-${name}
get_ock_check_name(check_name ${name})
add_custom_target(${check_name}
DEPENDS ${args_DEPENDS}
COMMENT "Running ${name} group checks")
if(NOT args_NOGLOBAL)
add_dependencies(${OCK_CHECK_TARGET} ${check_name})
endif()
endfunction()

#[=======================================================================[.rst:
Expand Down Expand Up @@ -1333,13 +1375,14 @@ endfunction()
Arguments:
* ``target`` - Named target to set output directory properties on. A target
``check-${target}-lit`` will be created which runs LIT tests producing XML
results in ``${target}-lit.xml``.
named by calling ``get_ock_check_name(check_target ${target}-lit)`` will
be created which runs LIT tests producing XML results in
``${target}-lit.xml``.
* ``comment`` - A comment to display to the terminal when running the check
target.
Keyword Arguments:
* ``NOGLOBAL`` - Flag to specify that ``check-${target}`` should not be
* ``NOGLOBAL`` - Flag to specify that the new target should not be
added to the global check target.
* ``PARAMS`` - Keyword after which one or more additional parameters to the
llvm-lit command can be specified. Each parameter is automatically
Expand Down Expand Up @@ -1403,31 +1446,31 @@ endfunction()
.. cmake:command:: add_ca_lit_testsuite
The ``add_ca_lit_testsuite(name)`` function creates a new lit test suite. A
new target called ``check-${name}-lit`` is created and a dependency for
``check-${name}-lit`` is added to the global check target. To run an
individual check build the ``check-${name}-lit`` target and to run all checks
build the ``check`` target. All checks are executed with a working directory
of ``${PROJECT_SOURCE_DIR}`` and a comment of the form "Running ${name}
checks" is displayed by the build system during execution.
new target, named by calling ``get_ock_check_name(target ${name}-lit)``, is
created and a dependency for that new target is added to the global check
target. To run an individual check build the new target and to run all checks
build the global check target. All checks are executed with a working
directory of ``${PROJECT_SOURCE_DIR}`` and a comment of the form "Running
${name} checks" is displayed by the build system during execution.
If ``EXCLUDE_FROM_UMBRELLAS`` is not set, the test suite will also be added
to all open umbrella targets (see ``ca_umbrella_lit_testsuite_open()`` and
``ca_umbrella_lit_testsuite_close()``).
Arguments:
* ``name`` - Target name suffix for the check, this will create a target
called ``check-${name}-lit``.
named as described above.
Keyword Arguments:
* ``NOGLOBAL`` - Flag to specify that ``check-${target}-lit`` should not be
* ``NOGLOBAL`` - Flag to specify that the new target should not be
added to the global check target.
* ``EXCLUDE_FROM_UMBRELLAS`` - Flag to specify that ``${name}``
should not be added to any currently open test-suite umbrellas.
* ``TARGET`` - Keyword after which a target name can be specified. If
set, the test suite will be appended to a global set of test suites
relating to that target. A global ``check-${target}-lit`` target will be
created, comprised of all test suites relating to ``target``. Has no
effect if ``EXCLUDE_FROM_UMBRELLAS`` is set.
relating to that target. A global target will be created, comprised of
all test suites relating to ``target``. Has no effect if
``EXCLUDE_FROM_UMBRELLAS`` is set.
* ``PARAMS`` - Keyword after which one or more additional parameters to the
llvm-lit command can be specified. Each parameter is automatically
prepended with --param.
Expand Down Expand Up @@ -1531,9 +1574,9 @@ endfunction()
The ``ca_umbrella_lit_testsuite_close(target)`` function closes an open umbrella
lit test suite.
A new check target with the name ``check-${target}-lit`` will be created
using test suites previously registered with ``add_ca_lit_testsuite`` while
the umbrella was open.
A new check target named by calling ``get_ock_check_name(check_target
${target}-lit)`` will be created using test suites previously registered with
``add_ca_lit_testsuite`` while the umbrella was open.
See ``ca_umbrella_lit_testsuite_open`` for more details.
Expand Down
2 changes: 2 additions & 0 deletions doc/developer-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,8 @@ The builtin CMake options used when invoking CMake on the command line.
selection of testing is used by continuous integration to verify a baseline of
correctness, individual test suites can also be tested in isolation by
specifying the target to test.
* Note that when building inside an LLVM tree, all `check-*` targets are
instead names `check-ock-*`.
* `internal_builtins`: Builds the compiler builtins functions, this target can
be used even if automatically building the builtins was disabled with
`CA_EXTERNAL_BUILTINS`, although this target will fail in cross compile
Expand Down
6 changes: 6 additions & 0 deletions doc/source/cl/test/unitcl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,12 @@ convention. It is possible that additional tests are added by a customer team
for a specific ComputeMux target that *do* test the compiler but *do not* match
any of the filter words.

.. note::

When building the oneAPI Construction Kit inside an LLVM tree, the
``check-*`` targets are instead prefixed ``check-ock-``: `check-ock-UnitCL`,
etc.

.. warning::

If the intent of a UnitCL test is to test the compiler and the various
Expand Down
16 changes: 9 additions & 7 deletions source/cl/cmake/AddCACL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,9 @@ function(add_ca_cl_icd_file target)
install(FILES DESTINATION share/OpenCL/vendors COMPONENT CLIcd)
endfunction()

if(NOT TARGET check-cl)
add_ca_check_group(cl)
get_ock_check_name(check_cl_name cl)
if(NOT TARGET ${check_cl_name})
add_ca_check_group(cl NOGLOBAL)
endif()

#[=======================================================================[.rst:
Expand Down Expand Up @@ -177,6 +178,7 @@ function(add_ca_cl_check name)
if (NOT CA_ENABLE_TESTS)
return()
endif()
get_ock_check_name(check_name ${name})
cmake_parse_arguments(args "" "" "ENVIRONMENT" ${ARGN})
set(environment ${args_ENVIRONMENT})
if(CA_CL_ENABLE_ICD_LOADER)
Expand Down Expand Up @@ -218,22 +220,22 @@ function(add_ca_cl_check name)
# to the Inject subdirectory of DumpDir and renamed.
set(injectPrepareBins
${PROJECT_SOURCE_DIR}/scripts/testing/inject-prepare-bins.py)
add_custom_target(check-${name}-prepare
add_custom_target(${check_name}-prepare
COMMAND ${PYTHON_EXECUTABLE}
${injectPrepareBins} --clean ${dumpDirectory}
DEPENDS check-${name}-dump
DEPENDS ${check_name}-dump
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMENT "Running ${name}-prepare checks")

# Enable injecting program binaries for check-${name}, this is stage 3
# Enable injecting program binaries for the check target. This is stage 3
# which uses the same target as the non OpenCL-Intercept-Layer path.
list(INSERT environment 0 "CLI_InjectProgramBinaries=1")
endif()
endif()
add_ca_check(${name}
${args_UNPARSED_ARGUMENTS} ENVIRONMENT ${environment})
add_dependencies(check-cl check-${name})
add_dependencies(${check_cl_name} ${check_name})
if(CA_CL_ENABLE_INTERCEPT_LAYER)
add_dependencies(check-${name} check-${name}-prepare)
add_dependencies(${check_name} ${check_name}-prepare)
endif()
endfunction()
15 changes: 6 additions & 9 deletions source/cl/test/UnitCL/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,9 @@ function(add_ca_unitcl_check name)
COMMAND UnitCL "--unitcl_platform=Codeplay Software Ltd."
--gtest_output=xml:${PROJECT_BINARY_DIR}/${name}.xml ${args_ARGS} ${filter}
${environment} CLEAN ${PROJECT_BINARY_DIR}/${name}.xml NOGLOBAL DEPENDS UnitCL)
get_ock_check_name(check_name ${name})
if (args_GROUP)
add_dependencies(${args_GROUP} check-${name})
add_dependencies(${args_GROUP} ${check_name})
endif()
endfunction()

Expand All @@ -440,12 +441,14 @@ add_ca_check_group(UnitCL-group-vecz)

# Convenience function to add a UnitCL check in the default group
function(add_ca_default_unitcl_check name)
add_ca_unitcl_check(${name} ${ARGV} GROUP check-UnitCL-group)
get_ock_check_name(group_check_name UnitCL-group)
add_ca_unitcl_check(${name} ${ARGV} GROUP ${group_check_name})
endfunction()

# Convenience function to add a UnitCL check in the vecz group
function(add_ca_vecz_unitcl_check name)
add_ca_unitcl_check(${name} ${ARGV} GROUP check-UnitCL-group-vecz)
get_ock_check_name(group_check_name UnitCL-group-vecz)
add_ca_unitcl_check(${name} ${ARGV} GROUP ${group_check_name})
endfunction()


Expand Down Expand Up @@ -493,9 +496,6 @@ add_ca_default_unitcl_check(UnitCL-prevec-vecz-full-scalarization COMPILER
add_ca_default_unitcl_check(UnitCL-prevec-opt-disable COMPILER
ENVIRONMENT "CA_EXTRA_COMPILE_OPTS=-cl-vec=all -cl-opt-disable")

# Add this group to the global check target
add_dependencies(check check-UnitCL-group)

if(NOT CA_CL_DISABLE_UNITCL_VECZ_CHECKS)
add_ca_vecz_unitcl_check(UnitCL-vecz COMPILER
ENVIRONMENT "CA_EXTRA_COMPILE_OPTS=-cl-wfv=always"
Expand Down Expand Up @@ -556,9 +556,6 @@ if(NOT CA_CL_DISABLE_UNITCL_VECZ_CHECKS)
ENVIRONMENT "CODEPLAY_VECZ_CHOICES=LinearizeBOSCC"
"CA_EXTRA_COMPILE_OPTS=-cl-vec=all -cl-wfv=always"
ARGS --vecz-check)

# Add this group to the global check target
add_dependencies(check check-UnitCL-group-vecz)
endif()

if(OCL_EXTENSION_cl_intel_unified_shared_memory)
Expand Down
Loading

0 comments on commit 9b0922b

Please sign in to comment.