Skip to content

Commit

Permalink
CMake: allow tests to be run using simulator
Browse files Browse the repository at this point in the history
This commit add support for running (cross-compiled) tests on
host using emulator, specified by `OMR_TEST_LAUNCHER` CMake variable.

To make this work, this commit introduces new function - `omr_add_test()`
that behaves just like CMake's `add_test()` but runs the command under
simulator if needed.

Signed-off-by: Jan Vrany <jan.vrany@fit.cvut.cz>
  • Loading branch information
janvrany committed Feb 1, 2021
1 parent 6ebbfd4 commit 68f2034
Show file tree
Hide file tree
Showing 22 changed files with 76 additions and 28 deletions.
2 changes: 2 additions & 0 deletions buildenv/jenkins/omrbuild.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ def SPECS = [
]
],
'test' : false
'testArgs' : '',
'junitPublish' : true
],
'linux_x86' : [
'label' : 'Linux && x86',
Expand Down
43 changes: 43 additions & 0 deletions cmake/modules/OmrTest.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
###############################################################################
# Copyright (c) 2021, 2021 IBM Corp. and others
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License 2.0 which accompanies this
# distribution and is available at http://eclipse.org/legal/epl-2.0
# or the Apache License, Version 2.0 which accompanies this distribution
# and is available at https://www.apache.org/licenses/LICENSE-2.0.
#
# This Source Code may also be made available under the following Secondary
# Licenses when the conditions for such availability set forth in the
# Eclipse Public License, v. 2.0 are satisfied: GNU General Public License,
# version 2 with the GNU Classpath Exception [1] and GNU General Public
# License, version 2 with the OpenJDK Assembly Exception [2].
#
# [1] https://www.gnu.org/software/classpath/license.html
# [2] http://openjdk.java.net/legal/assembly-exception.html
#
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
###############################################################################

if(OMR_TEST_)
return()
endif()
set(OMR_TEST_ 1)

if(NOT OMR_TEST_LAUNCHER)
if(OMR_EXE_LAUNCHER)
set(OMR_TEST_LAUNCHER "${OMR_EXE_LAUNCHER}")
endif()
endif()

function(omr_add_test)
cmake_parse_arguments(opt "" "NAME;COMMAND" "" ${ARGN})
if(NOT opt_COMMAND)
message(FATAL_ERROR "omr_add_test used without specifying COMMAND")
endif()
if(NOT opt_NAME)
message(FATAL_ERROR "omr_add_test used without specifying NAME")
endif()

add_test(NAME "${opt_NAME}" COMMAND ${OMR_TEST_LAUNCHER} ${opt_COMMAND} ${opt_UNPARSED_ARGUMENTS})
endfunction()
3 changes: 2 additions & 1 deletion example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
###############################################################################

include(OmrAssert)
include(OmrTest)

omr_assert(TEST OMR_EXAMPLE)

Expand Down Expand Up @@ -50,7 +51,7 @@ if(OMR_GC)
${OMR_PORT_LIB}
)

add_test(NAME gcexample COMMAND $<TARGET_FILE:gcexample>)
omr_add_test(NAME gcexample COMMAND $<TARGET_FILE:gcexample>)
endif(OMR_GC)

add_subdirectory(glue)
3 changes: 2 additions & 1 deletion fvtest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
###############################################################################
# Copyright (c) 2017, 2020 IBM Corp. and others
# Copyright (c) 2017, 2021 IBM Corp. and others
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License 2.0 which accompanies this
Expand All @@ -20,6 +20,7 @@
###############################################################################

include(OmrAssert)
include(OmrTest)

omr_assert(TEST OMR_FVTEST)

Expand Down
2 changes: 1 addition & 1 deletion fvtest/algotest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ endif()

set_property(TARGET omralgotest PROPERTY FOLDER fvtest)

