Refactor ExecutionEnvironment destruction order test

Change-Id: I4c7e8b0da1d2e97d6d688f62d7b311cbdc734323
Signed-off-by: Maciej Dziuban <maciej.dziuban@intel.com>
This commit is contained in:
Maciej Dziuban 2018-08-22 10:29:37 +02:00 committed by sys_ocldev
parent 00170eb998
commit 88c5d3f5c2
3 changed files with 78 additions and 64 deletions

View File

@ -20,6 +20,8 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "runtime/built_ins/built_ins.h"
#include "runtime/compiler_interface/compiler_interface.h"
#include "runtime/device/device.h"
#include "runtime/execution_environment/execution_environment.h"
#include "runtime/gmm_helper/gmm_helper.h"
@ -27,11 +29,11 @@
#include "runtime/memory_manager/os_agnostic_memory_manager.h"
#include "runtime/os_interface/os_interface.h"
#include "runtime/platform/platform.h"
#include "runtime/source_level_debugger/source_level_debugger.h"
#include "test.h"
#include "unit_tests/mocks/mock_csr.h"
#include "runtime/compiler_interface/compiler_interface.h"
#include "runtime/built_ins/built_ins.h"
#include "runtime/source_level_debugger/source_level_debugger.h"
#include "unit_tests/utilities/destructor_counted.h"
using namespace OCLRT;
@ -114,75 +116,44 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeMemoryManagerI
EXPECT_NE(nullptr, executionEnvironment->memoryManager);
}
auto destructorId = 0u;
static_assert(sizeof(ExecutionEnvironment) == sizeof(std::mutex) + (is64bit ? 80 : 44), "New members detected in ExecutionEnvironment, please ensure that destruction sequence of objects is correct");
TEST(ExecutionEnvironment, givenExecutionEnvironmentWithVariousMembersWhenItIsDestroyedThenDeleteSequenceIsSpecified) {
destructorId = 0u;
struct GmmHelperMock : public GmmHelper {
using GmmHelper::GmmHelper;
~GmmHelperMock() override {
EXPECT_EQ(destructorId, 6u);
destructorId++;
}
};
struct OsInterfaceMock : public OSInterface {
~OsInterfaceMock() override {
EXPECT_EQ(destructorId, 5u);
destructorId++;
}
};
struct MemoryMangerMock : public OsAgnosticMemoryManager {
~MemoryMangerMock() override {
EXPECT_EQ(destructorId, 4u);
destructorId++;
}
};
struct CommandStreamReceiverMock : public MockCommandStreamReceiver {
~CommandStreamReceiverMock() override {
EXPECT_EQ(destructorId, 3u);
destructorId++;
};
};
struct BuiltinsMock : public BuiltIns {
~BuiltinsMock() override {
EXPECT_EQ(destructorId, 2u);
destructorId++;
}
};
struct CompilerInterfaceMock : public CompilerInterface {
~CompilerInterfaceMock() override {
EXPECT_EQ(destructorId, 1u);
destructorId++;
}
};
struct SourceLevelDebuggerMock : public SourceLevelDebugger {
SourceLevelDebuggerMock() : SourceLevelDebugger(nullptr){};
~SourceLevelDebuggerMock() override {
EXPECT_EQ(destructorId, 0u);
destructorId++;
}
};
uint32_t destructorId = 0u;
struct MockExecutionEnvironment : ExecutionEnvironment {
using ExecutionEnvironment::gmmHelper;
};
struct GmmHelperMock : public DestructorCounted<GmmHelper, 6> {
GmmHelperMock(uint32_t &destructorId, const HardwareInfo *hwInfo) : DestructorCounted(destructorId, hwInfo) {}
};
struct OsInterfaceMock : public DestructorCounted<OSInterface, 5> {
OsInterfaceMock(uint32_t &destructorId) : DestructorCounted(destructorId) {}
};
struct MemoryMangerMock : public DestructorCounted<OsAgnosticMemoryManager, 4> {
MemoryMangerMock(uint32_t &destructorId) : DestructorCounted(destructorId) {}
};
struct CommandStreamReceiverMock : public DestructorCounted<MockCommandStreamReceiver, 3> {
CommandStreamReceiverMock(uint32_t &destructorId) : DestructorCounted(destructorId) {}
};
struct BuiltinsMock : public DestructorCounted<BuiltIns, 2> {
BuiltinsMock(uint32_t &destructorId) : DestructorCounted(destructorId) {}
};
struct CompilerInterfaceMock : public DestructorCounted<CompilerInterface, 1> {
CompilerInterfaceMock(uint32_t &destructorId) : DestructorCounted(destructorId) {}
};
struct SourceLevelDebuggerMock : public DestructorCounted<SourceLevelDebugger, 0> {
SourceLevelDebuggerMock(uint32_t &destructorId) : DestructorCounted(destructorId, nullptr) {}
};
std::unique_ptr<MockExecutionEnvironment> executionEnvironment(new MockExecutionEnvironment);
executionEnvironment->gmmHelper.reset(new GmmHelperMock(platformDevices[0]));
executionEnvironment->osInterface.reset(new OsInterfaceMock);
executionEnvironment->memoryManager.reset(new MemoryMangerMock);
executionEnvironment->commandStreamReceiver.reset(new CommandStreamReceiverMock);
executionEnvironment->builtins.reset(new BuiltinsMock());
executionEnvironment->compilerInterface.reset(new CompilerInterfaceMock());
executionEnvironment->sourceLevelDebugger.reset(new SourceLevelDebuggerMock);
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
executionEnvironment->gmmHelper = std::make_unique<GmmHelperMock>(destructorId, platformDevices[0]);
executionEnvironment->osInterface = std::make_unique<OsInterfaceMock>(destructorId);
executionEnvironment->memoryManager = std::make_unique<MemoryMangerMock>(destructorId);
executionEnvironment->commandStreamReceiver = std::make_unique<CommandStreamReceiverMock>(destructorId);
executionEnvironment->builtins = std::make_unique<BuiltinsMock>(destructorId);
executionEnvironment->compilerInterface = std::make_unique<CompilerInterfaceMock>(destructorId);
executionEnvironment->sourceLevelDebugger = std::make_unique<SourceLevelDebuggerMock>(destructorId);
executionEnvironment.reset(nullptr);
EXPECT_EQ(7u, destructorId);

View File

@ -27,6 +27,7 @@ set(IGDRCL_SRCS_tests_utilities
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/debug_file_reader_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/debug_file_reader_tests.inl
${CMAKE_CURRENT_SOURCE_DIR}/debug_settings_reader_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/destructor_counted.h
${CMAKE_CURRENT_SOURCE_DIR}/directory_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/heap_allocator_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/numeric_tests.cpp

View File

@ -0,0 +1,42 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include "test.h"
namespace OCLRT {
template <typename BaseType, uint32_t ordinal>
struct DestructorCounted : public BaseType {
template <typename... Args>
DestructorCounted(uint32_t &destructorId, Args... args) : BaseType(args...),
destructorId(destructorId) {}
~DestructorCounted() override {
EXPECT_EQ(ordinal, destructorId);
destructorId++;
}
private:
uint32_t &destructorId;
};
} // namespace OCLRT