Linux: consolidate chown implementation
[glibc.git] / elf / tst-getauxval-static.c
blobb1d057585e46feb34fd03e7df9bbb15462d537d3
1 /* Test getauxval from a dynamic library after static dlopen.
2 Copyright (C) 2021-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 <dlfcn.h>
20 #include <errno.h>
21 #include <stdio.h>
22 #include <support/check.h>
23 #include <support/xdlfcn.h>
24 #include <sys/auxv.h>
26 unsigned long getauxval_wrapper (unsigned long type, int *errnop);
28 static int
29 do_test (void)
31 unsigned long outer_random = getauxval (AT_RANDOM);
32 if (outer_random == 0)
33 FAIL_UNSUPPORTED ("getauxval does not support AT_RANDOM");
35 unsigned long missing_auxv_type;
36 for (missing_auxv_type = AT_RANDOM + 1; ; ++missing_auxv_type)
38 errno = 0;
39 if (getauxval (missing_auxv_type) == 0 && errno != 0)
41 TEST_COMPARE (errno, ENOENT);
42 break;
45 printf ("info: first missing type: %lu\n", missing_auxv_type);
47 void *handle = xdlopen ("tst-auxvalmod.so", RTLD_LAZY);
48 void *ptr = xdlsym (handle, "getauxval_wrapper");
50 __typeof__ (getauxval_wrapper) *wrapper = ptr;
51 int inner_errno = 0;
52 unsigned long inner_random = wrapper (AT_RANDOM, &inner_errno);
53 TEST_COMPARE (outer_random, inner_random);
55 inner_errno = 0;
56 TEST_COMPARE (wrapper (missing_auxv_type, &inner_errno), 0);
57 TEST_COMPARE (inner_errno, ENOENT);
59 TEST_COMPARE (getauxval (AT_HWCAP), wrapper (AT_HWCAP, &inner_errno));
60 TEST_COMPARE (getauxval (AT_HWCAP2), wrapper (AT_HWCAP2, &inner_errno));
62 xdlclose (handle);
63 return 0;
66 #include <support/test-driver.c>