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 09:50:19 +0100 [thread overview]
Message-ID: <8735dj1iy3.fsf@suse.de> (raw)
In-Reply-To: <a369a07d-9401-0437-2647-9a5f1737b732@suse.com>
Hello,
Andrea Cervesato via ltp <ltp@lists.linux.it> writes:
> On 8/26/22 10:40, Andrea Cervesato via ltp wrote:
>> Hi!
>>
>> On 8/26/22 09:04, Richard Palethorpe wrote:
>>> 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!
>>>
>> Isn't tst_reap_childread() already called at the end of the test_all
>> function? (tst_test.c:1354)
>>
>> Andrea
>>
>>
> The reason why I'm using SAFE_WAITPID here is that there are many
> other test functions and when test_invalid_perm is called without it,
> the tst_res messages might come out asynchronously with the other
> tests messages.
If asynchronous messages are a problem then you can explicitly call
tst_reap_children() after fork. If you use SAFE_WAITPID then you need to
check the exit status manually, it won't get checked later by the call
to tst_reap_children in tst_test.c. Because the child process has
already been reaped by waitpid.
I don't have a strong opinion on whether asynchronous messages are a
problem.
--
Thank you,
Richard.
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2022-08-26 8:57 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
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 [this message]
-- 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=8735dj1iy3.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