Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp5874105ybl; Tue, 27 Aug 2019 10:52:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqyIt8RY6ZHgttfe7mRwT7gb7Qh5YW4YJ1xtPAouMhDKgs5TXZcb2RgDOy2NtP366Fn7mP0F X-Received: by 2002:a17:902:a01:: with SMTP id 1mr76973plo.317.1566928366365; Tue, 27 Aug 2019 10:52:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566928366; cv=none; d=google.com; s=arc-20160816; b=Ze56IJG+GJY2H2pTFnAVxRSxs48srs+65bTvheiaKRqaZdm8RhbZHxAwMVcWl0ayE4 buhDFc44wUDa6/SPEiGKsG1ozQaQsjZQ3L9xWuNWCNizYkLjDj9/MMqQais2TMTAge9F 0a74VT/1aOyb+mup+gCZZjP7j9PaNRx/6mBlo/BEjG/lnyUFofQBLM1JEYJ+kMlfDlJS QLBuF6lK3JVcW3f2JjZcEGEsvXv/5A26dM8tYBxMibNfOsF0efo2GN2K9NQ3MxK/H78w NDHDtMosRJUDKWgL78dWNKxEKLip1vJIekUVZwQ1eddFEO4WtAnQe9AGuMaCgA4uv9gH XjBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:mime-version :message-id:date:dkim-signature; bh=kBdnxSxfNrFWkVEGyrNiJF2qYM16TCNtAyDwbg8s3Rk=; b=tln+meVVN72cqg0yfBbij/x38gklE3aXbZqGmuYgdjq7bk47/SOgKr498FR7VSNt+t RJkPpqoM1F0zOUS6ieV/r0mjzybPY/sRsW5IJ76MqkrBEjsu6RrjaGEvGh+fobajtDnI LAXPs7bT1ffXjS/idBSdKgdubhGaZcl4r2a0YvpaU/7DD6/eAR/oPZASiwMyj4/V2Dgf R+81lcPOSXKzqF1uVaKCbb0+VC+GKduSjfLjT0SPcHhylLb8DfJiX8t4GikesTk45F37 MKrKm3+/+k1nVKsybKY7U1KMkH6qP5OVYsSQq0qRP8rfofi8xYhO6PtwCpFoZDqWq81V T+Ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="HOn/Th1Q"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d4si11768pgc.75.2019.08.27.10.52.30; Tue, 27 Aug 2019 10:52:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="HOn/Th1Q"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730505AbfH0Rts (ORCPT + 99 others); Tue, 27 Aug 2019 13:49:48 -0400 Received: from mail-pl1-f202.google.com ([209.85.214.202]:35864 "EHLO mail-pl1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727401AbfH0Rtr (ORCPT ); Tue, 27 Aug 2019 13:49:47 -0400 Received: by mail-pl1-f202.google.com with SMTP id z7so1046685plo.3 for ; Tue, 27 Aug 2019 10:49:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=kBdnxSxfNrFWkVEGyrNiJF2qYM16TCNtAyDwbg8s3Rk=; b=HOn/Th1QKNcSzNR3M0ivHvPiRM2bzQGo8BrsuGTsP0yVKcaY9EThjCVmrGsqv68SRl 08AFZc+Ve9nLv+iuxMWWoQ8TfuoczhlgUagEpq4zf93CTKd5WfjAM71R3eFW1bl8x2kv a/If01mUOn+T/zWriHxXPvCBW8ssCgL7q7AQF+09Dzd8dYLWrmJQrx6Fr4RYWfa9nqr4 fHQiDDcS7vc9ks9Y0T0YBiDTEyShWi/5rmpo4XF6r+rl1EdZOn8wwU5cJSG0qA+IYNtL 7DxPEE9WqIzJhTBvuCB2Y9gMYcXYLFadNIklLwxHR7pfGvIJdBAaoSAsh5dWfLh2K7W1 Ihjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=kBdnxSxfNrFWkVEGyrNiJF2qYM16TCNtAyDwbg8s3Rk=; b=cR1kZdZDW4OPLLQSZA1hKC5bZMtxBReIt5RughMsKPF3RgYsKYQ3TrF2F4jAJjMuPp JEY32LFFr3xEjJkZhzHqwhbNTyBz/T4a6TGY7gCT33Wu2VlFQfjWEoCsMxz69ulOpuT7 UWfH4wbXoKaKhc8E8Mh33ezaannUmD7nrSVx/JBrE/rsH64KLyzH8/gvaI8DXSIZ1pAK 822xpmDA6hQkUvrF2MHxzv0t5cJgdUfWTHjtQdA2473ac2h3GkEueJmVvChw5F5hvl2t ZxRfXPki2ghnIJL2I+0zze44Vjj8Nln3WdtotX1jCvG60sAuQlLrcXqOG7Dfs43g5H58 G+ZQ== X-Gm-Message-State: APjAAAXi7IZOB+jLU02XSbVlDWsmsIh93sotZaIZw+dVJE1MwWEdnVs+ RCcVaLTDx2tblNxHs9V7FJkrrFniDN9lliKquCSkKg== X-Received: by 2002:a63:595d:: with SMTP id j29mr22734669pgm.134.1566928186602; Tue, 27 Aug 2019 10:49:46 -0700 (PDT) Date: Tue, 27 Aug 2019 10:49:32 -0700 Message-Id: <20190827174932.44177-1-brendanhiggins@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.23.0.187.g17f5b7556c-goog Subject: [PATCH v1] kunit: fix failure to build without printk From: Brendan Higgins To: shuah@kernel.org Cc: kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, frowand.list@gmail.com, sboyd@kernel.org, Brendan Higgins , Randy Dunlap , Stephen Rothwell Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Previously KUnit assumed that printk would always be present, which is not a valid assumption to make. Fix that by ifdefing out functions which directly depend on printk core functions similar to what dev_printk does. Reported-by: Randy Dunlap Link: https://lore.kernel.org/linux-kselftest/0352fae9-564f-4a97-715a-fabe016259df@kernel.org/T/#t Cc: Stephen Rothwell Signed-off-by: Brendan Higgins --- include/kunit/test.h | 7 +++++++ kunit/test.c | 41 ++++++++++++++++++++++++----------------- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/include/kunit/test.h b/include/kunit/test.h index 8b7eb03d4971..339af5f95c4a 100644 --- a/include/kunit/test.h +++ b/include/kunit/test.h @@ -339,9 +339,16 @@ static inline void *kunit_kzalloc(struct kunit *test, size_t size, gfp_t gfp) void kunit_cleanup(struct kunit *test); +#ifdef CONFIG_PRINTK void __printf(3, 4) kunit_printk(const char *level, const struct kunit *test, const char *fmt, ...); +#else +static inline void __printf(3, 4) kunit_printk(const char *level, + const struct kunit *test, + const char *fmt, ...) +{} +#endif /** * kunit_info() - Prints an INFO level message associated with @test. diff --git a/kunit/test.c b/kunit/test.c index b2ca9b94c353..0aa1caf07a6b 100644 --- a/kunit/test.c +++ b/kunit/test.c @@ -16,6 +16,7 @@ static void kunit_set_failure(struct kunit *test) WRITE_ONCE(test->success, false); } +#ifdef CONFIG_PRINTK static int kunit_vprintk_emit(int level, const char *fmt, va_list args) { return vprintk_emit(0, level, NULL, 0, fmt, args); @@ -40,6 +41,29 @@ static void kunit_vprintk(const struct kunit *test, kunit_printk_emit(level[1] - '0', "\t# %s: %pV", test->name, vaf); } +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); +} +#else /* CONFIG_PRINTK */ +static inline int kunit_printk_emit(int level, const char *fmt, ...) +{ + return 0; +} +#endif /* CONFIG_PRINTK */ + static void kunit_print_tap_version(void) { static bool kunit_has_printed_tap_version; @@ -504,20 +528,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); -} -- 2.23.0.187.g17f5b7556c-goog