Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2172,13 +2172,21 @@ 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)
add_test(NAME test-format COMMAND fastfetch-test-format)
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()

##################
Expand Down
16 changes: 10 additions & 6 deletions src/modules/gpu/gpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@

#include <stdlib.h>

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) {
Expand All @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/modules/gpu/gpu.h
Original file line number Diff line number Diff line change
@@ -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);

Expand Down
39 changes: 39 additions & 0 deletions tests/gpu.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "modules/gpu/gpu.h"

#include <stdlib.h>

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;
}