|
7 | 7 |
|
8 | 8 | #include "shared/test/common/mocks/mock_command_stream_receiver.h" |
9 | 9 |
|
| 10 | +#include "opencl/test/unit_test/mocks/mock_csr.h" |
10 | 11 | #include "test.h" |
11 | 12 |
|
12 | 13 | #include "level_zero/core/source/fence/fence.h" |
13 | 14 | #include "level_zero/core/test/unit_tests/fixtures/device_fixture.h" |
| 15 | +#include "level_zero/core/test/unit_tests/mocks/mock_built_ins.h" |
14 | 16 | #include "level_zero/core/test/unit_tests/mocks/mock_cmdqueue.h" |
15 | 17 |
|
16 | 18 | namespace L0 { |
@@ -63,5 +65,89 @@ TEST_F(FenceTest, whenQueryingStatusAndStateSignaledThenReturnSuccess) { |
63 | 65 | fence->destroy(); |
64 | 66 | } |
65 | 67 |
|
| 68 | +using FenceSynchronizeTest = Test<DeviceFixture>; |
| 69 | + |
| 70 | +TEST_F(FenceSynchronizeTest, givenCallToFenceHostSynchronizeWithTimeoutZeroAndStateInitialHostSynchronizeReturnsNotReady) { |
| 71 | + std::unique_ptr<MockCommandStreamReceiver> csr = nullptr; |
| 72 | + csr = std::make_unique<MockCommandStreamReceiver>(*neoDevice->getExecutionEnvironment(), 0, neoDevice->getDeviceBitfield()); |
| 73 | + |
| 74 | + Mock<CommandQueue> cmdQueue(device, csr.get()); |
| 75 | + std::unique_ptr<L0::Fence> fence; |
| 76 | + fence = std::unique_ptr<L0::Fence>(L0::Fence::create(&cmdQueue, nullptr)); |
| 77 | + EXPECT_NE(nullptr, fence); |
| 78 | + |
| 79 | + ze_result_t result = fence->hostSynchronize(0); |
| 80 | + EXPECT_EQ(ZE_RESULT_NOT_READY, result); |
| 81 | +} |
| 82 | + |
| 83 | +TEST_F(FenceSynchronizeTest, givenCallToFenceHostSynchronizeWithNonZeroTimeoutAndStateInitialHostSynchronizeReturnsNotReady) { |
| 84 | + std::unique_ptr<MockCommandStreamReceiver> csr = nullptr; |
| 85 | + csr = std::make_unique<MockCommandStreamReceiver>(*neoDevice->getExecutionEnvironment(), 0, neoDevice->getDeviceBitfield()); |
| 86 | + |
| 87 | + Mock<CommandQueue> cmdQueue(device, csr.get()); |
| 88 | + std::unique_ptr<L0::Fence> fence; |
| 89 | + fence = std::unique_ptr<L0::Fence>(L0::Fence::create(&cmdQueue, nullptr)); |
| 90 | + EXPECT_NE(nullptr, fence); |
| 91 | + ze_result_t result = fence->hostSynchronize(10); |
| 92 | + EXPECT_EQ(ZE_RESULT_NOT_READY, result); |
| 93 | +} |
| 94 | + |
| 95 | +TEST_F(FenceSynchronizeTest, givenCallToFenceHostSynchronizeWithTimeoutZeroAndStateSignaledHostSynchronizeReturnsSuccess) { |
| 96 | + std::unique_ptr<MockCommandStreamReceiver> csr = nullptr; |
| 97 | + csr = std::make_unique<MockCommandStreamReceiver>(*neoDevice->getExecutionEnvironment(), 0, neoDevice->getDeviceBitfield()); |
| 98 | + |
| 99 | + Mock<CommandQueue> cmdQueue(device, csr.get()); |
| 100 | + std::unique_ptr<L0::Fence> fence; |
| 101 | + fence = std::unique_ptr<L0::Fence>(L0::Fence::create(&cmdQueue, nullptr)); |
| 102 | + EXPECT_NE(nullptr, fence); |
| 103 | + auto alloc = &(fence->getAllocation()); |
| 104 | + auto hostAddr = static_cast<uint64_t *>(alloc->getUnderlyingBuffer()); |
| 105 | + *hostAddr = Fence::STATE_SIGNALED; |
| 106 | + ze_result_t result = fence->hostSynchronize(0); |
| 107 | + EXPECT_EQ(ZE_RESULT_SUCCESS, result); |
| 108 | +} |
| 109 | + |
| 110 | +TEST_F(FenceSynchronizeTest, givenCallToFenceHostSynchronizeWithTimeoutNonZeroAndStateSignaledHostSynchronizeReturnsSuccess) { |
| 111 | + std::unique_ptr<MockCommandStreamReceiver> csr = nullptr; |
| 112 | + csr = std::make_unique<MockCommandStreamReceiver>(*neoDevice->getExecutionEnvironment(), 0, neoDevice->getDeviceBitfield()); |
| 113 | + |
| 114 | + Mock<CommandQueue> cmdQueue(device, csr.get()); |
| 115 | + std::unique_ptr<L0::Fence> fence; |
| 116 | + fence = std::unique_ptr<L0::Fence>(L0::Fence::create(&cmdQueue, nullptr)); |
| 117 | + EXPECT_NE(nullptr, fence); |
| 118 | + auto alloc = &(fence->getAllocation()); |
| 119 | + auto hostAddr = static_cast<uint64_t *>(alloc->getUnderlyingBuffer()); |
| 120 | + *hostAddr = Fence::STATE_SIGNALED; |
| 121 | + ze_result_t result = fence->hostSynchronize(10); |
| 122 | + EXPECT_EQ(ZE_RESULT_SUCCESS, result); |
| 123 | +} |
| 124 | + |
| 125 | +using FenceAubCsrTest = Test<DeviceFixture>; |
| 126 | + |
| 127 | +HWTEST_F(FenceAubCsrTest, givenCallToFenceHostSynchronizeWithAubModeCsrReturnsSuccess) { |
| 128 | + std::unique_ptr<Mock<L0::DriverHandleImp>> driverHandle; |
| 129 | + NEO::MockDevice *neoDevice = nullptr; |
| 130 | + L0::Device *device = nullptr; |
| 131 | + |
| 132 | + neoDevice = NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(NEO::defaultHwInfo.get()); |
| 133 | + auto mockBuiltIns = new MockBuiltins(); |
| 134 | + neoDevice->executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(mockBuiltIns); |
| 135 | + NEO::DeviceVector devices; |
| 136 | + devices.push_back(std::unique_ptr<NEO::Device>(neoDevice)); |
| 137 | + driverHandle = std::make_unique<Mock<L0::DriverHandleImp>>(); |
| 138 | + driverHandle->initialize(std::move(devices)); |
| 139 | + device = driverHandle->devices[0]; |
| 140 | + int32_t tag; |
| 141 | + auto aubCsr = new MockCsrAub<FamilyType>(tag, *neoDevice->executionEnvironment, neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()); |
| 142 | + neoDevice->resetCommandStreamReceiver(aubCsr); |
| 143 | + |
| 144 | + Mock<CommandQueue> cmdQueue(device, aubCsr); |
| 145 | + auto fence = Fence::create(&cmdQueue, nullptr); |
| 146 | + |
| 147 | + ze_result_t result = fence->hostSynchronize(10); |
| 148 | + EXPECT_EQ(ZE_RESULT_SUCCESS, result); |
| 149 | + fence->destroy(); |
| 150 | +} |
| 151 | + |
66 | 152 | } // namespace ult |
67 | 153 | } // namespace L0 |
0 commit comments