Add debug flag to loop at initialize.

- This is to help debugging applications that requires attaching to them.

Change-Id: Ia7923c231b925ab9a473a70fb5fcc13fd99db1ca
This commit is contained in:
Mrozek, Michal
2018-08-14 13:54:33 +02:00
committed by sys_ocldev
parent 404c0cccb9
commit 077134faf4
5 changed files with 36 additions and 2 deletions

View File

@ -47,6 +47,7 @@ DECLARE_DEBUG_VARIABLE(bool, DisableResourceRecycling, false, "when set to true
DECLARE_DEBUG_VARIABLE(bool, ForceDispatchScheduler, false, "dispatches scheduler kernel instead of kernel enqueued")
DECLARE_DEBUG_VARIABLE(bool, TrackParentEvents, false, "events track their parents")
DECLARE_DEBUG_VARIABLE(bool, RebuildPrecompiledKernels, false, "forces driver to recompile precompiled kernels from sources")
DECLARE_DEBUG_VARIABLE(bool, LoopAtPlatformInitialize, false, "Adds endless loop in platform initalize, useful for debugging.")
/*LOGGING FLAGS*/
DECLARE_DEBUG_VARIABLE(bool, PrintDebugMessages, false, "when enabled, some debug messages will be propagated to console")
DECLARE_DEBUG_VARIABLE(bool, DumpKernels, false, "Enables dumping kernels' program source code to text files and program from binary to bin file")

View File

@ -33,6 +33,7 @@
#include "runtime/helpers/options.h"
#include "runtime/helpers/string.h"
#include "runtime/os_interface/device_factory.h"
#include "runtime/os_interface/debug_settings_manager.h"
#include "runtime/event/async_events_handler.h"
#include "runtime/sharings/sharing_factory.h"
#include "runtime/platform/extensions.h"
@ -138,6 +139,11 @@ bool Platform::initialize() {
return true;
}
if (DebugManager.flags.LoopAtPlatformInitialize.get()) {
while (DebugManager.flags.LoopAtPlatformInitialize.get())
this->initializationLoopHelper();
}
state = OCLRT::getDevices(&hwInfo, numDevicesReturned, *executionEnvironment) ? StateIniting : StateNone;
if (state == StateNone) {

View File

@ -78,7 +78,7 @@ class Platform : public BaseObject<_cl_platform_id> {
};
cl_uint state = StateNone;
void fillGlobalDispatchTable();
MOCKABLE_VIRTUAL void initializationLoopHelper(){};
std::unique_ptr<PlatformInfo> platformInfo;
DeviceVector devices;
std::string compilerExtensions;

View File

@ -24,6 +24,7 @@
#include "runtime/device/device.h"
#include "runtime/platform/extensions.h"
#include "runtime/sharings/sharing_factory.h"
#include "unit_tests/helpers/debug_manager_state_restore.h"
#include "unit_tests/fixtures/platform_fixture.h"
#include "unit_tests/mocks/mock_async_event_handler.h"
#include "unit_tests/mocks/mock_csr.h"
@ -208,3 +209,28 @@ TEST(PlatformConstructionTest, givenPlatformThatIsNotInitializedWhenGetDevicesIs
auto devices = platform.getDevices();
EXPECT_EQ(nullptr, devices);
}
TEST(PlatformInitLoopTests, givenPlatformWhenInitLoopHelperIsCalledThenItDoesNothing) {
struct mockPlatform : public Platform {
using Platform::initializationLoopHelper;
};
mockPlatform platform;
platform.initializationLoopHelper();
}
TEST(PlatformInitLoopTests, givenPlatformWithDebugSettingWhenInitIsCalledThenItEntersEndlessLoop) {
DebugManagerStateRestore stateRestore;
DebugManager.flags.LoopAtPlatformInitialize.set(true);
bool called = false;
struct mockPlatform : public Platform {
mockPlatform(bool &called) : called(called){};
void initializationLoopHelper() override {
DebugManager.flags.LoopAtPlatformInitialize.set(false);
called = true;
}
bool &called;
};
mockPlatform platform(called);
platform.initialize();
EXPECT_TRUE(called);
}

View File

@ -77,4 +77,5 @@ AUBDumpFilterKernelStartIdx = 0
AUBDumpFilterKernelEndIdx = -1
RebuildPrecompiledKernels = false
CreateMultipleDevices = 0
EnableExperimentalCommandBuffer = 0
EnableExperimentalCommandBuffer = 0
LoopAtPlatformInitialize = false