-
Notifications
You must be signed in to change notification settings - Fork 772
[SYCL] Only call shutdown when DLL is being unloaded, not when process is terminating #4983
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e386efe
[SYCL] Only call shutdown when DLL is being unloaded, not when proces…
d3ce279
Add unit-test
d81b4cb
Merge remote-tracking branch 'public/sycl' into fix-windows-shutdown2
9832e6e
Fixes in the test along with some outputs for verbosity
93744b3
Make unit-test a no-op on non-windows platform
3643090
Stylistic change
c183ba7
Stylistic change
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
add_sycl_unittest(WindowsDllMainTest OBJECT | ||
dllmain.cpp | ||
) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
//==----- dllmain.cpp --- verify behaviour of lib on process termination ---==// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
/* | ||
* This test calls DllMain on Windows. This means, the process performs actions | ||
* which are required for library unload. That said, the test requires to be a | ||
* distinct binary executable. | ||
*/ | ||
|
||
#include <CL/sycl.hpp> | ||
#include <helpers/CommonRedefinitions.hpp> | ||
#include <helpers/PiImage.hpp> | ||
#include <helpers/PiMock.hpp> | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#ifdef _WIN32 | ||
#include <windows.h> | ||
|
||
extern "C" BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, | ||
LPVOID lpReserved); | ||
|
||
static std::atomic<int> TearDownCalls{0}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit. I would add a |
||
|
||
pi_result redefinedTearDown(void *PluginParameter) { | ||
fprintf(stderr, "intercepted tear down\n"); | ||
s-kanaev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
++TearDownCalls; | ||
|
||
return PI_SUCCESS; | ||
} | ||
#endif | ||
|
||
TEST(Windows, DllMainCall) { | ||
#ifdef _WIN32 | ||
sycl::platform Plt{sycl::default_selector()}; | ||
if (Plt.is_host()) { | ||
printf("Test is not supported on host, skipping\n"); | ||
return; | ||
} | ||
sycl::unittest::PiMock Mock{Plt}; | ||
setupDefaultMockAPIs(Mock); | ||
Mock.redefine<sycl::detail::PiApiKind::piTearDown>(redefinedTearDown); | ||
|
||
// Teardown calls are only expected on sycl.dll library unload, not when | ||
// process gets terminated. | ||
// The first call to DllMain is to simulate library unload. The second one | ||
// is to simulate process termination | ||
fprintf(stderr, "Call DllMain for the first time\n"); | ||
DllMain((HINSTANCE)0, DLL_PROCESS_DETACH, (LPVOID)NULL); | ||
|
||
int TearDownCallsDone = TearDownCalls.load(); | ||
|
||
EXPECT_NE(TearDownCallsDone, 0); | ||
|
||
fprintf(stderr, "Call DllMain for the second time\n"); | ||
DllMain((HINSTANCE)0, DLL_PROCESS_DETACH, (LPVOID)0x01); | ||
|
||
EXPECT_EQ(TearDownCalls.load(), TearDownCallsDone); | ||
#endif | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.