1 /* Test error reporting for dlsym, dlvsym failures.
2 Copyright (C) 2016 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 <http://www.gnu.org/licenses/>. */
20 #include <gnu/lib-names.h>
25 /* Used to disambiguate symbol names. */
29 test_one (void *handle
, const char *name
, void *(func
) (void *, const char *),
34 snprintf (symbol
, sizeof (symbol
), "no_such_symbol_%d", counter
);
35 char *expected_message
;
36 if (asprintf (&expected_message
, ": undefined symbol: %s%s",
39 printf ("error: asprintf: %m\n");
43 void *addr
= func (handle
, symbol
);
46 printf ("error: %s: found symbol \"no_such_symbol\"\n", name
);
49 const char *message
= dlerror ();
52 printf ("error: %s: missing error message\n", name
);
55 const char *message_without_path
= strchrnul (message
, ':');
56 if (strcmp (message_without_path
, expected_message
) != 0)
58 printf ("error: %s: unexpected error message: %s\n", name
, message
);
61 free (expected_message
);
66 printf ("error: %s: unexpected error message: %s\n", name
, message
);
72 test_handles (const char *name
, void *(func
) (void *, const char *),
75 test_one (RTLD_DEFAULT
, name
, func
, suffix
);
76 test_one (RTLD_NEXT
, name
, func
, suffix
);
78 void *handle
= dlopen (LIBC_SO
, RTLD_LAZY
);
81 printf ("error: cannot dlopen %s: %s\n", LIBC_SO
, dlerror ());
84 test_one (handle
, name
, func
, suffix
);
89 dlvsym_no_such_version (void *handle
, const char *name
)
91 return dlvsym (handle
, name
, "NO_SUCH_VERSION");
95 dlvsym_glibc_private (void *handle
, const char *name
)
97 return dlvsym (handle
, name
, "GLIBC_PRIVATE");
103 test_handles ("dlsym", dlsym
, "");
104 test_handles ("dlvsym", dlvsym_no_such_version
,
105 ", version NO_SUCH_VERSION");
106 test_handles ("dlvsym", dlvsym_glibc_private
,
107 ", version GLIBC_PRIVATE");
113 #define TEST_FUNCTION do_test ()
114 #include "../test-skeleton.c"