From: Richard Palethorpe <rpalethorpe@suse.de>
To: Andrea Cervesato <andrea.cervesato@suse.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v1] Rewrite process_vm01 test using new LTP API
Date: Fri, 26 Aug 2022 08:04:21 +0100 [thread overview]
Message-ID: <87bks71nwg.fsf@suse.de> (raw)
In-Reply-To: <20220824124017.14286-1-andrea.cervesato@suse.com>
Hello,
Andrea Cervesato via ltp <ltp@lists.linux.it> writes:
> -static void cma_test_invalid_perm(void)
> +static void test_invalid_perm(void)
> {
> char nobody_uid[] = "nobody";
> struct passwd *ltpuser;
> - int status;
> struct process_vm_params *params;
> pid_t child_pid;
> pid_t parent_pid;
> - int ret = 0;
> + int status;
> +
> + tst_res(TINFO, "Testing invalid permissions on given PID");
>
> - tst_resm(TINFO, "test_invalid_perm");
> parent_pid = getpid();
> - child_pid = fork();
> - switch (child_pid) {
> - case -1:
> - tst_brkm(TBROK | TERRNO, cleanup, "fork");
> - break;
> - case 0:
> - ltpuser = getpwnam(nobody_uid);
> - if (ltpuser == NULL)
> - tst_brkm(TBROK | TERRNO, NULL, "getpwnam failed");
> - SAFE_SETUID(NULL, ltpuser->pw_uid);
> -
> - params = cma_alloc_sane_params();
> + child_pid = SAFE_FORK();
> + if (!child_pid) {
> + ltpuser = SAFE_GETPWNAM(nobody_uid);
> + SAFE_SETUID(ltpuser->pw_uid);
> +
> + params = alloc_params();
> params->pid = parent_pid;
> - cma_test_params(params);
> - ret |= cma_check_ret(-1, TEST_RETURN);
> - ret |= cma_check_errno(EPERM);
> - cma_free_params(params);
> - exit(ret);
> - default:
> - SAFE_WAITPID(cleanup, child_pid, &status, 0);
> - if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
> - tst_resm(TFAIL, "child returns %d", status);
> + test_params(params);
> + TST_EXP_EQ_LI(TST_RET, -1);
> + check_errno(EPERM);
> + free_params(params);
> + return;
> }
> +
> + SAFE_WAITPID(child_pid, &status, 0);
We want to use tst_reap_children() here which will check the exit
status.
In fact, if SAFE_WAITPID is removed altogether then the exit status will
be checked automatically at the end of the test when the lib calls
reap_children.
Otherwise LGTM!
--
Thank you,
Richard.
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2022-08-26 7:10 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-24 12:40 [LTP] [PATCH v1] Rewrite process_vm01 test using new LTP API Andrea Cervesato via ltp
2022-08-26 7:04 ` Richard Palethorpe [this message]
2022-08-26 8:40 ` Andrea Cervesato via ltp
2022-08-26 8:46 ` Andrea Cervesato via ltp
2022-08-26 8:50 ` Richard Palethorpe
-- strict thread matches above, loose matches on Subject: below --
2022-10-06 11:06 [LTP] [PATCH v1 0/3] Add process_madvise support Andrea Cervesato via ltp
2022-10-06 11:06 ` [LTP] [PATCH v1] Rewrite process_vm01 test using new LTP API Andrea Cervesato via ltp
2022-10-06 11:10 ` Andrea Cervesato 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=87bks71nwg.fsf@suse.de \
--to=rpalethorpe@suse.de \
--cc=andrea.cervesato@suse.com \
--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