[PATCH v2] tests/intel/xe_configfs: Add i2c adapter check in survivability mode

Kamil Konieczny kamil.konieczny at linux.intel.com
Thu Aug 21 15:23:03 UTC 2025


Hi Sk,
On 2025-08-13 at 15:31:11 +0530, Sk Anirban wrote:

please make it explicit that this is adding new test, maybe
something like:

[PATCH v2] tests/intel: Add new xe_survivability test for i2c adapter

Few more nits below.

> Add i2c adapter presence check in survivability mode to ensure
> the Add-In Management Controller (AMC) can receive firmware updates
> when the device is in survivability mode.

Could above be also a part of a comment or description
in a test or subtest?

> 
> v2: Create new file for test (Riana)
> 
> Signed-off-by: Sk Anirban <sk.anirban at intel.com>
> ---
>  tests/intel/xe_configfs.c      |  36 +------
>  tests/intel/xe_survivability.c | 174 +++++++++++++++++++++++++++++++++
>  tests/meson.build              |   1 +
>  3 files changed, 177 insertions(+), 34 deletions(-)
>  create mode 100644 tests/intel/xe_survivability.c
> 
> diff --git a/tests/intel/xe_configfs.c b/tests/intel/xe_configfs.c
> index 5c65cd01d..e573421aa 100644
> --- a/tests/intel/xe_configfs.c
> +++ b/tests/intel/xe_configfs.c
> @@ -2,7 +2,9 @@
>  /*
>   * Copyright © 2025 Intel Corporation
>   */
> +#include <dirent.h>
>  #include <limits.h>
> +#include <fcntl.h>

Move fcntl.h  after dirent.h

>  
>  #include "igt.h"
>  #include "igt_configfs.h"
> @@ -31,33 +33,6 @@ static void restore(int sig)
>  	igt_kmod_bind("xe", bus_addr);
>  }
>  
> -static void set_survivability_mode(int configfs_device_fd, bool value)
> -{
> -	igt_kmod_unbind("xe", bus_addr);
> -	igt_sysfs_set_boolean(configfs_device_fd, "survivability_mode", value);
> -	igt_kmod_bind("xe", bus_addr);
> -}
> -
> -/**
> - * SUBTEST: survivability-mode
> - * Description: Validate survivability mode by setting configfs
> - */
> -static void test_survivability_mode(int configfs_device_fd)
> -{
> -	char path[PATH_MAX];
> -	int fd;
> -
> -	/* Enable survivability mode */
> -	set_survivability_mode(configfs_device_fd, true);
> -
> -	/* check presence of survivability mode sysfs */
> -	snprintf(path, PATH_MAX, "/sys/bus/pci/devices/%s/survivability_mode", bus_addr);
> -
> -	fd = open(path, O_RDONLY);
> -	igt_assert_f(fd >= 0, "Survivability mode not set\n");
> -	close(fd);
> -}
> -
>  /**
>   * SUBTEST: engines-allowed-invalid
>   * Description: Validate engines_allowed attribute for invalid values
> @@ -128,13 +103,6 @@ igt_main
>  		configfs_device_fd = create_device_configfs_group(configfs_fd, fd);
>  	}
>  
> -	igt_describe("Validate survivability mode");
> -	igt_subtest("survivability-mode") {
> -		igt_require(IS_BATTLEMAGE(intel_get_drm_devid(fd)));
> -		igt_install_exit_handler(restore);
> -		test_survivability_mode(configfs_device_fd);
> -	}
> -
>  	igt_describe("Validate engines_allowed with invalid options");
>  	igt_subtest("engines-allowed-invalid") {
>  		igt_install_exit_handler(restore);
> diff --git a/tests/intel/xe_survivability.c b/tests/intel/xe_survivability.c
> new file mode 100644
> index 000000000..1bfcb2756
> --- /dev/null
> +++ b/tests/intel/xe_survivability.c
> @@ -0,0 +1,174 @@
> +// SPDX-License-Identifier: MIT
> +/*
> + * Copyright © 2025 Intel Corporation
> + */
> +#include <dirent.h>
> +#include <limits.h>
> +#include <fcntl.h>

Same here, fcntl.h header should be after dirent.h

