S390: Refactor wcschrnul ifunc handling.
[glibc.git] / nptl / tst-audit-threads.c
blobe4bf433bd85f3715df69a216c9a48c588eed8c06
1 /* Test multi-threading using LD_AUDIT.
3 Copyright (C) 2018 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
20 /* This test uses a dummy LD_AUDIT library (test-audit-threads-mod1) and a
21 library with a huge number of functions in order to validate lazy symbol
22 binding with an audit library. We use one thread per CPU to test that
23 concurrent lazy resolution does not have any defects which would cause
24 the process to fail. We use an LD_AUDIT library to force the testing of
25 the relocation resolution caching code in the dynamic loader i.e.
26 _dl_runtime_profile and _dl_profile_fixup. */
28 #include <support/xthread.h>
29 #include <strings.h>
30 #include <stdlib.h>
31 #include <sys/sysinfo.h>
33 static int do_test (void);
35 /* This test usually takes less than 3s to run. However, there are cases that
36 take up to 30s. */
37 #define TIMEOUT 60
38 #define TEST_FUNCTION do_test ()
39 #include "../test-skeleton.c"
41 /* Declare the functions we are going to call. */
42 #define externnum
43 #include "tst-audit-threads.h"
44 #undef externnum
46 int num_threads;
47 pthread_barrier_t barrier;
49 void
50 sync_all (int num)
52 pthread_barrier_wait (&barrier);
55 void
56 call_all_ret_nums (void)
58 /* Call each function one at a time from all threads. */
59 #define callnum
60 #include "tst-audit-threads.h"
61 #undef callnum
64 void *
65 thread_main (void *unused)
67 call_all_ret_nums ();
68 return NULL;
71 #define STR2(X) #X
72 #define STR(X) STR2(X)
74 static int
75 do_test (void)
77 int i;
78 pthread_t *threads;
80 num_threads = get_nprocs ();
81 if (num_threads <= 1)
82 num_threads = 2;
84 /* Used to synchronize all the threads after calling each retNumN. */
85 xpthread_barrier_init (&barrier, NULL, num_threads);
87 threads = (pthread_t *) xcalloc (num_threads, sizeof(pthread_t));
88 for (i = 0; i < num_threads; i++)
89 threads[i] = xpthread_create(NULL, thread_main, NULL);
91 for (i = 0; i < num_threads; i++)
92 xpthread_join(threads[i]);
94 free (threads);
96 return 0;