File: gdi_interface_tests.cpp

package info (click to toggle)
intel-compute-runtime 25.44.36015.8-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 79,632 kB
  • sloc: cpp: 931,547; lisp: 2,074; sh: 719; makefile: 162; python: 21
file content (135 lines) | stat: -rw-r--r-- 4,424 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
 * Copyright (C) 2018-2025 Intel Corporation
 *
 * SPDX-License-Identifier: MIT
 *
 */

#if defined(_WIN32)
#include "shared/source/os_interface/os_library.h"
#include "shared/source/os_interface/windows/gdi_interface.h"
#include "shared/source/os_interface/windows/gdi_interface_logging.h"
#include "shared/source/os_interface/windows/os_inc.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/helpers/stream_capture.h"
#include "shared/test/common/helpers/variable_backup.h"
#include "shared/test/common/mocks/mock_io_functions.h"
#include "shared/test/common/mocks/windows/mock_gdi_interface.h"
#include "shared/test/common/test_macros/hw_test.h"

#include "gtest/gtest.h"

TEST(GdiInterface, WhenGdiIsCreatedThenItIsInitialized) {
    NEO::Gdi gdi;
    ASSERT_TRUE(gdi.isInitialized());
}

TEST(GdiInterface, DISABLED_GivenInvalidGdiDllNameWhenCreatingGdiThenGdiIsNotInitialized) {
    const char *oldName = Os::gdiDllName;
    Os::gdiDllName = "surely_not_exists_.dll";

    NEO::Gdi gdi;
    EXPECT_FALSE(gdi.isInitialized());

    Os::gdiDllName = oldName;
}

TEST(GdiInterface, givenGdiOverridePathWhenGdiInterfaceIsCalledThenOverridePathIsUsed) {
    const char *oldName = Os::gdiDllName;

    DebugManagerStateRestore dbgRestorer;

    Os::gdiDllName = "surely_not_exists_.dll";
    debugManager.flags.OverrideGdiPath.set(oldName);

    NEO::Gdi gdi;
    EXPECT_TRUE(gdi.isInitialized());

    Os::gdiDllName = oldName;
}

TEST(GdiInterface, givenPrintKmdTimesWhenCallThkWrapperThenRecordTime) {
    if (!GdiLogging::gdiLoggingSupport) {
        GTEST_SKIP();
    }

    DebugManagerStateRestore dbgRestorer;
    debugManager.flags.PrintKmdTimes.set(1);

    auto gdi = std::make_unique<Gdi>();
    EXPECT_TRUE(gdi->isInitialized());

    StreamCapture capture;
    capture.captureStdout();

    D3DKMT_OPENADAPTERFROMLUID param = {};
    gdi->openAdapterFromLuid(&param);
    gdi->openAdapterFromLuid(&param);
    D3DKMT_CLOSEADAPTER closeAdapter = {};
    closeAdapter.hAdapter = param.hAdapter;
    gdi->closeAdapter(&closeAdapter);

    gdi.reset();
    auto output = capture.getCapturedStdout();
    EXPECT_TRUE(output.find("\n--- Gdi statistics ---\n") != std::string::npos);
}

TEST(ThkWrapperTest, givenThkWrapperWhenConstructedThenmFuncIsInitialized) {
    GdiProfiler profiler{};
    NEO::ThkWrapper<void *> wrapper(profiler, "nullptr", 0u);
    EXPECT_EQ(nullptr, wrapper.mFunc);
}

TEST(GdiInterface, GivenGdiLoggingSupportWhenLoggingEnabledAndLoggingToFileUsedThenExpectIoFunctionsUsed) {
    if (!GdiLogging::gdiLoggingSupport) {
        GTEST_SKIP();
    }

    VariableBackup<uint32_t> mockFopenCalledBackup(&NEO::IoFunctions::mockFopenCalled, 0);
    VariableBackup<uint32_t> mockFcloseCalledBackup(&NEO::IoFunctions::mockFcloseCalled, 0);
    VariableBackup<uint32_t> mockVfptrinfCalledBackup(&NEO::IoFunctions::mockVfptrinfCalled, 0);

    DebugManagerStateRestore dbgRestorer;
    debugManager.flags.LogGdiCalls.set(true);
    debugManager.flags.LogGdiCallsToFile.set(true);

    std::unique_ptr<Gdi> gdi = std::make_unique<Gdi>();
    EXPECT_EQ(1u, NEO::IoFunctions::mockFopenCalled);

    D3DKMT_OPENADAPTERFROMLUID param = {};
    gdi->openAdapterFromLuid(&param);
    EXPECT_EQ(2u, NEO::IoFunctions::mockVfptrinfCalled);

    gdi.reset(nullptr);
    EXPECT_EQ(1u, NEO::IoFunctions::mockFcloseCalled);
}

TEST(GdiInterface, GivenGdiLoggingSupportWhenLoggingEnabledAndLoggingToFileNotUsedThenExpectIoFunctionsUsed) {
    if (!GdiLogging::gdiLoggingSupport) {
        GTEST_SKIP();
    }

    VariableBackup<uint32_t> mockFopenCalledBackup(&NEO::IoFunctions::mockFopenCalled, 0);
    VariableBackup<uint32_t> mockFcloseCalledBackup(&NEO::IoFunctions::mockFcloseCalled, 0);
    VariableBackup<uint32_t> mockVfptrinfCalledBackup(&NEO::IoFunctions::mockVfptrinfCalled, 0);

    DebugManagerStateRestore dbgRestorer;
    debugManager.flags.LogGdiCalls.set(true);
    debugManager.flags.LogGdiCallsToFile.set(false);

    StreamCapture capture;
    capture.captureStdout();

    std::unique_ptr<Gdi> gdi = std::make_unique<Gdi>();
    EXPECT_EQ(0u, NEO::IoFunctions::mockFopenCalled);

    D3DKMT_OPENADAPTERFROMLUID param = {};
    gdi->openAdapterFromLuid(&param);
    EXPECT_EQ(2u, NEO::IoFunctions::mockVfptrinfCalled);

    gdi.reset(nullptr);
    EXPECT_EQ(0u, NEO::IoFunctions::mockFcloseCalled);

    capture.getCapturedStdout();
}
#endif