getsid01.c: Convert to new LTP API
PATCH v2 1/1 getsid01.c: Convert to new LTP API
Signed-off-by Avinesh Kumar <[email protected]>
--- testcases/kernel/syscalls/getsid/getsid01.c | 169 ++++---------------- 1 file changed, 30 insertions(+), 139 deletions(-)
testcases/kernel/syscalls/getsid/getsid01.c +30 -139
@@ -1,159 +1,50 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* -* * Copyright (c) International Business Machines Corp., 2001 -* -* 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 +* 07/2001 Ported by Wayne Boyer +* Copyright (c) 2022 SUSE LLC Avinesh Kumar <[email protected]> */ -/* -* NAME -* getsid01.c -* -* DESCRIPTION -* getsid01 - call getsid() and make sure it succeeds -* -* ALGORITHM -* loop if that option was specified -* issue the system call -* check the return value -* if return value == -1 -* issue a FAIL message, break remaining tests and cleanup -* if we are doing functional testing -* save the return value from the getsid() call - the session ID -* fork a child and get the child's session ID -* if the child's session ID == the parent's session ID -* issue a PASS message -* else -* issue a FAIL message -* else issue a PASS message -* call cleanup -* -* USAGE: <for command-line> -* getsid01 [-c n] [-f] [-i n] [-I x] [-P x] [-t] -* where, -c n : Run n copies concurrently. -* -f : Turn off functionality Testing. -* -i n : Execute test n times. -* -I x : Execute test for x seconds. -* -P x : Pause for x seconds between iterations. -* -t : Turn on syscall timing. -* -* HISTORY -* 07/2001 Ported by Wayne Boyer +/*\ +* [Description] * -* RESTRICTIONS -* none +* Verify that session IDs returned by getsid() (with argument pid=0) +* are same in parent and child process. */ -#define _GNU_SOURCE 1 -#include <errno.h> -#include <sys/wait.h> -#include <unistd.h> -#include "test.h" -void cleanup (void ); -void setup (void ); +#include "tst_test.h" -char *TCID ="getsid01" ; -int TST_TOTAL =1 ; +static pid_t p_sid; -pid_t p_sid; - -int main (int ac,char **av) +static void run (void ) { -int lc; -pid_t pid, c_pid, c_sid; - -tst_parse_opts (ac, av,NULL ,NULL ); - -setup ();/* global setup */ +pid_t pid, c_sid; -/* The following loop checks looping state if -i option given */ +TEST (getsid (0 )); +if (TST_RET ==-1 ) { +tst_res (TFAIL |TTERRNO ,"getsid(0) failed in parent" ); +return ; + } -for (lc =0 ;TEST_LOOPING (lc); lc++) { -/* reset tst_count in case we are looping */ - tst_count =0 ; + p_sid =TST_RET ; -/* call the system call with the TEST() macro */ + pid =SAFE_FORK (); +if (pid ==0 ) {TEST (getsid (0 )); - -if (TEST_RETURN ==-1 ) { -tst_resm (TFAIL ,"call failed - errno = %d " -"- %s" ,TEST_ERRNO ,strerror (TEST_ERRNO )); -continue ; - } - -/* save the return value in a global variable */ - p_sid =TEST_RETURN ; - -if ((pid =FORK_OR_VFORK ()) ==-1 ) { -tst_brkm (TBROK , cleanup,"could not fork" ); - } - -if (pid ==0 ) {/* child */ -if ((c_pid =getpid ()) ==-1 ) { -tst_resm (TINFO ,"getpid failed in " -"functionality test" ); -exit (1 ); - } - -/* -* if the session ID of the child is the -* same as the parent then things look good -*/ - -if ((c_sid =getsid (0 )) ==-1 ) { -tst_resm (TINFO ,"getsid failed in " -"functionality test" ); -exit (2 ); - } - -if (c_sid == p_sid) { -tst_resm (TPASS ,"session ID is " -"correct" ); - }else { -tst_resm (TFAIL ,"session ID is " -"not correct" ); - } -exit (0 ); - - }else { -waitpid (pid,NULL ,0 ); +if (TST_RET ==-1 ) { +tst_res (TFAIL |TTERRNO ,"getsid(0) failed in child" ); +return ; } + c_sid =TST_RET ; +TST_EXP_EQ_LI (p_sid, c_sid); + }else { +SAFE_WAITPID (pid,NULL ,0 ); } - -cleanup (); -tst_exit (); -} - -/* -* setup() - performs all the ONE TIME setup for this test. -*/ -void setup (void ) -{ - -tst_sig (FORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; } -/* -* cleanup() - performs all the ONE TIME cleanup for this test at completion -* or premature exit. -*/ -void cleanup (void ) -{ - -} +static struct tst_test test = { + .test_all = run, + .forks_child =1 +};
Signature · 5 lines
2.37.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp