Files
compute-runtime/unit_tests/os_interface/linux/file_logger_linux_tests.cpp
Mateusz Hoppe f0a6f6b057 Move DebugSettingsManager to core
- pass registry path in constructor

Change-Id: I2a121da2c9483a0df088989feea490a638c63016
Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
2019-12-17 10:39:53 +01:00

110 lines
3.9 KiB
C++

/*
* Copyright (C) 2019 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "core/debug_settings/debug_settings_manager.h"
#include "test.h"
#include "unit_tests/mocks/linux/mock_drm_allocation.h"
#include "unit_tests/utilities/file_logger_tests.h"
using namespace NEO;
TEST(FileLogger, GivenLogAllocationMemoryPoolFlagThenLogsCorrectInfo) {
std::string testFile = "testfile";
DebugVariables flags;
flags.LogAllocationMemoryPool.set(true);
FullyEnabledFileLogger fileLogger(testFile, flags);
// Log file not created
bool logFileCreated = fileExists(fileLogger.getLogFileName());
EXPECT_FALSE(logFileCreated);
MockDrmAllocation allocation(GraphicsAllocation::AllocationType::BUFFER, MemoryPool::System64KBPages);
MockBufferObject bo;
bo.handle = 4;
allocation.bufferObjects[0] = &bo;
fileLogger.logAllocation(&allocation);
std::thread::id thisThread = std::this_thread::get_id();
std::stringstream threadIDCheck;
threadIDCheck << " ThreadID: " << thisThread;
std::stringstream memoryPoolCheck;
memoryPoolCheck << " MemoryPool: " << allocation.getMemoryPool();
if (fileLogger.wasFileCreated(fileLogger.getLogFileName())) {
auto str = fileLogger.getFileString(fileLogger.getLogFileName());
EXPECT_TRUE(str.find(threadIDCheck.str()) != std::string::npos);
EXPECT_TRUE(str.find(memoryPoolCheck.str()) != std::string::npos);
EXPECT_TRUE(str.find("AllocationType: BUFFER") != std::string::npos);
EXPECT_TRUE(str.find("Handle: 4") != std::string::npos);
}
}
TEST(FileLogger, GivenDrmAllocationWithoutBOThenNoHandleLogged) {
std::string testFile = "testfile";
DebugVariables flags;
flags.LogAllocationMemoryPool.set(true);
FullyEnabledFileLogger fileLogger(testFile, flags);
// Log file not created
bool logFileCreated = fileExists(fileLogger.getLogFileName());
EXPECT_FALSE(logFileCreated);
MockDrmAllocation allocation(GraphicsAllocation::AllocationType::BUFFER, MemoryPool::System64KBPages);
fileLogger.logAllocation(&allocation);
std::thread::id thisThread = std::this_thread::get_id();
std::stringstream threadIDCheck;
threadIDCheck << " ThreadID: " << thisThread;
std::stringstream memoryPoolCheck;
memoryPoolCheck << " MemoryPool: " << allocation.getMemoryPool();
if (fileLogger.wasFileCreated(fileLogger.getLogFileName())) {
auto str = fileLogger.getFileString(fileLogger.getLogFileName());
EXPECT_TRUE(str.find(threadIDCheck.str()) != std::string::npos);
EXPECT_TRUE(str.find(memoryPoolCheck.str()) != std::string::npos);
EXPECT_TRUE(str.find("AllocationType: BUFFER") != std::string::npos);
EXPECT_FALSE(str.find("Handle: 4") != std::string::npos);
}
}
TEST(FileLogger, GivenLogAllocationMemoryPoolFlagSetFalseThenAllocationIsNotLogged) {
std::string testFile = "testfile";
DebugVariables flags;
flags.LogAllocationMemoryPool.set(false);
FullyEnabledFileLogger fileLogger(testFile, flags);
// Log file not created
bool logFileCreated = fileExists(fileLogger.getLogFileName());
EXPECT_FALSE(logFileCreated);
MockDrmAllocation allocation(GraphicsAllocation::AllocationType::BUFFER, MemoryPool::System64KBPages);
fileLogger.logAllocation(&allocation);
std::thread::id thisThread = std::this_thread::get_id();
std::stringstream threadIDCheck;
threadIDCheck << " ThreadID: " << thisThread;
std::stringstream memoryPoolCheck;
memoryPoolCheck << " MemoryPool: " << allocation.getMemoryPool();
if (fileLogger.wasFileCreated(fileLogger.getLogFileName())) {
auto str = fileLogger.getFileString(fileLogger.getLogFileName());
EXPECT_FALSE(str.find(threadIDCheck.str()) != std::string::npos);
EXPECT_FALSE(str.find(memoryPoolCheck.str()) != std::string::npos);
EXPECT_FALSE(str.find("AllocationType: BUFFER") != std::string::npos);
}
}