xref: /aosp_15_r20/external/OpenCL-CTS/test_conformance/computeinfo/pci_bus_info.cpp (revision 6467f958c7de8070b317fc65bcb0f6472e388d82)
1 //
2 // Copyright (c) 2021 The Khronos Group Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //    http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 #include "harness/compat.h"
17 
18 #include <array>
19 #include <bitset>
20 
21 #include "harness/testHarness.h"
22 #include "harness/deviceInfo.h"
23 
test_pci_bus_info(cl_device_id deviceID,cl_context context,cl_command_queue ignoreQueue,int num_elements)24 int test_pci_bus_info(cl_device_id deviceID, cl_context context,
25                       cl_command_queue ignoreQueue, int num_elements)
26 {
27     if (!is_extension_available(deviceID, "cl_khr_pci_bus_info"))
28     {
29         log_info("cl_khr_pci_bus_info not supported. Skipping test...\n");
30         return TEST_SKIPPED_ITSELF;
31     }
32 
33     cl_int error;
34 
35     cl_device_pci_bus_info_khr info;
36 
37     size_t size_ret;
38     error = clGetDeviceInfo(deviceID, CL_DEVICE_PCI_BUS_INFO_KHR, 0, NULL,
39                             &size_ret);
40     test_error(error, "Unable to query CL_DEVICE_PCI_BUS_INFO_KHR size");
41     test_assert_error(
42         size_ret == sizeof(info),
43         "Query for CL_DEVICE_PCI_BUS_INFO_KHR returned an unexpected size");
44 
45     error = clGetDeviceInfo(deviceID, CL_DEVICE_PCI_BUS_INFO_KHR, sizeof(info),
46                             &info, NULL);
47     test_error(error, "Unable to query CL_DEVICE_PCI_BUS_INFO_KHR");
48 
49     log_info("\tPCI Bus Info: %04x:%02x:%02x.%x\n", info.pci_domain,
50              info.pci_bus, info.pci_device, info.pci_function);
51 
52     return TEST_PASS;
53 }
54