public inbox for igt-dev@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Jani Nikula <jani.nikula@intel.com>
To: Kunal Joshi <kunal1.joshi@intel.com>, igt-dev@lists.freedesktop.org
Cc: Kunal Joshi <kunal1.joshi@intel.com>
Subject: Re: [PATCH i-g-t 6/6] tests/intel/kms_usb4_switch: Add USB4 switch test suite
Date: Tue, 14 Apr 2026 12:27:42 +0300	[thread overview]
Message-ID: <790e95881771844181284430d837e31c1cb9681b@intel.com> (raw)
In-Reply-To: <20260409043714.284108-7-kunal1.joshi@intel.com>

On Thu, 09 Apr 2026, Kunal Joshi <kunal1.joshi@intel.com> wrote:
> Add a comprehensive test suite for USB4/Thunderbolt dock/undock and
> port switching scenarios using the Microsoft USB4 Switch 3141:
>
>  - dock-undock: Basic dock/undock cycles with display verification
>  - dock-undock-sr: Dock/undock with suspend/resume stability
>  - dock-undock-during-suspend: Dock while system is suspended
>  - switch: Port-to-port switching with display verification
>  - switch-sr: Port switching with suspend/resume stability
>  - switch-during-suspend: Port switch during suspend via HW delay
>
> v2: Make timeout const (Arun)
>
> Signed-off-by: Kunal Joshi <kunal1.joshi@intel.com>
> ---
>  tests/intel/kms_usb4_switch.c | 1254 +++++++++++++++++++++++++++++++++
>  tests/meson.build             |    2 +
>  2 files changed, 1256 insertions(+)
>  create mode 100644 tests/intel/kms_usb4_switch.c
>
> diff --git a/tests/intel/kms_usb4_switch.c b/tests/intel/kms_usb4_switch.c
> new file mode 100644
> index 000000000..d26cacaf1
> --- /dev/null
> +++ b/tests/intel/kms_usb4_switch.c
> @@ -0,0 +1,1254 @@
> +// SPDX-License-Identifier: MIT
> +/*
> + * Copyright © 2026 Intel Corporation
> + */
> +
> +/**
> + * TEST: kms usb4 switch
> + * Category: Display
> + * Description:        USB4/Thunderbolt dock/undock and port switching tests
> + * Driver requirement: i915, xe
> + * Mega feature:       General Display Features
> + *
> + * SUBTEST: dock-undock
> + * Description:        Test dock/undock cycles with display verification.
> + *                     Verifies hotplug events, EDID serial matching, modeset with
> + *                     max non-joiner mode, and pipe CRC stability.
> + *
> + * SUBTEST: dock-undock-sr
> + * Description:        Test dock/undock with suspend/resume stability.
> + *                     Docks, verifies displays with modeset and CRC, suspends/resumes,
> + *                     then verifies displays still produce valid CRC after resume.
> + *
> + * SUBTEST: dock-during-suspend
> + * Description:        Test docking while system is suspended.
> + *                     Simulates user plugging into a suspended laptop by triggering
> + *                     dock during suspend using hardware delay command. Verifies
> + *                     modeset and pipe CRC after resume.
> + *
> + * SUBTEST: undock-during-suspend
> + * Description:        Test undocking while system is suspended.
> + *                     Docks first, verifies displays, then schedules a delayed
> + *                     undock during suspend. After resume, verifies all port
> + *                     displays have been removed.
> + *
> + * SUBTEST: switch
> + * Description:        Test switching between USB4 switch ports.
> + *                     Verifies hotplug events, display verification with modeset
> + *                     and pipe CRC when switching from one port to another.
> + *
> + * SUBTEST: switch-sr
> + * Description:        Test port switching with suspend/resume stability.
> + *                     Switches ports, verifies displays with modeset and CRC,
> + *                     suspends/resumes, then verifies CRC stability after resume.
> + *
> + * SUBTEST: switch-during-suspend
> + * Description:        Test port switching during suspend using hardware delay.
> + *                     Schedules a delayed switch, suspends system, switch occurs during
> + *                     suspend, then verifies modeset and pipe CRC on new port after resume.
> + */
> +
> +#include <ctype.h>
> +#include <sys/poll.h>
> +
> +#include "igt.h"
> +#include "igt_edid.h"
> +#include "igt_kms.h"
> +#include "igt_pipe_crc.h"
> +#include "igt_usb4_switch.h"
> +#include "igt_connector_helper.h"
> +#include "kms_joiner_helper.h"
> +
> +/*
> + * Extended timeout for switch operations.
> + * Port switching requires longer stabilization time than simple dock/undock
> + * due to hardware state transitions and MST topology rebuilds.
> + */
> +#define USB4_SWITCH_TIMEOUT_S 20
> +
> +/* Number of CRC samples for stability check (solid color FB should be stable) */
> +#define CRC_STABILITY_SAMPLES 3
> +
> +/* Maximum displays expected on a single USB4 switch port (MST hub) */
> +#define MAX_DISPLAYS_PER_PORT 4
> +
> +/* Number of reprobe cycles for MST topology stabilization after resume */
> +#define MST_STABILIZE_REPROBE_COUNT 10
> +
> +/* Inter-reprobe delay in microseconds (500 ms) */
> +#define MST_STABILIZE_DELAY_US 500000
> +
> +/*
> + * Iteration helpers for dynamic subtest generation.
> + * Skip ports (or pairs) that have no displays configured.
> + *
> + * for_each_usb4_port_pair iterates adjacent cyclic pairs (0->1, 1->2, ...,
> + * N-1->0).  For the 2-port Switch 3141 this covers the only possible pair.
> + * If the hardware grows beyond 2 ports, consider generating all distinct
> + * pairs instead.
> + */
> +#define for_each_usb4_port(sw, count, p, pcfg)				\
> +	for ((p) = 0,							\
> +	     (pcfg) = usb4switch_get_port_config((sw), 0);		\
> +	     (p) < (count) && (pcfg) && (pcfg)->display_count > 0;	\
> +	     (pcfg) = usb4switch_get_port_config((sw), ++(p)))
> +
> +#define for_each_usb4_port_pair(sw, count, p, pa, pb)			\
> +	for ((p) = 0,							\
> +	     (pa) = usb4switch_get_port_config((sw), 0),		\
> +	     (pb) = usb4switch_get_port_config((sw), 1 % (count));	\
> +	     (p) < (count) && (pa) && (pb) &&				\
> +	     (pa)->display_count > 0 && (pb)->display_count > 0;	\
> +	     ++(p),							\
> +	     (pa) = usb4switch_get_port_config((sw), (p)),		\
> +	     (pb) = usb4switch_get_port_config((sw), ((p) + 1) % (count)))

