Path: blob/main_old/src/tests/angle_system_info_tests_main.cpp
1693 views
//1// Copyright 2020 The ANGLE Project Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4//5// Simple unit test suite that prints out system info as JSON.6//7// Example output for a Windows/NV machine:8//9// {10// "activeGPUIndex": 0,11// "isOptimus": false,12// "isMacSwitchable": false,13// "machineManufacturer": "",14// "machineModelVersion": "",15// "gpus": [16// {17// "vendorId": 4318,18// "deviceId": 7040,19// "driverVendor": "NVIDIA Corporation",20// "driverVersion": "452.6.0.0",21// "driverDate": "",22// "detailedDriverVersion": {23// "major": 452,24// "minor": 6,25// "subMinor": 0,26// "patch": 027// }28// }29// ]30// }3132#include "gpu_info_util/SystemInfo.h"3334#include <cstdlib>3536#include <gtest/gtest.h>3738#include <rapidjson/document.h>39#include <rapidjson/prettywriter.h>40#include <rapidjson/stringbuffer.h>4142namespace js = rapidjson;4344bool gFailedToFindGPU;4546int main(int argc, char **argv)47{48angle::SystemInfo info;4950bool useVulkan = false;51bool listTests = false;5253for (int arg = 1; arg < argc; ++arg)54{55if (strcmp(argv[arg], "--vulkan") == 0)56{57useVulkan = true;58}59else if (strcmp(argv[arg], "--gtest_list_tests") == 0)60{61listTests = true;62}63}6465if (listTests)66{67testing::InitGoogleTest(&argc, argv);68return RUN_ALL_TESTS();69}7071if (useVulkan)72{73#if defined(ANGLE_ENABLE_VULKAN)74angle::GetSystemInfoVulkan(&info);75#else76printf("Vulkan not supported.\n");77return EXIT_FAILURE;78#endif // defined(ANGLE_ENABLE_VULKAN)79}80else81{82angle::GetSystemInfo(&info);83}8485if (info.gpus.empty())86{87gFailedToFindGPU = true;88}8990js::Document doc;91doc.SetObject();9293js::Document::AllocatorType &allocator = doc.GetAllocator();9495doc.AddMember("activeGPUIndex", info.activeGPUIndex, allocator);96doc.AddMember("isOptimus", info.isOptimus, allocator);97doc.AddMember("isMacSwitchable", info.isMacSwitchable, allocator);9899js::Value machineManufacturer;100machineManufacturer.SetString(info.machineManufacturer.c_str(), allocator);101doc.AddMember("machineManufacturer", machineManufacturer, allocator);102103js::Value machineModelVersion;104machineModelVersion.SetString(info.machineModelVersion.c_str(), allocator);105doc.AddMember("machineModelVersion", machineModelVersion, allocator);106107js::Value gpus;108gpus.SetArray();109110for (const angle::GPUDeviceInfo &gpu : info.gpus)111{112js::Value obj;113obj.SetObject();114115obj.AddMember("vendorId", gpu.vendorId, allocator);116obj.AddMember("deviceId", gpu.deviceId, allocator);117118js::Value driverVendor;119driverVendor.SetString(gpu.driverVendor.c_str(), allocator);120obj.AddMember("driverVendor", driverVendor, allocator);121122js::Value driverVersion;123driverVersion.SetString(gpu.driverVersion.c_str(), allocator);124obj.AddMember("driverVersion", driverVersion, allocator);125126js::Value driverDate;127driverDate.SetString(gpu.driverDate.c_str(), allocator);128obj.AddMember("driverDate", driverDate, allocator);129130js::Value versionInfo;131versionInfo.SetObject();132versionInfo.AddMember("major", gpu.detailedDriverVersion.major, allocator);133versionInfo.AddMember("minor", gpu.detailedDriverVersion.minor, allocator);134versionInfo.AddMember("subMinor", gpu.detailedDriverVersion.subMinor, allocator);135versionInfo.AddMember("patch", gpu.detailedDriverVersion.patch, allocator);136obj.AddMember("detailedDriverVersion", versionInfo, allocator);137138gpus.PushBack(obj, allocator);139}140141doc.AddMember("gpus", gpus, allocator);142143js::StringBuffer buffer;144js::PrettyWriter<js::StringBuffer> writer(buffer);145doc.Accept(writer);146147const char *output = buffer.GetString();148printf("%s\n", output);149150testing::InitGoogleTest(&argc, argv);151return RUN_ALL_TESTS();152}153154TEST(ANGLE, SystemInfo)155{156if (gFailedToFindGPU)157{158FAIL() << "Failed to find GPU info.";159}160}161162