From 52ee81cfdc13d3f44c1b5db041b14f236c57188c Mon Sep 17 00:00:00 2001 From: Jamie Madill Date: Wed, 23 Sep 2020 23:37:17 -0400 Subject: [PATCH] Add a small unit test that dumps system info. We can use this in the trace gold tests to identify system properties. The test uses Vulkan info collection when available and dumps out the known GPU info as JSON. Bug: angleproject:4090 Bug: b/168049670 Change-Id: Ib8d2244d82b650b94818da30adab180b471af556 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2427872 Commit-Queue: Jamie Madill Reviewed-by: Cody Northrop --- gni/angle.gni | 1 + src/tests/BUILD.gn | 11 ++ src/tests/angle_system_info_tests_main.cpp | 148 +++++++++++++++++++++ 3 files changed, 160 insertions(+) create mode 100644 src/tests/angle_system_info_tests_main.cpp diff --git a/gni/angle.gni b/gni/angle.gni index c7978d64b..4cc0b9999 100644 --- a/gni/angle.gni +++ b/gni/angle.gni @@ -211,6 +211,7 @@ set_defaults("angle_test") { sources = [] data = [] defines = [] + deps = [] data_deps = [] main = "" suppressed_configs = angle_remove_configs diff --git a/src/tests/BUILD.gn b/src/tests/BUILD.gn index bc6f66613..bfac835ef 100644 --- a/src/tests/BUILD.gn +++ b/src/tests/BUILD.gn @@ -110,6 +110,16 @@ angle_common_test_utils("angle_common_test_utils_static") { angle_util = "angle_util_static" } +# We use this in the restricted trace tests to load driver info. +angle_test("angle_system_info_test") { + standalone_harness = true + sources = [ "angle_system_info_tests_main.cpp" ] + deps = [ + "$angle_root:angle_gpu_info_util", + "$angle_root/util:angle_util_static", + ] +} + angle_test("angle_unittests") { sources = angle_unittests_sources main = "angle_unittest_main" @@ -1307,6 +1317,7 @@ group("angle_tests") { deps = [ ":angle_end2end_tests", ":angle_perftests", + ":angle_system_info_test", ":angle_unittests", "capture_replay_tests", ] diff --git a/src/tests/angle_system_info_tests_main.cpp b/src/tests/angle_system_info_tests_main.cpp new file mode 100644 index 000000000..909a3e55e --- /dev/null +++ b/src/tests/angle_system_info_tests_main.cpp @@ -0,0 +1,148 @@ +// +// 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 + +#include + +#include +#include +#include + +namespace js = rapidjson; + +int main(int argc, char **argv) +{ + angle::SystemInfo info; + + bool useVulkan = false; + bool listTests = false; + + 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; + } + } + + if (listTests) + { + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); + } + + if (useVulkan) + { +#if defined(ANGLE_ENABLE_VULKAN) + angle::GetSystemInfoVulkan(&info); +#else + printf("Vulkan not supported.\n"); + return EXIT_FAILURE; +#endif // defined(ANGLE_ENABLE_VULKAN) + } + else + { + angle::GetSystemInfo(&info); + } + + 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 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 writer(buffer); + doc.Accept(writer); + + const char *output = buffer.GetString(); + printf("%s\n", output); + + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + +TEST(ANGLE, SystemInfo) {} \ No newline at end of file