public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: Andrea Cervesato <andrea.cervesato@suse.de>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v2 3/3] Add process_mrelease02 test
Date: Mon, 7 Oct 2024 17:03:51 +0200	[thread overview]
Message-ID: <ZwP4VxOgCOI-BWMw@yuki.lan> (raw)
In-Reply-To: <20240812-process_mrelease-v2-3-e61249986a0a@suse.com>

Hi!
> +/*\
> + * [Description]
> + *
> + * This test verifies that process_mrelease() syscall is raising errors:
> + * * EBADF when a bad file descriptor is given
> + * * EINVAL when flags is not zero
> + * * EINVAL when memory of a task cannot be released because it's still running
> + * * ESRCH when child has been closed
> + */
> +
> +#include "tst_test.h"
> +#include "lapi/syscalls.h"
> +
> +static int badfd = -1;
> +static int pidfd;
> +
> +enum {
> +	NO_CHILD,
> +	EXIT_CHILD,
> +	WAIT_CHILD,
> +};
> +
> +static struct tcase {
> +	int child_type;
> +	int *fd;
> +	int flags;
> +	int exp_errno;
> +	char *msg;
> +} tcases[] = {
> +	{NO_CHILD, &badfd, 0, EBADF, "bad file descriptor"},
> +	{WAIT_CHILD, &pidfd, -1, EINVAL, "flags is not 0"},
> +	{WAIT_CHILD, &pidfd, 0, EINVAL, "task memory cannot be released"},
> +	{EXIT_CHILD, &pidfd, 0, ESRCH, "child is not running"},
> +};
> +
> +static void run(unsigned int n)
> +{
> +	struct tcase *tc = &tcases[n];
> +	int status;
> +
> +	if (tc->child_type != NO_CHILD) {
> +		pid_t pid;
> +
> +		pid = SAFE_FORK();
> +		if (!pid) {
> +			if (tc->child_type == WAIT_CHILD)
> +				TST_CHECKPOINT_WAIT(0);
> +
> +			exit(0);
> +		}
> +
> +		tst_res(TINFO, "Spawned waiting child with pid=%d", pid);
> +
> +		pidfd = SAFE_PIDFD_OPEN(pid, 0);
> +
> +		if (tc->child_type == EXIT_CHILD)
> +			SAFE_WAITPID(pid, &status, 0);
> +	}

Why don't we instead fork two children in the setup, one of the waits
and second exits and just set the pidfd once?

> +	TST_EXP_FAIL(tst_syscall(__NR_process_mrelease, *tc->fd, tc->flags),
> +		tc->exp_errno,
> +		"%s", tc->msg);
> +
> +	if (tc->child_type != NO_CHILD) {
> +		if (tc->child_type == WAIT_CHILD)
> +			TST_CHECKPOINT_WAKE(0);
> +
> +		SAFE_CLOSE(pidfd);
> +	}
> +}
> +
> +static struct tst_test test = {
> +	.test = run,
> +	.tcnt = ARRAY_SIZE(tcases),
> +	.needs_root = 1,
> +	.forks_child = 1,
> +	.min_kver = "5.15",
> +	.needs_checkpoints = 1,
> +};
> 
> -- 
> 2.43.0
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz

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

  reply	other threads:[~2024-10-07 15:05 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-12 11:46 [LTP] [PATCH v2 0/3] Add process_mrelease testing suite Andrea Cervesato
2024-08-12 11:46 ` [LTP] [PATCH v2 1/3] Add process_mrelease syscalls definition Andrea Cervesato
2024-08-12 11:46 ` [LTP] [PATCH v2 2/3] Add process_mrelease01 test Andrea Cervesato
2024-09-12 16:28   ` Cyril Hrubis
2024-10-10 12:33     ` Andrea Cervesato via ltp
2024-11-12 13:18       ` Andrea Cervesato via ltp
2025-09-10 10:49       ` Wei Gao via ltp
2024-08-12 11:46 ` [LTP] [PATCH v2 3/3] Add process_mrelease02 test Andrea Cervesato
2024-10-07 15:03   ` Cyril Hrubis [this message]
2024-10-10 12:24     ` Andrea Cervesato via ltp
2024-10-10 13:07       ` Cyril Hrubis
2025-09-10  9:28   ` Wei Gao via ltp

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=ZwP4VxOgCOI-BWMw@yuki.lan \
    --to=chrubis@suse.cz \
    --cc=andrea.cervesato@suse.de \
    --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