[LTP] [PATCH 2/2] syscalls/pause03: Refactor into new API
Ricardo B. Marlière
ricardo@marliere.net
Tue Feb 18 13:37:06 CET 2025
Hi Andrea!
Thanks for the review, I'll send a v2 addressing your points later.
On Tue Feb 18, 2025 at 9:26 AM -03, Andrea Cervesato wrote:
> Hi!
>
> On 2/17/25 23:01, Ricardo B. Marlière wrote:
>> Signed-off-by: Ricardo B. Marlière <ricardo@marliere.net>
>> ---
>> testcases/kernel/syscalls/pause/pause03.c | 114 +++++++-----------------------
>> 1 file changed, 25 insertions(+), 89 deletions(-)
>>
>> diff --git a/testcases/kernel/syscalls/pause/pause03.c b/testcases/kernel/syscalls/pause/pause03.c
>> index 459222045c08dc1fc4804efd2ece02316fe55a0e..641610a78290de1f25c1f8388c7ec5023dd00180 100644
>> --- a/testcases/kernel/syscalls/pause/pause03.c
>> +++ b/testcases/kernel/syscalls/pause/pause03.c
>> @@ -1,104 +1,40 @@
>> +// SPDX-License-Identifier: GPL-2.0-or-later
>> /*
>> * Copyright (c) International Business Machines Corp., 2001
>> - * 07/2001 Ported by Wayne Boyer
>> - *
>> - * 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 will 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 to the Free Software Foundation,
>> - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
>> + * Copyright (c) Linux Test Project, 2025
>> + * 07/2001 Ported by Wayne Boyer
> Here we are missing the "Copyright (c) International Business Machines
> Corp., 2001" copyright string before credit. Also, the "Ported" message
> should be aligned to the copyright with a tab. You can add your own
> credit as well like in the previous patch.
>> */
>> +
>> /*
> Missing documentation /*\ string.
>> - * Test Description:
>> - * pause() does not return due to receipt of SIGKILL signal and specified
>> - * process should be terminated.
>> + * This test verifies that pause() does not return after receiving a SIGKILL
>> + * signal, at which point the process should be terminated.
>> */
>> -#include <unistd.h>
>> -#include <errno.h>
>> -#include <fcntl.h>
>> -#include <sys/wait.h>
>> -
>> -#include "test.h"
>> -#include "safe_macros.h"
>> -
>> -static pid_t cpid;
>> -
>> -char *TCID = "pause03";
>> -int TST_TOTAL = 1;
>>
>> -static void do_child(void);
>> -static void setup(void);
>> -static void cleanup(void);
>> +#include "tst_test.h"
>>
>> -int main(int ac, char **av)
>> +void run(void)
>> {
>> - int lc;
>> int status;
>> + pid_t pid;
>>
>> - tst_parse_opts(ac, av, NULL, NULL);
>> -
>> - setup();
>> -
>> - for (lc = 0; TEST_LOOPING(lc); lc++) {
>> - tst_count = 0;
>> -
>> - if ((cpid = tst_fork()) == -1)
>> - tst_brkm(TBROK | TERRNO, NULL, "fork() failed");
>> -
>> - if (cpid == 0)
>> - do_child();
>> -
>> - TST_PROCESS_STATE_WAIT(cleanup, cpid, 'S');
>> -
>> - kill(cpid, SIGKILL);
>> -
>> - SAFE_WAIT(NULL, &status);
>> -
>> - if (WIFSIGNALED(status) && WTERMSIG(status) == SIGKILL) {
>> - tst_resm(TPASS, "pause() did not return after SIGKILL");
>> - continue;
>> - }
>> -
>> - if (WIFSIGNALED(status)) {
>> - tst_resm(TFAIL, "child killed by %s unexpectedly",
>> - tst_strsig(WTERMSIG(status)));
>> - continue;
>> - }
>> -
>> - tst_resm(TFAIL, "child exited with %i", WEXITSTATUS(status));
>> + pid = SAFE_FORK();
>> + if (!pid) {
>> + pause();
>> + tst_res(TFAIL, "Unexpected return from pause()");
> We can use TST_EXP_PASS(pause())
>> + exit(0);
>> }
>>
>> - cleanup();
>> - tst_exit();
>> + TST_PROCESS_STATE_WAIT(pid, 'S', 10000);
>> + kill(pid, SIGKILL);
>> + SAFE_WAITPID(pid, &status, 0);
>>
>> + if (WIFSIGNALED(status) && WTERMSIG(status) == SIGKILL)
>> + tst_res(TPASS, "pause() did not return after SIGKILL");
>> + else
>> + tst_res(TFAIL, "Child exited with %i", WEXITSTATUS(status));
>> }
>>
>> -void do_child(void)
>> -{
>> - TEST(pause());
>> -
>> - tst_resm(TFAIL, "Unexpected return from pause()");
>> -
>> - exit(0);
>> -}
>> -
>> -void setup(void)
>> -{
>> - tst_sig(FORK, DEF_HANDLER, cleanup);
>> -
>> - TEST_PAUSE;
>> -}
>> -
>> -
>> -void cleanup(void)
>> -{
>> - kill(cpid, SIGKILL);
>> -}
>> +static struct tst_test test = {
>> + .test_all = run,
>> + .forks_child = 1,
>> +};
> Andrea
More information about the ltp
mailing list