public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Florian Weimer <fw@sourceware.org>
To: glibc-cvs@sourceware.org
Subject: [glibc] elf: add test for dl-printf
Date: Thu, 25 May 2023 17:10:06 +0000 (GMT)	[thread overview]
Message-ID: <20230525171006.B5C123856DC7@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=d2b1af43057c2bde5b180868a67d2b2bc2de95b7

commit d2b1af43057c2bde5b180868a67d2b2bc2de95b7
Author: Roy Eldar <royeldar0@gmail.com>
Date:   Thu May 25 17:41:59 2023 +0300

    elf: add test for dl-printf
    
    This patch checks _dl_debug_vdprintf, by passing various inputs to
    _dl_dprintf and comparing the output with invocations of snprintf.
    
    Signed-off-by: Roy Eldar <royeldar0@gmail.com>
    Reviewed-by: Florian Weimer <fweimer@redhat.com>

Diff:
---
 elf/Makefile               |  1 +
 elf/tst-dl-printf-static.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 79 insertions(+)

diff --git a/elf/Makefile b/elf/Makefile
index 8640138a72..7430453a6b 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -275,6 +275,7 @@ tests-static-normal := \
 
 tests-static-internal := \
   tst-dl_find_object-static \
+  tst-dl-printf-static \
   tst-ptrguard1-static \
   tst-stackguard1-static \
   tst-tls1-static \
diff --git a/elf/tst-dl-printf-static.c b/elf/tst-dl-printf-static.c
new file mode 100644
index 0000000000..da89c44183
--- /dev/null
+++ b/elf/tst-dl-printf-static.c
@@ -0,0 +1,78 @@
+/* Check _dl_debug_vdprintf.
+   Copyright The GNU Toolchain Authors.
+   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
+   <https://www.gnu.org/licenses/>.  */
+
+#include <ldsodefs.h>
+#include <limits.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <support/check.h>
+#include <support/xunistd.h>
+
+#define BUFSZ 64
+
+#define TEST(fmt, ...)                                                        \
+  do                                                                          \
+    {                                                                         \
+      char str1[BUFSZ], str2[BUFSZ];                                          \
+      int len1 = snprintf (str1, BUFSZ, fmt, __VA_ARGS__);                    \
+      TEST_VERIFY_EXIT (len1 >= 0);                                           \
+      TEST_VERIFY_EXIT (len1 < BUFSZ);                                        \
+      _dl_dprintf (fds[1], fmt, __VA_ARGS__);                                 \
+      ssize_t len2 = read (fds[0], str2, BUFSZ);                              \
+      TEST_VERIFY_EXIT (len2 >= 0);                                           \
+      TEST_VERIFY_EXIT (len2 < BUFSZ);                                        \
+      str2[len2] = '\0';                                                      \
+      TEST_COMPARE_STRING (str1, str2);                                       \
+    }                                                                         \
+  while (0)
+
+static int
+do_test (void)
+{
+  int fds[2];
+  xpipe (fds);
+  TEST ("%d", 0);
+  TEST ("%d", 1);
+  TEST ("%d", INT_MAX);
+  TEST ("%d", -1);
+  TEST ("%d", INT_MIN + 1);
+  TEST ("%d", INT_MIN);
+  TEST ("%u", 0U);
+  TEST ("%u", 1U);
+  TEST ("%u", UINT_MAX);
+  TEST ("%x", 0);
+  TEST ("%x", 1);
+  TEST ("%x", UINT_MAX);
+  TEST ("%ld", 0L);
+  TEST ("%ld", 1L);
+  TEST ("%ld", LONG_MAX);
+  TEST ("%ld", -1L);
+  TEST ("%ld", LONG_MIN + 1);
+  TEST ("%ld", LONG_MIN);
+  TEST ("%lu", 0UL);
+  TEST ("%lu", 1UL);
+  TEST ("%lu", ULONG_MAX);
+  TEST ("%lx", 0UL);
+  TEST ("%lx", 1UL);
+  TEST ("%lx", ULONG_MAX);
+  xclose (fds[0]);
+  xclose (fds[1]);
+  return 0;
+}
+
+#include <support/test-driver.c>

                 reply	other threads:[~2023-05-25 17:10 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230525171006.B5C123856DC7@sourceware.org \
    --to=fw@sourceware.org \
    --cc=glibc-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).