public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Petr Vorel <pvorel@suse.cz>
To: Wei Gao <wegao@suse.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v3 2/2] getcwd01: Implement .test_variants
Date: Tue, 23 Jan 2024 10:45:54 +0100	[thread overview]
Message-ID: <20240123094554.GC149835@pevik> (raw)
In-Reply-To: <20240117125227.24700-3-wegao@suse.com>

Hi Wei,

> Signed-off-by: Wei Gao <wegao@suse.com>
> ---
>  testcases/kernel/syscalls/getcwd/getcwd01.c | 80 +++++++++++++++------
>  1 file changed, 60 insertions(+), 20 deletions(-)

> NOTE: Cyril give solution for run the test in a child and pass
> the test both on EFAULT and child being killed by SIGSEGV. But
> currently i have no idea how to do it since no SIGSEGV will hapeen
> if NULL buffer give to getcwd. This file just used for give a real
> user case for TST_EXP_FAIL_PTR.

@Cyril, could you please point out test which uses similar approach?
Maybe these?
testcases/kernel/syscalls/fstat/fstat03.c
testcases/kernel/syscalls/ipc/shmat/shmat01.c
testcases/kernel/syscalls/kill/kill11.c
testcases/kernel/syscalls/setrlimit/setrlimit05.c

Or can the current approach be used?

Below only nits (formatting).

> diff --git a/testcases/kernel/syscalls/getcwd/getcwd01.c b/testcases/kernel/syscalls/getcwd/getcwd01.c
> index 218bf4ef2..879c36206 100644
> --- a/testcases/kernel/syscalls/getcwd/getcwd01.c
> +++ b/testcases/kernel/syscalls/getcwd/getcwd01.c
> @@ -3,21 +3,34 @@
>   * Copyright (c) International Business Machines Corp., 2001

IBM in 2001 could be proud on this code :). There should have been some
copyright, I would add:
 * Copyright (c) Linux Test Project, 2002-2024

>   */

> -/*
> - * DESCRIPTION
> +/*\
> + * [Description]
> + *
>   * Testcase to test that getcwd(2) sets errno correctly.
> + *
> + * 1. getcwd(2) fails if buf points to a bad address.
> + * 2. getcwd(2) fails if the size is invalid.
> + * 3. getcwd(2) fails if the size is set to 0.
> + * 4. getcwd(2) fails if the size is set to 1.
> + * 5. getcwd(2) fails if buf points to NULL and the size is set to 1.
>   *
>   * Expected Result:
> + *
> + * linux syscall
> + *
> + * 1. getcwd(2) should return NULL and set errno to EFAULT.
I don't like repeating "getcwd(2) should return NULL and set errno to"

> + * 2. getcwd(2) should return NULL and set errno to EFAULT.
> + * 3. getcwd(2) should return NULL and set errno to ERANGE.
> + * 4. getcwd(2) should return NULL and set errno to ERANGE.
> + * 5. getcwd(2) should return NULL and set errno to ERANGE.
> + *
> + * glibc and uclibc{,-ng}.
Although in the past LTP developers cared only about glibc, now we generally
don't stick to any libc implementation. Thus it should be "libc syscall wrapper"

> + *
> + * 1. getcwd(2) should return NULL and set errno to EFAULT.
> + * 2. getcwd(2) should return NULL and set errno to ENOMEM.
> + * 3. getcwd(2) should return NULL and set errno to EINVAL.
> + * 4. getcwd(2) should return NULL and set errno to ERANGE.
> + * 5. getcwd(2) should return NULL and set errno to ERANGE.
>   */

How about to make it simple like this:
/*\
 * [Description]
 *
 * Testcase to test that getcwd(2) returns NULL and sets errno correctly.
 *
 * 1. getcwd(2) fails if buf points to a bad address (EFAULT).
 * 2. getcwd(2) fails if the size is invalid (syscall: EFAULT, libc wrapper: ENOMEM).
 * 3. getcwd(2) fails if the size is set to 0 (syscall: ERANGE, libc wrapper: EINVAL).
 * 4. getcwd(2) fails if the size is set to 1 (ERANGE).
 * 5. getcwd(2) fails if buf points to NULL and the size is set to 1 (ERANGE).
 */

>  #include <errno.h>
> @@ -32,23 +45,50 @@ static struct t_case {
>  	char *buf;
>  	size_t size;
>  	int exp_err;
> +	int exp_err_libc;
>  } tcases[] = {
> -	{(void *)-1, PATH_MAX, EFAULT},
> -	{NULL, (size_t)-1, EFAULT},
> -	{buffer, 0, ERANGE},
> -	{buffer, 1, ERANGE},
> -	{NULL, 1, ERANGE}
> +	{(void *)-1, PATH_MAX, EFAULT, EFAULT},
> +	{NULL, (size_t)-1, EFAULT, ENOMEM},
> +	{buffer, 0, ERANGE, EINVAL},
> +	{buffer, 1, ERANGE, ERANGE},
> +	{NULL, 1, ERANGE, ERANGE},
>  };

> +static inline void tst_getcwd(char *buf, size_t size, int exp_err, int exp_err_libc)
> +{
> +
> +	if (tst_variant == 0)
> +		TST_EXP_FAIL2(tst_syscall(__NR_getcwd, buf, size), exp_err);
> +	else
> +		TST_EXP_FAIL_PTR(getcwd(buf, size), exp_err_libc);
> +}
+1

