From: Cyril Hrubis <chrubis@suse.cz>
To: Andrea Cervesato <andrea.cervesato@suse.de>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v1] Refactoring setpgid03.c test using new LTP API
Date: Wed, 16 Feb 2022 14:11:50 +0100 [thread overview]
Message-ID: <Ygz4FlU4MGGLqixH@rei> (raw)
In-Reply-To: <20220128084409.21708-1-andrea.cervesato@suse.de>
Hi!
> + child_pid = SAFE_FORK();
> + if (!child_pid) {
> + do_child();
> + return;
> }
>
> - cleanup();
> - tst_exit();
> -}
> + TST_CHECKPOINT_WAIT(0);
>
> -static void do_child(void)
> -{
> - if (setsid() < 0) {
> - printf("CHILD: setsid() failed, errno: %d\n", errno);
> - exit(2);
> - }
> + TEST(setpgid(child_pid, getppid()));
> + if (TST_RET == -1 && TST_ERR == EPERM)
> + tst_res(TPASS, "setpgid failed with EPERM");
> + else
> + tst_res(TFAIL, "retval %ld, errno %s, expected EPERM", TST_RET,
> + tst_strerrno(TST_ERR));
Make use of the TST_EXP_FAIL() please.
> - TST_SAFE_CHECKPOINT_WAKE(NULL, 0);
> + TST_CHECKPOINT_WAKE(0);
>
> - TST_SAFE_CHECKPOINT_WAIT(NULL, 0);
> + if (wait(&status) < 0)
> + tst_res(TFAIL, "wait() for child 1 failed");
>
> - exit(0);
> -}
> + if (!(WIFEXITED(status)) || (WEXITSTATUS(status) != 0))
> + tst_res(TFAIL, "child 1 failed with status %d",
> + WEXITSTATUS(status));
No need to wait for the child here, just let the test library collect
it.
> -static void setup(void)
> -{
> - tst_sig(FORK, DEF_HANDLER, cleanup);
> + /* child after exec() we are no longer allowed to set pgid */
> + child_pid = SAFE_FORK();
> + if (!child_pid)
> + SAFE_EXECLP(TEST_APP, TEST_APP, NULL);
>
> - tst_tmpdir();
> + TST_CHECKPOINT_WAIT(0);
>
> - TST_CHECKPOINT_INIT(tst_rmdir);
> + TEST(setpgid(child_pid, getppid()));
> + if (TST_RET == -1 && TST_ERR == EACCES)
> + tst_res(TPASS, "setpgid failed with EACCES");
> + else
> + tst_res(TFAIL, "retval %ld, errno %s, expected EACCES", TST_RET,
> + tst_strerrno(TST_ERR));
Here as well.
> - umask(0);
> + TST_CHECKPOINT_WAKE(0);
>
> - TEST_PAUSE;
> -}
> + if (wait(&status) < 0)
> + tst_res(TFAIL, "wait() for child 2 failed");
>
> -static void cleanup(void)
> -{
> - tst_rmdir();
> + if (!(WIFEXITED(status)) || (WEXITSTATUS(status) != 0))
> + tst_res(TFAIL, "child 2 failed with status %d",
> + WEXITSTATUS(status));
> }
And here as well.
> +static struct tst_test test = {
> + .test_all = run,
> + .forks_child = 1,
> + .needs_checkpoints = 1,
> +};
> diff --git a/testcases/kernel/syscalls/setpgid/setpgid03_child.c b/testcases/kernel/syscalls/setpgid/setpgid03_child.c
> index 2657422a6..fdb22f24d 100644
> --- a/testcases/kernel/syscalls/setpgid/setpgid03_child.c
> +++ b/testcases/kernel/syscalls/setpgid/setpgid03_child.c
> @@ -1,32 +1,16 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> /*
> * Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved.
> - *
> - * This program is free software; you can redistribute it and/or
> - * modify it under the terms of the GNU General Public License as
> - * published by the Free Software Foundation; either version 2 of
> - * the License, or (at your option) any later version.
> - *
> - * This program is distributed in the hope that it would be useful,
> - * but WITHOUT ANY WARRANTY; without even the implied warranty of
> - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> - * GNU General Public License for more details.
> - *
> - * You should have received a copy of the GNU General Public License
> - * along with this program; if not, write the Free Software Foundation,
> - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
> + * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
> */
>
> -#include "test.h"
> -
> -char *TCID = "setpgid03_child";
> -
> +#define TST_NO_DEFAULT_MAIN
> +#include "tst_test.h"
>
> int main(void)
> {
> - TST_CHECKPOINT_INIT(NULL);
> -
> - TST_SAFE_CHECKPOINT_WAKE(NULL, 0);
> - TST_SAFE_CHECKPOINT_WAIT(NULL, 0);
> + tst_reinit();
> + TST_CHECKPOINT_WAKE_AND_WAIT(0);
>
> return 0;
> }
> --
> 2.34.1
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
prev parent reply other threads:[~2022-02-16 13:12 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-28 8:44 [LTP] [PATCH v1] Refactoring setpgid03.c test using new LTP API Andrea Cervesato
2022-02-16 13:11 ` Cyril Hrubis [this message]
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=Ygz4FlU4MGGLqixH@rei \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.