Skip to content

Commit 87a6699

Browse files
authored
[SYCL] Fix lifetime bug in root group unit tests (#19082)
Changes the `MockDeviceImage` and `MockDeviceImageArray` to static variables so that they're not created in each test case. Relates to #19068 and #19074. Fixes #18892. Signed-off-by: Michael Aziz <michael.aziz@intel.com>
1 parent 8d55836 commit 87a6699

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

sycl/unittests/Extensions/RootGroup.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,16 @@ struct KernelInfo<QueryKernel> : public unittest::MockKernelInfoBase {
4242
} // namespace _V1
4343
} // namespace sycl
4444

45+
static sycl::unittest::MockDeviceImage Img =
46+
sycl::unittest::generateDefaultImage({"QueryKernel"});
47+
static const sycl::unittest::MockDeviceImageArray<1> ImgArray{&Img};
48+
4549
// Test that querying max_num_work_groups with an invalid (zero) work-group size
4650
// throws the correct exception
4751
TEST(RootGroupTests, InvalidWorkGroupSize) {
4852
namespace syclex = sycl::ext::oneapi::experimental;
4953

50-
// Create a mock device image containing the QueryKernel
51-
sycl::unittest::MockDeviceImage Img =
52-
sycl::unittest::generateDefaultImage({"QueryKernel"});
53-
const sycl::unittest::MockDeviceImageArray<1> ImgArray{&Img};
54+
// Create a UR mock for testing
5455
const sycl::unittest::UrMock<> Mock;
5556

5657
const sycl::queue q;
@@ -75,10 +76,7 @@ TEST(RootGroupTests, InvalidWorkGroupSize) {
7576
TEST(RootGroupTests, ValidNumWorkGroupsQuery) {
7677
namespace syclex = sycl::ext::oneapi::experimental;
7778

78-
// Create a mock device image containing the QueryKernel
79-
sycl::unittest::MockDeviceImage Img =
80-
sycl::unittest::generateDefaultImage({"QueryKernel"});
81-
const sycl::unittest::MockDeviceImageArray<1> ImgArray{&Img};
79+
// Create a UR mock for testing
8280
const sycl::unittest::UrMock<> Mock;
8381

8482
// Set up a mock callback to return a specific group count when queried

0 commit comments

Comments
 (0)