1 /* Test running statically linked programs using ld.so.
2 Copyright (C) 2021-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 <support/check.h>
20 #include <support/support.h>
21 #include <support/capture_subprocess.h>
22 #include <string.h>
23 #include <stdlib.h>
24
25 static int
do_test(void)26 do_test (void)
27 {
28 char *ldconfig_path = xasprintf ("%s/elf/ldconfig", support_objdir_root);
29
30 {
31 char *argv[] = { (char *) "ld.so", ldconfig_path, (char *) "--help", NULL };
32 struct support_capture_subprocess cap
33 = support_capture_subprogram (support_objdir_elf_ldso, argv);
34 support_capture_subprocess_check (&cap, "no --argv0", 0, sc_allow_stdout);
35 puts ("info: output without --argv0:");
36 puts (cap.out.buffer);
37 TEST_VERIFY (strstr (cap.out.buffer, "Usage: ldconfig [OPTION...]\n")
38 == cap.out.buffer);
39 support_capture_subprocess_free (&cap);
40 }
41
42 {
43 char *argv[] =
44 {
45 (char *) "ld.so", (char *) "--argv0", (char *) "ldconfig-argv0",
46 ldconfig_path, (char *) "--help", NULL
47 };
48 struct support_capture_subprocess cap
49 = support_capture_subprogram (support_objdir_elf_ldso, argv);
50 support_capture_subprocess_check (&cap, "with --argv0", 0, sc_allow_stdout);
51 puts ("info: output with --argv0:");
52 puts (cap.out.buffer);
53 TEST_VERIFY (strstr (cap.out.buffer, "Usage: ldconfig-argv0 [OPTION...]\n")
54 == cap.out.buffer);
55 support_capture_subprocess_free (&cap);
56 }
57
58 free (ldconfig_path);
59 return 0;
60 }
61
62 #include <support/test-driver.c>
63