Skip to content

Commit 14fa772

Browse files
authored
[PTI-SDK] Add minimal testing of full and hybrid modes (#480)
- improves ze_collector.h code-coverage + 2% on lines, +3% on branches --------- Signed-off-by: jfedorov <[email protected]>
1 parent ccc6526 commit 14fa772

File tree

2 files changed

+46
-18
lines changed

2 files changed

+46
-18
lines changed

sdk/test/main_vecsqadd_fixture.cc

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -328,24 +328,32 @@ void RunVecsqadd(TestType a_test_type) {
328328
ASSERT_EQ(ptiFlushAllViews(), pti_result::PTI_SUCCESS);
329329
}
330330

331+
enum CollectionMode { kModeFull = 0, kModeHybrid = 1, kModeLocal = 2 };
332+
331333
} // namespace
332334

333-
class VecsqaddFixtureTest : public ::testing::Test {
335+
class VecsqaddFixtureTest : public ::testing::TestWithParam<CollectionMode> {
334336
protected:
335337
void SetUp() override {
336338
timestamps_monotonic = true;
337339
a_append_timestamp = 0;
338340
external_corr_map.clear();
339341
runtime_enq_2_gpu_kernel_name_map.clear();
340342
runtime_enq_2_gpu_mem_op_name_map.clear();
343+
CollectionMode _collection_mode = GetParam();
344+
// while passed ModeLocal local it is expected it will be selected automatically of course
345+
// in case introspection API is available
346+
if (_collection_mode != CollectionMode::kModeLocal) {
347+
utils::SetEnv("PTI_COLLECTION_MODE", std::to_string(_collection_mode).c_str());
348+
}
341349
}
342350

343351
void TearDown() override {
344352
// Called right before destructor after each test
345353
}
346354
};
347355

348-
TEST_F(VecsqaddFixtureTest, CorrelationIdsAndExternalCorrelationMatchForSq) {
356+
TEST_P(VecsqaddFixtureTest, CorrelationIdsAndExternalCorrelationMatchForSq) {
349357
EXPECT_EQ(ptiViewSetCallbacks(BufferRequested, BufferCompleted), pti_result::PTI_SUCCESS);
350358
RunVecsqadd(TestType::kExternalCorrId);
351359
uint64_t correlation_id = kernel_corr_id[0];
@@ -371,7 +379,7 @@ void EnableIndividualRuntimeApis() {
371379
pti_result::PTI_SUCCESS);
372380
}
373381

374-
TEST_F(VecsqaddFixtureTest, CorrelationIdsAndExternalCorrelationMatchForSqReducedOps) {
382+
TEST_P(VecsqaddFixtureTest, CorrelationIdsAndExternalCorrelationMatchForSqReducedOps) {
375383
utils::SetEnv("PTI_VIEW_RUNTIME_API", "1");
376384
EXPECT_EQ(ptiViewSetCallbacks(BufferRequested, BufferCompleted), pti_result::PTI_SUCCESS);
377385
EnableIndividualRuntimeApis();
@@ -393,7 +401,7 @@ TEST_F(VecsqaddFixtureTest, CorrelationIdsAndExternalCorrelationMatchForSqReduce
393401
}
394402
}
395403

396-
TEST_F(VecsqaddFixtureTest, CorrelationIdsMatchForAdd) {
404+
TEST_P(VecsqaddFixtureTest, CorrelationIdsMatchForAdd) {
397405
EXPECT_EQ(ptiViewSetCallbacks(BufferRequested, BufferCompleted), pti_result::PTI_SUCCESS);
398406
RunVecsqadd(TestType::kExternalCorrId);
399407
// Check that the correlation id of runtime and kernel matches
@@ -402,7 +410,7 @@ TEST_F(VecsqaddFixtureTest, CorrelationIdsMatchForAdd) {
402410
EXPECT_LE(sycl_kernel_start_time[1], kernel_append_time[1]);
403411
}
404412

405-
TEST_F(VecsqaddFixtureTest, CorrelationIdsMatchForAddReducedOps) {
413+
TEST_P(VecsqaddFixtureTest, CorrelationIdsMatchForAddReducedOps) {
406414
utils::SetEnv("PTI_VIEW_RUNTIME_API", "1");
407415
EXPECT_EQ(ptiViewSetCallbacks(BufferRequested, BufferCompleted), pti_result::PTI_SUCCESS);
408416
EnableIndividualRuntimeApis();
@@ -413,7 +421,7 @@ TEST_F(VecsqaddFixtureTest, CorrelationIdsMatchForAddReducedOps) {
413421
EXPECT_LE(sycl_kernel_start_time[1], kernel_append_time[1]);
414422
}
415423

416-
TEST_F(VecsqaddFixtureTest, TimestampWrapAroundOnOverflow) {
424+
TEST_P(VecsqaddFixtureTest, TimestampWrapAroundOnOverflow) {
417425
// TODO: Move this to the fixture if we get more stress tests. However, for now this is our only
418426
// one so we will soft disable it until it is enabled in CI.
419427
const auto result = utils::GetEnv("PTI_ENABLE_STRESS_TESTS");
@@ -427,3 +435,7 @@ TEST_F(VecsqaddFixtureTest, TimestampWrapAroundOnOverflow) {
427435
RunVecsqadd(TestType::kOverflowStress);
428436
EXPECT_EQ(timestamps_monotonic, true);
429437
}
438+
439+
INSTANTIATE_TEST_SUITE_P(VecSqAddSuite, VecsqaddFixtureTest,
440+
::testing::Values(CollectionMode::kModeFull, CollectionMode::kModeLocal,
441+
CollectionMode::kModeHybrid));

sdk/test/no_kernel_overlap.cc

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,16 @@ void TestCore(bool do_immediate) {
111111
std::cerr << "Error: Unknown exception caught." << '\n';
112112
}
113113
}
114-
} // namespace
115114

116115
bool ComparePair(std::pair<uint64_t, uint64_t> a_stamps, std::pair<uint64_t, uint64_t> b_stamps) {
117116
return a_stamps.first < b_stamps.first;
118117
}
118+
enum CollectionMode { kModeFull = 0, kModeHybrid = 1, kModeLocal = 2 };
119+
120+
} // namespace
119121

120-
class NoKernelOverlapParametrizedTestFixture : public ::testing::TestWithParam<bool> {
122+
class NoKernelOverlapParametrizedTestFixture
123+
: public ::testing::TestWithParam<std::tuple<bool, CollectionMode>> {
121124
protected:
122125
NoKernelOverlapParametrizedTestFixture() {
123126
// Setup work for each test
@@ -130,20 +133,28 @@ class NoKernelOverlapParametrizedTestFixture : public ::testing::TestWithParam<b
130133
static uint32_t times_buffer_completed;
131134
static std::vector<uint64_t> kernel_device_timestamps;
132135
static std::vector<uint64_t> kernel_host_timestamps;
133-
134-
static std::vector<std::pair<uint64_t, uint64_t> > kernel_device_timestamps_pairs;
136+
static std::vector<std::pair<uint64_t, uint64_t>> kernel_device_timestamps_pairs;
137+
static bool do_immediate;
135138

136139
void SetUp() override { // Called right after constructor before each test
137140
kernel_device_timestamps_pairs.clear();
138141
kernel_host_timestamps.clear();
139142
times_buffer_completed = 0;
143+
144+
auto [immediate, collection_mode] = GetParam();
145+
do_immediate = immediate;
146+
// while passed ModeLocal local it is expected it will be selected automatically of course
147+
// in case introspection API is available
148+
if (collection_mode != CollectionMode::kModeLocal) {
149+
utils::SetEnv("PTI_COLLECTION_MODE", std::to_string(collection_mode).c_str());
150+
}
140151
}
141152

142153
void TearDown() override {
143154
// Called right before destructor after each test
144155
}
145156

146-
bool TestForDeviceKernelsOverlap(std::vector<std::pair<uint64_t, uint64_t> >& timestamps) {
157+
bool TestForDeviceKernelsOverlap(std::vector<std::pair<uint64_t, uint64_t>>& timestamps) {
147158
if (timestamps.size() == 0) {
148159
std::cerr << "---> ERROR: Empty kernel timestamps array - Not expected " << std::endl;
149160
return false;
@@ -161,16 +172,16 @@ class NoKernelOverlapParametrizedTestFixture : public ::testing::TestWithParam<b
161172
<< std::endl;
162173
*/
163174
if (timestamps[item].first <= timestamps[item - 1].second) {
164-
std::cerr << "---> ERROR: Device kernel timestamps overlap start_of_i < end_of_i-1, at i: "
165-
<< item << ", start_of_i: " << timestamps[item].first
166-
<< ", end_of_i-1: " << timestamps[item - 1].second << std::endl;
175+
std::cerr << "---> ERROR: Device kernel timestamps overlap end_of_i < start_of_i-1, at i: "
176+
<< item << ", end_of_i: " << timestamps[item].first
177+
<< ", start_of_i-1: " << timestamps[item - 1].second << std::endl;
167178
return false;
168179
}
169180
}
170181
return true;
171182
}
172183

173-
bool TestForDeviceKernelDurationNonZero(std::vector<std::pair<uint64_t, uint64_t> >& timestamps) {
184+
bool TestForDeviceKernelDurationNonZero(std::vector<std::pair<uint64_t, uint64_t>>& timestamps) {
174185
if (timestamps.size() == 0) {
175186
std::cerr << "---> ERROR: Empty kernel timestamps array - Not expected " << std::endl;
176187
return false;
@@ -301,11 +312,11 @@ class NoKernelOverlapParametrizedTestFixture : public ::testing::TestWithParam<b
301312
// static members initialization
302313
uint32_t NoKernelOverlapParametrizedTestFixture::times_buffer_completed = 0;
303314
std::vector<uint64_t> NoKernelOverlapParametrizedTestFixture::kernel_host_timestamps{};
304-
std::vector<std::pair<uint64_t, uint64_t> >
315+
std::vector<std::pair<uint64_t, uint64_t>>
305316
NoKernelOverlapParametrizedTestFixture::kernel_device_timestamps_pairs{};
317+
bool NoKernelOverlapParametrizedTestFixture::do_immediate = true;
306318

307319
TEST_P(NoKernelOverlapParametrizedTestFixture, NoKernelOverlapImmediate) {
308-
bool do_immediate = GetParam();
309320
EXPECT_EQ(ptiViewSetCallbacks(BufferRequested, BufferCompleted), pti_result::PTI_SUCCESS);
310321

311322
RunTest(do_immediate);
@@ -323,4 +334,9 @@ TEST_P(NoKernelOverlapParametrizedTestFixture, NoKernelOverlapImmediate) {
323334
}
324335

325336
INSTANTIATE_TEST_SUITE_P(NoKernelOverlapTests, NoKernelOverlapParametrizedTestFixture,
326-
::testing::Values(true, false));
337+
::testing::Values(std::make_tuple(true, CollectionMode::kModeFull),
338+
std::make_tuple(false, CollectionMode::kModeFull),
339+
std::make_tuple(true, CollectionMode::kModeHybrid),
340+
std::make_tuple(false, CollectionMode::kModeHybrid),
341+
std::make_tuple(true, CollectionMode::kModeLocal),
342+
std::make_tuple(false, CollectionMode::kModeLocal)));

0 commit comments

Comments
 (0)