Rewrite the gettid() testing suite
cover Rewrite the gettid() testing suite
From: Andrea Cervesato <[email protected]>
Rewrite gettid01 and create a new gettid02 test in order to check all gettid() basic functionalities, according with its manual.
Andrea Cervesato (2):
Rewrite gettid01 test
Add gettid02 test
runtest/syscalls | 1 + testcases/kernel/syscalls/gettid/.gitignore | 1 + testcases/kernel/syscalls/gettid/Makefile | 4 +- testcases/kernel/syscalls/gettid/gettid01.c | 102 +++----------------- testcases/kernel/syscalls/gettid/gettid02.c | 68 +++++++++++++ 5 files changed, 87 insertions(+), 89 deletions(-) create mode 100644 testcases/kernel/syscalls/gettid/gettid02.c
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 1/2 Rewrite gettid01 test
From: Andrea Cervesato <[email protected]>
The old test wasn't doing anything meaningful, but just checking gettid() syscall was working. In this test we checks if gettid() is working and if PID differs from its return value.
--- testcases/kernel/syscalls/gettid/gettid01.c | 102 +++----------------- 1 file changed, 14 insertions(+), 88 deletions(-)
testcases/kernel/syscalls/gettid/gettid01.c +14 -88
@@ -1,96 +1,22 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* -* Crackerjack Project -* -* Copyright (C) 2007-2008, Hitachi, Ltd. -* Author(s): Takahiro Yasui <[email protected]>, -* Yumiko Sugita <[email protected]>, -* Satoshi Fujiwara <[email protected]> -* -* 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. -* -* $Id: gettid01.c,v 1.5 2009/10/26 14:55:47 subrata_modak Exp $ +* Copyright (C) 2023 SUSE LLC Andrea Cervesato <[email protected]> +*/ +/*\ +* [Description] * +* This test checks if parent pid is equal to tid in single-threaded +* application. */ -/* Porting from Crackerjack to LTP is done -by Masatake YAMATO <[email protected]> */ - -#include <sys/types.h> -#include <linux/unistd.h> -#include <errno.h> - -#include "test.h" - -void setup (); -void cleanup (); +#include "tst_test.h" +#include "lapi/syscalls.h" -char *TCID ="gettid01" ; - -int TST_TOTAL =1 ; - -pid_t my_gettid (void ) +static void run (void ) { -return (pid_t )syscall (__NR_gettid); +TST_EXP_EQ_LI (getpid (),tst_syscall (__NR_gettid)); } -int main (int ac,char **av) -{ -int lc; - -tst_parse_opts (ac, av,NULL ,NULL ); - -setup (); - -/* -* The following loop checks looping state if -c option given -*/ -for (lc =0 ;TEST_LOOPING (lc); lc++) { - - tst_count =0 ; - -TEST (my_gettid ()); - -if (TEST_RETURN ==-1 ) { -tst_resm (TFAIL ,"gettid() Failed, errno=%d: %s" , -TEST_ERRNO ,strerror (TEST_ERRNO )); - }else { -tst_resm (TPASS ,"gettid() returned %ld" , -TEST_RETURN ); - } - } - -cleanup (); -tst_exit (); -} - -/* -* setup() - performs all ONE TIME setup for this test. -*/ -void setup (void ) -{ - -tst_sig (NOFORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; - -} - -/* -* cleanup() - performs all ONE TIME cleanup for this test at -* completion or premature exit. -*/ -void cleanup (void ) -{ -} +static struct tst_test test = { + .test_all = run, +};
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v1 1/2] Rewrite gettid01 test
Hello,
Quoted 62 lines · Andrea Cervesato
From: Andrea Cervesato <[email protected]>
The old test wasn't doing anything meaningful, but just checking
gettid()syscall was working. In this test we checks ifgettid()is working and if PID differs from its return value.Signed-off-by Andrea Cervesato <[email protected]>--- testcases/kernel/syscalls/gettid/gettid01.c | 102 +++----------------- 1 file changed, 14 insertions(+), 88 deletions(-)testcases/kernel/syscalls/gettid/gettid01.c +9
-33@@ -1,96 +1,22 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* -* Crackerjack Project -* -* Copyright (C) 2007-2008, Hitachi, Ltd. -* Author(s): Takahiro Yasui <[email protected]>, -* Yumiko Sugita <[email protected]>, -* Satoshi Fujiwara <[email protected]> -* -* 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. -* -* $Id: gettid01.c,v 1.5 2009/10/26 14:55:47 subrata_modak Exp $ +* Copyright (C) 2023 SUSE LLC Andrea Cervesato <[email protected]> +*/ +/*\ +* [Description] * +* This test checks if parent pid is equal to tid in single-threaded +* application. */ -/* Porting from Crackerjack to LTP is done -by Masatake YAMATO <[email protected]> */ - -#include <sys/types.h> -#include <linux/unistd.h> -#include <errno.h> - -#include "test.h" - -void setup (); -void cleanup (); +#include "tst_test.h" +#include "lapi/syscalls.h"
testcases/kernel/syscalls/gettid/gettid01.c line 17
Quoted 10 lines
testcases/kernel/syscalls/gettid/gettid01.c +2
-6-char *TCID ="gettid01" ; - -int TST_TOTAL =1 ; - -pid_t my_gettid (void ) +static void run (void ) { -return (pid_t )syscall (__NR_gettid); +TST_EXP_EQ_LI (getpid (),tst_syscall (__NR_gettid));
Perhaps this is nit picking, but this assumes libc didn't put us in a thread or just caches the wrong value in getpid. So it is more a test of libc than the kernel.
Is there some other way we could check that the main test process is not a thread? There could be some file in proc I guess. Then we are comparing information from multiple sources and it should all align.
Also getpid could be called directly avoiding libc.
Quoted 56 lines
testcases/kernel/syscalls/gettid/gettid01.c +3
-49} -int main (int ac,char **av) -{ -int lc; - -tst_parse_opts (ac, av,NULL ,NULL ); - -setup (); - -/* -* The following loop checks looping state if -c option given -*/ -for (lc =0 ;TEST_LOOPING (lc); lc++) { - - tst_count =0 ; - -TEST (my_gettid ()); - -if (TEST_RETURN ==-1 ) { -tst_resm (TFAIL ,"gettid() Failed, errno=%d: %s" , -TEST_ERRNO ,strerror (TEST_ERRNO )); - }else { -tst_resm (TPASS ,"gettid() returned %ld" , -TEST_RETURN ); - } - } - -cleanup (); -tst_exit (); -} - -/* -* setup() - performs all ONE TIME setup for this test. -*/ -void setup (void ) -{ - -tst_sig (NOFORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; - -} - -/* -* cleanup() - performs all ONE TIME cleanup for this test at -* completion or premature exit. -*/ -void cleanup (void ) -{ -} +static struct tst_test test = { + .test_all = run, +};Signature · 1 line
2.35.3
Signature · 5 lines
Thank you, Richard. -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v1 1/2] Rewrite gettid01 test
Hi!
Quoted 67 lines · Richard Palethorpe
Hello,
Quoted 63 lines · Andrea Cervesato
From: Andrea Cervesato <[email protected]>
The old test wasn't doing anything meaningful, but just checking
gettid()syscall was working. In this test we checks ifgettid()is working and if PID differs from its return value.Signed-off-by Andrea Cervesato <[email protected]>--- testcases/kernel/syscalls/gettid/gettid01.c | 102 +++----------------- 1 file changed, 14 insertions(+), 88 deletions(-)testcases/kernel/syscalls/gettid/gettid01.c +9
-33@@ -1,96 +1,22 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* -* Crackerjack Project -* -* Copyright (C) 2007-2008, Hitachi, Ltd. -* Author(s): Takahiro Yasui <[email protected]>, -* Yumiko Sugita <[email protected]>, -* Satoshi Fujiwara <[email protected]> -* -* 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. -* -* $Id: gettid01.c,v 1.5 2009/10/26 14:55:47 subrata_modak Exp $ +* Copyright (C) 2023 SUSE LLC Andrea Cervesato <[email protected]> +*/ +/*\ +* [Description] * +* This test checks if parent pid is equal to tid in single-threaded +* application. */ -/* Porting from Crackerjack to LTP is done -by Masatake YAMATO <[email protected]> */ - -#include <sys/types.h> -#include <linux/unistd.h> -#include <errno.h> - -#include "test.h" - -void setup (); -void cleanup (); +#include "tst_test.h" +#include "lapi/syscalls.h"
Quoted 12 lines
testcases/kernel/syscalls/gettid/gettid01.c line 17
Quoted 9 lines
testcases/kernel/syscalls/gettid/gettid01.c +2
-6-char *TCID ="gettid01" ; - -int TST_TOTAL =1 ; - -pid_t my_gettid (void ) +static void run (void ) { -return (pid_t )syscall (__NR_gettid); +TST_EXP_EQ_LI (getpid (),tst_syscall (__NR_gettid));Perhaps this is nit picking, but this assumes libc didn't put us in a thread or just caches the wrong value in getpid. So it is more a test of libc than the kernel.
I understand the cache part. Probably we need to call tst_syscall(__NR_getpid) instead of getpid(), but I don't get the thread part. Is it possible that libc moves test function inside a thread?
Quoted 54 lines
Is there some other way we could check that the main test process is not a thread? There could be some file in proc I guess. Then we are comparing information from multiple sources and it should all align.
Also getpid could be called directly avoiding libc.
Quoted 48 lines
testcases/kernel/syscalls/gettid/gettid01.c +0
-46} -int main (int ac,char **av) -{ -int lc; - -tst_parse_opts (ac, av,NULL ,NULL ); - -setup (); - -/* -* The following loop checks looping state if -c option given -*/ -for (lc =0 ;TEST_LOOPING (lc); lc++) { - - tst_count =0 ; - -TEST (my_gettid ()); - -if (TEST_RETURN ==-1 ) { -tst_resm (TFAIL ,"gettid() Failed, errno=%d: %s" , -TEST_ERRNO ,strerror (TEST_ERRNO )); - }else { -tst_resm (TPASS ,"gettid() returned %ld" , -TEST_RETURN ); - } - } - -cleanup (); -tst_exit (); -} - -/* -* setup() - performs all ONE TIME setup for this test. -*/ -void setup (void ) -{ - -tst_sig (NOFORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; - -} - -/* -* cleanup() - performs all ONE TIME cleanup for this test at -* completion or premature exit. -*/
Quoted 9 lines
Quoted 8 lines
testcases/kernel/syscalls/gettid/gettid01.c +3
-3-void cleanup (void ) -{ -} +static struct tst_test test = { + .test_all = run, +};Signature · 1 line
2.35.3
Andrea
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v1 1/2] Rewrite gettid01 test
Hello,
Quoted 80 lines · Andrea Cervesato
Hi!
Quoted 69 lines · Richard Palethorpe
Hello,
Quoted 65 lines · Andrea Cervesato
From: Andrea Cervesato <[email protected]>
The old test wasn't doing anything meaningful, but just checking
gettid()syscall was working. In this test we checks ifgettid()is working and if PID differs from its return value.Signed-off-by Andrea Cervesato <[email protected]>--- testcases/kernel/syscalls/gettid/gettid01.c | 102 +++----------------- 1 file changed, 14 insertions(+), 88 deletions(-)testcases/kernel/syscalls/gettid/gettid01.c +9
-35@@ -1,96 +1,22 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* -* Crackerjack Project -* -* Copyright (C) 2007-2008, Hitachi, Ltd. -* Author(s): Takahiro Yasui <[email protected]>, -* Yumiko Sugita <[email protected]>, -* Satoshi Fujiwara <[email protected]> -* -* 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. -* -* $Id: gettid01.c,v 1.5 2009/10/26 14:55:47 subrata_modak Exp $ +* Copyright (C) 2023 SUSE LLC Andrea Cervesato <[email protected]> +*/ +/*\ +* [Description] * +* This test checks if parent pid is equal to tid in single-threaded +* application. */ -/* Porting from Crackerjack to LTP is done -by Masatake YAMATO <[email protected]> */ - -#include <sys/types.h> -#include <linux/unistd.h> -#include <errno.h> - -#include "test.h" - -void setup (); -void cleanup (); +#include "tst_test.h" +#include "lapi/syscalls.h" -char *TCID = "gettid01"; - -int TST_TOTAL =1 ; -Quoted 8 lines
testcases/kernel/syscalls/gettid/gettid01.c line 17
Quoted 5 lines
testcases/kernel/syscalls/gettid/gettid01.c +2
-2-pid_t my_gettid (void ) +static void run (void ) { -return (pid_t )syscall (__NR_gettid); +TST_EXP_EQ_LI (getpid (),tst_syscall (__NR_gettid));Perhaps this is nit picking, but this assumes libc didn't put us in a thread or just caches the wrong value in getpid. So it is more a test of libc than the kernel.
Quoted 4 lines
I understand the cache part. Probably we need to call
tst_syscall(__NR_getpid)instead ofgetpid(), but I don't get the thread part. Is it possible that libc moves test function inside a thread?
I suppose it is possible, but very unlikely. I haven't seen anything like that; I'm just using my wild imagination.
Perhaps we could check 'grep Threads /proc/self/status'? It should be equal to 1. If not then something may have instrumented the process or the system's libc is insane or something else. It's just some extra debug info.
Quoted 62 lines
Quoted 52 lines
Is there some other way we could check that the main test process is not a thread? There could be some file in proc I guess. Then we are comparing information from multiple sources and it should all align.
Also getpid could be called directly avoiding libc.
Quoted 46 lines
testcases/kernel/syscalls/gettid/gettid01.c +0
-44} -int main(int ac, char **av) -{ -int lc; - -tst_parse_opts (ac, av,NULL ,NULL ); - -setup (); - -/* -* The following loop checks looping state if -c option given -*/ -for (lc =0 ;TEST_LOOPING (lc); lc++) { - - tst_count =0 ; - -TEST (my_gettid ()); - -if (TEST_RETURN ==-1 ) { -tst_resm (TFAIL ,"gettid() Failed, errno=%d: %s" , -TEST_ERRNO ,strerror (TEST_ERRNO )); - }else { -tst_resm (TPASS ,"gettid() returned %ld" , -TEST_RETURN ); - } - } - -cleanup (); -tst_exit (); -} - -/* -* setup() - performs all ONE TIME setup for this test. -*/ -void setup (void ) -{ - -tst_sig (NOFORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; - -} - -/* -* cleanup() - performs all ONE TIME cleanup for this test at -* completion or premature exit. Quoted 9 lines
testcases/kernel/syscalls/gettid/gettid01.c
Quoted 8 lines
testcases/kernel/syscalls/gettid/gettid01.c +3
-5-*/ -void cleanup (void ) -{ -} +static struct tst_test test = { + .test_all = run, +}; -- 2.35.3Andrea
Signature · 5 lines
Thank you, Richard. -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 2/2 Add gettid02 test
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
This new test is checking if gettid() is properly handling a multi-threaded application, by assigning a different TID for each thread which differs from the parent ID.
--- runtest/syscalls | 1 + testcases/kernel/syscalls/gettid/.gitignore | 1 + testcases/kernel/syscalls/gettid/Makefile | 4 +- testcases/kernel/syscalls/gettid/gettid02.c | 68 +++++++++++++++++++++ 4 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 testcases/kernel/syscalls/gettid/gettid02.c
runtest/syscalls +1 -0
@@ -537,6 +537,7 @@ getsockopt01 getsockopt01 getsockopt02 getsockopt02 gettid01 gettid01 +gettid02 gettid02 gettimeofday01 gettimeofday01 gettimeofday02 gettimeofday02
testcases/kernel/syscalls/gettid/.gitignore +1 -0
@@ -1 +1,2 @@ /gettid01 +/gettid02
testcases/kernel/syscalls/gettid/Makefile +3 -1
@@ -10,7 +10,9 @@ top_srcdir ?= ../../../.. include $(top_srcdir)/include/mk/testcases.mk ifeq ($(ANDROID), 1) -FILTER_OUT_MAKE_TARGETS += gettid01 +FILTER_OUT_MAKE_TARGETS += gettid01 gettid02 endif +gettid02: LDLIBS += -lpthread + include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/gettid/gettid02.c new file +68 -0
68 lines not on this page · raw message
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v1 2/2] Add gettid02 test
Hello,
Quoted 71 lines · Andrea Cervesato
From: Andrea Cervesato <[email protected]>
This new test is checking if
gettid()is properly handling a multi-threaded application, by assigning a different TID for each thread which differs from the parent ID.Signed-off-by Andrea Cervesato <[email protected]>--- runtest/syscalls | 1 + testcases/kernel/syscalls/gettid/.gitignore | 1 + testcases/kernel/syscalls/gettid/Makefile | 4 +- testcases/kernel/syscalls/gettid/gettid02.c | 68 +++++++++++++++++++++ 4 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 testcases/kernel/syscalls/gettid/gettid02.cruntest/syscalls +1
-0@@ -537,6 +537,7 @@ getsockopt01 getsockopt01 getsockopt02 getsockopt02 gettid01 gettid01 +gettid02 gettid02 gettimeofday01 gettimeofday01 gettimeofday02 gettimeofday02testcases/kernel/syscalls/gettid/.gitignore +1
-0@@ -1 +1,2 @@ /gettid01 +/gettid02testcases/kernel/syscalls/gettid/Makefile +3
-1@@ -10,7 +10,9 @@ top_srcdir ?= ../../../.. include $(top_srcdir)/include/mk/testcases.mk ifeq ($(ANDROID), 1) -FILTER_OUT_MAKE_TARGETS += gettid01 +FILTER_OUT_MAKE_TARGETS += gettid01 gettid02 endif +gettid02: LDLIBS += -lpthread + include $(top_srcdir)/include/mk/generic_leaf_target.mktestcases/kernel/syscalls/gettid/gettid02.c new file +16
-0@@ -0,0 +1,68 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2023 SUSE LLC Andrea Cervesato <[email protected]> +*/ +/*\ +* [Description] +* +* This test spawns multiple threads, then check for each one of them if the +* parent ID is different AND if the thread ID is different from all the other +* spwaned threads. +*/ + +#include "tst_test.h" +#include "lapi/syscalls.h" +#include "tst_safe_pthread.h" +
testcases/kernel/syscalls/gettid/gettid02.c line 26
Quoted 10 lines
testcases/kernel/syscalls/gettid/gettid02.c new file +10
-0+#define THREADS_NUM 10 + +static pid_t tids[THREADS_NUM ]; + +static void *threaded (void *arg) +{ +int i = *(int *)arg; +pid_t pid, tid; + + pid =getpid ();
Maybe we could call __NR_getpid directly as well and compare it?
Same reason as with other test; libc's like to be clever and cache this value. So maybe we are not testing the kernel here.
Otherwise LGTM.
Signature · 5 lines
Thank you, Richard. -- Mailing list info: https://lists.linux.it/listinfo/ltp