diff --git a/CHANGELOG.md b/CHANGELOG.md index ed1c3fbcfe..2b88b1b1bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ Features: * Added new ARM SoCs (CPU, Linux / Android) Bugfixes: +* Fixed the default GPU output prefixing the Microsoft Basic Display Adapter label with the hardware vendor. (#2339, GPU, Windows) * Fixed I/O rate calculation precision in DiskIO and NetIO, and prevented division by zero. (DiskIO / NetIO) * Fixed the fast path of ash version detection. (Shell) * Fixed memory usage detection support on x86-32 FreeBSD (Memory, FreeBSD) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5d52ecd8e4..7bcc2bc0df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2172,6 +2172,13 @@ if (BUILD_TESTS) PRIVATE libfastfetch ) + add_executable(fastfetch-test-gpu + tests/gpu.c + ) + target_link_libraries(fastfetch-test-gpu + PRIVATE libfastfetch + ) + enable_testing() add_test(NAME test-strbuf COMMAND fastfetch-test-strbuf) add_test(NAME test-list COMMAND fastfetch-test-list) @@ -2179,6 +2186,7 @@ if (BUILD_TESTS) add_test(NAME test-color COMMAND fastfetch-test-color) add_test(NAME test-duration COMMAND fastfetch-test-duration) add_test(NAME test-strutil COMMAND fastfetch-test-strutil) + add_test(NAME test-gpu COMMAND fastfetch-test-gpu) endif() ################## diff --git a/src/modules/gpu/gpu.c b/src/modules/gpu/gpu.c index 159cbaf6b2..2024b08a7a 100644 --- a/src/modules/gpu/gpu.c +++ b/src/modules/gpu/gpu.c @@ -11,6 +11,15 @@ #include +void ffGPUAppendName(const FFGPUResult* gpu, FFstrbuf* output) { + // This is a generic driver label rather than a GPU model name. + if (gpu->vendor.length > 0 && !ffStrbufStartsWithIgnCase(&gpu->name, &gpu->vendor) && !ffStrbufEqualS(&gpu->name, "Microsoft Basic Display Adapter")) { + ffStrbufAppend(output, &gpu->vendor); + ffStrbufAppendC(output, ' '); + } + ffStrbufAppend(output, &gpu->name); +} + static void printGPUResult(FFGPUOptions* options, uint8_t index, const FFGPUResult* gpu) { const char* type; switch (gpu->type) { @@ -32,12 +41,7 @@ static void printGPUResult(FFGPUOptions* options, uint8_t index, const FFGPUResu FF_STRBUF_AUTO_DESTROY output = ffStrbufCreate(); - if (gpu->vendor.length > 0 && !ffStrbufStartsWithIgnCase(&gpu->name, &gpu->vendor)) { - ffStrbufAppend(&output, &gpu->vendor); - ffStrbufAppendC(&output, ' '); - } - - ffStrbufAppend(&output, &gpu->name); + ffGPUAppendName(gpu, &output); if (gpu->coreCount != FF_GPU_CORE_COUNT_UNSET) { ffStrbufAppendF(&output, " (%d)", gpu->coreCount); diff --git a/src/modules/gpu/gpu.h b/src/modules/gpu/gpu.h index c2a3c7a417..892df373f3 100644 --- a/src/modules/gpu/gpu.h +++ b/src/modules/gpu/gpu.h @@ -1,8 +1,10 @@ #pragma once #include "option.h" +#include "detection/gpu/gpu.h" bool ffPrintGPU(FFGPUOptions* options); +void ffGPUAppendName(const FFGPUResult* gpu, FFstrbuf* output); void ffInitGPUOptions(FFGPUOptions* options); void ffDestroyGPUOptions(FFGPUOptions* options); diff --git a/tests/gpu.c b/tests/gpu.c new file mode 100644 index 0000000000..ae1407f2bc --- /dev/null +++ b/tests/gpu.c @@ -0,0 +1,39 @@ +#include "modules/gpu/gpu.h" + +#include + +static void verify(const char* vendor, const char* name, const char* expected, int lineNo) { + // Supply detected data directly so output tests do not depend on installed GPU drivers. + FFGPUResult gpu = {}; + ffStrbufInitS(&gpu.vendor, vendor); + ffStrbufInitS(&gpu.name, name); + FF_STRBUF_AUTO_DESTROY output = ffStrbufCreate(); + ffGPUAppendName(&gpu, &output); + if (!ffStrbufEqualS(&output, expected)) { + fprintf(stderr, "[%d] Expected \"%s\", got \"%s\"\n", lineNo, expected, output.chars); + exit(1); + } + + // Rendering must not change the detected values used in JSON and custom formats. + if (!ffStrbufEqualS(&gpu.vendor, vendor) || !ffStrbufEqualS(&gpu.name, name)) { + fprintf(stderr, "[%d] Detected GPU data changed during rendering\n", lineNo); + exit(1); + } + ffStrbufDestroy(&gpu.vendor); + ffStrbufDestroy(&gpu.name); +} + +#define VERIFY(vendor, name, expected) verify((vendor), (name), (expected), __LINE__) + +int main(void) { + VERIFY("NVIDIA", "Microsoft Basic Display Adapter", "Microsoft Basic Display Adapter"); + VERIFY("AMD", "Microsoft Basic Display Adapter", "Microsoft Basic Display Adapter"); + VERIFY("Intel", "Microsoft Basic Display Adapter", "Microsoft Basic Display Adapter"); + VERIFY("", "Microsoft Basic Display Adapter", "Microsoft Basic Display Adapter"); + VERIFY("Microsoft", "Microsoft Basic Display Adapter", "Microsoft Basic Display Adapter"); + VERIFY("NVIDIA", "GeForce RTX 4090", "NVIDIA GeForce RTX 4090"); + VERIFY("NVIDIA", "NVIDIA GeForce RTX 4090", "NVIDIA GeForce RTX 4090"); + VERIFY("NVIDIA", "nvidia GeForce RTX 4090", "nvidia GeForce RTX 4090"); + VERIFY("", "GeForce RTX 4090", "GeForce RTX 4090"); + return 0; +}