|
7 | 7 |
|
8 | 8 | #include "shared/source/built_ins/sip.h" |
9 | 9 | #include "shared/source/os_interface/windows/wddm_allocation.h" |
| 10 | +#include "shared/source/os_interface/windows/wddm_debug.h" |
10 | 11 | #include "shared/test/common/mocks/mock_sip.h" |
11 | 12 | #include "shared/test/common/mocks/windows/mock_wddm_eudebug.h" |
12 | 13 | #include "shared/test/common/test_macros/hw_test.h" |
13 | 14 |
|
14 | 15 | #include "level_zero/core/test/unit_tests/fixtures/device_fixture.h" |
| 16 | +#include "level_zero/tools/source/debug/debug_handlers.h" |
15 | 17 | #include "level_zero/tools/source/debug/windows/debug_session.h" |
16 | 18 |
|
17 | 19 | #include "common/StateSaveAreaHeader.h" |
@@ -45,6 +47,7 @@ struct MockDebugSessionWindows : DebugSessionWindows { |
45 | 47 | using DebugSessionWindows::stateSaveAreaVA; |
46 | 48 | using DebugSessionWindows::wddm; |
47 | 49 | using DebugSessionWindows::writeGpuMemory; |
| 50 | + using L0::DebugSessionImp::apiEvents; |
48 | 51 | using L0::DebugSessionImp::getStateSaveAreaHeader; |
49 | 52 | using L0::DebugSessionImp::isValidGpuAddress; |
50 | 53 |
|
@@ -482,6 +485,79 @@ TEST_F(DebugApiWindowsTest, givenDebugDataEventTypeWhenReadAndHandleEventCalledT |
482 | 485 | EXPECT_EQ(elf.endVA, 0xa008u); |
483 | 486 | } |
484 | 487 |
|
| 488 | +TEST(DebugSessionTest, GivenNullptrEventWhenReadingEventThenErrorNullptrReturned) { |
| 489 | + zet_debug_config_t config = {}; |
| 490 | + config.pid = 0x1234; |
| 491 | + |
| 492 | + auto session = std::make_unique<MockDebugSessionWindows>(config, nullptr); |
| 493 | + ASSERT_NE(nullptr, session); |
| 494 | + |
| 495 | + auto result = session->readEvent(10, nullptr); |
| 496 | + EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_POINTER, result); |
| 497 | +} |
| 498 | + |
| 499 | +TEST_F(DebugApiWindowsTest, GivenMatchingDebugDataEventsForCommandQueueCreateWhenReadingEventsThenProcessEntryIsReturned) { |
| 500 | + zet_debug_config_t config = {}; |
| 501 | + config.pid = 0x1234; |
| 502 | + |
| 503 | + auto session = std::make_unique<MockDebugSessionWindows>(config, device); |
| 504 | + session->wddm = mockWddm; |
| 505 | + ASSERT_NE(nullptr, session); |
| 506 | + |
| 507 | + EXPECT_TRUE(session->apiEvents.empty()); |
| 508 | + mockWddm->numEvents = 1; |
| 509 | + mockWddm->eventQueue[0].readEventType = DBGUMD_READ_EVENT_CREATE_DEBUG_DATA; |
| 510 | + mockWddm->eventQueue[0].eventParamsBuffer.eventParamsBuffer.ReadCreateDebugDataParams.DebugDataType = static_cast<uint32_t>(NEO::DebugDataType::CMD_QUEUE_CREATED); |
| 511 | + mockWddm->eventQueue[0].eventParamsBuffer.eventParamsBuffer.ReadCreateDebugDataParams.DataBufferPtr = 0xa000; |
| 512 | + mockWddm->eventQueue[0].eventParamsBuffer.eventParamsBuffer.ReadCreateDebugDataParams.DataSize = 8; |
| 513 | + EXPECT_EQ(ZE_RESULT_SUCCESS, session->readAndHandleEvent(100)); |
| 514 | + EXPECT_EQ(session->apiEvents.size(), 1u); |
| 515 | + |
| 516 | + zet_debug_event_t event = {}; |
| 517 | + session->debugHandle = MockDebugSessionWindows::mockDebugHandle; |
| 518 | + ze_result_t result = zetDebugReadEvent(session->toHandle(), 0, &event); |
| 519 | + EXPECT_EQ(ZE_RESULT_SUCCESS, result); |
| 520 | + EXPECT_EQ(ZET_DEBUG_EVENT_TYPE_PROCESS_ENTRY, event.type); |
| 521 | +} |
| 522 | + |
| 523 | +TEST_F(DebugApiWindowsTest, GivenMatchingDebugDataEventsForCommandQueueDestroyWhenReadingEventsThenProcessExitIsReturned) { |
| 524 | + zet_debug_config_t config = {}; |
| 525 | + config.pid = 0x1234; |
| 526 | + |
| 527 | + auto session = std::make_unique<MockDebugSessionWindows>(config, device); |
| 528 | + session->wddm = mockWddm; |
| 529 | + ASSERT_NE(nullptr, session); |
| 530 | + |
| 531 | + EXPECT_TRUE(session->apiEvents.empty()); |
| 532 | + mockWddm->numEvents = 1; |
| 533 | + mockWddm->eventQueue[0].readEventType = DBGUMD_READ_EVENT_CREATE_DEBUG_DATA; |
| 534 | + mockWddm->eventQueue[0].eventParamsBuffer.eventParamsBuffer.ReadCreateDebugDataParams.DebugDataType = static_cast<uint32_t>(NEO::DebugDataType::CMD_QUEUE_DESTROYED); |
| 535 | + mockWddm->eventQueue[0].eventParamsBuffer.eventParamsBuffer.ReadCreateDebugDataParams.DataBufferPtr = 0xa000; |
| 536 | + mockWddm->eventQueue[0].eventParamsBuffer.eventParamsBuffer.ReadCreateDebugDataParams.DataSize = 8; |
| 537 | + EXPECT_EQ(ZE_RESULT_SUCCESS, session->readAndHandleEvent(100)); |
| 538 | + EXPECT_EQ(session->apiEvents.size(), 1u); |
| 539 | + |
| 540 | + zet_debug_event_t event = {}; |
| 541 | + session->debugHandle = MockDebugSessionWindows::mockDebugHandle; |
| 542 | + ze_result_t result = zetDebugReadEvent(session->toHandle(), 0, &event); |
| 543 | + EXPECT_EQ(ZE_RESULT_SUCCESS, result); |
| 544 | + EXPECT_EQ(ZET_DEBUG_EVENT_TYPE_PROCESS_EXIT, event.type); |
| 545 | +} |
| 546 | + |
| 547 | +TEST_F(DebugApiWindowsTest, GivenNoEventsAvailableWhenReadingEventThenResultNotReadyIsReturned) { |
| 548 | + zet_debug_config_t config = {}; |
| 549 | + config.pid = 0x1234; |
| 550 | + |
| 551 | + auto session = std::make_unique<MockDebugSessionWindows>(config, device); |
| 552 | + session->wddm = mockWddm; |
| 553 | + ASSERT_NE(nullptr, session); |
| 554 | + |
| 555 | + zet_debug_event_t event = {}; |
| 556 | + session->debugHandle = MockDebugSessionWindows::mockDebugHandle; |
| 557 | + ze_result_t result = zetDebugReadEvent(session->toHandle(), 0, &event); |
| 558 | + EXPECT_EQ(result, ZE_RESULT_NOT_READY); |
| 559 | +} |
| 560 | + |
485 | 561 | TEST_F(DebugApiWindowsTest, givenAllocationEventTypeForStateSaveWhenReadAndHandleEventCalledThenStateSaveIsCaptured) { |
486 | 562 | zet_debug_config_t config = {}; |
487 | 563 | config.pid = 0x1234; |
|
0 commit comments