Move SourceLevelDebugger ownership to execution environment

Change-Id: I7fc6fd1cde2e450dbd41a164f915373e80a4aaf8
This commit is contained in:
Jobczyk, Lukasz
2018-07-12 15:47:48 +02:00
committed by sys_ocldev
parent 6112ce4e8f
commit eebb919c18
12 changed files with 109 additions and 46 deletions

View File

@@ -28,6 +28,7 @@
#include "unit_tests/libult/source_level_debugger_library.h"
#include "unit_tests/libult/create_command_stream.h"
#include "unit_tests/mocks/mock_source_level_debugger.h"
#include "runtime/platform/platform.h"
#include <gtest/gtest.h>
#include <memory>
@@ -52,6 +53,20 @@ class DebuggerLibraryRestorer {
bool restoreAvailableState = false;
};
TEST(SourceLevelDebugger, givenPlatformWhenItIsCreatedThenSourceLevelDebuggerIsCreatedInExecutionEnvironment) {
DebuggerLibraryRestorer restorer;
if (platformDevices[0]->capabilityTable.sourceLevelDebuggerSupported) {
DebuggerLibrary::setLibraryAvailable(true);
DebuggerLibrary::setDebuggerActive(true);
Platform platform;
platform.initialize();
EXPECT_NE(nullptr, platform.peekExecutionEnvironment()->sourceLevelDebugger);
}
}
TEST(SourceLevelDebugger, givenNoKernelDebuggerLibraryWhenSourceLevelDebuggerIsCreatedThenLibraryIsNotLoaded) {
DebuggerLibraryRestorer restorer;
DebuggerLibrary::setLibraryAvailable(false);
@@ -391,13 +406,15 @@ TEST(SourceLevelDebugger, givenKernelDebuggerLibraryNotActiveWhenInitializeIsCal
TEST(SourceLevelDebugger, givenKernelDebuggerLibraryActiveWhenDeviceIsConstructedThenDebuggerIsInitialized) {
DebuggerLibraryRestorer restorer;
DebuggerLibraryInterceptor interceptor;
DebuggerLibrary::setLibraryAvailable(true);
DebuggerLibrary::setDebuggerActive(true);
DebuggerLibrary::injectDebuggerLibraryInterceptor(&interceptor);
if (platformDevices[0]->capabilityTable.sourceLevelDebuggerSupported) {
DebuggerLibraryInterceptor interceptor;
DebuggerLibrary::setLibraryAvailable(true);
DebuggerLibrary::setDebuggerActive(true);
DebuggerLibrary::injectDebuggerLibraryInterceptor(&interceptor);
unique_ptr<MockDevice> device(new MockDevice(*platformDevices[0]));
EXPECT_TRUE(interceptor.initCalled);
unique_ptr<MockDevice> device(new MockDevice(*platformDevices[0]));
EXPECT_TRUE(interceptor.initCalled);
}
}
TEST(SourceLevelDebugger, givenKernelDebuggerLibraryActiveWhenDeviceImplIsCreatedThenDebuggerIsNotified) {
@@ -447,7 +464,45 @@ TEST(SourceLevelDebugger, givenKernelDebuggerLibraryNotActiveWhenDeviceIsCreated
unique_ptr<MockDevice> device(DeviceHelper<>::create());
EXPECT_EQ(nullptr, device->sourceLevelDebugger.get());
EXPECT_EQ(nullptr, device->getSourceLevelDebugger());
EXPECT_FALSE(interceptor.initCalled);
EXPECT_FALSE(interceptor.newDeviceCalled);
}
TEST(SourceLevelDebugger, givenTwoDevicesWhenSecondIsCreatedThenNotCreatingNewSourceLevelDebugger) {
DebuggerLibraryRestorer restorer;
if (platformDevices[0]->capabilityTable.sourceLevelDebuggerSupported) {
DebuggerLibraryInterceptor interceptor;
DebuggerLibrary::setLibraryAvailable(true);
DebuggerLibrary::setDebuggerActive(true);
DebuggerLibrary::injectDebuggerLibraryInterceptor(&interceptor);
std::unique_ptr<ExecutionEnvironment> executionEnvironment(new ExecutionEnvironment);
executionEnvironment->incRefInternal();
std::unique_ptr<Device> device1(Device::create<OCLRT::Device>(nullptr, executionEnvironment.get()));
EXPECT_NE(nullptr, executionEnvironment->memoryManager);
EXPECT_TRUE(interceptor.initCalled);
interceptor.initCalled = false;
std::unique_ptr<Device> device2(Device::create<OCLRT::Device>(nullptr, executionEnvironment.get()));
EXPECT_NE(nullptr, executionEnvironment->memoryManager);
EXPECT_FALSE(interceptor.initCalled);
}
}
TEST(SourceLevelDebugger, givenMultipleDevicesWhenTheyAreCreatedTheyAllReuseTheSameSourceLevelDebugger) {
DebuggerLibraryRestorer restorer;
if (platformDevices[0]->capabilityTable.sourceLevelDebuggerSupported) {
DebuggerLibrary::setLibraryAvailable(true);
DebuggerLibrary::setDebuggerActive(true);
auto executionEnvironment = new ExecutionEnvironment;
std::unique_ptr<Device> device1(Device::create<OCLRT::Device>(nullptr, executionEnvironment));
auto sourceLevelDebugger = device1->getSourceLevelDebugger();
std::unique_ptr<Device> device2(Device::create<OCLRT::Device>(nullptr, executionEnvironment));
EXPECT_EQ(sourceLevelDebugger, device2->getSourceLevelDebugger());
}
}