2018-12-20 17:38:38 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2019 Intel Corporation
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2019-12-13 16:48:57 +01:00
|
|
|
#include "core/debug_settings/debug_settings_manager.h"
|
2019-02-27 11:39:32 +01:00
|
|
|
#include "test.h"
|
2019-02-14 11:38:04 +01:00
|
|
|
#include "unit_tests/mocks/linux/mock_drm_allocation.h"
|
2019-12-10 16:26:35 +01:00
|
|
|
#include "unit_tests/utilities/file_logger_tests.h"
|
2019-02-14 11:38:04 +01:00
|
|
|
|
2019-12-10 16:26:35 +01:00
|
|
|
using namespace NEO;
|
|
|
|
|
|
|
|
|
|
TEST(FileLogger, GivenLogAllocationMemoryPoolFlagThenLogsCorrectInfo) {
|
|
|
|
|
std::string testFile = "testfile";
|
|
|
|
|
DebugVariables flags;
|
|
|
|
|
flags.LogAllocationMemoryPool.set(true);
|
|
|
|
|
FullyEnabledFileLogger fileLogger(testFile, flags);
|
2018-12-20 17:38:38 +01:00
|
|
|
|
|
|
|
|
// Log file not created
|
2019-12-10 16:26:35 +01:00
|
|
|
bool logFileCreated = fileExists(fileLogger.getLogFileName());
|
2018-12-20 17:38:38 +01:00
|
|
|
EXPECT_FALSE(logFileCreated);
|
|
|
|
|
|
2019-02-27 11:38:25 +01:00
|
|
|
MockDrmAllocation allocation(GraphicsAllocation::AllocationType::BUFFER, MemoryPool::System64KBPages);
|
2019-02-14 11:38:04 +01:00
|
|
|
|
|
|
|
|
MockBufferObject bo;
|
|
|
|
|
bo.handle = 4;
|
|
|
|
|
|
2019-09-01 21:36:15 +02:00
|
|
|
allocation.bufferObjects[0] = &bo;
|
2019-02-14 11:38:04 +01:00
|
|
|
|
2019-12-10 16:26:35 +01:00
|
|
|
fileLogger.logAllocation(&allocation);
|
2019-02-14 11:38:04 +01:00
|
|
|
|
|
|
|
|
std::thread::id thisThread = std::this_thread::get_id();
|
|
|
|
|
|
|
|
|
|
std::stringstream threadIDCheck;
|
|
|
|
|
threadIDCheck << " ThreadID: " << thisThread;
|
|
|
|
|
|
|
|
|
|
std::stringstream memoryPoolCheck;
|
|
|
|
|
memoryPoolCheck << " MemoryPool: " << allocation.getMemoryPool();
|
|
|
|
|
|
2019-12-10 16:26:35 +01:00
|
|
|
if (fileLogger.wasFileCreated(fileLogger.getLogFileName())) {
|
|
|
|
|
auto str = fileLogger.getFileString(fileLogger.getLogFileName());
|
2019-02-14 11:38:04 +01:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-10 16:26:35 +01:00
|
|
|
TEST(FileLogger, GivenDrmAllocationWithoutBOThenNoHandleLogged) {
|
|
|
|
|
std::string testFile = "testfile";
|
|
|
|
|
DebugVariables flags;
|
|
|
|
|
flags.LogAllocationMemoryPool.set(true);
|
|
|
|
|
FullyEnabledFileLogger fileLogger(testFile, flags);
|
2019-02-14 11:38:04 +01:00
|
|
|
|
|
|
|
|
// Log file not created
|
2019-12-10 16:26:35 +01:00
|
|
|
bool logFileCreated = fileExists(fileLogger.getLogFileName());
|
2019-02-14 11:38:04 +01:00
|
|
|
EXPECT_FALSE(logFileCreated);
|
2019-02-27 11:38:25 +01:00
|
|
|
MockDrmAllocation allocation(GraphicsAllocation::AllocationType::BUFFER, MemoryPool::System64KBPages);
|
2018-12-20 17:38:38 +01:00
|
|
|
|
2019-12-10 16:26:35 +01:00
|
|
|
fileLogger.logAllocation(&allocation);
|
2018-12-20 17:38:38 +01:00
|
|
|
|
|
|
|
|
std::thread::id thisThread = std::this_thread::get_id();
|
|
|
|
|
|
|
|
|
|
std::stringstream threadIDCheck;
|
|
|
|
|
threadIDCheck << " ThreadID: " << thisThread;
|
|
|
|
|
|
|
|
|
|
std::stringstream memoryPoolCheck;
|
|
|
|
|
memoryPoolCheck << " MemoryPool: " << allocation.getMemoryPool();
|
|
|
|
|
|
2019-12-10 16:26:35 +01:00
|
|
|
if (fileLogger.wasFileCreated(fileLogger.getLogFileName())) {
|
|
|
|
|
auto str = fileLogger.getFileString(fileLogger.getLogFileName());
|
2018-12-20 17:38:38 +01:00
|
|
|
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);
|
2019-02-14 11:38:04 +01:00
|
|
|
EXPECT_FALSE(str.find("Handle: 4") != std::string::npos);
|
2018-12-20 17:38:38 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-10 16:26:35 +01:00
|
|
|
TEST(FileLogger, GivenLogAllocationMemoryPoolFlagSetFalseThenAllocationIsNotLogged) {
|
|
|
|
|
std::string testFile = "testfile";
|
|
|
|
|
DebugVariables flags;
|
|
|
|
|
flags.LogAllocationMemoryPool.set(false);
|
|
|
|
|
FullyEnabledFileLogger fileLogger(testFile, flags);
|
2018-12-20 17:38:38 +01:00
|
|
|
|
|
|
|
|
// Log file not created
|
2019-12-10 16:26:35 +01:00
|
|
|
bool logFileCreated = fileExists(fileLogger.getLogFileName());
|
2018-12-20 17:38:38 +01:00
|
|
|
EXPECT_FALSE(logFileCreated);
|
|
|
|
|
|
2019-02-27 11:38:25 +01:00
|
|
|
MockDrmAllocation allocation(GraphicsAllocation::AllocationType::BUFFER, MemoryPool::System64KBPages);
|
2018-12-20 17:38:38 +01:00
|
|
|
|
2019-12-10 16:26:35 +01:00
|
|
|
fileLogger.logAllocation(&allocation);
|
2018-12-20 17:38:38 +01:00
|
|
|
|
|
|
|
|
std::thread::id thisThread = std::this_thread::get_id();
|
|
|
|
|
|
|
|
|
|
std::stringstream threadIDCheck;
|
|
|
|
|
threadIDCheck << " ThreadID: " << thisThread;
|
|
|
|
|
|
|
|
|
|
std::stringstream memoryPoolCheck;
|
|
|
|
|
memoryPoolCheck << " MemoryPool: " << allocation.getMemoryPool();
|
|
|
|
|
|
2019-12-10 16:26:35 +01:00
|
|
|
if (fileLogger.wasFileCreated(fileLogger.getLogFileName())) {
|
|
|
|
|
auto str = fileLogger.getFileString(fileLogger.getLogFileName());
|
2018-12-20 17:38:38 +01:00
|
|
|
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);
|
|
|
|
|
}
|
2019-01-17 13:55:49 +01:00
|
|
|
}
|