x86_64: Fix svml_d_cosh2_core_sse4.S code formatting
[glibc.git] / elf / tst-audit25a.c
blob49173e862516e876cea162b278b27c9f9211fe07
1 /* Check LD_AUDIT and LD_BIND_NOW.
2 Copyright (C) 2022 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 <array_length.h>
20 #include <errno.h>
21 #include <getopt.h>
22 #include <limits.h>
23 #include <inttypes.h>
24 #include <string.h>
25 #include <stdlib.h>
26 #include <support/capture_subprocess.h>
27 #include <support/check.h>
28 #include <support/xstdio.h>
29 #include <support/support.h>
30 #include <sys/auxv.h>
32 static int restart;
33 #define CMDLINE_OPTIONS \
34 { "restart", no_argument, &restart, 1 },
36 void tst_audit25mod1_func1 (void);
37 void tst_audit25mod1_func2 (void);
38 void tst_audit25mod2_func1 (void);
39 void tst_audit25mod2_func2 (void);
41 static int
42 handle_restart (void)
44 tst_audit25mod1_func1 ();
45 tst_audit25mod1_func2 ();
46 tst_audit25mod2_func1 ();
47 tst_audit25mod2_func2 ();
49 return 0;
52 static inline bool
53 startswith (const char *str, const char *pre)
55 size_t lenpre = strlen (pre);
56 size_t lenstr = strlen (str);
57 return lenstr < lenpre ? false : memcmp (pre, str, lenpre) == 0;
60 static int
61 do_test (int argc, char *argv[])
63 /* We must have either:
64 - One or four parameters left if called initially:
65 + path to ld.so optional
66 + "--library-path" optional
67 + the library path optional
68 + the application name */
70 if (restart)
71 return handle_restart ();
73 setenv ("LD_AUDIT", "tst-auditmod25.so", 0);
75 char *spargv[9];
76 int i = 0;
77 for (; i < argc - 1; i++)
78 spargv[i] = argv[i + 1];
79 spargv[i++] = (char *) "--direct";
80 spargv[i++] = (char *) "--restart";
81 spargv[i] = NULL;
82 TEST_VERIFY_EXIT (i < array_length (spargv));
85 struct support_capture_subprocess result
86 = support_capture_subprogram (spargv[0], spargv);
87 support_capture_subprocess_check (&result, "tst-audit25a", 0,
88 sc_allow_stderr);
90 /* tst-audit25a is build with -Wl,-z,lazy and tst-audit25mod1 with
91 -Wl,-z,now; so only tst_audit25mod3_func1 should be expected to
92 have LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT. */
93 TEST_COMPARE_STRING (result.err.buffer,
94 "la_symbind: tst_audit25mod3_func1 1\n"
95 "la_symbind: tst_audit25mod1_func1 0\n"
96 "la_symbind: tst_audit25mod1_func2 0\n"
97 "la_symbind: tst_audit25mod2_func1 0\n"
98 "la_symbind: tst_audit25mod4_func1 0\n"
99 "la_symbind: tst_audit25mod2_func2 0\n");
101 support_capture_subprocess_free (&result);
105 setenv ("LD_BIND_NOW", "1", 0);
106 struct support_capture_subprocess result
107 = support_capture_subprogram (spargv[0], spargv);
108 support_capture_subprocess_check (&result, "tst-audit25a", 0,
109 sc_allow_stderr);
111 /* With LD_BIND_NOW all symbols are expected to have
112 LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT. Also the resolution
113 order is done in breadth-first order. */
114 TEST_COMPARE_STRING (result.err.buffer,
115 "la_symbind: tst_audit25mod4_func1 1\n"
116 "la_symbind: tst_audit25mod3_func1 1\n"
117 "la_symbind: tst_audit25mod1_func1 1\n"
118 "la_symbind: tst_audit25mod2_func1 1\n"
119 "la_symbind: tst_audit25mod1_func2 1\n"
120 "la_symbind: tst_audit25mod2_func2 1\n");
122 support_capture_subprocess_free (&result);
125 return 0;
128 #define TEST_FUNCTION_ARGV do_test
129 #include <support/test-driver.c>