These are difficult to understand, and more so because the param names
are too short and don't help at all.

> +
> +typedef struct {
> +	int drm_fd;
> +	igt_display_t display;
> +	struct usb4switch *sw;
> +	struct udev_monitor *hotplug_mon;
> +	int max_dotclock;
> +	uint32_t master_pipes;
> +	uint32_t valid_pipes;
> +} data_t;
> +
> +/*
> + * Per-display modeset state, used by the composable display building blocks.
> + * Holds everything needed to arm, commit, collect CRC, and disarm one display.
> + */
> +struct display_ctx {
> +	uint32_t conn_id;
> +	igt_output_t *output;
> +	igt_plane_t *primary;
> +	struct igt_fb fb;
> +	drmModeModeInfo mode;
> +	bool valid;
> +};
> +
> +/*
> + * find_output_by_id - Find an igt_output_t by DRM connector ID.
> + */
> +static igt_output_t *find_output_by_id(igt_display_t *display,
> +				       uint32_t connector_id)
> +{
> +	int i;
> +
> +	for (i = 0; i < display->n_outputs; i++) {

for_each_output()

> +		if (display->outputs[i].id == connector_id)
> +			return &display->outputs[i];
> +	}
> +
> +	return NULL;
> +}
> +
> +/*
> + * select_max_non_joiner_mode - Pick the largest mode that fits a single pipe.
> + *
> + * "Non-joiner" means hdisplay <= max_pipe_hdisplay AND clock <= max_dotclock.
> + * Among qualifying modes, pick by:
> + *   1. Highest pixel area (hdisplay * vdisplay)
> + *   2. Highest vrefresh (tie-break)
> + *   3. Highest clock (tie-break)
> + *
> + * If max_dotclock is 0 (debugfs unavailable), only hdisplay is checked.
> + *
> + * TODO: Remove this filter when joiner CRC collection is supported;
> + *       the pipe allocator already handles joiner pipe counts.
> + *
> + * Returns: Pointer to a function-static copy of the best mode, or NULL
> + *          if none found. Not reentrant — single-threaded callers only.
> + */
> +static drmModeModeInfo *select_max_non_joiner_mode(int drm_fd,
> +						   igt_output_t *output,
> +						   int max_dotclock)
> +{
> +	static drmModeModeInfo best;
> +	drmModeConnector *conn = output->config.connector;
> +	uint64_t best_area = 0;
> +	uint32_t best_vrefresh = 0;
> +	int best_clock = 0;
> +	bool found = false;
> +	int i;
> +
> +	if (!conn || conn->count_modes == 0)
> +		return NULL;
> +
> +	for (i = 0; i < conn->count_modes; i++) {

for_each_connector_mode()


-- 
Jani Nikula, Intel

  reply	other threads:[~2026-04-14  9:27 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-09  4:37 [PATCH i-g-t 0/6] add test to validate dock/undock and switch Kunal Joshi
2026-04-09  4:37 ` [PATCH i-g-t 1/6] lib/igt_edid: add EDID serial extraction helpers Kunal Joshi
2026-04-14  9:11   ` Jani Nikula
2026-04-14  9:55     ` Simon Ser
2026-04-09  4:37 ` [PATCH i-g-t 2/6] lib/igt_connector_helper: Add generic connector helpers Kunal Joshi
2026-04-09  4:37 ` [PATCH i-g-t 3/6] lib/igt_serial: add generic serial communication helper Kunal Joshi
2026-04-14  9:20   ` Jani Nikula
2026-04-09  4:37 ` [PATCH i-g-t 4/6] lib/igt_usb4_switch: add helper library for USB4 Switch 3141 Kunal Joshi
2026-04-09  4:37 ` [PATCH i-g-t 5/6] tests/kms_feature_discovery: add basic usb4 switch discovery Kunal Joshi
2026-04-14  9:23   ` Jani Nikula
2026-04-09  4:37 ` [PATCH i-g-t 6/6] tests/intel/kms_usb4_switch: Add USB4 switch test suite Kunal Joshi
2026-04-14  9:27   ` Jani Nikula [this message]
2026-04-10  0:18 ` ✓ i915.CI.BAT: success for add test to validate dock/undock and switch (rev4) Patchwork
2026-04-10  0:19 ` ✓ Xe.CI.BAT: " Patchwork
2026-04-10  2:45 ` ✗ Xe.CI.FULL: failure " Patchwork
2026-04-10 17:16 ` ✗ i915.CI.Full: " Patchwork
  -- strict thread matches above, loose matches on Subject: below --
2026-02-25 21:28 [PATCH i-g-t 0/6] add test to validate dock/undock and switch Kunal Joshi
2026-02-25 21:28 ` [PATCH i-g-t 6/6] tests/intel/kms_usb4_switch: Add USB4 switch test suite Kunal Joshi
2026-02-25 19:42 [PATCH i-g-t 0/6] add test to validate dock/undock and switch Kunal Joshi
2026-02-25 19:42 ` [PATCH i-g-t 6/6] tests/intel/kms_usb4_switch: Add USB4 switch test suite Kunal Joshi

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=790e95881771844181284430d837e31c1cb9681b@intel.com \
    --to=jani.nikula@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=kunal1.joshi@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