* [LTP] [PATCH v2 0/2] Rewrite the gettid() testing suite
@ 2023-10-05 13:49 Andrea Cervesato
2023-10-05 13:49 ` [LTP] [PATCH v2 1/2] Rewrite gettid01 test Andrea Cervesato
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Andrea Cervesato @ 2023-10-05 13:49 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
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 | 105 ++++----------------
testcases/kernel/syscalls/gettid/gettid02.c | 68 +++++++++++++
5 files changed, 93 insertions(+), 86 deletions(-)
create mode 100644 testcases/kernel/syscalls/gettid/gettid02.c
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 5+ messages in thread
* [LTP] [PATCH v2 1/2] Rewrite gettid01 test
2023-10-05 13:49 [LTP] [PATCH v2 0/2] Rewrite the gettid() testing suite Andrea Cervesato
@ 2023-10-05 13:49 ` Andrea Cervesato
2023-10-05 13:49 ` [LTP] [PATCH v2 2/2] Add gettid02 test Andrea Cervesato
2023-10-05 14:24 ` [LTP] [PATCH v2 0/2] Rewrite the gettid() testing suite Marius Kittler
2 siblings, 0 replies; 5+ messages in thread
From: Andrea Cervesato @ 2023-10-05 13:49 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
The old test wasn't doing anything meaningful, but just checking that
__NR_gettid syscall is working. In this test we check that
tid == pid, in the case we are not inside a thread.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
Check if we are inside a thread
Make use of tst_syscall
testcases/kernel/syscalls/gettid/gettid01.c | 105 ++++----------------
1 file changed, 20 insertions(+), 85 deletions(-)
diff --git a/testcases/kernel/syscalls/gettid/gettid01.c b/testcases/kernel/syscalls/gettid/gettid01.c
index 7e5b6b175..5f9623e9a 100644
--- a/testcases/kernel/syscalls/gettid/gettid01.c
+++ b/testcases/kernel/syscalls/gettid/gettid01.c
@@ -1,96 +1,31 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
/*
- * Crackerjack Project
- *
- * Copyright (C) 2007-2008, Hitachi, Ltd.
- * Author(s): Takahiro Yasui <takahiro.yasui.mp@hitachi.com>,
- * Yumiko Sugita <yumiko.sugita.yf@hitachi.com>,
- * Satoshi Fujiwara <sa-fuji@sdl.hitachi.co.jp>
- *
- * 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 <andrea.cervesato@suse.com>
+ */
+/*\
+ * [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 <yamato@redhat.com> */
-
-#include <sys/types.h>
-#include <linux/unistd.h>
-#include <errno.h>
-
-#include "test.h"
-
-void setup();
-void cleanup();
-
-char *TCID = "gettid01";
-
-int TST_TOTAL = 1;
-
-pid_t my_gettid(void)
-{
- return (pid_t) 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++) {
+#include "tst_test.h"
+#include "lapi/syscalls.h"
- 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)
+static void run(void)
{
+ long pid, tid;
- tst_sig(NOFORK, DEF_HANDLER, cleanup);
+ SAFE_FILE_LINES_SCANF("/proc/self/status", "Pid: %ld", &pid);
+ SAFE_FILE_LINES_SCANF("/proc/self/status", "Tgid: %ld", &tid);
- TEST_PAUSE;
+ if (pid != tid)
+ tst_brk(TBROK, "Test function has been moved inside a thread?");
+ TST_EXP_EQ_LI(tst_syscall(__NR_gettid), tst_syscall(__NR_getpid));
+ TST_EXP_EQ_LI(tst_syscall(__NR_gettid), pid);
}
-/*
- * 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,
+};
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [LTP] [PATCH v2 2/2] Add gettid02 test
2023-10-05 13:49 [LTP] [PATCH v2 0/2] Rewrite the gettid() testing suite Andrea Cervesato
2023-10-05 13:49 ` [LTP] [PATCH v2 1/2] Rewrite gettid01 test Andrea Cervesato
@ 2023-10-05 13:49 ` Andrea Cervesato
2023-10-05 14:24 ` [LTP] [PATCH v2 0/2] Rewrite the gettid() testing suite Marius Kittler
2 siblings, 0 replies; 5+ messages in thread
From: Andrea Cervesato @ 2023-10-05 13:49 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
This new test is checking if __NR_gettid syscall is properly handling a
multi-threaded application, by assigning a different TID for each
thread.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
Make use of tst_syscall
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
diff --git a/runtest/syscalls b/runtest/syscalls
index 8652e0bd3..bba266ea3 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -538,6 +538,7 @@ getsockopt01 getsockopt01
getsockopt02 getsockopt02
gettid01 gettid01
+gettid02 gettid02
gettimeofday01 gettimeofday01
gettimeofday02 gettimeofday02
diff --git a/testcases/kernel/syscalls/gettid/.gitignore b/testcases/kernel/syscalls/gettid/.gitignore
index 78dce3499..9014f7c3a 100644
--- a/testcases/kernel/syscalls/gettid/.gitignore
+++ b/testcases/kernel/syscalls/gettid/.gitignore
@@ -1 +1,2 @@
/gettid01
+/gettid02
diff --git a/testcases/kernel/syscalls/gettid/Makefile b/testcases/kernel/syscalls/gettid/Makefile
index 4e9982f76..5345eb0f5 100644
--- a/testcases/kernel/syscalls/gettid/Makefile
+++ b/testcases/kernel/syscalls/gettid/Makefile
@@ -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
diff --git a/testcases/kernel/syscalls/gettid/gettid02.c b/testcases/kernel/syscalls/gettid/gettid02.c
new file mode 100644
index 000000000..22e843bad
--- /dev/null
+++ b/testcases/kernel/syscalls/gettid/gettid02.c
@@ -0,0 +1,68 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2023 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+/*\
+ * [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"
+
+#define THREADS_NUM 10
+
+static pid_t tids[THREADS_NUM];
+
+static void *threaded(void *arg)
+{
+ int i = *(int *)arg;
+ pid_t pid, tid;
+
+ pid = tst_syscall(__NR_getpid);
+ tid = tst_syscall(__NR_gettid);
+
+ TST_EXP_EXPR(pid != tid,
+ "parent ID (%d) differs from thread[%d] ID (%d)",
+ pid, i, tid);
+
+ return (void *)tst_syscall(__NR_gettid);
+}
+
+static void run(void)
+{
+ pthread_t thread;
+ int error = 0;
+
+ for (int i = 0; i < THREADS_NUM; i++) {
+ SAFE_PTHREAD_CREATE(&thread, NULL, threaded, &i);
+ SAFE_PTHREAD_JOIN(thread, (void **)&tids[i]);
+ }
+
+ for (int i = 0; i < THREADS_NUM; i++) {
+ for (int j = 0; j < THREADS_NUM; j++) {
+ if (i == j)
+ continue;
+
+ if (tids[i] == tids[j]) {
+ tst_res(TINFO, "thread[%d] and thread[%d] have the same ID", i, j);
+ error = 1;
+ goto end;
+ }
+ }
+ }
+
+end:
+ if (error)
+ tst_res(TFAIL, "Some threads have the same TID");
+ else
+ tst_res(TPASS, "All threads have a different TID");
+}
+
+static struct tst_test test = {
+ .test_all = run,
+};
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [LTP] [PATCH v2 0/2] Rewrite the gettid() testing suite
2023-10-05 13:49 [LTP] [PATCH v2 0/2] Rewrite the gettid() testing suite Andrea Cervesato
2023-10-05 13:49 ` [LTP] [PATCH v2 1/2] Rewrite gettid01 test Andrea Cervesato
2023-10-05 13:49 ` [LTP] [PATCH v2 2/2] Add gettid02 test Andrea Cervesato
@ 2023-10-05 14:24 ` Marius Kittler
2023-10-05 14:39 ` Andrea Cervesato via ltp
2 siblings, 1 reply; 5+ messages in thread
From: Marius Kittler @ 2023-10-05 14:24 UTC (permalink / raw)
To: ltp
Am Donnerstag, 5. Oktober 2023, 15:49:09 CEST schrieb Andrea Cervesato:
> From: Andrea Cervesato <andrea.cervesato@suse.com>
>
> 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 | 105 ++++----------------
> testcases/kernel/syscalls/gettid/gettid02.c | 68 +++++++++++++
> 5 files changed, 93 insertions(+), 86 deletions(-)
> create mode 100644 testcases/kernel/syscalls/gettid/gettid02.c
Looks generally good to merge.
I'm only wondering whether the goto in the 2nd test could be avoided. After
all it might even be a benefit to get an info for all the wrongly equivalent
thread IDs (and not just the first).
Then it would also make sense to use `int j = i + 1;` in the inner loop to
avoid duplicate/redundant commutative comparisons. And then you could actually
also drop the `i == j` check.
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [LTP] [PATCH v2 0/2] Rewrite the gettid() testing suite
2023-10-05 14:24 ` [LTP] [PATCH v2 0/2] Rewrite the gettid() testing suite Marius Kittler
@ 2023-10-05 14:39 ` Andrea Cervesato via ltp
0 siblings, 0 replies; 5+ messages in thread
From: Andrea Cervesato via ltp @ 2023-10-05 14:39 UTC (permalink / raw)
To: ltp
Hi!
On 10/5/23 16:24, Marius Kittler wrote:
> Am Donnerstag, 5. Oktober 2023, 15:49:09 CEST schrieb Andrea Cervesato:
>> From: Andrea Cervesato <andrea.cervesato@suse.com>
>>
>> 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 | 105 ++++----------------
>> testcases/kernel/syscalls/gettid/gettid02.c | 68 +++++++++++++
>> 5 files changed, 93 insertions(+), 86 deletions(-)
>> create mode 100644 testcases/kernel/syscalls/gettid/gettid02.c
> Looks generally good to merge.
>
> I'm only wondering whether the goto in the 2nd test could be avoided. After
> all it might even be a benefit to get an info for all the wrongly equivalent
> thread IDs (and not just the first).
>
> Then it would also make sense to use `int j = i + 1;` in the inner loop to
> avoid duplicate/redundant commutative comparisons. And then you could actually
> also drop the `i == j` check.
>
>
>
>
It makes sense, I update the code.
Andrea
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-10-05 14:39 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-05 13:49 [LTP] [PATCH v2 0/2] Rewrite the gettid() testing suite Andrea Cervesato
2023-10-05 13:49 ` [LTP] [PATCH v2 1/2] Rewrite gettid01 test Andrea Cervesato
2023-10-05 13:49 ` [LTP] [PATCH v2 2/2] Add gettid02 test Andrea Cervesato
2023-10-05 14:24 ` [LTP] [PATCH v2 0/2] Rewrite the gettid() testing suite Marius Kittler
2023-10-05 14:39 ` Andrea Cervesato via ltp
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.