File tree Expand file tree Collapse file tree 3 files changed +38
-15
lines changed
Expand file tree Collapse file tree 3 files changed +38
-15
lines changed Original file line number Diff line number Diff line change @@ -85,13 +85,24 @@ function(add_offload_unittest test_dirname)
8585 set (target_name "${test_dirname} .unittests" )
8686
8787 list (TRANSFORM ARGN PREPEND "${CMAKE_CURRENT_SOURCE_DIR} /" OUTPUT_VARIABLE files )
88+ list (APPEND files ${CMAKE_CURRENT_SOURCE_DIR} /common/Environment .cpp)
8889
89- add_unittest(OffloadUnitTests "${target_name} "
90- ${CMAKE_CURRENT_SOURCE_DIR} /common/Environment .cpp
91- ${files} )
90+ if ( NOT LLVM_BUILD_TESTS )
91+ set (EXCLUDE_FROM_ALL ON )
92+ endif ()
93+ add_llvm_executable(${target_name} IGNORE_EXTERNALIZE_DEBUGINFO NO_INSTALL_RPATH ${files} )
94+ get_subproject_title(subproject_title)
95+ set_target_properties (${target_name} PROPERTIES FOLDER "${subproject_title} /Tests/Unit" )
96+
97+ target_link_options (${target_name} PRIVATE "${LLVM_UNITTEST_LINK_FLAGS} " )
98+
99+ set (outdir ${CMAKE_CURRENT_BINARY_DIR} /${CMAKE_CFG_INTDIR} )
100+ set_output_directory(${target_name} BINARY_DIR ${outdir} LIBRARY_DIR ${outdir} )
101+ target_link_libraries (${target_name} PRIVATE llvm_gtest ${LLVM_PTHREAD_LIB} ${PLUGINS_TEST_COMMON} )
102+
103+ add_dependencies (OffloadUnitTests ${target_name} )
92104 add_dependencies (${target_name} ${PLUGINS_TEST_COMMON} offload_device_binaries)
93105 target_compile_definitions (${target_name} PRIVATE DEVICE_CODE_PATH="${OFFLOAD_TEST_DEVICE_CODE_PATH} " )
94- target_link_libraries (${target_name} PRIVATE ${PLUGINS_TEST_COMMON} )
95106 target_include_directories (${target_name} PRIVATE ${PLUGINS_TEST_INCLUDE} )
96107endfunction ()
97108
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ add_offload_unittest("event"
1616
1717add_offload_unittest("init"
1818 init/olInit.cpp)
19- target_compile_definitions ("init.unittests" PRIVATE DISABLE_WRAPPER )
19+ target_compile_definitions ("init.unittests" PRIVATE DISABLE_OL_INIT )
2020
2121add_offload_unittest("kernel"
2222 kernel/olLaunchKernel.cpp)
Original file line number Diff line number Diff line change 1111#include " llvm/Support/CommandLine.h"
1212#include " llvm/Support/MemoryBuffer.h"
1313#include < OffloadAPI.h>
14+ #include < OffloadPrint.hpp>
1415#include < fstream>
1516
1617using namespace llvm ;
1718
18- // Wrapper so we don't have to constantly init and shutdown Offload in every
19- // test, while having sensible lifetime for the platform environment
20- #ifndef DISABLE_WRAPPER
21- struct OffloadInitWrapper {
22- OffloadInitWrapper () { olInit (); }
23- ~OffloadInitWrapper () { olShutDown (); }
24- };
25- static OffloadInitWrapper Wrapper{};
26- #endif
27-
2819static cl::opt<std::string>
2920 SelectedPlatform (" platform" , cl::desc(" Only test the specified platform" ),
3021 cl::value_desc(" platform" ));
@@ -193,3 +184,24 @@ bool TestEnvironment::loadDeviceBinary(
193184 BinaryOut = std::move (SourceFile.get ());
194185 return true ;
195186}
187+
188+ int main (int argc, char **argv) {
189+ #ifndef DISABLE_OL_INIT
190+ if (auto Err = olInit ()) {
191+ errs () << " Failed to initialize liboffload: " << Err->Code << " \n " ;
192+ return -1 ;
193+ }
194+ #endif
195+
196+ ::testing::InitGoogleTest (&argc, argv);
197+ int Result = RUN_ALL_TESTS ();
198+
199+ #ifndef DISABLE_OL_INIT
200+ if (auto Err = olShutDown ()) {
201+ errs () << " Failed to shut down liboffload: " << Err->Code << " \n " ;
202+ return -1 ;
203+ }
204+ #endif
205+
206+ return Result;
207+ }
You can’t perform that action at this time.
0 commit comments