add_test(NAME algotest COMMAND $<TARGET_FILE:omralgotest> --gtest_output=xml:${CMAKE_CURRENT_BINARY_DIR}/omralgotest-results.xml -avltest:${CMAKE_CURRENT_SOURCE_DIR}/avltest.lst)
omr_add_test(NAME algotest COMMAND $<TARGET_FILE:omralgotest> --gtest_output=xml:${CMAKE_CURRENT_BINARY_DIR}/omralgotest-results.xml -avltest:${CMAKE_CURRENT_SOURCE_DIR}/avltest.lst)
2 changes: 1 addition & 1 deletion fvtest/compilertest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,5 @@ target_link_libraries(compilertest
set_property(TARGET compilertest PROPERTY FOLDER fvtest)

if (NOT OMR_HOST_OS STREQUAL "aix")
add_test(NAME CompilerTest COMMAND $<TARGET_FILE:compilertest> --gtest_output=xml:${CMAKE_CURRENT_BINARY_DIR}/compilertest-results.xml)
omr_add_test(NAME CompilerTest COMMAND $<TARGET_FILE:compilertest> --gtest_output=xml:${CMAKE_CURRENT_BINARY_DIR}/compilertest-results.xml)
endif()
2 changes: 1 addition & 1 deletion fvtest/compilertriltest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ endif()

set_property(TARGET comptest PROPERTY FOLDER fvtest)

add_test(
omr_add_test(
NAME comptest
COMMAND $<TARGET_FILE:comptest> --gtest_color=yes --gtest_output=xml:${CMAKE_CURRENT_BINARY_DIR}/comptest-results.xml
)
2 changes: 1 addition & 1 deletion fvtest/compilerunittest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ target_link_libraries(compunittest

set_property(TARGET compunittest PROPERTY FOLDER fvtest)

add_test(
omr_add_test(
NAME compunittest
COMMAND $<TARGET_FILE:compunittest> --gtest_color=yes --gtest_output=xml:${CMAKE_CURRENT_BINARY_DIR}/compunittest-results.xml
)
4 changes: 2 additions & 2 deletions fvtest/coretest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
###############################################################################
# Copyright (c) 2018, 2020 IBM Corp. and others
# Copyright (c) 2018, 2021 IBM Corp. and others
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -31,7 +31,7 @@ function(omr_add_core_test testname)
omrvmstartup
omrGtestGlue
)
add_test(
omr_add_test(
NAME "${testname}"
COMMAND "${testname}" --gtest_output=xml:${CMAKE_CURRENT_BINARY_DIR}/${testname}-results.xml
)
Expand Down
4 changes: 2 additions & 2 deletions fvtest/gc_api_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
###############################################################################
# Copyright (c) 2018, 2020 IBM Corp. and others
# Copyright (c) 2018, 2021 IBM Corp. and others
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -34,7 +34,7 @@ function(omr_add_gc_test testname)
omrgc
omrGtestGlue
)
add_test(
omr_add_test(
NAME "${testname}"
COMMAND "$<TARGET_FILE:${testname}>" "--gtest_output=xml:${CMAKE_CURRENT_BINARY_DIR}/${testname}-results.xml"
)
Expand Down
2 changes: 1 addition & 1 deletion fvtest/gctest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ endif()

set_property(TARGET omrgctest PROPERTY FOLDER fvtest)

add_test(NAME gctest
omr_add_test(NAME gctest
COMMAND $<TARGET_FILE:omrgctest> "--gtest_filter=gcFunctionalTest*" "--gtest_output=xml:${CMAKE_CURRENT_BINARY_DIR}/omrgctest-results.xml"
WORKING_DIRECTORY "${omr_SOURCE_DIR}"
)
2 changes: 1 addition & 1 deletion fvtest/jitbuildertest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@ set_property(TARGET jitbuildertest PROPERTY FOLDER fvtest)
# Disable JitBuilder tests on RISC-V. This is essentially a workaround
# until #4764 is addressed. Once done, tests should be properly skipped.
if(NOT OMR_HOST_ARCH STREQUAL "riscv")
add_test(NAME JitBuilderTest COMMAND $<TARGET_FILE:jitbuildertest> --gtest_output=xml:${CMAKE_CURRENT_BINARY_DIR}/jitbuildertest-results.xml)
omr_add_test(NAME JitBuilderTest COMMAND $<TARGET_FILE:jitbuildertest> --gtest_output=xml:${CMAKE_CURRENT_BINARY_DIR}/jitbuildertest-results.xml)
endif()
2 changes: 1 addition & 1 deletion fvtest/lljbtest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ target_link_libraries(lljb_run

function(add_lljb_test test)
generate_module_from_cxx(${test})
add_test(
omr_add_test(
NAME lljb_${test}_test
COMMAND $<TARGET_FILE:lljb>_run ${test}.ll
)
Expand Down
4 changes: 2 additions & 2 deletions fvtest/porttest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,14 @@ if(OMR_HOST_OS STREQUAL "aix")
endif()

if (NOT OMR_HOST_OS STREQUAL "aix" AND NOT OMR_HOST_OS STREQUAL "zos")
add_test(
omr_add_test(
NAME porttest
COMMAND $<TARGET_FILE:omrporttest> --gtest_output=xml:${CMAKE_CURRENT_BINARY_DIR}/omrporttest-results.xml
)
endif()

if(OMR_OPT_CUDA)
add_test(
omr_add_test(
NAME cuda_porttest
COMMAND $<TARGET_FILE:omrporttest> --gtest_output=xml:${CMAKE_CURRENT_BINARY_DIR}/omrporttest-results.xml --gtest_filter="Cuda*" -earlyExit
)
Expand Down
6 changes: 3 additions & 3 deletions fvtest/rastest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ add_dependencies(omrtraceoptiontest
traceOptionAgent
)

add_test(NAME rastest COMMAND $<TARGET_FILE:omrrastest> --gtest_output=xml:${CMAKE_CURRENT_BINARY_DIR}/omrrastest-results.xml)
add_test(NAME subscribertest COMMAND $<TARGET_FILE:omrsubscribertest> --gtest_output=xml:${CMAKE_CURRENT_BINARY_DIR}/omrsubscribertest-results.xml)
add_test(NAME traceoptiontest COMMAND $<TARGET_FILE:omrtraceoptiontest> --gtest_output=xml:${CMAKE_CURRENT_BINARY_DIR}/omrtraceoptiontest-results.xml)
omr_add_test(NAME rastest COMMAND $<TARGET_FILE:omrrastest> --gtest_output=xml:${CMAKE_CURRENT_BINARY_DIR}/omrrastest-results.xml)
omr_add_test(NAME subscribertest COMMAND $<TARGET_FILE:omrsubscribertest> --gtest_output=xml:${CMAKE_CURRENT_BINARY_DIR}/omrsubscribertest-results.xml)
omr_add_test(NAME traceoptiontest COMMAND $<TARGET_FILE:omrtraceoptiontest> --gtest_output=xml:${CMAKE_CURRENT_BINARY_DIR}/omrtraceoptiontest-results.xml)

set_target_properties(
omrrastest
Expand Down
2 changes: 1 addition & 1 deletion fvtest/sigtest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@ endif()

set_property(TARGET omrsigtest PROPERTY FOLDER fvtest)

add_test(NAME sigtest COMMAND $<TARGET_FILE:omrsigtest> --gtest_output=xml:${CMAKE_CURRENT_BINARY_DIR}/omrsigtest-results.xml)
omr_add_test(NAME sigtest COMMAND $<TARGET_FILE:omrsigtest> --gtest_output=xml:${CMAKE_CURRENT_BINARY_DIR}/omrsigtest-results.xml)
2 changes: 1 addition & 1 deletion fvtest/threadextendedtest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ endif()
set_property(TARGET omrthreadextendedtest PROPERTY FOLDER fvtest)

if (NOT OMR_HOST_OS STREQUAL "zos")
add_test(NAME threadextendedtest COMMAND $<TARGET_FILE:omrthreadextendedtest> --gtest_output=xml:${CMAKE_CURRENT_BINARY_DIR}/omrthreadextendedtest-results.xml)
omr_add_test(NAME threadextendedtest COMMAND $<TARGET_FILE:omrthreadextendedtest> --gtest_output=xml:${CMAKE_CURRENT_BINARY_DIR}/omrthreadextendedtest-results.xml)
endif()
6 changes: 3 additions & 3 deletions fvtest/threadtest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ endif()

set_property(TARGET omrthreadtest PROPERTY FOLDER fvtest)

add_test(NAME threadtest COMMAND $<TARGET_FILE:omrthreadtest> --gtest_output=xml:${CMAKE_CURRENT_BINARY_DIR}/omrthreadtest-results.xml)
add_test(NAME threadSetAttrThreadWeightTest COMMAND $<TARGET_FILE:omrthreadtest> --gtest_output=xml:${CMAKE_CURRENT_BINARY_DIR}/omrthreadtest-results.xml --gtest_also_run_disabled_tests --gtest_filter=ThreadCreateTest.DISABLED_SetAttrThreadWeight)
omr_add_test(NAME threadtest COMMAND $<TARGET_FILE:omrthreadtest> --gtest_output=xml:${CMAKE_CURRENT_BINARY_DIR}/omrthreadtest-results.xml)
omr_add_test(NAME threadSetAttrThreadWeightTest COMMAND $<TARGET_FILE:omrthreadtest> --gtest_output=xml:${CMAKE_CURRENT_BINARY_DIR}/omrthreadtest-results.xml --gtest_also_run_disabled_tests --gtest_filter=ThreadCreateTest.DISABLED_SetAttrThreadWeight)
if(OMR_HOST_OS STREQUAL "linux")
add_test(NAME threadRealtimeTest COMMAND $<TARGET_FILE:omrthreadtest> --gtest_output=xml:${CMAKE_CURRENT_BINARY_DIR}/omrthreadtest-results.xml --gtest_filter=ThreadCreateTest.* -realtime)
omr_add_test(NAME threadRealtimeTest COMMAND $<TARGET_FILE:omrthreadtest> --gtest_output=xml:${CMAKE_CURRENT_BINARY_DIR}/omrthreadtest-results.xml --gtest_filter=ThreadCreateTest.* -realtime)
endif()
2 changes: 1 addition & 1 deletion fvtest/tril/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ target_compile_options(triltest

set_property(TARGET triltest PROPERTY FOLDER fvtest/tril)

add_test(
omr_add_test(
NAME triltest
COMMAND $<TARGET_FILE:triltest> --gtest_output=xml:${CMAKE_CURRENT_BINARY_DIR}/triltest-results.xml
)
2 changes: 1 addition & 1 deletion fvtest/utiltest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ endif()

set_property(TARGET omrutiltest PROPERTY FOLDER fvtest)

add_test(NAME utiltest COMMAND $<TARGET_FILE:omrutiltest> --gtest_output=xml:${CMAKE_CURRENT_BINARY_DIR}/omrutiltest-results.xml)
omr_add_test(NAME utiltest COMMAND $<TARGET_FILE:omrutiltest> --gtest_output=xml:${CMAKE_CURRENT_BINARY_DIR}/omrutiltest-results.xml)
2 changes: 1 addition & 1 deletion fvtest/vmtest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ target_link_libraries(omrvmtest

set_property(TARGET omrvmtest PROPERTY FOLDER fvtest)

add_test(NAME vmtest COMMAND $<TARGET_FILE:omrvmtest> --gtest_output=xml:${CMAKE_CURRENT_BINARY_DIR}/omrvmtest-results.xml)
omr_add_test(NAME vmtest COMMAND $<TARGET_FILE:omrvmtest> --gtest_output=xml:${CMAKE_CURRENT_BINARY_DIR}/omrvmtest-results.xml)
5 changes: 3 additions & 2 deletions jitbuilder/release/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
###############################################################################
# Copyright (c) 2017, 2020 IBM Corp. and others
# Copyright (c) 2017, 2021 IBM Corp. and others
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License 2.0 which accompanies this
Expand All @@ -20,6 +20,7 @@
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
###############################################################################

include(OmrTest)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
Expand All @@ -31,7 +32,7 @@ macro(create_jitbuilder_test target)
target_link_libraries(${target}
jitbuilder
${CMAKE_DL_LIBS})
add_test(NAME ${target}_example_as_test COMMAND $<TARGET_FILE:${target}>)
omr_add_test(NAME ${target}_example_as_test COMMAND $<TARGET_FILE:${target}>)
endmacro(create_jitbuilder_test)

# Basic Tests: These should run properly on all platforms.
Expand Down

0 comments on commit 68f2034

Please sign in to comment.