From patchwork Mon Sep 23 09:02:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brendan Higgins X-Patchwork-Id: 11156453 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DEF4E912 for ; Mon, 23 Sep 2019 09:03:49 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BC2CB21907 for ; Mon, 23 Sep 2019 09:03:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="UK2H4JmD" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BC2CB21907 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-nvdimm-bounces@lists.01.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 867CA202F4FF4; Mon, 23 Sep 2019 02:06:21 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:4864:20::64a; helo=mail-pl1-x64a.google.com; envelope-from=3c4qixq4kdjw7naj96jdeccejockkcha.8kihejqt-jr9eiiheopo.wx.knc@flex--brendanhiggins.bounces.google.com; receiver=linux-nvdimm@lists.01.org Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id B7D69202ECFC3 for ; Mon, 23 Sep 2019 02:06:19 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id g7so70510plo.5 for ; Mon, 23 Sep 2019 02:03:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=kn+0r7CDFmPHQws2Z+HRgp03O+EE7Nh4RU07v5olnXQ=; b=UK2H4JmD8+WOv9z4GP6oT90ytRiYGqA9wmrSBgp1lmkE4yPq9fuWTFQdmCDgaSLE4l wDivaV1U6LtFrkmdGn6ORQYQ5HVpoxo5hPmoR+FeL+5Basjmi+x0YzDwxA2xcgAUmhaI UD5i7tVqHFJpGFHzAs1Dd6EIZuvrDir7LW3lqR/PDwodVPJ5xqDrieqBkoFDUJ4BTnYP uaA66laKrNgQQaFQM4NUTL88ry/C3A1uVhjLdCx3D/46BxJWwIVaJiO+tUiHFX32BOo3 7VLcLLMzz4I+8g83fPbp5FlEHzqzwNskQwe0epD31reK5c2ZJNy4NfNWvZwmBlOIU66r 9oFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=kn+0r7CDFmPHQws2Z+HRgp03O+EE7Nh4RU07v5olnXQ=; b=UHKA5qijRsD8SXQBTQ9CmiTU/VEvL36aTM4yh6RIV8No8fhfQmMGp+qGqizPvQ2U9P HW1WFcWl/Uxb1EcFvFC0RkS4JGMXZIukKnAMiRslOnP4k2J6vh+L6fR+aoBBdDWsXSUW h36AUwNGmVuKmx6KzeixCBefF86x/6JeE9i01iQ0egXinv7Ir2I4MCmvjgWQRHygmmJD CtSybaouz8U7/BmuP3ZGZeGJlFOWQ34QymUk5/fVWeOiWgI3M1WTIPNqcx6692okbeBV +sz0xBrIdo4E9ht2JhHzOUSWT5KmterT7HfjNQhA8BLyBfY3sX9qkD7VLcelzywQWnCx yHxw== X-Gm-Message-State: APjAAAWj1VMlJp5CRmGsoKwn5wul3QcLPbJyMVn0xb6haRVNFu8ypKOr OdXD0yr01bEx/EzhNkFCHRdrHPhtYrpU/bBLYFJJOg== X-Google-Smtp-Source: APXvYqw5hkGZ6d7ns2sOz8UJ01PHxqogvA1kzw2ON/JL9yOn7dOS+xz1Wch3S41MY3LBCY2PXLG83fwtsfvUctx2eoT1Lw== X-Received: by 2002:a65:620a:: with SMTP id d10mr27851195pgv.8.1569229427015; Mon, 23 Sep 2019 02:03:47 -0700 (PDT) Date: Mon, 23 Sep 2019 02:02:49 -0700 In-Reply-To: <20190923090249.127984-1-brendanhiggins@google.com> Message-Id: <20190923090249.127984-20-brendanhiggins@google.com> Mime-Version: 1.0 References: <20190923090249.127984-1-brendanhiggins@google.com> X-Mailer: git-send-email 2.23.0.351.gc4317032e6-goog Subject: [PATCH v18 19/19] kunit: fix failure to build without printk From: Brendan Higgins To: frowand.list@gmail.com, gregkh@linuxfoundation.org, jpoimboe@redhat.com, keescook@google.com, kieran.bingham@ideasonboard.com, mcgrof@kernel.org, peterz@infradead.org, robh@kernel.org, sboyd@kernel.org, shuah@kernel.org, tytso@mit.edu, yamada.masahiro@socionext.com X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sergey Senozhatsky , pmladek@suse.com, linux-doc@vger.kernel.org, amir73il@gmail.com, Brendan Higgins , dri-devel@lists.freedesktop.org, Alexander.Levin@microsoft.com, linux-kselftest@vger.kernel.org, Stephen Rothwell , linux-nvdimm@lists.01.org, khilman@baylibre.com, knut.omang@oracle.com, wfg@linux.intel.com, joel@jms.id.au, rientjes@google.com, jdike@addtoit.com, dan.carpenter@oracle.com, devicetree@vger.kernel.org, linux-kbuild@vger.kernel.org, Tim.Bird@sony.com, linux-um@lists.infradead.org, rostedt@goodmis.org, julia.lawall@lip6.fr, kunit-dev@googlegroups.com, richard@nod.at, torvalds@linux-foundation.org, rdunlap@infradead.org, linux-kernel@vger.kernel.org, daniel@ffwll.ch, mpe@ellerman.id.au, linux-fsdevel@vger.kernel.org, Joe Perches Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" Previously KUnit assumed that printk would always be present, which is not a valid assumption to make. Fix that by removing call to vprintk_emit, and calling printk directly. This fixes a build error[1] reported by Randy. For context this change comes after much discussion. My first stab[2] at this was just to make the KUnit logging code compile out; however, it was agreed that if we were going to use vprintk_emit, then vprintk_emit should provide a no-op stub, which lead to my second attempt[3]. In response to me trying to stub out vprintk_emit, Sergey Senozhatsky suggested a way for me to remove our usage of vprintk_emit, which led to my third attempt at solving this[4]. In my third version of this patch[4], I completely removed vprintk_emit, as suggested by Sergey; however, there was a bit of debate over whether Sergey's solution was the best. The debate arose due to Sergey's version resulting in a checkpatch warning, which resulted in a debate over correct printk usage. Joe Perches offered an alternative fix which was somewhat less far reaching than what Sergey had suggested and importantly relied on continuing to use %pV. Much of the debated centered around whether %pV should be widely used, and whether Sergey's version would result in object size bloat. Ultimately, we decided to go with Sergey's version. Reported-by: Randy Dunlap Link[1]: https://lore.kernel.org/linux-kselftest/c7229254-0d90-d90e-f3df-5b6d6fc0b51f@infradead.org/ Link[2]: https://lore.kernel.org/linux-kselftest/20190827174932.44177-1-brendanhiggins@google.com/ Link[3]: https://lore.kernel.org/linux-kselftest/20190827234835.234473-1-brendanhiggins@google.com/ Link[4]: https://lore.kernel.org/linux-kselftest/20190828093143.163302-1-brendanhiggins@google.com/ Cc: Stephen Rothwell Cc: Sergey Senozhatsky Cc: Joe Perches Cc: Tim.Bird@sony.com Signed-off-by: Brendan Higgins Acked-by: Randy Dunlap # build-tested Reviewed-by: Petr Mladek --- include/kunit/test.h | 5 ++-- lib/kunit/test.c | 57 +++++--------------------------------------- 2 files changed, 8 insertions(+), 54 deletions(-) diff --git a/include/kunit/test.h b/include/kunit/test.h index 8b7eb03d4971..dba48304b3bd 100644 --- a/include/kunit/test.h +++ b/include/kunit/test.h @@ -339,9 +339,8 @@ static inline void *kunit_kzalloc(struct kunit *test, size_t size, gfp_t gfp) void kunit_cleanup(struct kunit *test); -void __printf(3, 4) kunit_printk(const char *level, - const struct kunit *test, - const char *fmt, ...); +#define kunit_printk(lvl, test, fmt, ...) \ + printk(lvl "\t# %s: " fmt, (test)->name, ##__VA_ARGS__) /** * kunit_info() - Prints an INFO level message associated with @test. diff --git a/lib/kunit/test.c b/lib/kunit/test.c index b2ca9b94c353..c83c0fa59cbd 100644 --- a/lib/kunit/test.c +++ b/lib/kunit/test.c @@ -16,36 +16,12 @@ static void kunit_set_failure(struct kunit *test) WRITE_ONCE(test->success, false); } -static int kunit_vprintk_emit(int level, const char *fmt, va_list args) -{ - return vprintk_emit(0, level, NULL, 0, fmt, args); -} - -static int kunit_printk_emit(int level, const char *fmt, ...) -{ - va_list args; - int ret; - - va_start(args, fmt); - ret = kunit_vprintk_emit(level, fmt, args); - va_end(args); - - return ret; -} - -static void kunit_vprintk(const struct kunit *test, - const char *level, - struct va_format *vaf) -{ - kunit_printk_emit(level[1] - '0', "\t# %s: %pV", test->name, vaf); -} - static void kunit_print_tap_version(void) { static bool kunit_has_printed_tap_version; if (!kunit_has_printed_tap_version) { - kunit_printk_emit(LOGLEVEL_INFO, "TAP version 14\n"); + pr_info("TAP version 14\n"); kunit_has_printed_tap_version = true; } } @@ -64,10 +40,8 @@ static size_t kunit_test_cases_len(struct kunit_case *test_cases) static void kunit_print_subtest_start(struct kunit_suite *suite) { kunit_print_tap_version(); - kunit_printk_emit(LOGLEVEL_INFO, "\t# Subtest: %s\n", suite->name); - kunit_printk_emit(LOGLEVEL_INFO, - "\t1..%zd\n", - kunit_test_cases_len(suite->test_cases)); + pr_info("\t# Subtest: %s\n", suite->name); + pr_info("\t1..%zd\n", kunit_test_cases_len(suite->test_cases)); } static void kunit_print_ok_not_ok(bool should_indent, @@ -87,9 +61,7 @@ static void kunit_print_ok_not_ok(bool should_indent, else ok_not_ok = "not ok"; - kunit_printk_emit(LOGLEVEL_INFO, - "%s%s %zd - %s\n", - indent, ok_not_ok, test_number, description); + pr_info("%s%s %zd - %s\n", indent, ok_not_ok, test_number, description); } static bool kunit_suite_has_succeeded(struct kunit_suite *suite) @@ -133,11 +105,11 @@ static void kunit_print_string_stream(struct kunit *test, kunit_err(test, "Could not allocate buffer, dumping stream:\n"); list_for_each_entry(fragment, &stream->fragments, node) { - kunit_err(test, fragment->fragment); + kunit_err(test, "%s", fragment->fragment); } kunit_err(test, "\n"); } else { - kunit_err(test, buf); + kunit_err(test, "%s", buf); kunit_kfree(test, buf); } } @@ -504,20 +476,3 @@ void kunit_cleanup(struct kunit *test) kunit_resource_free(test, resource); } } - -void kunit_printk(const char *level, - const struct kunit *test, - const char *fmt, ...) -{ - struct va_format vaf; - va_list args; - - va_start(args, fmt); - - vaf.fmt = fmt; - vaf.va = &args; - - kunit_vprintk(test, level, &vaf); - - va_end(args); -}