Skip to content

Commit 04aaf36

Browse files
authored
Only Enable Teardown thread on windows and remove debug on success (#323)
Signed-off-by: Neil R. Spruit <neil.r.spruit@intel.com>
1 parent 4765e48 commit 04aaf36

4 files changed

Lines changed: 33 additions & 9 deletions

File tree

samples/zello_world/zello_world.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,14 @@ int main( int argc, char *argv[] )
196196
zeEventHostSynchronize(event, UINT64_MAX );
197197
std::cout << "Congratulations, the device completed execution!\n";
198198

199-
zeContextDestroy(context);
200-
zeCommandListDestroy(command_list);
201-
zeEventDestroy(event);
202-
zeEventPoolDestroy(event_pool);
199+
if (!zelCheckIsLoaderInTearDown())
200+
zeContextDestroy(context);
201+
if (!zelCheckIsLoaderInTearDown())
202+
zeCommandListDestroy(command_list);
203+
if (!zelCheckIsLoaderInTearDown())
204+
zeEventDestroy(event);
205+
if (!zelCheckIsLoaderInTearDown())
206+
zeEventPoolDestroy(event_pool);
203207

204208
if (tracing_enabled) {
205209
status = zelTracerDestroy(tracer);

source/lib/ze_lib.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -489,18 +489,14 @@ zelCheckIsLoaderInTearDown() {
489489
if (ze_lib::destruction || ze_lib::context == nullptr) {
490490
return true;
491491
}
492-
#ifdef DYNAMIC_LOAD_LOADER
492+
#if defined(DYNAMIC_LOAD_LOADER) && defined(_WIN32)
493493
std::promise<int> stabilityPromise;
494494
std::future<int> resultFuture = stabilityPromise.get_future();
495495
int result = -1;
496496
try {
497497
// Launch the stability checker thread
498498
std::thread stabilityThread(stabilityCheck, std::move(stabilityPromise));
499499
result = resultFuture.get(); // Blocks until the result is available
500-
if (ze_lib::context->debugTraceEnabled) {
501-
std::string message = "Stability checker thread completed with result: " + std::to_string(result);
502-
ze_lib::context->debug_trace_message(message, "");
503-
}
504500
stabilityThread.join();
505501
} catch (const std::exception& e) {
506502
if (ze_lib::context->debugTraceEnabled) {

test/CMakeLists.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,27 @@ endif()
9797
add_test(NAME tests_loader_teardown_check COMMAND tests --gtest_filter=*GivenLoaderNotInDestructionStateWhenCallingzelCheckIsLoaderInTearDownThenFalseIsReturned)
9898
set_property(TEST tests_loader_teardown_check PROPERTY ENVIRONMENT "ZE_ENABLE_LOADER_DEBUG_TRACE=1;ZE_ENABLE_NULL_DRIVER=1")
9999

100+
add_test(NAME test_zello_world_legacy COMMAND zello_world --enable_legacy_init --enable_null_driver --force_loader_intercepts --enable_validation_layer --enable_tracing_layer --enable_tracing_layer_runtime)
101+
set_property(TEST test_zello_world_legacy PROPERTY ENVIRONMENT "ZE_ENABLE_LOADER_DEBUG_TRACE=1")
102+
103+
add_test(NAME test_zello_world_legacy_intercept COMMAND zello_world --enable_legacy_init --enable_null_driver --force_loader_intercepts)
104+
set_property(TEST test_zello_world_legacy_intercept PROPERTY ENVIRONMENT "ZE_ENABLE_LOADER_DEBUG_TRACE=1")
105+
106+
add_test(NAME test_zello_world_legacy_validation_layer COMMAND zello_world --enable_legacy_init --enable_null_driver --enable_validation_layer)
107+
set_property(TEST test_zello_world_legacy_validation_layer PROPERTY ENVIRONMENT "ZE_ENABLE_LOADER_DEBUG_TRACE=1")
108+
109+
add_test(NAME test_zello_world_legacy_tracing COMMAND zello_world --enable_legacy_init --enable_null_driver --enable_tracing_layer)
110+
set_property(TEST test_zello_world_legacy_tracing PROPERTY ENVIRONMENT "ZE_ENABLE_LOADER_DEBUG_TRACE=1")
111+
112+
add_test(NAME test_zello_world_legacy_dynamic_tracing COMMAND zello_world --enable_legacy_init --enable_null_driver --enable_tracing_layer_runtime)
113+
set_property(TEST test_zello_world_legacy_dynamic_tracing PROPERTY ENVIRONMENT "ZE_ENABLE_LOADER_DEBUG_TRACE=1")
114+
115+
add_test(NAME test_zello_world_legacy_all_tracing COMMAND zello_world --enable_legacy_init --enable_null_driver --force_loader_intercepts --enable_validation_layer --enable_tracing_layer)
116+
set_property(TEST test_zello_world_legacy_all_tracing PROPERTY ENVIRONMENT "ZE_ENABLE_LOADER_DEBUG_TRACE=1")
117+
118+
add_test(NAME test_zello_world_legacy_all_tracing_dynamic COMMAND zello_world --enable_legacy_init --enable_null_driver --force_loader_intercepts --enable_validation_layer --enable_tracing_layer_runtime)
119+
set_property(TEST test_zello_world_legacy_all_tracing_dynamic PROPERTY ENVIRONMENT "ZE_ENABLE_LOADER_DEBUG_TRACE=1")
120+
100121
# These tests are currently not supported on Windows. The reason is that the std::cerr is not being redirected to a pipe in Windows to be then checked against the expected output.
101122
if(NOT MSVC)
102123
add_test(NAME tests_event_deadlock COMMAND tests --gtest_filter=*GivenLevelZeroLoaderPresentWhenCallingzeCommandListAppendMemoryCopyWithCircularDependencyOnEventsThenValidationLayerPrintsWarningOfDeadlock*)

test/loader_api.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,9 @@ TEST(
374374

375375
EXPECT_EQ(ZE_RESULT_SUCCESS, zeInit(0));
376376
EXPECT_FALSE(zelCheckIsLoaderInTearDown());
377+
EXPECT_FALSE(zelCheckIsLoaderInTearDown());
378+
EXPECT_FALSE(zelCheckIsLoaderInTearDown());
379+
EXPECT_FALSE(zelCheckIsLoaderInTearDown());
377380
}
378381

379382
class CaptureOutput {

0 commit comments

Comments
 (0)