public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Avinesh Kumar <akumar@suse.de>
To: Yang Xu <xuyang2018.jy@fujitsu.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH] flock: Add negative tests for flock
Date: Thu, 30 May 2024 16:13:08 +0200	[thread overview]
Message-ID: <1934768.7Z3S40VBb9@localhost> (raw)
In-Reply-To: <20240416080237.22627-1-xuyang2018.jy@fujitsu.com>

Hi Yang Xu,


When I am testing this by running multiple times, EINTR test is getting
timed out randomly.

tst_test.c:1625: TINFO: Timeout per run is 0h 00m 30s
flock07.c:46: TINFO: Got SIGUSR1
Test timeouted, sending SIGKILL!
tst_test.c:1673: TINFO: Killed the leftover descendant processes
tst_test.c:1679: TINFO: If you are running on slow machine, try exporting LTP_TIMEOUT_MUL > 1
tst_test.c:1681: TBROK: Test killed! (timeout?)

In these cases I see that there are two locks (held or waiting) by the process
even after SIGUSER1 signal is delivered, so somehow signal is being ignored.

flock07         16520  FLOCK        WRITE* 0          0          0 /tmp...
flock07         16519  FLOCK        WRITE  0          0          0 /tmp...


And I feel we should add EWOULDBLOCK errno test to flock02.c file,
and keep only EINTR testcase here. 


On Tuesday, April 16, 2024 10:02:37 AM GMT+2 Yang Xu via ltp wrote:
> Add negative cases for flock(), when errno is EINTR or EWOULDBLOCK
> 
> Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
> ---
>  runtest/syscalls                           |  1 +
>  testcases/kernel/syscalls/flock/.gitignore |  1 +
>  testcases/kernel/syscalls/flock/flock07.c  | 98 ++++++++++++++++++++++
>  3 files changed, 100 insertions(+)
>  create mode 100644 testcases/kernel/syscalls/flock/flock07.c
> 
> diff --git a/runtest/syscalls b/runtest/syscalls
> index 9578e991a..de4f5a633 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -375,6 +375,7 @@ flock02 flock02
>  flock03 flock03
>  flock04 flock04
>  flock06 flock06
> +flock07 flock07
>  
>  fmtmsg01 fmtmsg01
>  
> diff --git a/testcases/kernel/syscalls/flock/.gitignore b/testcases/kernel/syscalls/flock/.gitignore
> index c8cb0fc54..9bac582e1 100644
> --- a/testcases/kernel/syscalls/flock/.gitignore
> +++ b/testcases/kernel/syscalls/flock/.gitignore
> @@ -3,3 +3,4 @@
>  /flock03
>  /flock04
>  /flock06
> +/flock07
> diff --git a/testcases/kernel/syscalls/flock/flock07.c b/testcases/kernel/syscalls/flock/flock07.c
> new file mode 100644
> index 000000000..6fd650186
> --- /dev/null
> +++ b/testcases/kernel/syscalls/flock/flock07.c
> @@ -0,0 +1,98 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2024 FUJITSU LIMITED. All Rights Reserved.
> + * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
> + */
> +
> +/*\
> + * [Description]
> + *
> + * Verify that flock(2) fails with
> + *
> + * - EINTR when waiting lock, call is interrupted by signal
> + * - EWOULDBLOCK when file is locked and LOCK_NB flag is selected
> + */
> +
> +#include <signal.h>
> +#include <sys/file.h>
> +#include <sys/wait.h>
> +#include "tst_test.h"
> +
> +#define TEST_INTR "test_intr"
> +#define TEST_EWOULDBLOCK "test_ewouldblock"
> +
> +static struct test_case_t {
> +	char *filename;
> +	int expected_errno;
> +	int child;
> +	char *desc;
> +} tcases[] = {
> +	{TEST_INTR, EINTR, 1,
> +		"while waiting lock, call is interrupted by signal"},
> +	{TEST_EWOULDBLOCK, EWOULDBLOCK, 0,
> +		"file is locked and LOCK_NB flag is selected"},
> +};
> +
> +static void setup(void)
> +{
> +	SAFE_TOUCH(TEST_INTR, 0777, NULL);
> +	SAFE_TOUCH(TEST_EWOULDBLOCK, 0777, NULL);
> +}
> +
> +static void handler(int sig)
> +{
> +	switch (sig) {
> +	case SIGUSR1:
> +		tst_res(TINFO, "%s", "Got SIGUSR1");
> +	break;
> +	default:
> +		tst_res(TINFO, "%s", "Got other signal");
> +	break;
> +	}
> +}
> +
> +static void child_do(int fd, struct test_case_t *tc)
> +{
> +	struct sigaction sa;
> +
> +	sa.sa_handler = handler;
> +	SAFE_SIGEMPTYSET(&sa.sa_mask);
> +	SAFE_SIGACTION(SIGUSR1, &sa, NULL);
> +
> +	TST_EXP_FAIL(flock(fd, LOCK_EX), tc->expected_errno, "%s", tc->desc);
> +}
> +
> +static void verify_flock(unsigned int i)
> +{
> +	struct test_case_t *tc = &tcases[i];
> +	pid_t pid;
> +	int fd1 = SAFE_OPEN(tc->filename, O_RDWR);
> +	int fd2 = SAFE_OPEN(tc->filename, O_RDWR);
> +
> +	if (tc->child) {
> +		flock(fd1, LOCK_EX);
> +		pid = SAFE_FORK();
> +		if (!pid) {
> +			child_do(fd2, tc);
> +			exit(0);
> +		}
> +		sleep(1);
> +		SAFE_KILL(pid, SIGUSR1);
> +		SAFE_WAITPID(pid, NULL, 0);
> +	} else {
> +		flock(fd1, LOCK_EX);
> +		TST_EXP_FAIL(flock(fd2, LOCK_EX | LOCK_NB), tc->expected_errno,
> +			"%s", tc->desc);
> +	}
> +	SAFE_CLOSE(fd1);
> +	SAFE_CLOSE(fd2);
> +}
> +
> +static struct tst_test test = {
> +	.setup = setup,
> +	.tcnt = ARRAY_SIZE(tcases),
> +	.test = verify_flock,
> +	.needs_tmpdir = 1,
> +	.needs_root = 1,
> +	.forks_child = 1,
> +};
> 

Regards,
Avinesh




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

  reply	other threads:[~2024-05-30 14:13 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-16  8:02 [LTP] [PATCH] flock: Add negative tests for flock Yang Xu via ltp
2024-05-30 14:13 ` Avinesh Kumar [this message]
2024-10-21 14:28   ` Petr Vorel
2024-05-30 14:40 ` [LTP] [PATCH v2] flock: Add test for verifying EINTR errno Avinesh Kumar
2024-05-30 14:48   ` [LTP] [PATCH v3] " Avinesh Kumar
2024-10-21 19:55     ` Petr Vorel
2025-01-14 15:54       ` Avinesh Kumar
2025-01-31 11:01         ` Petr Vorel
2025-02-03  9:41           ` Avinesh Kumar
2025-02-03 10:12             ` Petr Vorel
2025-02-03 14:22     ` Petr Vorel
2025-02-03 14:55       ` Avinesh Kumar
2025-02-03 15:33         ` Petr Vorel

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=1934768.7Z3S40VBb9@localhost \
    --to=akumar@suse.de \
    --cc=ltp@lists.linux.it \
    --cc=xuyang2018.jy@fujitsu.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