1 | /* Test support for single-thread optimizations. No threads. |
2 | Copyright (C) 2020-2022 Free Software Foundation, Inc. |
3 | This file is part of the GNU C Library. |
4 | |
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. |
9 | |
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. |
14 | |
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/>. */ |
18 | |
19 | #include <stddef.h> |
20 | #include <stdio.h> |
21 | #include <support/check.h> |
22 | #include <support/namespace.h> |
23 | #include <support/xdlfcn.h> |
24 | #include <sys/single_threaded.h> |
25 | |
26 | /* Defined in tst-single-threaded-mod1.so. */ |
27 | extern _Bool single_threaded_1 (void); |
28 | |
29 | /* Initialized via dlsym. */ |
30 | _Bool (*single_threaded_2) (void); |
31 | _Bool (*single_threaded_3) (void); |
32 | |
33 | static void |
34 | subprocess (void *closure) |
35 | { |
36 | TEST_VERIFY (__libc_single_threaded); |
37 | TEST_VERIFY (single_threaded_1 ()); |
38 | if (single_threaded_2 != NULL) |
39 | TEST_VERIFY (single_threaded_2 ()); |
40 | if (single_threaded_3 != NULL) |
41 | TEST_VERIFY (!single_threaded_3 ()); |
42 | } |
43 | |
44 | static int |
45 | do_test (void) |
46 | { |
47 | TEST_VERIFY (__libc_single_threaded); |
48 | TEST_VERIFY (single_threaded_1 ()); |
49 | support_isolate_in_subprocess (callback: subprocess, NULL); |
50 | |
51 | void *handle_mod2 = xdlopen (filename: "tst-single_threaded-mod2.so" , RTLD_LAZY); |
52 | single_threaded_2 = xdlsym (handle: handle_mod2, symbol: "single_threaded_2" ); |
53 | TEST_VERIFY (single_threaded_2 ()); |
54 | support_isolate_in_subprocess (callback: subprocess, NULL); |
55 | |
56 | /* The current implementation treats the inner namespace as |
57 | multi-threaded. */ |
58 | void *handle_mod3 = dlmopen (LM_ID_NEWLM, file: "tst-single_threaded-mod3.so" , |
59 | RTLD_LAZY); |
60 | single_threaded_3 = xdlsym (handle: handle_mod3, symbol: "single_threaded_3" ); |
61 | TEST_VERIFY (!single_threaded_3 ()); |
62 | support_isolate_in_subprocess (callback: subprocess, NULL); |
63 | |
64 | xdlclose (handle: handle_mod3); |
65 | xdlclose (handle: handle_mod2); |
66 | |
67 | return 0; |
68 | } |
69 | |
70 | #include <support/test-driver.c> |
71 | |