diff --git a/compiler-rt/lib/orc/CMakeLists.txt b/compiler-rt/lib/orc/CMakeLists.txt --- a/compiler-rt/lib/orc/CMakeLists.txt +++ b/compiler-rt/lib/orc/CMakeLists.txt @@ -172,6 +172,4 @@ endforeach() endif() # not Apple -if(COMPILER_RT_INCLUDE_TESTS) - add_subdirectory(unittests) -endif() +add_subdirectory(tests) diff --git a/compiler-rt/lib/orc/unittests/CMakeLists.txt b/compiler-rt/lib/orc/tests/CMakeLists.txt rename from compiler-rt/lib/orc/unittests/CMakeLists.txt rename to compiler-rt/lib/orc/tests/CMakeLists.txt --- a/compiler-rt/lib/orc/unittests/CMakeLists.txt +++ b/compiler-rt/lib/orc/tests/CMakeLists.txt @@ -2,13 +2,19 @@ include_directories(..) +# Unit tests target. add_custom_target(OrcRTUnitTests) set_target_properties(OrcRTUnitTests PROPERTIES FOLDER "OrcRT unittests") +# Testing tools target. +add_custom_target(OrcRTTools) +set_target_properties(OrcRTTools PROPERTIES FOLDER "OrcRT tools") + set(ORC_UNITTEST_CFLAGS +# FIXME: This should be set for all unit tests. + -std=c++17 ${ORC_CFLAGS} ${COMPILER_RT_UNITTEST_CFLAGS} - ${COMPILER_RT_GTEST_CFLAGS} -I${COMPILER_RT_SOURCE_DIR}/lib/orc ) @@ -47,10 +53,10 @@ append_list_if(COMPILER_RT_HAS_LIBEXECINFO -lexecinfo ORC_UNITTEST_LINK_FLAGS) endif() -set(ORC_DEPS llvm_gtest orc) +set(ORC_DEPS orc) # ORC uses C++ standard library headers. if (TARGET cxx-headers OR HAVE_LIBCXX) - set(ORC_DEPS cxx-headers) + list(APPEND ORC_DEPS cxx-headers) endif() macro(add_orc_unittest testname) @@ -64,37 +70,42 @@ SOURCES ${TEST_SOURCES} ${COMPILER_RT_GTEST_SOURCE} RUNTIME "${ORC_RUNTIME_LIBS}" COMPILE_DEPS ${TEST_HEADERS} ${ORC_HEADERS} - DEPS ${ORC_DEPS} - CFLAGS ${ORC_UNITTEST_CFLAGS} + DEPS llvm_gtest ${ORC_DEPS} + CFLAGS ${ORC_UNITTEST_CFLAGS} ${COMPILER_RT_GTEST_CFLAGS} LINK_FLAGS ${ORC_UNITTEST_LINK_FLAGS}) endforeach() endif() endmacro() -set(UNITTEST_SOURCES - adt_test.cpp - c_api_test.cpp - endian_test.cpp - error_test.cpp - executor_address_test.cpp - extensible_rtti_test.cpp - orc_unit_test_main.cpp - wrapper_function_utils_test.cpp - simple_packed_serialization_test.cpp - ) - -if (COMPILER_RT_CAN_EXECUTE_TESTS) - - if (APPLE) - add_orc_lib("RTOrc.test.osx" - $) - else() - foreach(arch ${ORC_SUPPORTED_ARCH}) - add_orc_lib("RTOrc.test.${arch}" - $) +macro(add_orc_tool toolname) + cmake_parse_arguments(TOOL "" "" "SOURCES;HEADERS" ${ARGN}) + if(UNIX) + foreach(arch ${ORC_TEST_ARCH}) + set(TOOL_OBJECTS) + get_orc_lib_for_arch(${arch} ORC_RUNTIME_LIBS) + generate_compiler_rt_tests(TOOL_OBJECTS + OrcRTTools "${toolname}-${arch}" "${arch}" + SOURCES ${TOOL_SOURCES} + RUNTIME "${ORC_RUNTIME_LIBS}" + COMPILE_DEPS ${TOOL_HEADERS} ${ORC_HEADERS} + DEPS ${ORC_DEPS} + CFLAGS ${ORC_UNITTEST_CFLAGS} + LINK_FLAGS ${ORC_UNITTEST_LINK_FLAGS}) endforeach() endif() +endmacro() - add_orc_unittest(OrcUnitTest SOURCES ${UNITTEST_SOURCES}) +if (APPLE) + add_orc_lib("RTOrc.test.osx" + $) +else() + foreach(arch ${ORC_SUPPORTED_ARCH}) + add_orc_lib("RTOrc.test.${arch}" + $) + endforeach() +endif() +if(COMPILER_RT_INCLUDE_TESTS) + add_subdirectory(unit) endif() +add_subdirectory(tools) diff --git a/compiler-rt/lib/orc/tests/tools/CMakeLists.txt b/compiler-rt/lib/orc/tests/tools/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/compiler-rt/lib/orc/tests/tools/CMakeLists.txt @@ -0,0 +1 @@ +add_orc_tool(orc-rt-executor SOURCES orc-rt-executor.cpp) diff --git a/compiler-rt/lib/orc/tests/tools/orc-rt-executor.cpp b/compiler-rt/lib/orc/tests/tools/orc-rt-executor.cpp new file mode 100644 --- /dev/null +++ b/compiler-rt/lib/orc/tests/tools/orc-rt-executor.cpp @@ -0,0 +1,49 @@ +//===- orc-rt-executor.cpp ------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// Contains the orc-rt-executor test tool. This is a "blank executable" that +// links the ORC runtime and can accept code from a JIT controller like lii or +// llvm-jitlink. +// +//===----------------------------------------------------------------------===// + +#include +#include +#include +#include + +void printHelp(std::string_view ProgName, std::ostream &OS) { + OS << "usage: " << ProgName << " [help] [] ...\n" + << " -- specify how to listen for JIT'd program\n" + << " filedesc=, -- read from filedesc, write to out\n" + << " tcp=: -- listen on the given host/port\n" + << " help -- print help and exit\n" + << "\n" + << " Notes:\n" + << " Program arguments will be made available to the JIT controller.\n" + << " When running a JIT'd program containing a main function the\n" + << " controller may choose to pass these on to main, however\n" + << " orc-rt-executor does not enforce this.\n"; +} + +int main(int argc, char *argv[]) { + if (argc < 2) { + printHelp("orc-rt-executor", std::cerr); + std::cerr << "error: insufficient arguments.\n"; + exit(1); + } + + if (!strcmp(argv[1], "help")) { + printHelp(argv[0], std::cerr); + exit(0); + } + + std::cerr << "error: One day I will be a real program, but I am not yet.\n"; + + return 0; +} diff --git a/compiler-rt/lib/orc/tests/unit/CMakeLists.txt b/compiler-rt/lib/orc/tests/unit/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/compiler-rt/lib/orc/tests/unit/CMakeLists.txt @@ -0,0 +1,15 @@ +set(UNITTEST_SOURCES + adt_test.cpp + c_api_test.cpp + endian_test.cpp + error_test.cpp + executor_address_test.cpp + extensible_rtti_test.cpp + orc_unit_test_main.cpp + wrapper_function_utils_test.cpp + simple_packed_serialization_test.cpp + ) + +if (COMPILER_RT_CAN_EXECUTE_TESTS) + add_orc_unittest(OrcUnitTest SOURCES ${UNITTEST_SOURCES}) +endif() diff --git a/compiler-rt/lib/orc/unittests/adt_test.cpp b/compiler-rt/lib/orc/tests/unit/adt_test.cpp rename from compiler-rt/lib/orc/unittests/adt_test.cpp rename to compiler-rt/lib/orc/tests/unit/adt_test.cpp diff --git a/compiler-rt/lib/orc/unittests/c_api_test.cpp b/compiler-rt/lib/orc/tests/unit/c_api_test.cpp rename from compiler-rt/lib/orc/unittests/c_api_test.cpp rename to compiler-rt/lib/orc/tests/unit/c_api_test.cpp diff --git a/compiler-rt/lib/orc/unittests/endian_test.cpp b/compiler-rt/lib/orc/tests/unit/endian_test.cpp rename from compiler-rt/lib/orc/unittests/endian_test.cpp rename to compiler-rt/lib/orc/tests/unit/endian_test.cpp diff --git a/compiler-rt/lib/orc/unittests/error_test.cpp b/compiler-rt/lib/orc/tests/unit/error_test.cpp rename from compiler-rt/lib/orc/unittests/error_test.cpp rename to compiler-rt/lib/orc/tests/unit/error_test.cpp diff --git a/compiler-rt/lib/orc/unittests/executor_address_test.cpp b/compiler-rt/lib/orc/tests/unit/executor_address_test.cpp rename from compiler-rt/lib/orc/unittests/executor_address_test.cpp rename to compiler-rt/lib/orc/tests/unit/executor_address_test.cpp diff --git a/compiler-rt/lib/orc/unittests/extensible_rtti_test.cpp b/compiler-rt/lib/orc/tests/unit/extensible_rtti_test.cpp rename from compiler-rt/lib/orc/unittests/extensible_rtti_test.cpp rename to compiler-rt/lib/orc/tests/unit/extensible_rtti_test.cpp diff --git a/compiler-rt/lib/orc/unittests/orc_unit_test_main.cpp b/compiler-rt/lib/orc/tests/unit/orc_unit_test_main.cpp rename from compiler-rt/lib/orc/unittests/orc_unit_test_main.cpp rename to compiler-rt/lib/orc/tests/unit/orc_unit_test_main.cpp diff --git a/compiler-rt/lib/orc/unittests/simple_packed_serialization_test.cpp b/compiler-rt/lib/orc/tests/unit/simple_packed_serialization_test.cpp rename from compiler-rt/lib/orc/unittests/simple_packed_serialization_test.cpp rename to compiler-rt/lib/orc/tests/unit/simple_packed_serialization_test.cpp diff --git a/compiler-rt/lib/orc/unittests/wrapper_function_utils_test.cpp b/compiler-rt/lib/orc/tests/unit/wrapper_function_utils_test.cpp rename from compiler-rt/lib/orc/unittests/wrapper_function_utils_test.cpp rename to compiler-rt/lib/orc/tests/unit/wrapper_function_utils_test.cpp diff --git a/compiler-rt/test/orc/TestCases/Generic/lit.local.cfg.py b/compiler-rt/test/orc/TestCases/Generic/lit.local.cfg.py new file mode 100644 --- /dev/null +++ b/compiler-rt/test/orc/TestCases/Generic/lit.local.cfg.py @@ -0,0 +1,2 @@ +if not config.test_target_is_host_executable: + config.unsupported = True diff --git a/compiler-rt/test/orc/TestCases/Generic/orc-rt-executor-usage.test b/compiler-rt/test/orc/TestCases/Generic/orc-rt-executor-usage.test new file mode 100644 --- /dev/null +++ b/compiler-rt/test/orc/TestCases/Generic/orc-rt-executor-usage.test @@ -0,0 +1,6 @@ +// Test that the orc-remote-executor tool errors out as expected when called +// with no arguments. +// +// RUN: not %orc_rt_executor 2>&1 | FileCheck %s + +// CHECK: usage: orc-rt-executor [help] [] ... diff --git a/compiler-rt/test/orc/lit.cfg.py b/compiler-rt/test/orc/lit.cfg.py --- a/compiler-rt/test/orc/lit.cfg.py +++ b/compiler-rt/test/orc/lit.cfg.py @@ -8,11 +8,16 @@ # Setup source root. config.test_source_root = os.path.dirname(__file__) -def build_invocation(compile_flags): - return ' ' + ' '.join([config.clang] + compile_flags) + ' ' +# Determine whether the test target is compatible with execution on the host. +host_arch_compatible = config.target_arch == config.host_arch + +if config.host_arch == "x86_64h" and config.target_arch == "x86_64": + host_arch_compatible = True +config.test_target_is_host_executable = config.target_os == config.host_os and host_arch_compatible # Assume that llvm-jitlink is in the config.llvm_tools_dir. llvm_jitlink = os.path.join(config.llvm_tools_dir, 'llvm-jitlink') +orc_rt_executor_stem = os.path.join(config.compiler_rt_obj_root, 'lib/orc/tests/tools/orc-rt-executor') lli = os.path.join(config.llvm_tools_dir, 'lli') if config.host_os == 'Darwin': orc_rt_path = '%s/libclang_rt.orc_osx.a' % config.compiler_rt_libdir @@ -24,6 +29,9 @@ shared_libunwind_path = os.path.join(config.libunwind_install_dir, 'libunwind.so') config.substitutions.append( ("%shared_libunwind", shared_libunwind_path) ) +def build_invocation(compile_flags): + return ' ' + ' '.join([config.clang] + compile_flags) + ' ' + config.substitutions.append( ('%clang ', build_invocation([config.target_cflags]))) config.substitutions.append( @@ -36,11 +44,13 @@ else: config.substitutions.append( ('%llvm_jitlink', (llvm_jitlink + ' -orc-runtime=' + orc_rt_path))) +config.substitutions.append( + ('%orc_rt_executor', orc_rt_executor_stem + "-" + config.host_arch)) config.substitutions.append( ('%lli_orc_jitlink', (lli + ' -jit-kind=orc -jit-linker=jitlink -orc-runtime=' + orc_rt_path))) # Default test suffixes. -config.suffixes = ['.c', '.cpp', '.S', '.ll'] +config.suffixes = ['.c', '.cpp', '.S', '.ll', '.test'] # Exclude Inputs directories. config.excludes = ['Inputs'] diff --git a/compiler-rt/test/orc/lit.site.cfg.py.in b/compiler-rt/test/orc/lit.site.cfg.py.in --- a/compiler-rt/test/orc/lit.site.cfg.py.in +++ b/compiler-rt/test/orc/lit.site.cfg.py.in @@ -5,6 +5,7 @@ config.orc_lit_source_dir = "@ORC_LIT_SOURCE_DIR@" config.target_cflags = "@ORC_TEST_TARGET_CFLAGS@" config.target_arch = "@ORC_TEST_TARGET_ARCH@" +config.target_os = "@ORC_TEST_TARGET_OS@" config.built_with_llvm = ("@COMPILER_RT_STANDALONE_BUILD@" != "TRUE") config.libunwind_shared = "@LIBUNWIND_ENABLE_SHARED@" config.libunwind_install_dir = "@LLVM_BINARY_DIR@/@LIBUNWIND_INSTALL_LIBRARY_DIR@"