public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Petr Vorel <pvorel@suse.cz>
To: Andrea Cervesato <andrea.cervesato@suse.de>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v2 09/11] Refactor pty01 test
Date: Wed, 8 Jan 2025 13:39:46 +0100	[thread overview]
Message-ID: <20250108123946.GA27248@pevik> (raw)
In-Reply-To: <20250106-fix_setsid_tests-v2-9-c43f57a2bab6@suse.com>

Hi Andrea,

> Rewrite part of the code using the new LTP library and fix the execution
> of the test inside a new session via setsid(). The test is now split
> into multiple files, instead of having multiple test* functions
> executing all in one file.

> Fixes: https://github.com/linux-test-project/kirk/issues/28
+1

> +++ b/testcases/kernel/pty/pty01.c
...
> +#define STRING_LEN strlen(STRING)
IMHO this is not much useful, it runs strlen() more times.
How about save the result in the test function to size_t variable?

...
> +static void run(void)
>  {
> -	int masterfd;		/* master pty fd */
> -	int slavefd;		/* slave pty fd */
> +	int masterfd;
> +	int slavefd;
>  	char *slavename;
>  	struct stat st;
> -	char buf[TESTSIZE];
> +	char buf[BUFSIZ];

> -	masterfd = SAFE_OPEN(NULL, MASTERCLONE, O_RDWR);
> +	memset(buf, 0, BUFSIZ);

> -	slavename = ptsname(masterfd);
> -	if (slavename == NULL) {
> -		tst_brkm(TBROK | TERRNO, NULL, "ptsname() call failed");
> -	}
> +	masterfd = SAFE_OPEN(MASTERCLONE, O_RDWR);
> +	slavename = SAFE_PTSNAME(masterfd);

These two should be in the setup() as Cyril noted to other tests.

> -	if (grantpt(masterfd) != 0) {
> -		tst_brkm(TBROK | TERRNO, NULL, "grantpt() call failed");
> -	}
> +	if (grantpt(masterfd) == -1)
> +		tst_brk(TBROK | TERRNO, "grantpt() error");

> -	if (stat(slavename, &st) != 0) {
> -		tst_brkm(TBROK | TERRNO, NULL, "stat(%s) failed", slavename);
> -	}
> -	if (st.st_uid != getuid()) {
> -		tst_brkm(TBROK, NULL, "uid mismatch");
> +	TST_EXP_PASS_SILENT(unlockpt(masterfd));
> +	if (TST_RET == -1) {
> +		SAFE_CLOSE(masterfd);
> +		return;
If you have this in the cleanup() as Cyril suggested for other test, there would
be a simple return.

> +	SAFE_STAT(slavename, &st);
> +	TST_EXP_EQ_LI(st.st_uid, getuid());
> +
> +	/* grantpt() is a no-op in bionic. */
>  #ifndef __BIONIC__
> -	if (st.st_mode != (S_IFCHR | S_IRUSR | S_IWUSR | S_IWGRP)) {
> -		tst_brkm(TBROK, NULL, "mode mismatch (mode=%o)", st.st_mode);
> -	}
> +	TST_EXP_EQ_LI(st.st_mode, 0620);

Here it continues testing, does it makes sense? Previously it quit with
tst_brkm().

> +static void setup(void)
>  {
> +	if (access(MASTERCLONE, F_OK))
> +		tst_brk(TBROK, "%s device doesn't exist", MASTERCLONE);

IMHO this should be TCONF (SUT is not configured to have /dev/ptmx.

Kind regards,
Petr

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

  reply	other threads:[~2025-01-08 12:40 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-06 10:31 [LTP] [PATCH v2 00/11] Fix tests failing with setsid Andrea Cervesato
2025-01-06 10:31 ` [LTP] [PATCH v2 01/11] Refactor setpgid01 test Andrea Cervesato
2025-01-07 15:26   ` Cyril Hrubis
2025-01-06 10:31 ` [LTP] [PATCH v2 02/11] Add SAFE_PTSNAME macro Andrea Cervesato
2025-01-07 15:32   ` Cyril Hrubis
2025-01-08 12:01   ` Petr Vorel
2025-01-06 10:31 ` [LTP] [PATCH v2 03/11] Refactor ptem01 test Andrea Cervesato
2025-01-07 16:01   ` Cyril Hrubis
2025-01-08 12:47     ` Petr Vorel
2025-01-06 10:31 ` [LTP] [PATCH v2 04/11] Add ptem02 test Andrea Cervesato
2025-01-07 16:14   ` Cyril Hrubis
2025-01-06 10:31 ` [LTP] [PATCH v2 05/11] Add ptem03 test Andrea Cervesato
2025-01-07 16:30   ` Cyril Hrubis
2025-01-06 10:31 ` [LTP] [PATCH v2 06/11] Add ptem04 test Andrea Cervesato
2025-01-06 10:31 ` [LTP] [PATCH v2 07/11] Add ptem05 test Andrea Cervesato
2025-01-06 10:31 ` [LTP] [PATCH v2 08/11] Add ptem06 test Andrea Cervesato
2025-01-06 10:31 ` [LTP] [PATCH v2 09/11] Refactor pty01 test Andrea Cervesato
2025-01-08 12:39   ` Petr Vorel [this message]
2025-01-09  8:28     ` Andrea Cervesato via ltp
2025-01-06 10:31 ` [LTP] [PATCH v2 10/11] Add pty08 test Andrea Cervesato
2025-01-06 10:31 ` [LTP] [PATCH v2 11/11] Add pty09 test Andrea Cervesato

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=20250108123946.GA27248@pevik \
    --to=pvorel@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