|
| 1 | +/* |
| 2 | + * Copyright (C) 2022 Intel Corporation |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: MIT |
| 5 | + * |
| 6 | + */ |
| 7 | + |
| 8 | +#include "shared/test/common/mocks/mock_os_library.h" |
| 9 | + |
| 10 | +#include "level_zero/tools/source/pin/pin.h" |
| 11 | + |
| 12 | +#include "gtest/gtest.h" |
| 13 | + |
| 14 | +namespace ult { |
| 15 | + |
| 16 | +TEST(PinInitializationTest, GivenValidLibraryPinContextInitSucceeds) { |
| 17 | + uint32_t (*openPinHandler)(void *) = [](void *arg) -> uint32_t { return 0; }; |
| 18 | + auto newPtr = new MockOsLibrary(reinterpret_cast<void *>(openPinHandler), false); |
| 19 | + MockOsLibrary::loadLibraryNewObject = newPtr; |
| 20 | + L0::PinContext::osLibraryLoadFunction = MockOsLibrary::load; |
| 21 | + EXPECT_EQ(L0::PinContext::init(), ZE_RESULT_SUCCESS); |
| 22 | + L0::PinContext::osLibraryLoadFunction = NEO::OsLibrary::load; |
| 23 | + MockOsLibrary::loadLibraryNewObject = nullptr; |
| 24 | + delete newPtr; |
| 25 | +} |
| 26 | + |
| 27 | +TEST(PinInitializationTest, GivenBadLibraryNamePinContextInitFAILS) { |
| 28 | + MockOsLibrary::loadLibraryNewObject = nullptr; |
| 29 | + L0::PinContext::osLibraryLoadFunction = MockOsLibrary::load; |
| 30 | + EXPECT_EQ(L0::PinContext::init(), ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE); |
| 31 | + L0::PinContext::osLibraryLoadFunction = NEO::OsLibrary::load; |
| 32 | + MockOsLibrary::loadLibraryNewObject = nullptr; |
| 33 | +} |
| 34 | + |
| 35 | +TEST(PinInitializationTest, GivenBadProcAddressPinContextInitFAILS) { |
| 36 | + auto newPtr = new MockOsLibrary(nullptr, false); |
| 37 | + MockOsLibrary::loadLibraryNewObject = newPtr; |
| 38 | + L0::PinContext::osLibraryLoadFunction = MockOsLibrary::load; |
| 39 | + EXPECT_EQ(L0::PinContext::init(), ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE); |
| 40 | + L0::PinContext::osLibraryLoadFunction = NEO::OsLibrary::load; |
| 41 | + MockOsLibrary::loadLibraryNewObject = nullptr; |
| 42 | + delete newPtr; |
| 43 | +} |
| 44 | + |
| 45 | +TEST(PinInitializationTest, GivenBadPinHandlerPinContextInitFAILS) { |
| 46 | + uint32_t (*openPinHandler)(void *) = [](void *arg) -> uint32_t { return 1; }; |
| 47 | + auto newPtr = new MockOsLibrary(reinterpret_cast<void *>(openPinHandler), false); |
| 48 | + MockOsLibrary::loadLibraryNewObject = newPtr; |
| 49 | + L0::PinContext::osLibraryLoadFunction = MockOsLibrary::load; |
| 50 | + EXPECT_EQ(L0::PinContext::init(), ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE); |
| 51 | + L0::PinContext::osLibraryLoadFunction = NEO::OsLibrary::load; |
| 52 | + MockOsLibrary::loadLibraryNewObject = nullptr; |
| 53 | + delete newPtr; |
| 54 | +} |
| 55 | + |
| 56 | +} // namespace ult |
0 commit comments