mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-11 16:45:25 +08:00
move files to core folder
gdi_interface os_inc thk_wrapper api_intercept perf_profiler Change-Id: I943807da06da31244c7c2540dcba2747f4f05b70
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
|
||||
#include "core/command_stream/preemption.h"
|
||||
#include "core/execution_environment/root_device_environment.h"
|
||||
#include "runtime/os_interface/windows/gdi_interface.h"
|
||||
#include "core/os_interface/windows/gdi_interface.h"
|
||||
#include "test.h"
|
||||
#include "unit_tests/mocks/mock_execution_environment.h"
|
||||
#include "unit_tests/mocks/mock_wddm.h"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018-2019 Intel Corporation
|
||||
* Copyright (C) 2018-2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include "core/execution_environment/root_device_environment.h"
|
||||
#include "core/helpers/aligned_memory.h"
|
||||
#include "runtime/os_interface/windows/gdi_interface.h"
|
||||
#include "core/os_interface/windows/gdi_interface.h"
|
||||
#include "runtime/os_interface/windows/wddm_allocation.h"
|
||||
#include "unit_tests/mock_gdi/mock_gdi.h"
|
||||
#include "unit_tests/mocks/mock_wddm_residency_allocations_container.h"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#
|
||||
# Copyright (C) 2018-2019 Intel Corporation
|
||||
# Copyright (C) 2018-2020 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
@@ -12,12 +12,10 @@ set(IGDRCL_SRCS_tests_os_interface_windows
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/driver_info_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/file_logger_win_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gdi_dll_fixture.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gdi_interface_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gmm_memory_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/hw_info_config_win_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/hw_info_config_win_tests.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_environment_variables.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_gdi_interface.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_kmdaf_listener.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_os_time_win.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_performance_counters_win.cpp
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "core/helpers/hw_cmds.h"
|
||||
#include "core/helpers/options.h"
|
||||
#include "core/unit_tests/helpers/debug_manager_state_restore.h"
|
||||
#include "core/unit_tests/os_interface/windows/mock_gdi_interface.h"
|
||||
#include "runtime/command_stream/aub_command_stream_receiver.h"
|
||||
#include "runtime/command_stream/command_stream_receiver.h"
|
||||
#include "runtime/command_stream/command_stream_receiver_with_aub_dump.h"
|
||||
@@ -41,7 +42,6 @@
|
||||
#include "unit_tests/mocks/mock_program.h"
|
||||
#include "unit_tests/mocks/mock_submissions_aggregator.h"
|
||||
#include "unit_tests/mocks/mock_wddm_interface23.h"
|
||||
#include "unit_tests/os_interface/windows/mock_gdi_interface.h"
|
||||
#include "unit_tests/os_interface/windows/mock_wddm_memory_manager.h"
|
||||
#include "unit_tests/os_interface/windows/wddm_fixture.h"
|
||||
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017-2019 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include "core/os_interface/os_library.h"
|
||||
#include "core/unit_tests/helpers/debug_manager_state_restore.h"
|
||||
#include "runtime/os_interface/windows/gdi_interface.h"
|
||||
#include "test.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
TEST(GdiInterface, creation) {
|
||||
NEO::Gdi gdi;
|
||||
ASSERT_TRUE(gdi.isInitialized());
|
||||
}
|
||||
|
||||
TEST(GdiInterface, failLoad) {
|
||||
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(ThkWrapperTest, givenThkWrapperWhenConstructedThenmFuncIsInitialized) {
|
||||
NEO::ThkWrapper<void *> wrapper;
|
||||
EXPECT_EQ(nullptr, wrapper.mFunc);
|
||||
}
|
||||
#endif
|
||||
@@ -1,161 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017-2019 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "runtime/os_interface/windows/gdi_interface.h"
|
||||
|
||||
namespace NEO {
|
||||
|
||||
class MockGdi : public Gdi {
|
||||
public:
|
||||
MockGdi() {
|
||||
initialized = getAllProcAddresses();
|
||||
}
|
||||
~MockGdi(){};
|
||||
|
||||
bool nonZeroNumBytesToTrim = false;
|
||||
|
||||
void setNonZeroNumBytesToTrimInEvict() {
|
||||
nonZeroNumBytesToTrim = true;
|
||||
initialized = getAllProcAddresses();
|
||||
}
|
||||
|
||||
static NTSTATUS __stdcall makeResidentMock(IN OUT D3DDDI_MAKERESIDENT *arg) {
|
||||
getMakeResidentArg() = *arg;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static NTSTATUS __stdcall evictMock(IN D3DKMT_EVICT *arg) {
|
||||
getEvictArg() = *arg;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static NTSTATUS __stdcall evictMockWithNonZeroTrim(IN D3DKMT_EVICT *arg) {
|
||||
getEvictArg() = *arg;
|
||||
arg->NumBytesToTrim = 4096;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static NTSTATUS __stdcall registerTrimNotificationMock(IN D3DKMT_REGISTERTRIMNOTIFICATION *arg) {
|
||||
getRegisterTrimNotificationArg() = *arg;
|
||||
arg->Handle = reinterpret_cast<VOID *>(1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static NTSTATUS __stdcall unregisterTrimNotificationMock(IN D3DKMT_UNREGISTERTRIMNOTIFICATION *arg) {
|
||||
getUnregisterTrimNotificationArg() = *arg;
|
||||
arg->Handle = reinterpret_cast<VOID *>(1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static NTSTATUS __stdcall destroyAllocation2Mock(IN D3DKMT_DESTROYALLOCATION2 *arg) {
|
||||
getDestroyArg() = *arg;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static NTSTATUS __stdcall waitFromCpuMock(IN CONST D3DKMT_WAITFORSYNCHRONIZATIONOBJECTFROMCPU *arg) {
|
||||
getWaitFromCpuArg() = *arg;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static NTSTATUS __stdcall createSynchronizationObject2Mock(IN OUT D3DKMT_CREATESYNCHRONIZATIONOBJECT2 *arg) {
|
||||
getCreateSynchronizationObject2Arg() = *arg;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static NTSTATUS __stdcall queryResourceInfoMock(IN OUT D3DKMT_QUERYRESOURCEINFO *arg) {
|
||||
getQueryResourceInfoArgIn() = *arg;
|
||||
arg->NumAllocations = getQueryResourceInfoArgOut().NumAllocations;
|
||||
arg->ResourcePrivateDriverDataSize = getQueryResourceInfoArgOut().ResourcePrivateDriverDataSize;
|
||||
arg->TotalPrivateDriverDataSize = getQueryResourceInfoArgOut().TotalPrivateDriverDataSize;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static NTSTATUS __stdcall openResourceMock(IN OUT D3DKMT_OPENRESOURCE *arg) {
|
||||
getOpenResourceArgIn() = *arg;
|
||||
if (arg->NumAllocations > 0) {
|
||||
arg->pOpenAllocationInfo[0].hAllocation = getOpenResourceArgOut().pOpenAllocationInfo->hAllocation;
|
||||
arg->pOpenAllocationInfo[0].PrivateDriverDataSize = getOpenResourceArgOut().pOpenAllocationInfo->PrivateDriverDataSize;
|
||||
arg->pOpenAllocationInfo[0].pPrivateDriverData = getOpenResourceArgOut().pOpenAllocationInfo->pPrivateDriverData;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool getAllProcAddresses() override {
|
||||
makeResident = reinterpret_cast<PFND3DKMT_MAKERESIDENT>(makeResidentMock);
|
||||
if (nonZeroNumBytesToTrim) {
|
||||
evict = reinterpret_cast<PFND3DKMT_EVICT>(evictMockWithNonZeroTrim);
|
||||
} else {
|
||||
evict = reinterpret_cast<PFND3DKMT_EVICT>(evictMock);
|
||||
}
|
||||
registerTrimNotification = reinterpret_cast<PFND3DKMT_REGISTERTRIMNOTIFICATION>(registerTrimNotificationMock);
|
||||
unregisterTrimNotification = reinterpret_cast<PFND3DKMT_UNREGISTERTRIMNOTIFICATION>(unregisterTrimNotificationMock);
|
||||
destroyAllocation2 = reinterpret_cast<PFND3DKMT_DESTROYALLOCATION2>(destroyAllocation2Mock);
|
||||
waitForSynchronizationObjectFromCpu = reinterpret_cast<PFND3DKMT_WAITFORSYNCHRONIZATIONOBJECTFROMCPU>(waitFromCpuMock);
|
||||
queryResourceInfo = reinterpret_cast<PFND3DKMT_QUERYRESOURCEINFO>(queryResourceInfoMock);
|
||||
openResource = reinterpret_cast<PFND3DKMT_OPENRESOURCE>(openResourceMock);
|
||||
return true;
|
||||
}
|
||||
|
||||
static D3DDDI_MAKERESIDENT &getMakeResidentArg() {
|
||||
static D3DDDI_MAKERESIDENT makeResidentArg;
|
||||
return makeResidentArg;
|
||||
}
|
||||
|
||||
static D3DKMT_EVICT &getEvictArg() {
|
||||
static D3DKMT_EVICT evictArg;
|
||||
return evictArg;
|
||||
}
|
||||
|
||||
static D3DKMT_REGISTERTRIMNOTIFICATION &getRegisterTrimNotificationArg() {
|
||||
static D3DKMT_REGISTERTRIMNOTIFICATION registerTrimArg;
|
||||
return registerTrimArg;
|
||||
}
|
||||
|
||||
static D3DKMT_UNREGISTERTRIMNOTIFICATION &getUnregisterTrimNotificationArg() {
|
||||
static D3DKMT_UNREGISTERTRIMNOTIFICATION unregisterTrimArg;
|
||||
return unregisterTrimArg;
|
||||
}
|
||||
|
||||
static D3DKMT_DESTROYALLOCATION2 &getDestroyArg() {
|
||||
static D3DKMT_DESTROYALLOCATION2 destroyArg;
|
||||
return destroyArg;
|
||||
}
|
||||
|
||||
static D3DKMT_WAITFORSYNCHRONIZATIONOBJECTFROMCPU &getWaitFromCpuArg() {
|
||||
static D3DKMT_WAITFORSYNCHRONIZATIONOBJECTFROMCPU waitFromCpu;
|
||||
return waitFromCpu;
|
||||
}
|
||||
|
||||
static D3DKMT_CREATESYNCHRONIZATIONOBJECT2 getCreateSynchronizationObject2Arg() {
|
||||
static D3DKMT_CREATESYNCHRONIZATIONOBJECT2 createSynchronizationObject2;
|
||||
return createSynchronizationObject2;
|
||||
}
|
||||
|
||||
static D3DKMT_QUERYRESOURCEINFO &getQueryResourceInfoArgIn() {
|
||||
static D3DKMT_QUERYRESOURCEINFO queryResourceInfo;
|
||||
return queryResourceInfo;
|
||||
}
|
||||
|
||||
static D3DKMT_QUERYRESOURCEINFO &getQueryResourceInfoArgOut() {
|
||||
static D3DKMT_QUERYRESOURCEINFO queryResourceInfo;
|
||||
return queryResourceInfo;
|
||||
}
|
||||
|
||||
static D3DKMT_OPENRESOURCE &getOpenResourceArgIn() {
|
||||
static D3DKMT_OPENRESOURCE openResource;
|
||||
return openResource;
|
||||
}
|
||||
|
||||
static D3DKMT_OPENRESOURCE &getOpenResourceArgOut() {
|
||||
static D3DKMT_OPENRESOURCE openResource;
|
||||
return openResource;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace NEO
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018-2019 Intel Corporation
|
||||
* Copyright (C) 2018-2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -8,9 +8,9 @@
|
||||
#include "core/command_stream/preemption.h"
|
||||
#include "core/helpers/hw_helper.h"
|
||||
#include "core/memory_manager/memory_constants.h"
|
||||
#include "core/os_interface/windows/gdi_interface.h"
|
||||
#include "core/unit_tests/helpers/debug_manager_state_restore.h"
|
||||
#include "runtime/execution_environment/execution_environment.h"
|
||||
#include "runtime/os_interface/windows/gdi_interface.h"
|
||||
#include "runtime/os_interface/windows/os_context_win.h"
|
||||
#include "runtime/os_interface/windows/os_interface.h"
|
||||
#include "runtime/platform/platform.h"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2017-2019 Intel Corporation
|
||||
* Copyright (C) 2017-2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -10,8 +10,9 @@
|
||||
#include "core/command_stream/preemption.h"
|
||||
#include "core/execution_environment/root_device_environment.h"
|
||||
#include "core/helpers/hw_helper.h"
|
||||
#include "core/os_interface/windows/gdi_interface.h"
|
||||
#include "core/unit_tests/os_interface/windows/mock_gdi_interface.h"
|
||||
#include "runtime/execution_environment/execution_environment.h"
|
||||
#include "runtime/os_interface/windows/gdi_interface.h"
|
||||
#include "runtime/os_interface/windows/os_context_win.h"
|
||||
#include "runtime/os_interface/windows/os_interface.h"
|
||||
#include "runtime/os_interface/windows/wddm_memory_operations_handler.h"
|
||||
@@ -21,7 +22,6 @@
|
||||
#include "unit_tests/mocks/mock_wddm_interface20.h"
|
||||
#include "unit_tests/mocks/mock_wddm_residency_allocations_container.h"
|
||||
#include "unit_tests/os_interface/windows/gdi_dll_fixture.h"
|
||||
#include "unit_tests/os_interface/windows/mock_gdi_interface.h"
|
||||
|
||||
#include "mock_gmm_memory.h"
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018-2019 Intel Corporation
|
||||
* Copyright (C) 2018-2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "core/command_stream/preemption.h"
|
||||
#include "core/execution_environment/root_device_environment.h"
|
||||
#include "core/gmm_helper/gmm_helper.h"
|
||||
#include "core/unit_tests/os_interface/windows/mock_gdi_interface.h"
|
||||
#include "runtime/gmm_helper/gmm.h"
|
||||
#include "runtime/memory_manager/memory_manager.h"
|
||||
#include "runtime/os_interface/windows/wddm/wddm.h"
|
||||
@@ -15,7 +16,6 @@
|
||||
#include "runtime/platform/platform.h"
|
||||
#include "test.h"
|
||||
#include "unit_tests/mock_gdi/mock_gdi.h"
|
||||
#include "unit_tests/os_interface/windows/mock_gdi_interface.h"
|
||||
#include "unit_tests/os_interface/windows/mock_kmdaf_listener.h"
|
||||
#include "unit_tests/os_interface/windows/mock_wddm_allocation.h"
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2017-2019 Intel Corporation
|
||||
* Copyright (C) 2017-2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "core/unit_tests/os_interface/windows/mock_gdi_interface.h"
|
||||
#include "runtime/os_interface/windows/os_interface.h"
|
||||
#include "runtime/os_interface/windows/wddm_memory_operations_handler.h"
|
||||
#include "test.h"
|
||||
@@ -15,7 +16,6 @@
|
||||
#include "unit_tests/mocks/mock_gmm.h"
|
||||
#include "unit_tests/mocks/mock_gmm_page_table_mngr.h"
|
||||
#include "unit_tests/mocks/mock_wddm_residency_allocations_container.h"
|
||||
#include "unit_tests/os_interface/windows/mock_gdi_interface.h"
|
||||
#include "unit_tests/os_interface/windows/mock_wddm_memory_manager.h"
|
||||
#include "unit_tests/os_interface/windows/wddm_fixture.h"
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018-2019 Intel Corporation
|
||||
* Copyright (C) 2018-2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "core/execution_environment/root_device_environment.h"
|
||||
#include "core/helpers/hw_helper.h"
|
||||
#include "core/memory_manager/memory_operations_handler.h"
|
||||
#include "core/unit_tests/os_interface/windows/mock_gdi_interface.h"
|
||||
#include "runtime/execution_environment/execution_environment.h"
|
||||
#include "runtime/os_interface/os_context.h"
|
||||
#include "runtime/os_interface/os_interface.h"
|
||||
@@ -22,7 +23,6 @@
|
||||
#include "unit_tests/mocks/mock_allocation_properties.h"
|
||||
#include "unit_tests/mocks/mock_execution_environment.h"
|
||||
#include "unit_tests/mocks/mock_wddm.h"
|
||||
#include "unit_tests/os_interface/windows/mock_gdi_interface.h"
|
||||
#include "unit_tests/os_interface/windows/mock_wddm_allocation.h"
|
||||
#include "unit_tests/os_interface/windows/mock_wddm_memory_manager.h"
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#
|
||||
# Copyright (C) 2017-2019 Intel Corporation
|
||||
# Copyright (C) 2017-2020 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
@@ -11,7 +11,6 @@ set(IGDRCL_SRCS_tests_utilities
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/debug_settings_reader_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/file_logger_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/file_logger_tests.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/perf_profiler.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tag_allocator_tests.cpp
|
||||
)
|
||||
|
||||
|
||||
@@ -1,294 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017-2019 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "runtime/utilities/perf_profiler.h"
|
||||
|
||||
#include "test.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
using namespace NEO;
|
||||
|
||||
using namespace std;
|
||||
|
||||
TEST(PerfProfiler, create) {
|
||||
PerfProfiler *ptr = PerfProfiler::create();
|
||||
ASSERT_NE(nullptr, ptr);
|
||||
EXPECT_EQ(1, PerfProfiler::getCurrentCounter());
|
||||
PerfProfiler *ptr2 = PerfProfiler::create();
|
||||
EXPECT_EQ(ptr, ptr2);
|
||||
EXPECT_EQ(1, PerfProfiler::getCurrentCounter());
|
||||
|
||||
PerfProfiler::destroyAll();
|
||||
EXPECT_EQ(0, PerfProfiler::getCurrentCounter());
|
||||
EXPECT_EQ(nullptr, PerfProfiler::getObject(0));
|
||||
}
|
||||
|
||||
TEST(PerfProfiler, createDestroyCreate) {
|
||||
// purpose of this test is multiple create and destroy, so check the state machine works correctly
|
||||
EXPECT_EQ(0, PerfProfiler::getCurrentCounter());
|
||||
PerfProfiler *ptr = PerfProfiler::create();
|
||||
ASSERT_NE(nullptr, ptr);
|
||||
EXPECT_EQ(1, PerfProfiler::getCurrentCounter());
|
||||
EXPECT_EQ(ptr, PerfProfiler::getObject(0));
|
||||
PerfProfiler::destroyAll();
|
||||
EXPECT_EQ(0, PerfProfiler::getCurrentCounter());
|
||||
EXPECT_EQ(nullptr, PerfProfiler::getObject(0));
|
||||
PerfProfiler *ptr2 = PerfProfiler::create();
|
||||
ASSERT_NE(nullptr, ptr2);
|
||||
EXPECT_EQ(1, PerfProfiler::getCurrentCounter());
|
||||
EXPECT_EQ(ptr2, PerfProfiler::getObject(0));
|
||||
|
||||
uint32_t systemId = 1;
|
||||
const char *func = "createDestroyCreate()";
|
||||
|
||||
ptr2->apiEnter();
|
||||
ptr2->systemEnter();
|
||||
ptr2->systemLeave(systemId);
|
||||
ptr2->apiLeave(func);
|
||||
|
||||
PerfProfiler::destroyAll();
|
||||
EXPECT_EQ(0, PerfProfiler::getCurrentCounter());
|
||||
EXPECT_EQ(nullptr, PerfProfiler::getObject(0));
|
||||
}
|
||||
|
||||
TEST(PerfProfiler, destroyAll) {
|
||||
struct PerfProfilerMock : PerfProfiler {
|
||||
static void addNullObjects() {
|
||||
PerfProfiler::objects[0] = nullptr;
|
||||
PerfProfiler::counter = 1;
|
||||
}
|
||||
};
|
||||
|
||||
PerfProfiler::destroyAll(); // destroy 0 objects
|
||||
EXPECT_EQ(0, PerfProfiler::getCurrentCounter());
|
||||
PerfProfilerMock::addNullObjects(); // skip null objects
|
||||
EXPECT_EQ(1, PerfProfiler::getCurrentCounter());
|
||||
PerfProfiler::destroyAll(); //destroy no object altough counter is incorrect
|
||||
EXPECT_EQ(0, PerfProfiler::getCurrentCounter());
|
||||
EXPECT_EQ(nullptr, PerfProfiler::getObject(0));
|
||||
}
|
||||
|
||||
TEST(PerfProfiler, PerfProfilerXmlVerifier) {
|
||||
std::unique_ptr<std::stringstream> logs = std::unique_ptr<std::stringstream>(new std::stringstream());
|
||||
std::unique_ptr<std::stringstream> sysLogs = std::unique_ptr<std::stringstream>(new std::stringstream());
|
||||
std::unique_ptr<PerfProfiler> ptr(new PerfProfiler(1, std::move(logs), std::move(sysLogs)));
|
||||
ASSERT_NE(nullptr, ptr.get());
|
||||
|
||||
uint32_t systemId = 10;
|
||||
const std::string func = "PerfProfilerXmlVerifier()";
|
||||
|
||||
ptr->apiEnter();
|
||||
ptr->systemEnter();
|
||||
ptr->systemLeave(systemId);
|
||||
ptr->apiLeave(func.c_str());
|
||||
|
||||
{
|
||||
std::stringstream logDump{static_cast<std::stringstream *>(ptr->getLogStream())->str()};
|
||||
bool caughtException = false;
|
||||
try {
|
||||
long long startR = -1;
|
||||
long long endR = -1;
|
||||
long long spanR = -1;
|
||||
unsigned long long totalSystemR = UINT64_MAX;
|
||||
std::string functionR = "";
|
||||
PerfProfiler::readAndVerify(logDump, "<report>\n");
|
||||
PerfProfiler::LogBuilder::read(logDump, startR, endR, spanR, totalSystemR, functionR);
|
||||
char c = 0;
|
||||
logDump.read(&c, 1);
|
||||
EXPECT_TRUE(logDump.eof());
|
||||
EXPECT_EQ(func, functionR);
|
||||
EXPECT_LE(0, startR);
|
||||
EXPECT_LE(0, endR);
|
||||
EXPECT_LE(startR, endR);
|
||||
EXPECT_LE(0, spanR);
|
||||
} catch (...) {
|
||||
caughtException = true;
|
||||
}
|
||||
EXPECT_FALSE(caughtException);
|
||||
}
|
||||
|
||||
{
|
||||
std::stringstream sysLogDump{static_cast<std::stringstream *>(ptr->getSystemLogStream())->str()};
|
||||
bool caughtException = false;
|
||||
try {
|
||||
long long startR = -1;
|
||||
unsigned int funcId = 0;
|
||||
unsigned long long totalSystemR = UINT64_MAX;
|
||||
PerfProfiler::readAndVerify(sysLogDump, "<report>\n");
|
||||
PerfProfiler::SysLogBuilder::read(sysLogDump, startR, totalSystemR, funcId);
|
||||
char c = 0;
|
||||
sysLogDump.read(&c, 1);
|
||||
EXPECT_TRUE(sysLogDump.eof());
|
||||
EXPECT_LE(0, startR);
|
||||
EXPECT_EQ(systemId, funcId);
|
||||
} catch (...) {
|
||||
caughtException = true;
|
||||
}
|
||||
EXPECT_FALSE(caughtException);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(PerfProfiler, ApiEnterLeave) {
|
||||
PerfProfiler *ptr = PerfProfiler::create(false);
|
||||
ASSERT_NE(nullptr, ptr);
|
||||
EXPECT_EQ(1, PerfProfiler::getCurrentCounter());
|
||||
const char *func = "ApiEnterLeave()";
|
||||
ptr->apiEnter();
|
||||
ptr->apiLeave(func);
|
||||
{
|
||||
bool caughtException = false;
|
||||
try {
|
||||
std::stringstream logDump{static_cast<std::stringstream *>(ptr->getLogStream())->str()};
|
||||
std::string functionR = "";
|
||||
long long startR = -1;
|
||||
long long endR = -1;
|
||||
long long spanR = -1;
|
||||
unsigned long long totalSystemR = UINT64_MAX;
|
||||
PerfProfiler::readAndVerify(logDump, "<report>\n");
|
||||
PerfProfiler::LogBuilder::read(logDump, startR, endR, spanR, totalSystemR, functionR);
|
||||
EXPECT_EQ(func, functionR);
|
||||
} catch (...) {
|
||||
caughtException = true;
|
||||
}
|
||||
EXPECT_FALSE(caughtException);
|
||||
}
|
||||
|
||||
PerfProfiler::destroyAll();
|
||||
EXPECT_EQ(0, PerfProfiler::getCurrentCounter());
|
||||
}
|
||||
|
||||
TEST(PerfProfiler, SystemEnterLeave) {
|
||||
PerfProfiler *ptr = PerfProfiler::create(false);
|
||||
ASSERT_NE(nullptr, ptr);
|
||||
EXPECT_EQ(1, PerfProfiler::getCurrentCounter());
|
||||
|
||||
uint32_t systemId = 3;
|
||||
|
||||
ptr->systemEnter();
|
||||
ptr->systemLeave(systemId);
|
||||
|
||||
{
|
||||
std::string sysString = static_cast<std::stringstream *>(ptr->getSystemLogStream())->str();
|
||||
std::stringstream sysLogDump{sysString};
|
||||
bool caughtException = false;
|
||||
try {
|
||||
PerfProfiler::readAndVerify(sysLogDump, "<report>\n");
|
||||
char c = 0;
|
||||
sysLogDump.read(&c, 1);
|
||||
EXPECT_TRUE(sysLogDump.eof());
|
||||
} catch (...) {
|
||||
caughtException = true;
|
||||
}
|
||||
EXPECT_FALSE(caughtException);
|
||||
}
|
||||
|
||||
PerfProfiler::destroyAll();
|
||||
EXPECT_EQ(0, PerfProfiler::getCurrentCounter());
|
||||
}
|
||||
|
||||
TEST(PerfProfiler, readAndVerify) {
|
||||
std::string log = "someData";
|
||||
std::stringstream in{log + log};
|
||||
bool exceptionCaught = false;
|
||||
try {
|
||||
PerfProfiler::readAndVerify(in, "some");
|
||||
EXPECT_FALSE(in.eof());
|
||||
PerfProfiler::readAndVerify(in, "Data");
|
||||
EXPECT_FALSE(in.eof());
|
||||
PerfProfiler::readAndVerify(in, "some");
|
||||
EXPECT_FALSE(in.eof());
|
||||
PerfProfiler::readAndVerify(in, "Data");
|
||||
} catch (const std::runtime_error &) {
|
||||
exceptionCaught = true;
|
||||
}
|
||||
EXPECT_FALSE(exceptionCaught);
|
||||
|
||||
try {
|
||||
PerfProfiler::readAndVerify(in, "anything");
|
||||
} catch (const std::runtime_error &) {
|
||||
exceptionCaught = true;
|
||||
}
|
||||
EXPECT_TRUE(exceptionCaught);
|
||||
|
||||
exceptionCaught = false;
|
||||
std::stringstream in2{"someData"};
|
||||
try {
|
||||
PerfProfiler::readAndVerify(in2, "somXXata");
|
||||
} catch (const std::runtime_error &) {
|
||||
exceptionCaught = true;
|
||||
}
|
||||
EXPECT_TRUE(exceptionCaught);
|
||||
|
||||
exceptionCaught = false;
|
||||
std::stringstream in3{"someData"};
|
||||
try {
|
||||
PerfProfiler::readAndVerify(in3, "someDataX");
|
||||
} catch (const std::runtime_error &) {
|
||||
exceptionCaught = true;
|
||||
}
|
||||
EXPECT_TRUE(exceptionCaught);
|
||||
}
|
||||
|
||||
TEST(PerfProfiler, LogBuilderReadAndWrite) {
|
||||
std::stringstream out;
|
||||
long long startW = 3, startR = 0;
|
||||
long long endW = 5, endR = 0;
|
||||
long long spanW = 7, spanR = 0;
|
||||
unsigned long long totalSystemW = 11, totalSystemR = 0;
|
||||
std::string functionW = {"someFunc"}, functionR;
|
||||
PerfProfiler::LogBuilder::write(out, startW, endW, spanW, totalSystemW, functionW.c_str());
|
||||
|
||||
std::stringstream in(out.str());
|
||||
PerfProfiler::LogBuilder::read(in, startR, endR, spanR, totalSystemR, functionR);
|
||||
|
||||
char end = 0;
|
||||
in.read(&end, 1);
|
||||
EXPECT_TRUE(in.eof());
|
||||
EXPECT_EQ(startW, startR);
|
||||
EXPECT_EQ(endW, endR);
|
||||
EXPECT_EQ(spanW, spanR);
|
||||
EXPECT_EQ(totalSystemW, totalSystemR);
|
||||
EXPECT_EQ(functionW, functionR);
|
||||
}
|
||||
|
||||
TEST(PerfProfiler, LogBuilderGivenLogWithBrokenFunctionNameWhenCantFindTrailingQuotationThenWillThrowException) {
|
||||
std::stringstream in{"<api name=\"funcName"};
|
||||
long long startR = 0;
|
||||
long long endR = 0;
|
||||
long long spanR = 0;
|
||||
unsigned long long totalSystemR = 0;
|
||||
std::string functionR;
|
||||
|
||||
bool exceptionCaught = false;
|
||||
try {
|
||||
PerfProfiler::LogBuilder::read(in, startR, endR, spanR, totalSystemR, functionR);
|
||||
} catch (const std::runtime_error &) {
|
||||
exceptionCaught = true;
|
||||
}
|
||||
EXPECT_TRUE(exceptionCaught);
|
||||
}
|
||||
|
||||
TEST(PerfProfiler, SysLogBuilderReadAndWrite) {
|
||||
std::stringstream out;
|
||||
long long startW = 3, startR = 0;
|
||||
unsigned long long timeW = 7, timeR = 0;
|
||||
unsigned int idW = 11, idR = 0;
|
||||
PerfProfiler::SysLogBuilder::write(out, startW, timeW, idW);
|
||||
|
||||
std::stringstream in(out.str());
|
||||
PerfProfiler::SysLogBuilder::read(in, startR, timeR, idR);
|
||||
char end = 0;
|
||||
in.read(&end, 1);
|
||||
EXPECT_TRUE(in.eof());
|
||||
EXPECT_EQ(startW, startR);
|
||||
EXPECT_EQ(timeW, timeR);
|
||||
EXPECT_EQ(idW, idR);
|
||||
}
|
||||
Reference in New Issue
Block a user