From patchwork Mon May 15 20:29:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roy Eldar X-Patchwork-Id: 1781675 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=KJ7oJc2w; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QKrdx6FRwz20dX for ; Tue, 16 May 2023 06:32:37 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 394DE385700F for ; Mon, 15 May 2023 20:32:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 394DE385700F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1684182755; bh=t29+fHhESA799MtuPob1OCQ91QVZbdMhP5Y7CiaOU/g=; 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=KJ7oJc2wkfwtLVjOGCXSyHSRvaQf3cX6dxkyjIefDrncIbB1cJJeksJomvJ7DWtLR BMqpcbbKRQZ9rYTCMucnTGFXEtbDAO1YBQ/JVO5ulxoDoC8FDezNWLDGj6k/kF25as m7VKvgOiRn0x3wlPvtEShMGSFflctlpVvAD6Mpbw= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id 5FD36385773C for ; Mon, 15 May 2023 20:32:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5FD36385773C Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-3063b5f32aaso8609125f8f.2 for ; Mon, 15 May 2023 13:32:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684182739; x=1686774739; 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=t29+fHhESA799MtuPob1OCQ91QVZbdMhP5Y7CiaOU/g=; b=fuLt5M66iU/dna+mwPqf+G9eeUihCXnt55sccYLI6V29FbO0ReZ5o0yZWl9E9hhfu0 X+cLBEqDz37MrgAeP9MojSUeSx64ZbXsUOxJMqqycMQbdM0Sm0j9s8WHl5ipWfcLFQKY PoOCqtvSvnnpRye/HjfaH7+hkdRVHDp0IEPWqZEK/q+4xhJdKnEfZNqRmOoFkrwlNO0I GAMHzz4F6+WQrYO2H+IhZ/VKsd8Utt8QQUqDV4LUhmDq3+6U9HIdZ8awP9qfzuKmPWta IjBMQ5n7TNjT3bDvA2u5FDSKSSJHgciKVkjmt22x/lj7HnMt9pSpB4wxTpBH1HG0tiL1 2qMw== X-Gm-Message-State: AC+VfDzrRYJedHT8RnZ0Qexlhtcwn9Qen4veU1LjF3RNMOg4UreEK+z6 JYAYMfyFsD0v8Ia8fDP+08M= X-Google-Smtp-Source: ACHHUZ7q2BBM7cUiAjtZPVp/Vfzd3qZV4c2jrz+Ii5XipJRCoEbShCPpht2/qDbexeNvO+FZ7Sl3Lg== X-Received: by 2002:adf:df0c:0:b0:306:2baf:b10c with SMTP id y12-20020adfdf0c000000b003062bafb10cmr23316328wrl.62.1684182738750; Mon, 15 May 2023 13:32:18 -0700 (PDT) Received: from DESKTOP-FOQ07IR.localdomain ([2a00:a041:e93f:fc3f:ad66:510d:e87c:71d]) by smtp.gmail.com with ESMTPSA id d12-20020a5d644c000000b003062c0ef959sm210776wrw.69.2023.05.15.13.32.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 May 2023 13:32:17 -0700 (PDT) To: fweimer@redhat.com Cc: Roy Eldar , libc-alpha@sourceware.org, carlos@redhat.com Subject: [PATCH] elf: add test for dl-printf Date: Mon, 15 May 2023 23:29:42 +0300 Message-Id: <20230515202942.8307-1-royeldar0@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <87mt2fq6qp.fsf@oldenburg.str.redhat.com> References: <87mt2fq6qp.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+incoming=patchwork.ozlabs.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 --- elf/Makefile | 1 + elf/tst-dl-printf-static.c | 75 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 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..a31759a006 --- /dev/null +++ b/elf/tst-dl-printf-static.c @@ -0,0 +1,75 @@ +/* Check _dl_debug_vdprintf. + Copyright (C) 2016-2023 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 +#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