From: Soham Purkait <soham.purkait@intel.com>
To: igt-dev@lists.freedesktop.org, riana.tauro@intel.com,
badal.nilawar@intel.com, kamil.konieczny@intel.com
Cc: anshuman.gupta@intel.com, soham.purkait@intel.com
Subject: [PATCH i-g-t] tests/intel/xe_ras: Add test for GPU health indicator
Date: Thu, 16 Jul 2026 21:07:38 +0530 [thread overview]
Message-ID: <20260716153739.744575-2-soham.purkait@intel.com> (raw)
Add a new Xe RAS test exercising the gpu_health sysfs attribute
exposed by the Xe driver on platforms that provide the system
controller. The attribute reports and allows updating the GPU
health state.
The gpu-health subtest validates each valid state by writing it
and reading the value back, and checks that invalid writes are
rejected with -EINVAL, guarding against regressions in the
implementation.
Signed-off-by: Soham Purkait <soham.purkait@intel.com>
---
tests/intel/xe_ras.c | 127 +++++++++++++++++++++++++++++++++++++++++++
tests/meson.build | 1 +
2 files changed, 128 insertions(+)
create mode 100644 tests/intel/xe_ras.c
diff --git a/tests/intel/xe_ras.c b/tests/intel/xe_ras.c
new file mode 100644
index 000000000..e2465cbb1
--- /dev/null
+++ b/tests/intel/xe_ras.c
@@ -0,0 +1,127 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright © 2026 Intel Corporation
+ */
+
+/**
+ * TEST: Test Xe RAS (Reliability, Availability, Serviceability) functionality
+ * Category: Core
+ * Functionality: ras
+ * Mega feature: RAS
+ * Sub-category: RAS tests
+ * Test category: Functional tests
+ *
+ * SUBTEST: gpu-health
+ * Description: Verify the gpu_health sysfs attribute accepts each valid
+ * state (ok/warning/critical) and rejects invalid writes
+ * with EINVAL.
+ */
+
+#include <errno.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "igt.h"
+#include "igt_sysfs.h"
+
+#include "xe_drm.h"
+#include "xe/xe_query.h"
+
+IGT_TEST_DESCRIPTION("Tests for Xe RAS");
+
+/*
+ * gpu_health lives on the PCI device, reachable via the "device" symlink
+ * under the DRM char sysfs directory returned by igt_sysfs_open().
+ */
+#define GPU_HEALTH_ATTR "device/gpu_health"
+
+static const char * const gpu_health_states[] = {
+ "ok",
+ "warning",
+ "critical",
+};
+
+static bool valid_gpu_health(const char *s)
+{
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(gpu_health_states); i++)
+ if (!strcmp(s, gpu_health_states[i]))
+ return true;
+
+ return false;
+}
+
+static void test_gpu_health(int xe)
+{
+ char *orig_health = NULL, *health = NULL;
+ int sys_fd;
+ int ret;
+ int i;
+
+ sys_fd = igt_sysfs_open(xe);
+ igt_assert(sys_fd >= 0);
+
+ igt_require_f(igt_sysfs_has_attr(sys_fd, GPU_HEALTH_ATTR),
+ "gpu_health sysfs attribute not exposed by driver\n");
+
+ orig_health = igt_sysfs_get(sys_fd, GPU_HEALTH_ATTR);
+ igt_assert_f(orig_health, "Failed to read %s\n", GPU_HEALTH_ATTR);
+ igt_debug("initial gpu_health: %s\n", orig_health);
+ igt_assert_f(valid_gpu_health(orig_health),
+ "Unexpected initial gpu_health value: '%s'\n", orig_health);
+
+ /**
+ * Invalid writes must be rejected with EINVAL.
+ */
+ errno = 0;
+ ret = igt_sysfs_write(sys_fd, GPU_HEALTH_ATTR, "bogus", strlen("bogus"));
+ igt_assert_f(ret < 0,
+ "Write of invalid value to %s unexpectedly succeeded\n",
+ GPU_HEALTH_ATTR);
+ igt_assert_f(ret == -EINVAL,
+ "Invalid write to %s returned %d, expected -EINVAL\n",
+ GPU_HEALTH_ATTR, ret);
+
+ /**
+ * Write each valid state and read it back to confirm the driver
+ * accepts and reflects the requested value.
+ */
+ for (i = 0; i < ARRAY_SIZE(gpu_health_states); i++) {
+ const char *state = gpu_health_states[i];
+
+ igt_assert_f(igt_sysfs_set(sys_fd, GPU_HEALTH_ATTR, state),
+ "Failed to write '%s' to %s\n",
+ state, GPU_HEALTH_ATTR);
+
+ health = igt_sysfs_get(sys_fd, GPU_HEALTH_ATTR);
+ igt_assert(health);
+ igt_assert_f(!strcmp(health, state),
+ "gpu_health readback mismatch: wrote '%s', read '%s'\n",
+ state, health);
+ free(health);
+ }
+
+ /**
+ * Restore the original value.
+ */
+ igt_assert_f(igt_sysfs_set(sys_fd, GPU_HEALTH_ATTR, orig_health),
+ "Failed to restore original gpu_health '%s'\n", orig_health);
+
+ free(orig_health);
+ close(sys_fd);
+}
+
+int igt_main()
+{
+ int xe;
+
+ igt_fixture()
+ xe = drm_open_driver(DRIVER_XE);
+
+ igt_subtest("gpu-health")
+ test_gpu_health(xe);
+
+ igt_fixture()
+ drm_close_driver(xe);
+}
diff --git a/tests/meson.build b/tests/meson.build
index 6d90627b9..4ab4ef603 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -333,6 +333,7 @@ intel_xe_progs = [
'xe_prime_self_import',
'xe_pxp',
'xe_query',
+ 'xe_ras',
'xe_render_copy',
'xe_vm',
'xe_userptr_pressure',
--
2.43.0
next reply other threads:[~2026-07-16 15:38 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-16 15:37 Soham Purkait [this message]
2026-07-16 17:32 ` ✓ Xe.CI.BAT: success for tests/intel/xe_ras: Add test for GPU health indicator Patchwork
2026-07-16 17:44 ` ✓ i915.CI.BAT: " Patchwork
2026-07-16 22:19 ` ✓ Xe.CI.FULL: " Patchwork
2026-07-17 0:22 ` ✗ i915.CI.Full: failure " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260716153739.744575-2-soham.purkait@intel.com \
--to=soham.purkait@intel.com \
--cc=anshuman.gupta@intel.com \
--cc=badal.nilawar@intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=kamil.konieczny@intel.com \
--cc=riana.tauro@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox