Skip to content

Commit d55a0ae

Browse files
Detect enable program debugging env variable
Resolves: NEO-4713 Change-Id: Id9ce30b84943c4b364f7756a430d58df2614a28b Signed-off-by: Mateusz Hoppe <[email protected]>
1 parent dadbd5a commit d55a0ae

File tree

17 files changed

+107
-25
lines changed

17 files changed

+107
-25
lines changed

level_zero/core/source/driver/driver_handle_imp.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "shared/source/debug_settings/debug_settings_manager.h"
1111
#include "shared/source/device/device.h"
1212
#include "shared/source/memory_manager/memory_manager.h"
13+
#include "shared/source/os_interface/debug_env_reader.h"
1314
#include "shared/source/os_interface/os_library.h"
1415

1516
#include "level_zero/core/source/device/device_imp.h"
@@ -161,7 +162,9 @@ DriverHandle *DriverHandle::create(std::vector<std::unique_ptr<NEO::Device>> dev
161162
DriverHandleImp *driverHandle = new DriverHandleImp;
162163
UNRECOVERABLE_IF(nullptr == driverHandle);
163164

164-
driverHandle->getEnv("ZE_AFFINITY_MASK", driverHandle->affinityMask);
165+
NEO::EnvironmentVariableReader envReader;
166+
driverHandle->affinityMask = envReader.getSetting("ZE_AFFINITY_MASK", static_cast<int32_t>(driverHandle->affinityMask));
167+
driverHandle->enableProgramDebugging = envReader.getSetting("ZET_ENABLE_PROGRAM_DEBUGGING", driverHandle->enableProgramDebugging);
165168

166169
ze_result_t res = driverHandle->initialize(std::move(devices));
167170
if (res != ZE_RESULT_SUCCESS) {

level_zero/core/source/driver/driver_handle_imp.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,14 @@ struct DriverHandleImp : public DriverHandle {
5858
size_t size,
5959
bool *allocationRangeCovered) override;
6060

61-
template <typename T>
62-
bool getEnv(const char *varName, T &varValue) {
63-
char *varChar = getenv(varName);
64-
if (varChar) {
65-
varValue = static_cast<T>(atoi(varChar));
66-
return true;
67-
}
68-
return false;
69-
}
70-
7161
uint32_t numDevices = 0;
7262
std::unordered_map<std::string, void *> extensionFunctionsLookupMap;
7363
std::vector<Device *> devices;
7464
NEO::MemoryManager *memoryManager = nullptr;
7565
NEO::SVMAllocsManager *svmAllocsManager = nullptr;
7666

7767
uint32_t affinityMask = std::numeric_limits<uint32_t>::max();
68+
bool enableProgramDebugging = false;
7869
};
7970

8071
} // namespace L0

