From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1944) id CE7A0385042D; Thu, 19 May 2022 09:52:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CE7A0385042D Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Szabolcs Nagy To: glibc-cvs@sourceware.org Subject: [glibc/release/2.35/master] linux: Add a getauxval test [BZ #23293] X-Act-Checkin: glibc X-Git-Author: Szabolcs Nagy X-Git-Refname: refs/heads/release/2.35/master X-Git-Oldrev: f5f7144dfcbf2a11fd2c17316c213928307c1db3 X-Git-Newrev: 2b128a7d30f5f808c5246034f71d249010521f1b Message-Id: <20220519095207.CE7A0385042D@sourceware.org> Date: Thu, 19 May 2022 09:52:07 +0000 (GMT) X-BeenThere: glibc-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Glibc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 May 2022 09:52:07 -0000 https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=2b128a7d30f5f808c5246034f71d249010521f1b commit 2b128a7d30f5f808c5246034f71d249010521f1b Author: Szabolcs Nagy Date: Tue May 3 13:18:04 2022 +0100 linux: Add a getauxval test [BZ #23293] This is for bug 23293 and it relies on the glibc test system running tests via explicit ld.so invokation by default. Reviewed-by: Florian Weimer Reviewed-by: Adhemerval Zanella (cherry picked from commit 9faf5262c77487c96da8a3e961b88c0b1879e186) Diff: --- sysdeps/unix/sysv/linux/Makefile | 1 + sysdeps/unix/sysv/linux/tst-getauxval.c | 74 +++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index 7122f55975..e897f55f3a 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -126,6 +126,7 @@ tests += tst-clone tst-clone2 tst-clone3 tst-fanotify tst-personality \ tst-prctl \ tst-scm_rights \ tst-epoll \ + tst-getauxval \ # tests # Test for the symbol version of fcntl that was replaced in glibc 2.28. diff --git a/sysdeps/unix/sysv/linux/tst-getauxval.c b/sysdeps/unix/sysv/linux/tst-getauxval.c new file mode 100644 index 0000000000..c4b6195743 --- /dev/null +++ b/sysdeps/unix/sysv/linux/tst-getauxval.c @@ -0,0 +1,74 @@ +/* Basic test for getauxval. + Copyright (C) 2022 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include + +static int missing; +static int mismatch; + +static void +check_nonzero (unsigned long t, const char *s) +{ + unsigned long v = getauxval (t); + printf ("%s: %lu (0x%lx)\n", s, v, v); + if (v == 0) + missing++; +} + +static void +check_eq (unsigned long t, const char *s, unsigned long want) +{ + unsigned long v = getauxval (t); + printf ("%s: %lu want: %lu\n", s, v, want); + if (v != want) + mismatch++; +} + +#define NZ(x) check_nonzero (x, #x) +#define EQ(x, want) check_eq (x, #x, want) + +static int +do_test (void) +{ + /* These auxv entries should be non-zero on Linux. */ + NZ (AT_PHDR); + NZ (AT_PHENT); + NZ (AT_PHNUM); + NZ (AT_PAGESZ); + NZ (AT_ENTRY); + NZ (AT_CLKTCK); + NZ (AT_RANDOM); + NZ (AT_EXECFN); + if (missing) + FAIL_EXIT1 ("Found %d missing auxv entries.\n", missing); + + /* Check against syscalls. */ + EQ (AT_UID, getuid ()); + EQ (AT_EUID, geteuid ()); + EQ (AT_GID, getgid ()); + EQ (AT_EGID, getegid ()); + if (mismatch) + FAIL_EXIT1 ("Found %d mismatching auxv entries.\n", mismatch); + + return 0; +} + +#include