[compiler-rt] 1169586 - [ORC-RT] Refactor ORC runtime CMake for future test tool(s).
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 2 21:24:39 PDT 2022
Author: Lang Hames
Date: 2022-09-02T20:59:57-07:00
New Revision: 1169586dcde0376ef291802208daedc4f8107c7e
URL: https://github.com/llvm/llvm-project/commit/1169586dcde0376ef291802208daedc4f8107c7e
DIFF: https://github.com/llvm/llvm-project/commit/1169586dcde0376ef291802208daedc4f8107c7e.diff
LOG: [ORC-RT] Refactor ORC runtime CMake for future test tool(s).
We want to move functionality from the LLVM ORCTargetProcess library into the
ORC runtime, and this will mean implementing remote-executor testing tools
(like llvm-jitlink-executor and lli-child-target) in the ORC runtime.
This patch refactors the ORC runtime build system to introduce an
add_orc_tool function that can be used to add new test tools. The code is
modeled on existing functions for adding unit tests.
A placeholder orc-rt-executor tool and test are added to verify that the
config changes behave as expected.
Reviewed By: phosek
Differential Revision: https://reviews.llvm.org/D133084
Added:
compiler-rt/lib/orc/tests/CMakeLists.txt
compiler-rt/lib/orc/tests/tools/CMakeLists.txt
compiler-rt/lib/orc/tests/tools/orc-rt-executor.cpp
compiler-rt/lib/orc/tests/unit/CMakeLists.txt
compiler-rt/lib/orc/tests/unit/adt_test.cpp
compiler-rt/lib/orc/tests/unit/c_api_test.cpp
compiler-rt/lib/orc/tests/unit/endian_test.cpp
compiler-rt/lib/orc/tests/unit/error_test.cpp
compiler-rt/lib/orc/tests/unit/executor_address_test.cpp
compiler-rt/lib/orc/tests/unit/extensible_rtti_test.cpp
compiler-rt/lib/orc/tests/unit/orc_unit_test_main.cpp
compiler-rt/lib/orc/tests/unit/simple_packed_serialization_test.cpp
compiler-rt/lib/orc/tests/unit/wrapper_function_utils_test.cpp
compiler-rt/test/orc/TestCases/Generic/lit.local.cfg.py
compiler-rt/test/orc/TestCases/Generic/orc-rt-executor-usage.test
Modified:
compiler-rt/lib/orc/CMakeLists.txt
compiler-rt/test/orc/lit.cfg.py
compiler-rt/test/orc/lit.site.cfg.py.in
Removed:
compiler-rt/lib/orc/unittests/CMakeLists.txt
compiler-rt/lib/orc/unittests/adt_test.cpp
compiler-rt/lib/orc/unittests/c_api_test.cpp
compiler-rt/lib/orc/unittests/endian_test.cpp
compiler-rt/lib/orc/unittests/error_test.cpp
compiler-rt/lib/orc/unittests/executor_address_test.cpp
compiler-rt/lib/orc/unittests/extensible_rtti_test.cpp
compiler-rt/lib/orc/unittests/orc_unit_test_main.cpp
compiler-rt/lib/orc/unittests/simple_packed_serialization_test.cpp
compiler-rt/lib/orc/unittests/wrapper_function_utils_test.cpp
################################################################################
diff --git a/compiler-rt/lib/orc/CMakeLists.txt b/compiler-rt/lib/orc/CMakeLists.txt
index 2a2b056b8933d..a40a1090e01b8 100644
--- a/compiler-rt/lib/orc/CMakeLists.txt
+++ b/compiler-rt/lib/orc/CMakeLists.txt
@@ -172,6 +172,4 @@ else() # not Apple
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
similarity index 66%
rename from compiler-rt/lib/orc/unittests/CMakeLists.txt
rename to compiler-rt/lib/orc/tests/CMakeLists.txt
index aa6b2dc0f43c1..6014ed328d2cc 100644
--- a/compiler-rt/lib/orc/unittests/CMakeLists.txt
+++ b/compiler-rt/lib/orc/tests/CMakeLists.txt
@@ -2,13 +2,19 @@ include(CompilerRTCompile)
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 @@ else()
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 @@ macro(add_orc_unittest testname)
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"
- $<TARGET_OBJECTS:RTOrc.osx>)
- else()
- foreach(arch ${ORC_SUPPORTED_ARCH})
- add_orc_lib("RTOrc.test.${arch}"
- $<TARGET_OBJECTS:RTOrc.${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"
+ $<TARGET_OBJECTS:RTOrc.osx>)
+else()
+ foreach(arch ${ORC_SUPPORTED_ARCH})
+ add_orc_lib("RTOrc.test.${arch}"
+ $<TARGET_OBJECTS:RTOrc.${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
index 0000000000000..796e341c2f385
--- /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
index 0000000000000..da45a2d64d687
--- /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 <cstring>
+#include <iostream>
+#include <optional>
+#include <string_view>
+
+void printHelp(std::string_view ProgName, std::ostream &OS) {
+ OS << "usage: " << ProgName << " [help] [<mode>] <program arguments>...\n"
+ << " <mode> -- specify how to listen for JIT'd program\n"
+ << " filedesc=<in>,<out> -- read from <in> filedesc, write to out\n"
+ << " tcp=<host>:<port> -- 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
index 0000000000000..a5b2a0ed81834
--- /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
similarity index 100%
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
similarity index 100%
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
similarity index 100%
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
similarity index 100%
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
similarity index 100%
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
similarity index 100%
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
similarity index 100%
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
similarity index 100%
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
similarity index 100%
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
index 0000000000000..05be16df78e20
--- /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
index 0000000000000..951688d7961d4
--- /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] [<mode>] <program arguments>...
diff --git a/compiler-rt/test/orc/lit.cfg.py b/compiler-rt/test/orc/lit.cfg.py
index 2c2619842ebd4..696395687239d 100644
--- 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 @@ def build_invocation(compile_flags):
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 @@ def build_invocation(compile_flags):
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
index cd06712797413..a33ef3d7d7207 100644
--- 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.name_suffix = "@ORC_TEST_CONFIG_SUFFIX@"
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@"
More information about the llvm-commits
mailing list