| 
 | 1 | +//===---------------------------- Tests.cpp -------------------------------===//  | 
 | 2 | +//  | 
 | 3 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.  | 
 | 4 | +// See https://llvm.org/LICENSE.txt for license information.  | 
 | 5 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception  | 
 | 6 | +//  | 
 | 7 | +//===----------------------------------------------------------------------===//  | 
 | 8 | + | 
 | 9 | +#include <sycl/detail/device_filter.hpp>  | 
 | 10 | +#include <sycl/exception.hpp>  | 
 | 11 | + | 
 | 12 | +#include <gtest/gtest.h>  | 
 | 13 | + | 
 | 14 | +#include <vector>  | 
 | 15 | +#include <utility>  | 
 | 16 | +#include <string>  | 
 | 17 | + | 
 | 18 | +TEST(OneAPIDeviceSelector, IsCaseInsensitive) {  | 
 | 19 | +  ASSERT_EQ(sycl::detail::Parse_ONEAPI_DEVICE_SELECTOR("OPENCL:*"),  | 
 | 20 | +            sycl::detail::Parse_ONEAPI_DEVICE_SELECTOR("opencl:*"))  | 
 | 21 | +      << " backend should be case-insensitive";  | 
 | 22 | + | 
 | 23 | +  ASSERT_EQ(sycl::detail::Parse_ONEAPI_DEVICE_SELECTOR("*:GPU"),  | 
 | 24 | +            sycl::detail::Parse_ONEAPI_DEVICE_SELECTOR("*:gpu"))  | 
 | 25 | +      << " device type should be case-insensitive";  | 
 | 26 | +}  | 
 | 27 | + | 
 | 28 | +TEST(OneAPIDeviceSelector, EmitsErrorIfOnlyBackendIsSpecified) {  | 
 | 29 | +  try {  | 
 | 30 | +    std::ignore = sycl::detail::Parse_ONEAPI_DEVICE_SELECTOR("level_zero");  | 
 | 31 | +    FAIL() << "An exception was expected";  | 
 | 32 | +  } catch (const sycl::exception &e) {  | 
 | 33 | +    ASSERT_EQ(e.code(), sycl::errc::invalid);  | 
 | 34 | +    ASSERT_EQ(std::string(e.what()),  | 
 | 35 | +              "Incomplete selector!  Try 'level_zero:*' if all "  | 
 | 36 | +              "devices under the backend was original intention.");  | 
 | 37 | +  }  | 
 | 38 | +}  | 
 | 39 | + | 
 | 40 | +TEST(OneAPIDeviceSelector, EmitsErrorIfBackendStringIsInvalid) {  | 
 | 41 | +  try {  | 
 | 42 | +    std::ignore = sycl::detail::Parse_ONEAPI_DEVICE_SELECTOR("macaroni:*");  | 
 | 43 | +    FAIL() << "An exception was expected";  | 
 | 44 | +  } catch (const sycl::exception &e) {  | 
 | 45 | +    ASSERT_EQ(e.code(), sycl::errc::invalid);  | 
 | 46 | +    // FIXME: the error below could be better  | 
 | 47 | +    ASSERT_EQ(std::string(e.what()),  | 
 | 48 | +              "ONEAPI_DEVICE_SELECTOR parsing error. Backend is required but "  | 
 | 49 | +              "missing from \"macaroni:*\"");  | 
 | 50 | +  }  | 
 | 51 | +}  | 
 | 52 | + | 
 | 53 | +// TODO: test case ":"  | 
 | 54 | +// TODO: test case ":cpu"  | 
 | 55 | +// TODO: test case "level_zero:cpu:cpu"  | 
 | 56 | +// TODO: test case "opencl:"  | 
 | 57 | +// TODO: other positive test cases for parsing device, sub-devices, etc.  | 
0 commit comments