Add tests for linux sys calls

Signed-off-by: Kamil Diedrich <kamil.diedrich@intel.com>
This commit is contained in:
Kamil Diedrich
2021-02-22 11:22:38 +01:00
committed by Compute-Runtime-Automation
parent a246c358e5
commit f766e6a4c1
6 changed files with 65 additions and 10 deletions

View File

@@ -24,7 +24,7 @@ ClDevice *VADevice::getRootDeviceFromVaDisplay(Platform *pPlatform, VADisplay va
VADisplayContextP pDisplayContext_test = reinterpret_cast<VADisplayContextP>(vaDisplay);
UNRECOVERABLE_IF(pDisplayContext_test->vadpy_magic != 0x56414430);
VADriverContextP pDriverContext_test = pDisplayContext_test->pDriverContext;
int deviceFd = *(int *)pDriverContext_test->drm_state;
int deviceFd = *static_cast<int *>(pDriverContext_test->drm_state);
UNRECOVERABLE_IF(deviceFd < 0);

View File

@@ -32,6 +32,7 @@ add_executable(igdrcl_${target_name}
${NEO_SOURCE_DIR}/opencl/test/unit_test/os_interface/linux/create_drm_memory_manager.cpp
)
if(NEO__LIBVA_FOUND)
include_directories("${NEO__LIBVA_INCLUDE_DIR}")
target_sources(igdrcl_${target_name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/va_tests.cpp)
endif()

View File

@@ -10,6 +10,8 @@
#include <cassert>
#include <dirent.h>
#include <iostream>
#include <sys/stat.h>
#include <sys/sysmacros.h>
int (*c_open)(const char *pathname, int flags, ...) = nullptr;
int (*openFull)(const char *pathname, int flags, ...) = nullptr;
@@ -36,11 +38,30 @@ int failOnVirtualMemoryCreate = 0;
int failOnSetPriority = 0;
int failOnPreemption = 0;
int failOnDrmVersion = 0;
int accessCalledTimes = 0;
int readLinkCalledTimes = 0;
int fstatCalledTimes = 0;
char providedDrmVersion[5] = {'i', '9', '1', '5', '\0'};
uint64_t gpuTimestamp = 0;
int ioctlSeq[8] = {0, 0, 0, 0, 0, 0, 0, 0};
size_t ioctlCnt = 0;
int fstat(int fd, struct stat *buf) {
++fstatCalledTimes;
buf->st_rdev = 0x0;
return 0;
}
int access(const char *pathname, int mode) {
++accessCalledTimes;
return 0;
}
ssize_t readlink(const char *path, char *buf, size_t bufsiz) {
++readLinkCalledTimes;
return -1;
}
int open(const char *pathname, int flags, ...) {
if (openFull != nullptr) {
return openFull(pathname, flags);

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2017-2020 Intel Corporation
* Copyright (C) 2017-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -17,6 +17,7 @@
#include <fcntl.h>
#include <stdarg.h>
#include <sys/types.h>
#include <unistd.h>
extern int (*c_open)(const char *pathname, int flags, ...);
extern int (*openFull)(const char *pathname, int flags, ...);
@@ -46,3 +47,6 @@ extern int ioctlSeq[8];
extern size_t ioctlCnt;
extern bool failOnOpenDir;
extern uint32_t entryIndex;
extern int accessCalledTimes;
extern int readLinkCalledTimes;
extern int fstatCalledTimes;

View File

@@ -7,9 +7,13 @@
#include "shared/test/common/helpers/variable_backup.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 "test.h"
#include <va/va_backend.h>
using namespace NEO;
TEST(VaTests, whenLibvaSo2IsNotInstalledThenFail) {
@@ -36,3 +40,28 @@ TEST(VaTests, whenLibvaSo2IsNotInstalledThenFail) {
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);
}

View File

@@ -1240,7 +1240,7 @@ TEST_F(VaDeviceTests, givenVADeviceWhenGetDeviceFromVAIsCalledThenRootDeviceIsRe
auto drmState = std::make_unique<int>();
vaDisplay->pDriverContext = contextPtr.get();
contextPtr->drm_state = drmState.get();
*(int *)contextPtr->drm_state = 1;
*static_cast<int *>(contextPtr->drm_state) = 1;
auto device = pPlatform->getClDevice(0);
NEO::Device *neoDevice = &device->getDevice();
@@ -1260,7 +1260,7 @@ TEST_F(VaDeviceTests, givenVADeviceAndInvalidPciPathOfClDeviceWhenGetDeviceFromV
auto drmState = std::make_unique<int>();
vaDisplay->pDriverContext = contextPtr.get();
contextPtr->drm_state = drmState.get();
*(int *)contextPtr->drm_state = 1;
*static_cast<int *>(contextPtr->drm_state) = 1;
auto device = pPlatform->getClDevice(0);
NEO::Device *neoDevice = &device->getDevice();
@@ -1280,7 +1280,7 @@ TEST_F(VaDeviceTests, givenVADeviceAndInvalidFDWhenGetDeviceFromVAIsCalledThenNu
auto drmState = std::make_unique<int>();
vaDisplay->pDriverContext = contextPtr.get();
contextPtr->drm_state = drmState.get();
*(int *)contextPtr->drm_state = 0;
*static_cast<int *>(contextPtr->drm_state) = 0;
VADevice vaDevice{};
auto clDevice = vaDevice.getDeviceFromVA(pPlatform, vaDisplay.get());
@@ -1302,7 +1302,7 @@ TEST_F(VaDeviceTests, givenVADeviceAndNegativeFdWhenGetDeviceFromVAIsCalledThenU
auto drmState = std::make_unique<int>();
vaDisplay->pDriverContext = contextPtr.get();
contextPtr->drm_state = drmState.get();
*(int *)contextPtr->drm_state = -1;
*static_cast<int *>(contextPtr->drm_state) = -1;
VADevice vaDevice{};
EXPECT_ANY_THROW(vaDevice.getDeviceFromVA(pPlatform, vaDisplay.get()));
@@ -1323,7 +1323,7 @@ TEST_F(VaDeviceTests, givenVADeviceAndFakeDevicePathWhenGetDeviceFromVAIsCalledT
auto drmState = std::make_unique<int>();
vaDisplay->pDriverContext = contextPtr.get();
contextPtr->drm_state = drmState.get();
*(int *)contextPtr->drm_state = 1;
*static_cast<int *>(contextPtr->drm_state) = 1;
VADevice vaDevice{};
auto clDevice = vaDevice.getDeviceFromVA(pPlatform, vaDisplay.get());
@@ -1339,7 +1339,7 @@ TEST_F(VaDeviceTests, givenVADeviceAndAbsolutePathWhenGetDeviceFromVAIsCalledThe
auto drmState = std::make_unique<int>();
vaDisplay->pDriverContext = contextPtr.get();
contextPtr->drm_state = drmState.get();
*(int *)contextPtr->drm_state = 1;
*static_cast<int *>(contextPtr->drm_state) = 1;
VADevice vaDevice{};
auto clDevice = vaDevice.getDeviceFromVA(pPlatform, vaDisplay.get());
@@ -1356,7 +1356,7 @@ TEST_F(VaDeviceTests, givenValidPlatformWithInvalidVaDisplayWhenGetDeviceIdsFrom
auto drmState = std::make_unique<int>();
vaDisplay->pDriverContext = contextPtr.get();
contextPtr->drm_state = drmState.get();
*(int *)contextPtr->drm_state = 1;
*static_cast<int *>(contextPtr->drm_state) = 1;
auto device = pPlatform->getClDevice(0);
NEO::Device *neoDevice = &device->getDevice();
@@ -1380,7 +1380,7 @@ TEST_F(VaDeviceTests, givenValidPlatformWhenGetDeviceIdsFromVaApiMediaAdapterCal
auto drmState = std::make_unique<int>();
vaDisplay->pDriverContext = contextPtr.get();
contextPtr->drm_state = drmState.get();
*(int *)contextPtr->drm_state = 1;
*static_cast<int *>(contextPtr->drm_state) = 1;
auto device = pPlatform->getClDevice(0);
NEO::Device *neoDevice = &device->getDevice();