> -static void verify_getcwd(unsigned int n)
> +static void run(unsigned int n)
>  {
>  	struct t_case *tc = &tcases[n];

> -	TST_EXP_FAIL2(tst_syscall(__NR_getcwd, tc->buf, tc->size), tc->exp_err);
> +	/* https://github.com/linux-test-project/ltp/issues/1084 */
IMHO this comment should go to the commit message.

> +#if !defined(__GLIBC__) && !defined(__ANDROID__)
I'll ask AOSP developers to check this.

> +	if (tst_variant && !tc->buf) {
> +		tst_res(TCONF, "NULL buffer test skipped on MUSL due different implementation");
> +		return;
> +	}
> +#endif
> +
> +	tst_getcwd(tc->buf, tc->size, tc->exp_err, tc->exp_err_libc);
> +}
> +
> +static void setup(void)
> +{
> +	if (tst_variant == 0)
> +		tst_res(TINFO, "Testing getcwd with raw syscall");
> +	else
> +		tst_res(TINFO, "Testing getcwd with wrap syscall");

"wrap syscall" => "libc syscall wrapper"

Kind regards,
Petr

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

  reply	other threads:[~2024-01-23  9:46 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-11  1:26 [LTP] [PATCH v1] Add TST_EXP_FAIL_PTR Wei Gao via ltp
2024-01-16 17:49 ` Petr Vorel
2024-01-17  8:07   ` Wei Gao via ltp
2024-01-17  8:04 ` [LTP] [PATCH v2] " Wei Gao via ltp
2024-01-17  9:49   ` Petr Vorel
2024-01-30 12:21     ` Petr Vorel
2024-01-17 12:52   ` [LTP] [PATCH v3 0/2] lib: TST_EXP_FAIL_PTR Wei Gao via ltp
2024-01-17 12:52     ` [LTP] [PATCH v3 1/2] " Wei Gao via ltp
2024-01-23  8:45       ` Petr Vorel
2024-01-23 10:41       ` Cyril Hrubis
2024-01-30 12:20         ` Petr Vorel
2024-01-17 12:52     ` [LTP] [PATCH v3 2/2] getcwd01: Implement .test_variants Wei Gao via ltp
2024-01-23  9:45       ` Petr Vorel [this message]
2024-02-08  1:32     ` [LTP] [PATCH v4 0/3] lib: TST_EXP_{FAIL,PASS}_PTR_{NULL,VOID} Wei Gao via ltp
2024-02-08  1:32       ` [LTP] [PATCH v4 1/3] " Wei Gao via ltp
2024-03-20 10:47         ` Petr Vorel
2024-03-26 10:54         ` Cyril Hrubis
2024-02-08  1:32       ` [LTP] [PATCH v4 2/3] shmat02.c: Use TST_EXP_FAIL_PTR_VOID Wei Gao via ltp
2024-03-20 10:47         ` Petr Vorel
2024-02-08  1:32       ` [LTP] [PATCH v4 3/3] realpath01.c: use TST_EXP_FAIL_PTR_NULL Wei Gao via ltp
2024-03-20 10:47         ` Petr Vorel
2024-03-27  3:49       ` [LTP] [PATCH v5 0/3] lib: TST_EXP_{FAIL,PASS}_PTR_{NULL,VOID} Wei Gao via ltp
2024-03-27  3:49         ` [LTP] [PATCH v5 1/3] " Wei Gao via ltp
2024-03-28 11:29           ` Petr Vorel
2024-03-28 11:49           ` Petr Vorel
2024-03-28 11:57             ` Petr Vorel
2024-03-28 12:11           ` Petr Vorel
2024-03-27  3:49         ` [LTP] [PATCH v5 2/3] shmat02.c: Use TST_EXP_FAIL_PTR_VOID Wei Gao via ltp
2024-03-27  3:49         ` [LTP] [PATCH v5 3/3] realpath01.c: use TST_EXP_FAIL_PTR_NULL Wei Gao via ltp
2024-04-03  3:28         ` [LTP] [PATCH v6 0/3] lib: TST_EXP_{FAIL,PASS}_PTR_{NULL,VOID} Wei Gao via ltp
2024-04-03  3:28           ` [LTP] [PATCH v6 1/3] " Wei Gao via ltp
2024-04-04 13:51             ` Cyril Hrubis
2024-04-04 16:01               ` Petr Vorel
2024-04-05  8:53                 ` Cyril Hrubis
2024-04-05 10:28                   ` Petr Vorel
2024-04-05 11:23                     ` Cyril Hrubis
2024-04-05 14:03                       ` Petr Vorel
2024-04-07 23:31                         ` Wei Gao via ltp
2024-04-03  3:28           ` [LTP] [PATCH v6 2/3] shmat02.c: Use TST_EXP_FAIL_PTR_VOID Wei Gao via ltp
2024-04-03  3:28           ` [LTP] [PATCH v6 3/3] realpath01.c: use TST_EXP_FAIL_PTR_NULL 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=20240123094554.GC149835@pevik \
    --to=pvorel@suse.cz \
    --cc=ltp@lists.linux.it \
    --cc=wegao@suse.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