diff --git a/sycl/source/detail/config.hpp b/sycl/source/detail/config.hpp index 1fdf229860022..633a8227873ad 100644 --- a/sycl/source/detail/config.hpp +++ b/sycl/source/detail/config.hpp @@ -270,6 +270,13 @@ template <> class SYCLConfig { } const char *ValStr = BaseT::getRawValue(); if (ValStr) { + // Throw if the input string is empty. + if (ValStr[0] == '\0') + throw invalid_parameter_error( + "Invalid value for ONEAPI_DEVICE_SELECTOR environment " + "variable: value should not be null.", + PI_ERROR_INVALID_VALUE); + DeviceTargets = &GlobalHandler::instance().getOneapiDeviceSelectorTargets(ValStr); } diff --git a/sycl/test-e2e/OneapiDeviceSelector/illegal_input.cpp b/sycl/test-e2e/OneapiDeviceSelector/illegal_input.cpp index 59129cf820abe..e21915ad9b23f 100644 --- a/sycl/test-e2e/OneapiDeviceSelector/illegal_input.cpp +++ b/sycl/test-e2e/OneapiDeviceSelector/illegal_input.cpp @@ -9,6 +9,7 @@ // RUN: env ONEAPI_DEVICE_SELECTOR="level_zero:" %{run-unfiltered-devices} %t.out // RUN: env ONEAPI_DEVICE_SELECTOR="level_zero:::gpu" %{run-unfiltered-devices} %t.out // RUN: env ONEAPI_DEVICE_SELECTOR="level_zero:.1" %{run-unfiltered-devices} %t.out +// RUN: env ONEAPI_DEVICE_SELECTOR="" %{run-unfiltered-devices} %t.out // XFAIL: * // Calling ONEAPI_DEVICE_SELECTOR with an illegal input should result in an diff --git a/sycl/test/basic_tests/device-selectors-exception.cpp b/sycl/test/basic_tests/device-selectors-exception.cpp index 5bddf0ed43454..2256b7f4745b8 100644 --- a/sycl/test/basic_tests/device-selectors-exception.cpp +++ b/sycl/test/basic_tests/device-selectors-exception.cpp @@ -1,7 +1,9 @@ // RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out // RUN: env SYCL_DEVICE_FILTER="" %t.out // RUN: %if preview-breaking-changes-supported %{ %clangxx -fsycl -fsycl-targets=%sycl_triple -fpreview-breaking-changes %s -o %t.out %} -// RUN: %if preview-breaking-changes-supported %{ env ONEAPI_DEVICE_SELECTOR="" %t.out %} +// ONEAPI_DEVICE_SELECTOR="*:-1" causes this test to not select any device at +// all. +// RUN: %if preview-breaking-changes-supported %{ env ONEAPI_DEVICE_SELECTOR="*:-1" %t.out %} #include using namespace sycl;