[LTP] [PATCH v3] uevent02: Make wait_for_uevents() order-independent

Cyril Hrubis chrubis@suse.cz
Tue Sep 15 12:53:51 CEST 2026


Hi!
>  static inline void wait_for_uevents(int fd, const struct uevent_desc *const uevents[])
>  {
> -	int i = 0;
> +	int i, cnt = 0, remaining;
> +
> +	while (uevents[cnt])
> +		cnt++;
> +
> +	uint8_t matched[cnt];
> +
> +	memset(matched, 0, sizeof(matched));
>  
> -	while (1) {
> +	remaining = cnt;
> +
> +	while (remaining) {
>  		int len;
>  		char buf[4096];
>  
> @@ -136,11 +155,15 @@ static inline void wait_for_uevents(int fd, const struct uevent_desc *const ueve
>  
>  		print_uevent(buf, len);
>  
> -		if (uevent_match(buf, len, uevents[i])) {
> -			tst_res(TPASS, "Got expected UEVENT");
> -			if (!uevents[++i]) {
> -				close(fd);
> -				return;
> +		for (i = 0; i < cnt; i++) {
> +			if (matched[i])
> +				continue;
> +
> +			if (uevent_match(buf, len, uevents[i])) {
> +				tst_res(TPASS, "Got expected UEVENT");
> +				matched[i] = 1;
> +				remaining--;
> +				break;
>  			}
>  		}
>  	}

Unfortunately this is not yet ready either. The problem is that this
relaxes the conditions for uevent01.c and uevent03.c too, since these
two tests does not inforce any order after this change.

Well techically for uevent01.c the order does not matter, since the two
events for attach/detach are the same, as the event only reports
"change".

But uevent03.c is exactly the same patter, sequence of add and remove
events. Hence we have to enforce at least partial order. I would however
enforce the full order unless we are told otherwise. So maybe we need
two different wait_for_uevents() helpers one that would keep the order
and one that would match events in any order. And we should use the
order enforcing one in the uevent01 and uevent03.

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list