Check SourceLevelDebugger is non-nullptr before use

Change-Id: I0c270158e743ee8d301903d4ad3b6b9815a758b8
Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
This commit is contained in:
Mateusz Hoppe 2020-07-01 09:35:41 +02:00 committed by sys_ocldev
parent 29821b5a25
commit da3c9dba0e
4 changed files with 27 additions and 11 deletions

View File

@ -52,7 +52,7 @@ ClDevice::ClDevice(Device &device, Platform *platform) : device(device), platfor
subDevices.push_back(std::move(pClSubDevice));
}
}
if (getSharedDeviceInfo().debuggerActive) {
if (getSharedDeviceInfo().debuggerActive && getSourceLevelDebugger()) {
auto osInterface = device.getRootDeviceEnvironment().osInterface.get();
getSourceLevelDebugger()->notifyNewDevice(osInterface ? osInterface->getDeviceHandle() : 0);
}
@ -60,7 +60,7 @@ ClDevice::ClDevice(Device &device, Platform *platform) : device(device), platfor
ClDevice::~ClDevice() {
if (getSharedDeviceInfo().debuggerActive) {
if (getSharedDeviceInfo().debuggerActive && getSourceLevelDebugger()) {
getSourceLevelDebugger()->notifyDeviceDestruction();
}

View File

@ -87,4 +87,13 @@ class MockClDevice : public ClDevice {
std::vector<EngineControl> &engines;
};
class MockDeviceWithDebuggerActive : public MockDevice {
public:
MockDeviceWithDebuggerActive(ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex) : MockDevice(executionEnvironment, deviceIndex) {}
void initializeCaps() override {
MockDevice::initializeCaps();
this->setDebuggerActive(true);
}
};
} // namespace NEO

View File

@ -18,15 +18,6 @@
using PreambleTest = ::testing::Test;
using namespace NEO;
class MockDeviceWithDebuggerActive : public MockDevice {
public:
MockDeviceWithDebuggerActive(ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex) : MockDevice(executionEnvironment, deviceIndex) {}
void initializeCaps() override {
MockDevice::initializeCaps();
this->setDebuggerActive(true);
}
};
TEST(DeviceWithSourceLevelDebugger, givenDeviceWithSourceLevelDebuggerActiveWhenDeviceIsDestructedThenSourceLevelDebuggerIsNotified) {
ExecutionEnvironment *executionEnvironment = platform()->peekExecutionEnvironment();
auto gmock = new ::testing::NiceMock<GMockSourceLevelDebugger>(new MockOsLibrary);

View File

@ -542,6 +542,22 @@ TEST(SourceLevelDebugger, givenKernelDebuggerLibraryNotActiveWhenGettingSourceLe
EXPECT_EQ(nullptr, device->getSourceLevelDebugger());
}
TEST(SourceLevelDebugger, givenDeviceWithDebuggerActiveSetWhenSourceLevelDebuggerIsNotCreatedThenNotificationsAreNotCalled) {
DebuggerLibraryRestorer restorer;
DebuggerLibraryInterceptor interceptor;
DebuggerLibrary::setLibraryAvailable(false);
DebuggerLibrary::setDebuggerActive(false);
DebuggerLibrary::injectDebuggerLibraryInterceptor(&interceptor);
auto device = std::make_unique<MockClDevice>(MockDevice::createWithNewExecutionEnvironment<MockDeviceWithDebuggerActive>(nullptr));
EXPECT_TRUE(device->isDebuggerActive());
EXPECT_EQ(nullptr, device->getDebugger());
EXPECT_FALSE(interceptor.newDeviceCalled);
EXPECT_FALSE(interceptor.deviceDestructionCalled);
}
TEST(SourceLevelDebugger, givenTwoRootDevicesWhenSecondIsCreatedThenCreatingNewSourceLevelDebugger) {
DebuggerLibraryRestorer restorer;