level_zero/core/test/unit_tests/mocks/mock_driver_handle.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ namespace L0 {
2121
namespace ult {
2222

2323
template <>
24-
struct WhiteBox<::L0::DriverHandleImp> : public ::L0::DriverHandleImp {
24+
struct WhiteBox<::L0::DriverHandle> : public ::L0::DriverHandleImp {
25+
using ::L0::DriverHandleImp::enableProgramDebugging;
2526
};
2627

27-
using DriverHandle = WhiteBox<::L0::DriverHandleImp>;
28+
using DriverHandle = WhiteBox<::L0::DriverHandle>;
2829

2930
template <>
3031
struct Mock<DriverHandle> : public DriverHandleImp {

level_zero/core/test/unit_tests/sources/driver/test_driver.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "shared/source/os_interface/hw_info_config.h"
1010
#include "shared/test/unit_test/helpers/debug_manager_state_restore.h"
1111

12+
#include "opencl/test/unit_test/mocks/mock_io_functions.h"
1213
#include "test.h"
1314

1415
#include "level_zero/core/source/driver/driver_handle_imp.h"
@@ -60,6 +61,40 @@ TEST(DriverTestFamilySupport, whenInitializingDriverOnNotSupportedFamilyThenDriv
6061
EXPECT_EQ(nullptr, driverHandle);
6162
}
6263

64+
TEST(DriverTest, givenNullEnvVariableWhenCreatingDriverThenEnableProgramDebuggingIsFalse) {
65+
NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get();
66+
hwInfo.capabilityTable.levelZeroSupported = true;
67+
68+
NEO::MockDevice *neoDevice = NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo);
69+
NEO::DeviceVector devices;
70+
devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
71+
72+
auto driverHandle = whitebox_cast(DriverHandle::create(std::move(devices)));
73+
EXPECT_NE(nullptr, driverHandle);
74+
75+
EXPECT_FALSE(driverHandle->enableProgramDebugging);
76+
77+
delete driverHandle;
78+
}
79+
80+
TEST(DriverTest, givenEnvVariableNonZeroWhenCreatingDriverThenEnableProgramDebuggingIsSetTrue) {
81+
NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get();
82+
hwInfo.capabilityTable.levelZeroSupported = true;
83+
84+
VariableBackup<bool> mockDeviceFlagBackup(&IoFunctions::returnMockEnvValue, true);
85+
86+
NEO::MockDevice *neoDevice = NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo);
87+
NEO::DeviceVector devices;
88+
devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
89+
90+
auto driverHandle = whitebox_cast(DriverHandle::create(std::move(devices)));
91+
EXPECT_NE(nullptr, driverHandle);
92+
93+
EXPECT_TRUE(driverHandle->enableProgramDebugging);
94+
95+
delete driverHandle;
96+
}
97+
6398
struct DriverTestMultipleFamilySupport : public ::testing::Test {
6499
void SetUp() override {
65100
VariableBackup<bool> mockDeviceFlagBackup(&MockDevice::createSingleDevice, false);

opencl/test/unit_test/command_stream/command_stream_receiver_flush_task_gmock_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include "shared/source/helpers/ptr_math.h"
1818
#include "shared/source/memory_manager/graphics_allocation.h"
1919
#include "shared/source/memory_manager/memory_manager.h"
20-
#include "shared/source/os_interface/linux/debug_env_reader.h"
20+
#include "shared/source/os_interface/debug_env_reader.h"
2121
#include "shared/test/unit_test/cmd_parse/hw_parse.h"
2222
#include "shared/test/unit_test/helpers/debug_manager_state_restore.h"
2323
#include "shared/test/unit_test/helpers/dispatch_flags_helper.h"

opencl/test/unit_test/command_stream/command_stream_receiver_hw_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include "shared/source/memory_manager/graphics_allocation.h"
2020
#include "shared/source/memory_manager/memory_manager.h"
2121
#include "shared/source/memory_manager/unified_memory_manager.h"
22-
#include "shared/source/os_interface/linux/debug_env_reader.h"
22+
#include "shared/source/os_interface/debug_env_reader.h"
2323
#include "shared/source/os_interface/os_context.h"
2424
#include "shared/test/unit_test/cmd_parse/hw_parse.h"
2525
#include "shared/test/unit_test/helpers/debug_manager_state_restore.h"

opencl/test/unit_test/libult/io_functions.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@ namespace IoFunctions {
1212
fopenFuncPtr fopenPtr = &mockFopen;
1313
vfprintfFuncPtr vfprintfPtr = &mockVfptrinf;
1414
fcloseFuncPtr fclosePtr = &mockFclose;
15+
getenvFuncPtr getenvPtr = &mockGetenv;
1516

1617
uint32_t mockFopenCalled = 0;
1718
uint32_t mockVfptrinfCalled = 0;
1819
uint32_t mockFcloseCalled = 0;
20+
bool returnMockEnvValue = false;
21+
std::string mockEnvValue = "1";
22+
1923
} // namespace IoFunctions
2024
} // namespace NEO

opencl/test/unit_test/mocks/mock_io_functions.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,17 @@
99
#include "shared/source/utilities/io_functions.h"
1010

1111
#include <cstdint>
12+
#include <string>
1213

1314
namespace NEO {
1415
namespace IoFunctions {
1516
extern uint32_t mockFopenCalled;
1617
extern uint32_t mockVfptrinfCalled;
1718
extern uint32_t mockFcloseCalled;
1819

20+
extern bool returnMockEnvValue;
21+
extern std::string mockEnvValue;
22+
1923
inline FILE *mockFopen(const char *filename, const char *mode) {
2024
mockFopenCalled++;
2125
return reinterpret_cast<FILE *>(0x40);
@@ -30,5 +34,13 @@ inline int mockFclose(FILE *stream) {
3034
mockFcloseCalled++;
3135
return 0;
3236
}
37+
38+
inline char *mockGetenv(const char *name) noexcept {
39+
if (returnMockEnvValue) {
40+
return const_cast<char *>(mockEnvValue.c_str());
41+
}
42+
return getenv(name);
43+
}
44+
3345
} // namespace IoFunctions
3446
} // namespace NEO

opencl/test/unit_test/os_interface/linux/debug_env_reader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
*/
77

8-
#include "shared/source/os_interface/linux/debug_env_reader.h"
8+
#include "shared/source/os_interface/debug_env_reader.h"
99

1010
#include "test.h"
1111

opencl/test/unit_test/utilities/debug_settings_reader_tests.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@
1919

2020
using namespace NEO;
2121

22+
class MockSettingsReader : public SettingsReader {
23+
public:
24+
std::string getSetting(const char *settingName, const std::string &value) override {
25+
return value;
26+
}
27+
bool getSetting(const char *settingName, bool defaultValue) override { return defaultValue; };
28+
int64_t getSetting(const char *settingName, int64_t defaultValue) override { return defaultValue; };
29+
int32_t getSetting(const char *settingName, int32_t defaultValue) override { return defaultValue; };
30+
const char *appSpecificLocation(const std::string &name) override { return name.c_str(); };
31+
};
32+
2233
TEST(SettingsReader, Create) {
2334
SettingsReader *reader = SettingsReader::create(oclRegPath);
2435
EXPECT_NE(nullptr, reader);
@@ -82,10 +93,17 @@ TEST(SettingsReader, givenPrintDebugStringWhenCalledWithTrueItPrintsToOutput) {
8293
std::string output = testing::internal::GetCapturedStdout();
8394
EXPECT_STRNE(output.c_str(), "");
8495
}
96+
8597
TEST(SettingsReader, givenPrintDebugStringWhenCalledWithFalseThenNothingIsPrinted) {
8698
int i = 4;
8799
testing::internal::CaptureStdout();
88100
printDebugString(false, stderr, "Error String %d", i);
89101
std::string output = testing::internal::GetCapturedStdout();
90102
EXPECT_STREQ(output.c_str(), "");
91103
}
104+
105+
TEST(SettingsReader, givenNonExistingEnvVarWhenGettingEnvThenNullptrIsReturned) {
106+
MockSettingsReader reader;
107+
auto value = reader.getenv("ThisEnvVarDoesNotExist");
108+
EXPECT_EQ(nullptr, value);
109+
}

0 commit comments

Comments
 (0)