Skip to content

Commit 077134f

Browse files
Add debug flag to loop at initialize.
- This is to help debugging applications that requires attaching to them. Change-Id: Ia7923c231b925ab9a473a70fb5fcc13fd99db1ca
1 parent 404c0cc commit 077134f

File tree

5 files changed

+36
-2
lines changed

5 files changed

+36
-2
lines changed

runtime/os_interface/DebugVariables_base.inl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ DECLARE_DEBUG_VARIABLE(bool, DisableResourceRecycling, false, "when set to true
4747
DECLARE_DEBUG_VARIABLE(bool, ForceDispatchScheduler, false, "dispatches scheduler kernel instead of kernel enqueued")
4848
DECLARE_DEBUG_VARIABLE(bool, TrackParentEvents, false, "events track their parents")
4949
DECLARE_DEBUG_VARIABLE(bool, RebuildPrecompiledKernels, false, "forces driver to recompile precompiled kernels from sources")
50+
DECLARE_DEBUG_VARIABLE(bool, LoopAtPlatformInitialize, false, "Adds endless loop in platform initalize, useful for debugging.")
5051
/*LOGGING FLAGS*/
5152
DECLARE_DEBUG_VARIABLE(bool, PrintDebugMessages, false, "when enabled, some debug messages will be propagated to console")
5253
DECLARE_DEBUG_VARIABLE(bool, DumpKernels, false, "Enables dumping kernels' program source code to text files and program from binary to bin file")

runtime/platform/platform.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "runtime/helpers/options.h"
3434
#include "runtime/helpers/string.h"
3535
#include "runtime/os_interface/device_factory.h"
36+
#include "runtime/os_interface/debug_settings_manager.h"
3637
#include "runtime/event/async_events_handler.h"
3738
#include "runtime/sharings/sharing_factory.h"
3839
#include "runtime/platform/extensions.h"
@@ -138,6 +139,11 @@ bool Platform::initialize() {
138139
return true;
139140
}
140141

142+
if (DebugManager.flags.LoopAtPlatformInitialize.get()) {
143+
while (DebugManager.flags.LoopAtPlatformInitialize.get())
144+
this->initializationLoopHelper();
145+
}
146+
141147
state = OCLRT::getDevices(&hwInfo, numDevicesReturned, *executionEnvironment) ? StateIniting : StateNone;
142148

143149
if (state == StateNone) {

runtime/platform/platform.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class Platform : public BaseObject<_cl_platform_id> {
7878
};
7979
cl_uint state = StateNone;
8080
void fillGlobalDispatchTable();
81-
81+
MOCKABLE_VIRTUAL void initializationLoopHelper(){};
8282
std::unique_ptr<PlatformInfo> platformInfo;
8383
DeviceVector devices;
8484
std::string compilerExtensions;

unit_tests/platform/platform_tests.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "runtime/device/device.h"
2525
#include "runtime/platform/extensions.h"
2626
#include "runtime/sharings/sharing_factory.h"
27+
#include "unit_tests/helpers/debug_manager_state_restore.h"
2728
#include "unit_tests/fixtures/platform_fixture.h"
2829
#include "unit_tests/mocks/mock_async_event_handler.h"
2930
#include "unit_tests/mocks/mock_csr.h"
@@ -208,3 +209,28 @@ TEST(PlatformConstructionTest, givenPlatformThatIsNotInitializedWhenGetDevicesIs
208209
auto devices = platform.getDevices();
209210
EXPECT_EQ(nullptr, devices);
210211
}
212+
213+
TEST(PlatformInitLoopTests, givenPlatformWhenInitLoopHelperIsCalledThenItDoesNothing) {
214+
struct mockPlatform : public Platform {
215+
using Platform::initializationLoopHelper;
216+
};
217+
mockPlatform platform;
218+
platform.initializationLoopHelper();
219+
}
220+
221+
TEST(PlatformInitLoopTests, givenPlatformWithDebugSettingWhenInitIsCalledThenItEntersEndlessLoop) {
222+
DebugManagerStateRestore stateRestore;
223+
DebugManager.flags.LoopAtPlatformInitialize.set(true);
224+
bool called = false;
225+
struct mockPlatform : public Platform {
226+
mockPlatform(bool &called) : called(called){};
227+
void initializationLoopHelper() override {
228+
DebugManager.flags.LoopAtPlatformInitialize.set(false);
229+
called = true;
230+
}
231+
bool &called;
232+
};
233+
mockPlatform platform(called);
234+
platform.initialize();
235+
EXPECT_TRUE(called);
236+
}

unit_tests/test_files/igdrcl.config

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,5 @@ AUBDumpFilterKernelStartIdx = 0
7777
AUBDumpFilterKernelEndIdx = -1
7878
RebuildPrecompiledKernels = false
7979
CreateMultipleDevices = 0
80-
EnableExperimentalCommandBuffer = 0
80+
EnableExperimentalCommandBuffer = 0
81+
LoopAtPlatformInitialize = false

0 commit comments

Comments
 (0)