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

Riana Tauro riana.tauro at intel.com
Tue Aug 5 04:39:39 UTC 2025


Hi Anirban


On 8/5/2025 12:54 AM, Sk Anirban wrote:
> 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.
> 
> Signed-off-by: Sk Anirban <sk.anirban at intel.com>
> ---
>   tests/intel/xe_configfs.c | 50 ++++++++++++++++++++++++++++++++++-----

Don't add this in configfs file. Let's create a new test for 
survivability and move runtime survivability and i2c check there.
Configfs here shouldn't be checking the entire functionality of
survivability mode. This is only to have basic checks

Thanks
Riana
>   1 file changed, 44 insertions(+), 6 deletions(-)
> 
> diff --git a/tests/intel/xe_configfs.c b/tests/intel/xe_configfs.c
> index 5c65cd01d..a3af84b6a 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>
>   
>   #include "igt.h"
>   #include "igt_configfs.h"
> @@ -24,6 +26,34 @@
>   
>   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;
> +
> +	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) {
> +			sscanf(dirent->d_name, "i2c-%d", &i2c_adapter);
> +			closedir(device_dir);
> +			return i2c_adapter;
> +		}
> +	}
> +
> +	closedir(device_dir);
> +	return i2c_adapter;
> +}
> +
>   static void restore(int sig)
>   {
>   	/* Restore after survivability mode */
> @@ -42,10 +72,12 @@ static void set_survivability_mode(int configfs_device_fd, bool value)
>    * SUBTEST: survivability-mode
>    * Description: Validate survivability mode by setting configfs
>    */
> -static void test_survivability_mode(int configfs_device_fd)
> +static void test_survivability_mode(int configfs_device_fd, struct pci_device *pci_xe)
>   {
>   	char path[PATH_MAX];
> -	int fd;
> +	int file_fd, i2c_adapter;
> +
> +	i2c_adapter = find_i2c_adapter(pci_xe);
>   
>   	/* Enable survivability mode */
>   	set_survivability_mode(configfs_device_fd, true);
> @@ -53,9 +85,13 @@ static void test_survivability_mode(int configfs_device_fd)
>   	/* 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);
> +	file_fd = open(path, O_RDONLY);
> +	igt_assert_f(file_fd >= 0, "Survivability mode not set\n");
> +
> +	if (i2c_adapter >= 0)
> +		igt_assert_f(find_i2c_adapter(pci_xe) >= 0, "Failed to find i2c adapter in survivability mode\n");
> +
> +	close(file_fd);
>   }
>   
>   /**
> @@ -120,9 +156,11 @@ static int create_device_configfs_group(int configfs_fd, int 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);
> @@ -132,7 +170,7 @@ igt_main
>   	igt_subtest("survivability-mode") {
>   		igt_require(IS_BATTLEMAGE(intel_get_drm_devid(fd)));
>   		igt_install_exit_handler(restore);
> -		test_survivability_mode(configfs_device_fd);
> +		test_survivability_mode(configfs_device_fd, pci_xe);
>   	}
>   
>   	igt_describe("Validate engines_allowed with invalid options");



More information about the igt-dev mailing list