From patchwork Thu May 25 14:41:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roy Eldar X-Patchwork-Id: 70080 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7706C3858291 for ; Thu, 25 May 2023 14:43:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7706C3858291 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1685025800; bh=kl8KemRuAJDN5C4o/Hxdr3nXPuSMm6QxuwZaLQzClOY=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=YkkSDonrgjMt5/GDRhCkqRg9l2pc9nQxEQYRwPtDBlC3lLy7xlahpY6bj0lIaYIqC YsXiW8TzW7XY1Q4ucmw/J/0PB+myfdUM2yalU7WLvgyS4abl38iZnEMO9/rB49KJH0 /wg9ax65/njq++Icn1aDhbse30ysT5rY/cESg/NU= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id EF4E3385840F for ; Thu, 25 May 2023 14:42:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EF4E3385840F Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-309550d4f73so825009f8f.1 for ; Thu, 25 May 2023 07:42:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685025774; x=1687617774; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kl8KemRuAJDN5C4o/Hxdr3nXPuSMm6QxuwZaLQzClOY=; b=Lw6T96wvj5pJ04+e3H1roKY3yhoTtAb9cLZlo4iVzOiBgjgkZdKUXwVZ6fO6c9FgLk vu7m6DVJXb/n1r+WaCWRWMmOg1It0EXZX1QWMWsNnVLtsS6XR70NQvJfrk4h8Yrqang5 0nxmVSbeU8AS+C6V9u7dCsA604Vta2fHRN3YDy7KhEPaup7f5g/dyUYMeljb35zLT7ti 63UuyIheiiL22hsMVQjx3s+3aXCYp0qhPPqDIhJvOOK/pcTHxHtd3MYfGdOfBZZ3kTns 3ozLPsd0t88GQAYob7sJ0+P+VQ7lpyEkAg4fr24rBRwclWS7ZR8SOvwcK4mnB6zgoqtr 8/Qw== X-Gm-Message-State: AC+VfDzwmZdTmcfD0ywGVSYuIfW2IpUAG0+nHK3ef6rLECbxzFCyZkG+ POQU54eoot2L+LXL4IVtMnez5aY7Fote8w== X-Google-Smtp-Source: ACHHUZ68kLkyKiTuRuaMSLv7or839DebsHYVIr2HEF1KtIbdcVw00bBOXOfc34fUYh0/73ltagH78w== X-Received: by 2002:a5d:65c8:0:b0:30a:8fc5:4411 with SMTP id e8-20020a5d65c8000000b0030a8fc54411mr2421819wrw.32.1685025774447; Thu, 25 May 2023 07:42:54 -0700 (PDT) Received: from DESKTOP-FOQ07IR.localdomain ([2a00:a041:e93f:fc3f:c8bb:8ad7:8b86:a3a]) by smtp.gmail.com with ESMTPSA id 2-20020a05600c028200b003f42cc3262asm5873447wmk.34.2023.05.25.07.42.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 May 2023 07:42:53 -0700 (PDT) To: fweimer@redhat.com Cc: Roy Eldar , libc-alpha@sourceware.org, carlos@redhat.com Subject: [PATCH v2] elf: add test for dl-printf Date: Thu, 25 May 2023 17:41:59 +0300 Message-Id: <20230525144159.2935-2-royeldar0@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <87jzwwq2ho.fsf@oldenburg.str.redhat.com> References: <87jzwwq2ho.fsf@oldenburg.str.redhat.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Roy Eldar via Libc-alpha From: Roy Eldar Reply-To: Roy Eldar Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" 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 Reviewed-by: Florian Weimer --- elf/Makefile | 1 + elf/tst-dl-printf-static.c | 78 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 elf/tst-dl-printf-static.c diff --git a/elf/Makefile b/elf/Makefile index 396ec51424..90ccd65db1 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 + . */ + +#include +#include +#include +#include +#include +#include + +#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