Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp690018pxj; Fri, 11 Jun 2021 09:02:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyjuopiS06i/E2MIM2CrvYrzDu7HuAKoArV+KhcsZydc9kjHlPameDtgpvtdQyLmxa0L391 X-Received: by 2002:a05:6402:157:: with SMTP id s23mr4606266edu.282.1623427377057; Fri, 11 Jun 2021 09:02:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623427377; cv=none; d=google.com; s=arc-20160816; b=Iux5WUcIbSuuAUXbv7Ie/5ykJszvmwNZb0kErpx1hybUUu4qvrw0FFdgIu4YFJS7OD L23M6/YQvh6T4O4MCXDeVHiE5GdJY9dW9UV431zGUVEoCDE6+60nNI6mVYdqSCTAr1lz Mn482R3vqB+MKjvVJ6N+xV8tPxFROZ3gQriWKTlXxDX3de9SAjePooK64Dcyno30jeSG vk0lEq4g73mKRw9A2Hy+YUMXxY2s3NLOFUSqwHvUOCSiZvZlGLBKPl9QRS4WF0BaerR1 WYBBMQbOY6KxUsiSUEq4yg5RQ1/DMrfSKMjTwBaxQIa2ldn6MlNvukg8g8/+Xmb6Wor/ KpPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=K0Qhgz0qkkjhlCz/qt57hVJNwtPFE77g0Fto7efMVJQ=; b=vppcm44kgWSnTHyLjQkwTjwI1WyJHCsH1ywRdl1v2b6lWWCjaTWqRhCZ0hm7FTYR2p nV5G0KpUGQ6QZ25f5LRD7Y58JUQFVSthuYa71GPS2igHPKRgoo3xxNdK7dVZJuFtRW5J mdgYHa/SJSz4M8evGFhXWZr7490SRAKa1VVpq+WJPwHQ4mIrPWSHlJ5B0XaBBtXU7SlU FlzDPWp+nUQzgBoNilzZmu4vWQOxVJzTTetpp5oA6scOYBZNtZ7JiCCkPm36Pt9HaGyQ E7qXJg5GKSrlXDcH22K5th7u9tYr4J+Hm/hnZ+sdIvDZ8RrL3DE6lOWbxyNbio8Jx2/n DCYA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b16si5051328edw.36.2021.06.11.09.02.32; Fri, 11 Jun 2021 09:02:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230507AbhFKQCZ (ORCPT + 99 others); Fri, 11 Jun 2021 12:02:25 -0400 Received: from foss.arm.com ([217.140.110.172]:33800 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230492AbhFKQCY (ORCPT ); Fri, 11 Jun 2021 12:02:24 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D28521476; Fri, 11 Jun 2021 09:00:25 -0700 (PDT) Received: from entos-ampere-02.shanghai.arm.com (entos-ampere-02.shanghai.arm.com [10.169.214.103]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 6EF023F719; Fri, 11 Jun 2021 09:00:21 -0700 (PDT) From: Jia He To: Petr Mladek , Steven Rostedt , Sergey Senozhatsky , Andy Shevchenko , Rasmus Villemoes , Jonathan Corbet , Alexander Viro , Linus Torvalds Cc: "Peter Zijlstra (Intel)" , Eric Biggers , "Ahmed S. Darwish" , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Jia He Subject: [PATCH RFCv3 3/3] lib/test_printf: add test cases for '%pD' Date: Fri, 11 Jun 2021 23:59:53 +0800 Message-Id: <20210611155953.3010-4-justin.he@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210611155953.3010-1-justin.he@arm.com> References: <20210611155953.3010-1-justin.he@arm.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org After the behaviour of specifier '%pD' is changed to print full path of struct file, the related test cases are also updated. Given the string is prepended from the end of the buffer, the check of "wrote beyond the nul-terminator" should be skipped. Signed-off-by: Jia He --- lib/test_printf.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/test_printf.c b/lib/test_printf.c index ec0d5976bb69..3632bd6cf906 100644 --- a/lib/test_printf.c +++ b/lib/test_printf.c @@ -16,6 +16,7 @@ #include #include +#include #include #include @@ -34,6 +35,7 @@ KSTM_MODULE_GLOBALS(); static char *test_buffer __initdata; static char *alloced_buffer __initdata; +static bool is_prepend_buf; extern bool no_hash_pointers; @@ -78,7 +80,7 @@ do_test(int bufsize, const char *expect, int elen, return 1; } - if (memchr_inv(test_buffer + written + 1, FILL_CHAR, BUF_SIZE + PAD_SIZE - (written + 1))) { + if (!is_prepend_buf && memchr_inv(test_buffer + written + 1, FILL_CHAR, BUF_SIZE + PAD_SIZE - (written + 1))) { pr_warn("vsnprintf(buf, %d, \"%s\", ...) wrote beyond the nul-terminator\n", bufsize, fmt); return 1; @@ -496,6 +498,27 @@ dentry(void) test(" bravo/alfa| bravo/alfa", "%12pd2|%*pd2", &test_dentry[2], 12, &test_dentry[2]); } +static struct vfsmount test_vfsmnt = {}; + +static struct file test_file __initdata = { + .f_path = { .dentry = &test_dentry[2], + .mnt = &test_vfsmnt, + }, +}; + +static void __init +f_d_path(void) +{ + test("(null)", "%pD", NULL); + test("(efault)", "%pD", PTR_INVALID); + + is_prepend_buf = true; + test("/bravo/alfa |/bravo/alfa ", "%-14pD|%*pD", &test_file, -14, &test_file); + test(" /bravo/alfa| /bravo/alfa", "%14pD|%*pD", &test_file, 14, &test_file); + test(" /bravo/alfa|/bravo/alfa ", "%14pD|%-14pD", &test_file, &test_file); + is_prepend_buf = false; +} + static void __init struct_va_format(void) { @@ -779,6 +802,7 @@ test_pointer(void) ip(); uuid(); dentry(); + f_d_path(); struct_va_format(); time_and_date(); struct_clk(); -- 2.17.1