Hash :
f8a2229e
Author :
Date :
2022-03-16T10:58:07
angle_system_info_test also exports androidSdkLevel Value being non-zero would unambiguously indicate that target is Android, not sure if the actual value is really needed but it's probably good to have. Bug: angleproject:6854 Change-Id: I685e8e0ffbb666349801203e9d09b082135af17e Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3529966 Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Roman Lavrov <romanl@google.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
//
// Copyright 2020 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Simple unit test suite that prints out system info as JSON.
//
// Example output for a Windows/NV machine:
//
// {
// "activeGPUIndex": 0,
// "isOptimus": false,
// "isMacSwitchable": false,
// "machineManufacturer": "",
// "machineModelVersion": "",
// "gpus": [
// {
// "vendorId": 4318,
// "deviceId": 7040,
// "driverVendor": "NVIDIA Corporation",
// "driverVersion": "452.6.0.0",
// "driverDate": "",
// "detailedDriverVersion": {
// "major": 452,
// "minor": 6,
// "subMinor": 0,
// "patch": 0
// }
// }
// ]
// }
#include "gpu_info_util/SystemInfo.h"
#include <gtest/gtest.h>
#include <rapidjson/document.h>
#include <rapidjson/prettywriter.h>
#include <rapidjson/stringbuffer.h>
#include <cstdlib>
#include "common/debug.h"
#if defined(ANGLE_ENABLE_VULKAN)
# include "gpu_info_util/SystemInfo_vulkan.h"
#endif // defined(ANGLE_ENABLE_VULKAN)
namespace js = rapidjson;
bool gFailedToFindGPU;
constexpr char kRenderTestOutputDir[] = "--render-test-output-dir=";
int main(int argc, char **argv)
{
angle::SystemInfo info;
bool useVulkan = false;
bool listTests = false;
bool useSwiftShader = false;
std::string output_dir;
for (int arg = 1; arg < argc; ++arg)
{
if (strcmp(argv[arg], "--vulkan") == 0)
{
useVulkan = true;
}
else if (strcmp(argv[arg], "--gtest_list_tests") == 0)
{
listTests = true;
}
else if (strcmp(argv[arg], "--swiftshader") == 0)
{
useSwiftShader = true;
}
else if (strstr(argv[arg], kRenderTestOutputDir))
{
output_dir = argv[arg] + strlen(kRenderTestOutputDir);
}
}
if (listTests)
{
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
if (useVulkan)
{
#if defined(ANGLE_ENABLE_VULKAN)
angle::vk::ICD preferredICD =
useSwiftShader ? angle::vk::ICD::SwiftShader : angle::vk::ICD::Default;
angle::GetSystemInfoVulkanWithICD(&info, preferredICD);
#else
ANGLE_UNUSED_VARIABLE(useSwiftShader);
printf("Vulkan not supported.\n");
return EXIT_FAILURE;
#endif // defined(ANGLE_ENABLE_VULKAN)
}
else
{
angle::GetSystemInfo(&info);
}
if (info.gpus.empty())
{
gFailedToFindGPU = true;
}
js::Document doc;
doc.SetObject();
js::Document::AllocatorType &allocator = doc.GetAllocator();
doc.AddMember("activeGPUIndex", info.activeGPUIndex, allocator);
doc.AddMember("isOptimus", info.isOptimus, allocator);
doc.AddMember("isMacSwitchable", info.isMacSwitchable, allocator);
js::Value machineManufacturer;
machineManufacturer.SetString(info.machineManufacturer.c_str(), allocator);
doc.AddMember("machineManufacturer", machineManufacturer, allocator);
js::Value machineModelVersion;
machineModelVersion.SetString(info.machineModelVersion.c_str(), allocator);
doc.AddMember("machineModelVersion", machineModelVersion, allocator);
js::Value androidSdkLevel;
androidSdkLevel.SetInt(info.androidSdkLevel);
doc.AddMember("androidSdkLevel", androidSdkLevel, allocator);
js::Value gpus;
gpus.SetArray();
for (const angle::GPUDeviceInfo &gpu : info.gpus)
{
js::Value obj;
obj.SetObject();
obj.AddMember("vendorId", gpu.vendorId, allocator);
obj.AddMember("deviceId", gpu.deviceId, allocator);
js::Value driverVendor;
driverVendor.SetString(gpu.driverVendor.c_str(), allocator);
obj.AddMember("driverVendor", driverVendor, allocator);
js::Value driverVersion;
driverVersion.SetString(gpu.driverVersion.c_str(), allocator);
obj.AddMember("driverVersion", driverVersion, allocator);
js::Value driverDate;
driverDate.SetString(gpu.driverDate.c_str(), allocator);
obj.AddMember("driverDate", driverDate, allocator);
js::Value versionInfo;
versionInfo.SetObject();
versionInfo.AddMember("major", gpu.detailedDriverVersion.major, allocator);
versionInfo.AddMember("minor", gpu.detailedDriverVersion.minor, allocator);
versionInfo.AddMember("subMinor", gpu.detailedDriverVersion.subMinor, allocator);
versionInfo.AddMember("patch", gpu.detailedDriverVersion.patch, allocator);
obj.AddMember("detailedDriverVersion", versionInfo, allocator);
gpus.PushBack(obj, allocator);
}
doc.AddMember("gpus", gpus, allocator);
js::StringBuffer buffer;
js::PrettyWriter<js::StringBuffer> writer(buffer);
doc.Accept(writer);
const char *output = buffer.GetString();
printf("%s\n", output);
if (!output_dir.empty())
{
std::string outputFile = output_dir + "/angle_system_info.json";
FILE *fp = fopen(outputFile.c_str(), "w");
if (fp)
{
fwrite(output, sizeof(char), strlen(output), fp);
fclose(fp);
}
}
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
TEST(ANGLE, SystemInfo)
{
if (gFailedToFindGPU)
{
FAIL() << "Failed to find GPU info.";
}
}