Skip to content

Commit

Permalink
[ODS] Fix not returning invalid values
Browse files Browse the repository at this point in the history
After allowing urDeviceGetSelected to return zero devices rather than
returning an error, a number of unit tests started failing. This patch
fixes these tests by returning the expected error code during parsing,
rather than after processing all ODS terms. This has the caveat of not
processing all ODS terms before reporting an error and should be
revisited once more robust testing is in place.
  • Loading branch information
kbenzie committed Feb 28, 2024
1 parent 4957bd0 commit d2a2fe0
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions source/loader/ur_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,10 @@ ur_result_t urDeviceGetSelected(ur_platform_handle_t hPlatform,

for (auto &termPair : mapODS) {
std::string backend = termPair.first;
if (backend
.empty()) { // FIXME: never true because getenv_to_map rejects this case
// TODO: Figure out how to process all ODS errors rather than returning
// on the first error.
if (backend.empty()) {
// FIXME: never true because getenv_to_map rejects this case
// malformed term: missing backend -- output ERROR, then continue
logger::error("ERROR: missing backend, format of filter = "
"'[!]backend:filterStrings'");
Expand Down Expand Up @@ -459,20 +461,19 @@ ur_result_t urDeviceGetSelected(ur_platform_handle_t hPlatform,
std::tolower(static_cast<unsigned char>(b));
})) {
// irrelevant term for current request: different backend -- silently ignore
logger::warning(
"WARNING: ignoring term with irrelevant backend '{}'", backend);
continue;
logger::error("unrecognised backend '{}'", backend);
return UR_RESULT_ERROR_INVALID_VALUE;
}
if (termPair.second.size() == 0) {
// malformed term: missing filterStrings -- output ERROR, then continue
logger::error("ERROR missing filterStrings, format of filter = "
// malformed term: missing filterStrings -- output ERROR
logger::error("missing filterStrings, format of filter = "
"'[!]backend:filterStrings'");
continue;
return UR_RESULT_ERROR_INVALID_VALUE;
}
if (std::find_if(termPair.second.cbegin(), termPair.second.cend(),
[](const auto &s) { return s.empty(); }) !=
termPair.second
.cend()) { // FIXME: never true because getenv_to_map rejects this case
termPair.second.cend()) {
// FIXME: never true because getenv_to_map rejects this case
// malformed term: missing filterString -- output warning, then continue
logger::warning(
"WARNING: empty filterString, format of filterStrings "
Expand All @@ -483,10 +484,10 @@ ur_result_t urDeviceGetSelected(ur_platform_handle_t hPlatform,
[](const auto &s) {
return std::count(s.cbegin(), s.cend(), '.') > 2;
}) != termPair.second.cend()) {
// malformed term: too many dots in filterString -- output warning, then continue
logger::warning("WARNING: too many dots in filterString, format of "
"filterString = 'root[.sub[.subsub]]'");
continue;
// malformed term: too many dots in filterString
logger::error("too many dots in filterString, format of "
"filterString = 'root[.sub[.subsub]]'");
return UR_RESULT_ERROR_INVALID_VALUE;
}
if (std::find_if(
termPair.second.cbegin(), termPair.second.cend(),
Expand All @@ -504,10 +505,9 @@ ur_result_t urDeviceGetSelected(ur_platform_handle_t hPlatform,
}
return false; // no BAD things, so must be okay
}) != termPair.second.cend()) {
// malformed term: star dot no-star in filterString -- output warning, then continue
logger::warning(
"WARNING: invalid wildcard in filterString, '*.' => '*.*'");
continue;
// malformed term: star dot no-star in filterString
logger::error( "invalid wildcard in filterString, '*.' => '*.*'");
return UR_RESULT_ERROR_INVALID_VALUE;
}

// TODO -- use regex validation_pattern to catch all other syntax errors in the ODS string
Expand Down

0 comments on commit d2a2fe0

Please sign in to comment.