File: va_tests.cpp

package info (click to toggle)
intel-compute-runtime 25.48.36300.8-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 80,652 kB
  • sloc: cpp: 939,022; lisp: 2,090; sh: 722; makefile: 162; python: 21
file content (68 lines) | stat: -rw-r--r-- 2,373 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
/*
 * Copyright (C) 2018-2025 Intel Corporation
 *
 * SPDX-License-Identifier: MIT
 *
 */

#include "shared/test/common/helpers/variable_backup.h"
#include "shared/test/common/test_macros/test.h"

#include "opencl/source/sharings/va/va_device.h"
#include "opencl/source/sharings/va/va_sharing_functions.h"
#include "opencl/test/unit_test/linux/mock_os_layer.h"

#include <va/va_backend.h>

using namespace NEO;

TEST(VaTests, whenLibvaSo2IsNotInstalledThenFail) {
    VariableBackup<decltype(VASharingFunctions::fdlopen)> dlopenBackup(&VASharingFunctions::fdlopen);
    VariableBackup<decltype(VASharingFunctions::fdlclose)> dlcloseBackup(&VASharingFunctions::fdlclose);
    VariableBackup<decltype(VASharingFunctions::fdlsym)> dlsymBackup(&VASharingFunctions::fdlsym);

    VASharingFunctions::fdlopen = [&](const char *filename, int flag) -> void * {
        if (!strncmp(filename, "libva.so.2", 10)) {
            return (void *)0xdeadbeef;
        } else {
            return 0;
        }
    };
    VASharingFunctions::fdlclose = [&](void *handle) -> int {
        return 0;
    };

    VASharingFunctions::fdlsym = [&](void *handle, const char *symbol) -> void * {
        return nullptr;
    };

    VADisplay vaDisplay = nullptr;
    VASharingFunctions va(vaDisplay);

    EXPECT_EQ(true, va.isVaLibraryAvailable());
}

TEST(VaTests, givenVADeviceWhenGetDeviceFromVAIsCalledThenProperSyscallsAreUsed) {
    VariableBackup<decltype(accessCalledTimes)> backupAccessCalledTimes(&accessCalledTimes);
    VariableBackup<decltype(readLinkCalledTimes)> backupReadLinkCalledTimes(&readLinkCalledTimes);
    VariableBackup<decltype(fstatCalledTimes)> backupFstatCalledTimes(&fstatCalledTimes);
    accessCalledTimes = 0;
    readLinkCalledTimes = 0;
    fstatCalledTimes = 0;

    auto vaDisplay = std::make_unique<VADisplayContext>();
    vaDisplay->vadpy_magic = 0x56414430;
    auto contextPtr = std::make_unique<VADriverContext>();
    auto drmState = std::make_unique<int>();
    vaDisplay->pDriverContext = contextPtr.get();
    contextPtr->drm_state = drmState.get();
    *static_cast<int *>(contextPtr->drm_state) = 1;

    VADevice vaDevice{};
    auto clDevice = vaDevice.getDeviceFromVA(nullptr, vaDisplay.get());
    EXPECT_EQ(clDevice, nullptr);

    EXPECT_EQ(accessCalledTimes, 1);
    EXPECT_EQ(readLinkCalledTimes, 1);
    EXPECT_EQ(fstatCalledTimes, 1);
}