localedata: dz_BT, bo_CN: convert to UTF-8
[glibc.git] / sysdeps / unix / sysv / linux / tst-gettid.c
blobb992a5810261a40a17e4c903cff2a49b3f497c1c
1 /* Smoke test for the gettid system call.
2 Copyright (C) 2019-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 #include <support/check.h>
20 #include <support/namespace.h>
21 #include <support/xthread.h>
22 #include <support/xunistd.h>
24 /* TID of the initial (main) thread. */
25 static pid_t initial_tid;
27 /* Check that PID and TID are the same in a subprocess. */
28 static void
29 subprocess (void *closure)
31 TEST_COMPARE (getpid (), gettid ());
32 TEST_VERIFY (gettid () != initial_tid);
35 /* Check that the TID changes in a new thread. */
36 static void *
37 threadfunc (void *closure)
39 TEST_VERIFY (getpid () != gettid ());
40 TEST_VERIFY (gettid () != initial_tid);
41 return NULL;
44 /* Check for interactions with vfork. */
45 static void
46 test_vfork (void)
48 pid_t proc = vfork ();
49 if (proc == 0)
51 if (getpid () != gettid ())
52 _exit (1);
53 if (gettid () == initial_tid)
54 _exit (2);
55 _exit (0);
57 int status;
58 xwaitpid (proc, &status, 0);
59 TEST_COMPARE (status, 0);
62 static int
63 do_test (void)
65 initial_tid = gettid ();
67 /* The main thread has the same TID as the PID. */
68 TEST_COMPARE (getpid (), gettid ());
70 test_vfork ();
72 support_isolate_in_subprocess (subprocess, NULL);
74 xpthread_join (xpthread_create (NULL, threadfunc, NULL));
76 return 0;
79 #include <support/test-driver.c>