2424// /
2525// ===----------------------------------------------------------------------===//
2626
27+ #include " ../helper/include/dpctl_utils_helper.h"
2728#include " dpctl_sycl_device_interface.h"
2829#include " dpctl_sycl_device_manager.h"
2930#include " dpctl_sycl_device_selector_interface.h"
3031#include < gtest/gtest.h>
32+ #include < string>
3133
3234struct TestDPCTLDeviceManager : public ::testing::TestWithParam<const char *>
3335{
@@ -81,12 +83,12 @@ INSTANTIATE_TEST_SUITE_P(DeviceMgrFunctions,
8183 " opencl:cpu:0" ,
8284 " level_zero:gpu:0" ));
8385
84- struct TestDPCTLDeviceVector : public ::testing::TestWithParam<int >
86+ struct TestDPCTLGetDevices : public ::testing::TestWithParam<int >
8587{
8688 DPCTLDeviceVectorRef DV = nullptr ;
8789 size_t nDevices = 0 ;
8890
89- TestDPCTLDeviceVector ()
91+ TestDPCTLGetDevices ()
9092 {
9193 EXPECT_NO_FATAL_FAILURE (DV = DPCTLDeviceMgr_GetDevices (GetParam ()));
9294 EXPECT_TRUE (DV != nullptr );
@@ -100,14 +102,14 @@ struct TestDPCTLDeviceVector : public ::testing::TestWithParam<int>
100102 }
101103 }
102104
103- ~TestDPCTLDeviceVector ()
105+ ~TestDPCTLGetDevices ()
104106 {
105107 EXPECT_NO_FATAL_FAILURE (DPCTLDeviceVector_Clear (DV));
106108 EXPECT_NO_FATAL_FAILURE (DPCTLDeviceVector_Delete (DV));
107109 }
108110};
109111
110- TEST_P (TestDPCTLDeviceVector , ChkGetAt)
112+ TEST_P (TestDPCTLGetDevices , ChkGetAt)
111113{
112114 for (auto i = 0ul ; i < nDevices; ++i) {
113115 DPCTLSyclDeviceRef DRef = nullptr ;
@@ -118,14 +120,18 @@ TEST_P(TestDPCTLDeviceVector, ChkGetAt)
118120
119121INSTANTIATE_TEST_SUITE_P (
120122 GetDevices,
121- TestDPCTLDeviceVector ,
123+ TestDPCTLGetDevices ,
122124 ::testing::Values (DPCTLSyclBackendType::DPCTL_HOST,
123125 DPCTLSyclBackendType::DPCTL_LEVEL_ZERO,
124126 DPCTLSyclBackendType::DPCTL_OPENCL,
125127 DPCTLSyclBackendType::DPCTL_OPENCL |
126128 DPCTLSyclDeviceType::DPCTL_GPU));
127129
128- TEST (TestDPCTLDeviceVector, ChkDPCTLDeviceVectorCreate)
130+ struct TestDPCTLDeviceVector : public ::testing::Test
131+ {
132+ };
133+
134+ TEST_F (TestDPCTLDeviceVector, ChkDPCTLDeviceVectorCreate)
129135{
130136 DPCTLDeviceVectorRef DVRef = nullptr ;
131137 size_t nDevices = 0 ;
@@ -135,3 +141,63 @@ TEST(TestDPCTLDeviceVector, ChkDPCTLDeviceVectorCreate)
135141 EXPECT_TRUE (nDevices == 0 );
136142 EXPECT_NO_FATAL_FAILURE (DPCTLDeviceVector_Delete (DVRef));
137143}
144+
145+ struct TestDPCTLGetDevicesOrdering : public ::testing::TestWithParam<int >
146+ {
147+ DPCTLDeviceVectorRef DV = nullptr ;
148+ size_t nDevices = 0 ;
149+
150+ TestDPCTLGetDevicesOrdering ()
151+ {
152+ const int device_type_mask =
153+ (GetParam () & DPCTLSyclDeviceType::DPCTL_ALL) |
154+ DPCTLSyclBackendType::DPCTL_ALL_BACKENDS;
155+ EXPECT_NO_FATAL_FAILURE (
156+ DV = DPCTLDeviceMgr_GetDevices (device_type_mask));
157+ EXPECT_TRUE (DV != nullptr );
158+ EXPECT_NO_FATAL_FAILURE (nDevices = DPCTLDeviceVector_Size (DV));
159+ }
160+
161+ void SetUp ()
162+ {
163+ if (!nDevices) {
164+ GTEST_SKIP_ (" Skipping as no devices returned for identifier" );
165+ }
166+ }
167+
168+ ~TestDPCTLGetDevicesOrdering ()
169+ {
170+ EXPECT_NO_FATAL_FAILURE (DPCTLDeviceVector_Clear (DV));
171+ EXPECT_NO_FATAL_FAILURE (DPCTLDeviceVector_Delete (DV));
172+ }
173+ };
174+
175+ TEST_P (TestDPCTLGetDevicesOrdering, ChkConsistencyWithFilterSelector)
176+ {
177+ for (auto i = 0ul ; i < nDevices; ++i) {
178+ DPCTLSyclDeviceType Dty;
179+ std::string fs_device_type, fs;
180+ DPCTLSyclDeviceRef DRef = nullptr , D0Ref = nullptr ;
181+ DPCTLSyclDeviceSelectorRef DSRef = nullptr ;
182+ EXPECT_NO_FATAL_FAILURE (DRef = DPCTLDeviceVector_GetAt (DV, i));
183+ EXPECT_NO_FATAL_FAILURE (Dty = DPCTLDevice_GetDeviceType (DRef));
184+ EXPECT_NO_FATAL_FAILURE (
185+ fs_device_type = DPCTL_DeviceTypeToStr (
186+ DPCTL_DPCTLDeviceTypeToSyclDeviceType (Dty)));
187+ EXPECT_NO_FATAL_FAILURE (fs = fs_device_type + " :" + std::to_string (i));
188+ EXPECT_NO_FATAL_FAILURE (DSRef = DPCTLFilterSelector_Create (fs.c_str ()));
189+ EXPECT_NO_FATAL_FAILURE (D0Ref = DPCTLDevice_CreateFromSelector (DSRef));
190+ EXPECT_NO_FATAL_FAILURE (DPCTLDeviceSelector_Delete (DSRef));
191+ EXPECT_TRUE (DPCTLDevice_AreEq (DRef, D0Ref));
192+ EXPECT_NO_FATAL_FAILURE (DPCTLDevice_Delete (D0Ref));
193+ EXPECT_NO_FATAL_FAILURE (DPCTLDevice_Delete (DRef));
194+ }
195+ }
196+
197+ INSTANTIATE_TEST_SUITE_P (
198+ GetDevices,
199+ TestDPCTLGetDevicesOrdering,
200+ ::testing::Values (DPCTLSyclDeviceType::DPCTL_HOST_DEVICE,
201+ DPCTLSyclDeviceType::DPCTL_ACCELERATOR,
202+ DPCTLSyclDeviceType::DPCTL_GPU,
203+ DPCTLSyclDeviceType::DPCTL_CPU));
0 commit comments