Skip to content

Commit

Permalink
test: amdgpu: convert metrics to host endian
Browse files Browse the repository at this point in the history
  • Loading branch information
flightlessmango committed May 21, 2024
1 parent 0caded8 commit faa3b1c
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion tests/test_amdgpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,25 @@ extern "C" {
#include "stdio.h"
#include "../src/amdgpu.h"
#include "../src/cpu.h"
#include <endian.h>

#define UNUSED(x) (void)(x)

static void convert_metrics_to_host_endian(struct amdgpu_common_metrics *metrics) {
metrics->gpu_load_percent = le16toh(metrics->gpu_load_percent);
metrics->average_gfx_power_w = le16toh(metrics->average_gfx_power_w);
metrics->average_cpu_power_w = le16toh(metrics->average_cpu_power_w);
metrics->current_gfxclk_mhz = le16toh(metrics->current_gfxclk_mhz);
metrics->current_uclk_mhz = le16toh(metrics->current_uclk_mhz);
metrics->gpu_temp_c = le16toh(metrics->gpu_temp_c);
metrics->soc_temp_c = le16toh(metrics->soc_temp_c);
metrics->apu_cpu_temp_c = le16toh(metrics->apu_cpu_temp_c);
metrics->is_power_throttled = le16toh(metrics->is_power_throttled);
metrics->is_current_throttled = le16toh(metrics->is_current_throttled);
metrics->is_temp_throttled = le16toh(metrics->is_temp_throttled);
metrics->is_other_throttled = le16toh(metrics->is_other_throttled);
}

static void test_amdgpu_verify_metrics(void **state) {
UNUSED(state);

Expand All @@ -32,6 +48,7 @@ static void test_amdgpu_get_instant_metrics(void **state) {
metrics_path = "./gpu_metrics";
metrics = {};
amdgpu_get_instant_metrics(&metrics);
convert_metrics_to_host_endian(&metrics);
assert_int_equal(metrics.gpu_load_percent, 64);
assert_float_equal(metrics.average_gfx_power_w, 33, 0);
assert_float_equal(metrics.average_cpu_power_w, 0, 0);
Expand All @@ -49,6 +66,7 @@ static void test_amdgpu_get_instant_metrics(void **state) {
metrics_path = "./gpu_metrics_reserved_throttle_bits";
metrics = {};
amdgpu_get_instant_metrics(&metrics);
convert_metrics_to_host_endian(&metrics);
assert_false(metrics.is_power_throttled);
assert_false(metrics.is_current_throttled);
assert_false(metrics.is_temp_throttled);
Expand All @@ -57,6 +75,7 @@ static void test_amdgpu_get_instant_metrics(void **state) {
metrics_path = "./gpu_metrics_apu";
metrics = {};
amdgpu_get_instant_metrics(&metrics);
convert_metrics_to_host_endian(&metrics);
assert_int_equal(metrics.gpu_load_percent, 100);
assert_float_equal(metrics.average_gfx_power_w, 6.161, 0);
assert_float_equal(metrics.average_cpu_power_w, 9.235, 0);
Expand Down Expand Up @@ -97,4 +116,4 @@ const struct CMUnitTest amdgpu_tests[] = {

int main(void) {
return cmocka_run_group_tests(amdgpu_tests, NULL, NULL);
}
}

0 comments on commit faa3b1c

Please sign in to comment.