Skip to content

Commit 621b8be

Browse files
committed
Exit early with levelzero in unit tests
Signed-off-by: Tuomas Katila <[email protected]>
1 parent 6d500ce commit 621b8be

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

.github/workflows/lib-validate.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ jobs:
6666
- run: make go-mod-tidy
6767
- run: make BUILDTAGS=kerneldrv
6868
- run: make test BUILDTAGS=kerneldrv
69+
env:
70+
UNITTEST: 1
6971
- run: make check-github-actions
7072
#- name: Codecov report
7173
# run: bash <(curl -s https://codecov.io/bash)

cmd/gpu_levelzero/ze.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include <stdio.h>
1616
#include <string.h>
17+
#include <stdlib.h>
1718

1819
#include <ze_api.h>
1920

@@ -92,6 +93,10 @@ static ze_driver_handle_t initialize_ze(void)
9293

9394
bool ze_try_initialize(void)
9495
{
96+
if (getenv("UNITTEST") != NULL) {
97+
return false;
98+
}
99+
95100
return zeInit(0) == ZE_RESULT_SUCCESS;
96101
}
97102

@@ -101,6 +106,10 @@ bool ze_try_initialize(void)
101106
/// @return Number of indices stored
102107
int ze_intel_device_indices(uint32_t* indices, uint32_t indices_size, uint32_t *error)
103108
{
109+
if (getenv("UNITTEST") != NULL) {
110+
return 0;
111+
}
112+
104113
if (indices == NULL || 0 == indices_size) {
105114
*error = ZE_RESULT_ERROR_INVALID_NULL_POINTER;
106115

cmd/gpu_levelzero/zes.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ static bool device_enumerated = false;
3535

3636
bool zes_try_initialize(void)
3737
{
38+
if (getenv("UNITTEST") != NULL) {
39+
return false;
40+
}
41+
3842
return zesInit(0) == ZE_RESULT_SUCCESS;
3943
}
4044

@@ -161,6 +165,10 @@ bool is_integrated(zes_device_handle_t handle)
161165
/// @return memory amount for the device
162166
uint64_t zes_device_memory_amount(char* bdf_address, uint32_t* error)
163167
{
168+
if (getenv("UNITTEST") != NULL) {
169+
return 0;
170+
}
171+
164172
ze_result_t res = ZE_RESULT_SUCCESS;
165173

166174
if (!device_enumerated) {
@@ -208,6 +216,10 @@ uint64_t zes_device_memory_amount(char* bdf_address, uint32_t* error)
208216
/// @return true for good, false for bad
209217
bool zes_device_memory_is_healthy(char* bdf_address, uint32_t* error)
210218
{
219+
if (getenv("UNITTEST") != NULL) {
220+
return false;
221+
}
222+
211223
if (!device_enumerated) {
212224
ze_result_t res = enumerate_zes_devices();
213225
if (res != ZE_RESULT_SUCCESS) {
@@ -254,6 +266,10 @@ bool zes_device_memory_is_healthy(char* bdf_address, uint32_t* error)
254266
/// @return true for good, false for bad
255267
bool zes_device_bus_is_healthy(char* bdf_address, uint32_t* error)
256268
{
269+
if (getenv("UNITTEST") != NULL) {
270+
return false;
271+
}
272+
257273
if (!device_enumerated) {
258274
ze_result_t res = enumerate_zes_devices();
259275
if (res != ZE_RESULT_SUCCESS) {

0 commit comments

Comments
 (0)