> +
> +#include "igt.h"
> +#include "igt_configfs.h"
> +#include "igt_device.h"
> +#include "igt_fs.h"
> +#include "igt_kmod.h"
> +#include "igt_sysfs.h"
> +#include "xe/xe_query.h"
> +
> +/**
> + * TEST: Comprehensive survivability mode testing
> + * Category: Core
> + * Mega feature: General Core features
> + * Sub-category: survivability
> + * Functionality: survivability mode
> + * Description: validate survivability mode functionality including i2c and runtime behavior
> + * Test category: functionality test
> + */
> +
> +static char bus_addr[NAME_MAX];
> +
> +static int find_i2c_adapter(struct pci_device *pci_xe)
> +{
> +	char device_path[PATH_MAX];
> +	struct dirent *dirent;
> +	int i2c_adapter = -1;
> +	DIR *device_dir;
> +	int ret;
> +
> +	igt_require(igt_kmod_load("i2c-dev", NULL) == 0);
> +
> +	snprintf(device_path, sizeof(device_path), "/sys/bus/pci/devices/%s/%s.%hu", bus_addr,
> +		 "i2c_designware", (pci_xe->bus << 8) | (pci_xe->dev));
> +	device_dir = opendir(device_path);
> +
> +	if (!device_dir)
> +		return -1;
> +
> +	while ((dirent = readdir(device_dir))) {
> +		if (strncmp(dirent->d_name, "i2c-", 4) == 0) {
> +			ret = sscanf(dirent->d_name, "i2c-%d", &i2c_adapter);
> +			igt_assert_f(ret == 1, "Failed to parse i2c adapter number");
> +			closedir(device_dir);
> +			return i2c_adapter;
> +		}
> +	}
> +
> +	closedir(device_dir);
> +	return i2c_adapter;
> +}
> +
> +static void restore(int sig)
> +{
> +	/* Restore after survivability mode */
> +	igt_kmod_unbind("xe", bus_addr);
> +	igt_kmod_bind("xe", bus_addr);
> +}
> +
> +static void set_survivability_mode(int configfs_device_fd, bool value)
> +{
> +	igt_kmod_unbind("xe", bus_addr);
> +	igt_sysfs_set_boolean(configfs_device_fd, "survivability_mode", value);
> +	igt_kmod_bind("xe", bus_addr);
> +}
> +
> +/**
> + * SUBTEST: i2c-functionality
> + * Description: Validate i2c adapter functionality in survivability mode
> + */
> +static void test_i2c_functionality(int configfs_device_fd, struct pci_device *pci_xe)
> +{
> +	int i2c_adapter_before, i2c_adapter_after;
> +	char path[PATH_MAX];
> +	int fd;
> +
> +	/* Check i2c adapter before survivability mode */
> +	i2c_adapter_before = find_i2c_adapter(pci_xe);
> +
> +	/* Enable survivability mode */
> +	set_survivability_mode(configfs_device_fd, true);
> +
> +	/* check presence of survivability mode sysfs */
> +	snprintf(path, PATH_MAX, "/sys/bus/pci/devices/%s/survivability_mode", bus_addr);
> +
> +	fd = open(path, O_RDONLY);
> +	igt_assert_f(fd >= 0, "Survivability mode not set\n");
> +	close(fd);
> +
> +	/* Check i2c adapter after survivability mode */
> +	i2c_adapter_after = find_i2c_adapter(pci_xe);
> +	if (i2c_adapter_before >= 0) {
> +		igt_assert_f(i2c_adapter_after >= 0,
> +			     "i2c adapter disappeared in survivability mode (was %d)",
> +			     i2c_adapter_before);
> +	}
> +}
> +
> +/**
> + * SUBTEST: survivability-mode
> + * Description: Validate survivability mode by setting configfs
> + */
> +static void test_survivability_mode(int configfs_device_fd)
> +{
> +	char path[PATH_MAX];
> +	int fd;
> +
> +	/* Enable survivability mode */
> +	set_survivability_mode(configfs_device_fd, true);
> +
> +	/* check presence of survivability mode sysfs */
> +	snprintf(path, PATH_MAX, "/sys/bus/pci/devices/%s/survivability_mode", bus_addr);
> +
> +	fd = open(path, O_RDONLY);
> +	igt_assert_f(fd >= 0, "Survivability mode not set\n");
> +	close(fd);
> +}
> +
> +static int create_device_configfs_group(int configfs_fd, int fd)
> +{
> +	int configfs_device_fd;
> +	struct pci_device *pci_dev;
> +	mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
> +
> +	pci_dev = igt_device_get_pci_device(fd);
> +	snprintf(bus_addr, sizeof(bus_addr), "%04x:%02x:%02x.%01x",
> +		 pci_dev->domain, pci_dev->bus, pci_dev->dev, pci_dev->func);
> +
> +	configfs_device_fd = igt_fs_create_dir(configfs_fd, bus_addr, mode);
> +	igt_assert(configfs_device_fd);
> +
> +	return configfs_device_fd;
> +}
> +
> +igt_main
> +{
> +	int fd, configfs_fd, configfs_device_fd;
> +	struct pci_device *pci_xe;
> +
> +	igt_fixture {
> +		fd = drm_open_driver(DRIVER_XE);
> +		pci_xe = igt_device_get_pci_device(fd);
> +		configfs_fd = igt_configfs_open("xe");
> +		igt_require(configfs_fd != -1);
> +		configfs_device_fd = create_device_configfs_group(configfs_fd, fd);
> +		igt_require(IS_BATTLEMAGE(intel_get_drm_devid(fd)));
> +	}
> +
> +	igt_describe("Validate survivability mode");
> +	igt_subtest("survivability-mode") {
> +		igt_require(IS_BATTLEMAGE(intel_get_drm_devid(fd)));
> +		igt_install_exit_handler(restore);
> +		test_survivability_mode(configfs_device_fd);
> +	}
> +
> +	igt_describe("Validate i2c adapter functionality in survivability mode");
> +	igt_subtest("i2c-functionality") {
> +		igt_install_exit_handler(restore);
> +		test_i2c_functionality(configfs_device_fd, pci_xe);
> +	}
> +
> +	igt_fixture {
> +		igt_fs_remove_dir(configfs_fd, bus_addr);
> +		close(configfs_device_fd);
> +		close(configfs_fd);
> +		close(fd);

Use drm_close_driver() here. Also see Lucas patchseries

https://patchwork.freedesktop.org/series/153175/
tests/intel/xe_configfs: Unbind before tests

for possible improvements needed in your test.

Regards,
Kamil

> +	}
> +}
> diff --git a/tests/meson.build b/tests/meson.build
> index 5c01c64e9..8f264d8e8 100644
> --- a/tests/meson.build
> +++ b/tests/meson.build
> @@ -329,6 +329,7 @@ intel_xe_progs = [
>  	'xe_sriov_auto_provisioning',
>  	'xe_sriov_flr',
>  	'xe_sriov_scheduling',
> +	'xe_survivability',
>  	'xe_sysfs_defaults',
>  	'xe_sysfs_preempt_timeout',
>  	'xe_sysfs_scheduler',
> -- 
> 2.43.0
> 


More information about the igt-dev mailing list