public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Martin Doucha <mdoucha@suse.cz>
To: Cyril Hrubis <chrubis@suse.cz>, ltp@lists.linux.it
Subject: Re: [LTP] [PATCH 2/2] syscalls/msgstress01: Fix timeouts
Date: Thu, 23 May 2024 16:37:46 +0200	[thread overview]
Message-ID: <bdcd318e-d71d-420b-bf96-e2571831078e@suse.cz> (raw)
In-Reply-To: <20240523133132.13978-3-chrubis@suse.cz>

Hi,
for both patches:
Reviewed-by: Martin Doucha <mdoucha@suse.cz>

On 23. 05. 24 15:31, Cyril Hrubis wrote:
> Make the test exit if runtime has been exhausted before we finished the
> requested amount of iterations.
> 
> For that to happen we let the main test process to loop while checking
> the runtime and set the stop flag if runtime was exhausted. We also need
> to separte the stop and fail flag and add counter for finished children.
> 
> Also if we exhaust our runtime during the initial fork phase we print a
> warning, since we hardly did a meaningful testing in that case.
> 
> The changes can be tested with -I parameter, e.g. -I 5 should trigger
> the TWARN message and you should be able to get the test to stop in the
> message sending phase with larger -I value.
> 
> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
> ---
>   .../syscalls/ipc/msgstress/msgstress01.c      | 53 ++++++++++++++++---
>   1 file changed, 47 insertions(+), 6 deletions(-)
> 
> diff --git a/testcases/kernel/syscalls/ipc/msgstress/msgstress01.c b/testcases/kernel/syscalls/ipc/msgstress/msgstress01.c
> index 62ffcf63b..fb1d4263d 100644
> --- a/testcases/kernel/syscalls/ipc/msgstress/msgstress01.c
> +++ b/testcases/kernel/syscalls/ipc/msgstress/msgstress01.c
> @@ -50,6 +50,9 @@ static char *str_num_iterations;
>   static int num_messages = 1000;
>   static int num_iterations = MAXNREPS;
>   static volatile int *stop;
> +static volatile int *fail;
> +static int *finished;
> +static int *flags;
>   
>   static int get_used_sysvipc(void)
>   {
> @@ -77,6 +80,10 @@ static void reset_messages(void)
>   
>   	for (int i = 0; i < num_messages; i++)
>   		ipc_data[i].id = -1;
> +
> +	*stop = 0;
> +	*fail = 0;
> +	*finished = 0;
>   }
>   
>   static int create_message(const int id)
> @@ -112,6 +119,8 @@ static void writer(const int id, const int pos)
>   			tst_brk(TBROK | TERRNO, "msgsnd() failed");
>   		}
>   	}
> +
> +	tst_atomic_inc(finished);
>   }
>   
>   static void reader(const int id, const int pos)
> @@ -138,6 +147,7 @@ static void reader(const int id, const int pos)
>   			tst_res(TFAIL, "Received the wrong message type");
>   
>   			*stop = 1;
> +			*fail = 1;
>   			return;
>   		}
>   
> @@ -145,6 +155,7 @@ static void reader(const int id, const int pos)
>   			tst_res(TFAIL, "Received the wrong message data length");
>   
>   			*stop = 1;
> +			*fail = 1;
>   			return;
>   		}
>   
> @@ -155,6 +166,7 @@ static void reader(const int id, const int pos)
>   					buff->msg.data.pbytes[i]);
>   
>   				*stop = 1;
> +				*fail = 1;
>   				return;
>   			}
>   		}
> @@ -163,6 +175,8 @@ static void reader(const int id, const int pos)
>   		tst_res(TDEBUG, "msg_recv.type = %ld", msg_recv.type);
>   		tst_res(TDEBUG, "msg_recv.data.len = %d", msg_recv.data.len);
>   	}
> +
> +	tst_atomic_inc(finished);
>   }
>   
>   static void remove_queues(void)
> @@ -196,12 +210,37 @@ static void run(void)
>   
>   		if (*stop)
>   			break;
> +
> +		if (!tst_remaining_runtime()) {
> +			tst_res(TWARN, "Out of runtime during forking...");
> +			*stop = 1;
> +			break;
> +		}
> +	}
> +
> +	if (!(*stop))
> +		tst_res(TINFO, "All processes running.");
> +
> +	for (;;) {
> +		if (tst_atomic_load(finished) == 2 * num_messages)
> +			break;
> +
> +		if (*stop)
> +			break;
> +
> +		if (!tst_remaining_runtime()) {
> +			tst_res(TINFO, "Out of runtime, stopping processes...");
> +			*stop = 1;
> +			break;
> +		}
> +
> +		sleep(1);
>   	}
>   
>   	tst_reap_children();
>   	remove_queues();
>   
> -	if (!(*stop))
> +	if (!(*fail))
>   		tst_res(TPASS, "Test passed. All messages have been received");
>   }
>   
> @@ -242,14 +281,16 @@ static void setup(void)
>   		MAP_SHARED | MAP_ANONYMOUS,
>   		-1, 0);
>   
> -	stop = SAFE_MMAP(
> +	flags = SAFE_MMAP(
>   		NULL,
> -		sizeof(int),
> +		sizeof(int) * 3,
>   		PROT_READ | PROT_WRITE,
>   		MAP_SHARED | MAP_ANONYMOUS,
>   		-1, 0);
>   
> -	reset_messages();
> +	stop = &flags[0];
> +	fail = &flags[1];
> +	finished = &flags[2];
>   }
>   
>   static void cleanup(void)
> @@ -260,7 +301,7 @@ static void cleanup(void)
>   	remove_queues();
>   
>   	SAFE_MUNMAP(ipc_data, sizeof(struct sysv_data) * num_messages);
> -	SAFE_MUNMAP((void *)stop, sizeof(int));
> +	SAFE_MUNMAP(flags, sizeof(int) * 3);
>   }
>   
>   static struct tst_test test = {
> @@ -271,7 +312,7 @@ static struct tst_test test = {
>   	.max_runtime = 180,
>   	.options = (struct tst_option[]) {
>   		{"n:", &str_num_messages, "Number of messages to send (default: 1000)"},
> -		{"l:", &str_num_iterations, "Number iterations per message (default: 10000)"},
> +		{"l:", &str_num_iterations, "Number iterations per message (default: " TST_TO_STR(MAXNREPS) ")"},
>   		{},
>   	},
>   };

-- 
Martin Doucha   mdoucha@suse.cz
SW Quality Engineer
SUSE LINUX, s.r.o.
CORSO IIa
Krizikova 148/34
186 00 Prague 8
Czech Republic


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  reply	other threads:[~2024-05-23 14:38 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-23 13:31 [LTP] [PATCH 0/2] Fix msgstress01 timeouts Cyril Hrubis
2024-05-23 13:31 ` [LTP] [PATCH 1/2] syscalls/msgstress01: Fix the stop logic Cyril Hrubis
2024-05-23 13:40   ` Andrea Cervesato via ltp
2024-05-23 13:31 ` [LTP] [PATCH 2/2] syscalls/msgstress01: Fix timeouts Cyril Hrubis
2024-05-23 14:37   ` Martin Doucha [this message]
2024-05-23 15:20   ` Petr Vorel
2024-05-23 15:33     ` Cyril Hrubis
2024-05-23 15:41   ` Petr Vorel
2024-05-23 15:43     ` Petr Vorel
2024-05-23 15:55       ` Petr Vorel
2024-05-23 15:55     ` Cyril Hrubis

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=bdcd318e-d71d-420b-bf96-e2571831078e@suse.cz \
    --to=mdoucha@suse.cz \
    --cc=chrubis@suse.cz \
    --cc=ltp@lists.linux.it \
    /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