Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7635096imu; Mon, 3 Dec 2018 16:37:59 -0800 (PST) X-Google-Smtp-Source: AFSGD/W6LYlL20WPH5+C0jiqqUghNd7nPqIPunDRg1KXm+PjKfZtEhx+gNPHOzRKNNmTGgShfEsZ X-Received: by 2002:a62:7c47:: with SMTP id x68mr18194532pfc.209.1543883879705; Mon, 03 Dec 2018 16:37:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543883879; cv=none; d=google.com; s=arc-20160816; b=Wux74sMJVoSJE46S+xojm0xQ22OlfEK+QWDRIblDLpTfHoLV7EWLSZtfN1sWwQ/lYP cQJ4BCY5zZOWEJpzEuCGG6x7I4Bvuxd60Ti71I5sdoUAa58eouv2RBrkDqL36jQv6hkJ tJYNmGhcSo6Z2tRbLfolTGPIVlv8uEnLTw9vPjBVcthg+/7EV+fmFk1HQRfoVaAJv2It EBlDYRTAvVX1up5pRhz1gstxs4cJ7eHuEQ2YyRs/u5eIMhK3W7YNZE/Ht+7o8j2QPSuD f/iIdrJANnVvUn93FK+Fy/Hr0irE/0gVS/0SeYhmYaXu1VVevG8EkiKBHq3e09stfjCG LzYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=OctTzfGiKx9+SW307GLGZ4f1lZnGP2F7kKB6Nur7RAA=; b=ZAdEZccEZdGya1rg5K2qU9IG/S/02PLEcBanPq0HjOKK6bnBdiSCw4Mwya4OYDafVB mnja1UCHJjayTF6hXveY7IALzMB1ZL8o943Ztnn/gRicg4UUL0IW2+E9LclKbbF2kPHP lKvu+Ha3jxROe6tSs8/I1zMMVddPQYTQQl27P7ww4vqWb8rAEahPh0fkMARWGq1pdZYl XKaSsXHs0vElbTf2prUGw7loW6bT67yrUjiADltpv3YYBihyN52n8e3EGr6UT2s8nRtH wfXp/kQDVx+RF0tlJcbnaxzBT3u+2OD5vWUsmuiZeV7czKe5pYodmPRcHxxsOjqvE93E bgmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="E/wBMkJj"; 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 d39si10920653pla.278.2018.12.03.16.37.43; Mon, 03 Dec 2018 16:37:59 -0800 (PST) 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="E/wBMkJj"; 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 S1726075AbeLDAfZ (ORCPT + 99 others); Mon, 3 Dec 2018 19:35:25 -0500 Received: from mail-oi1-f193.google.com ([209.85.167.193]:34091 "EHLO mail-oi1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725976AbeLDAfY (ORCPT ); Mon, 3 Dec 2018 19:35:24 -0500 Received: by mail-oi1-f193.google.com with SMTP id h25so12772968oig.1 for ; Mon, 03 Dec 2018 16:35:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=OctTzfGiKx9+SW307GLGZ4f1lZnGP2F7kKB6Nur7RAA=; b=E/wBMkJjigcH7Rxq7ZQW0RsQay8T+t+NBXjok5bs1I6tpMH4rf2r4S6Cz+YjLGFxyg FNphztIQi+sWkcTlJfPzV0aq9mYKdatlLJ5m8XrxHrJ+ZJtwDISc3EXlJC7cwAs0aLB5 mqdQzcZVH1uNiH7XJjXKrpWVJOR4zJMF3i09E0wGH5Zys9nBH8zZrC10E9T//eI6YYAR aNp5YYHmBo0b0rWH4NqQrX4BPXxkE+bQxwNcuXzDzr0889sZirYPnMs4rkj2vMcfaNzq FXXP06IFvXnTy6wFQHTVfCeT0x3BIgtXvIkBquMBs4MFLoL0BKfylqywnY3FXJEL07Sv StLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=OctTzfGiKx9+SW307GLGZ4f1lZnGP2F7kKB6Nur7RAA=; b=pvEfPjj8B9YiI+hPQ75g9FsutsIDLerYfhpTZPAm9SBsQqCCJT/aF0UtsH/Kt2LZoM dovzG1uvieO7/hTQonsorkqhrySEj+Ci1md1W/e89AXEwV6Vc1SZ/WE4lXZUVhT+hPPF 9T5SzufnKJ1MKm04tFcvbaB9Fh2IbEkdBt/nzBAyb8TEphfBxtVAz8goMyVAA7oMJMEA WZFrGsTMxxzmBbE0cpK7Kds3QrBsHZvVx2eBe37sah6UFQ5mu7EMnpU06mX7gPdCLlTd IoWIbXHOkusfUDeIiZFMw8/gcv1Q7JUdh5GvTxOynyGMLIKo8sHkfX85QyNY2pca1Vn6 iDVg== X-Gm-Message-State: AA+aEWYy2QwK/1FvR1VOPiTnEDU2VZzOlszFA9dSsL8PBKGwCeW+nDfn cMSs5hc2roACKYJfholmtB/gz8yj664rg6I6WvZl2A== X-Received: by 2002:aca:bd41:: with SMTP id n62mr11688409oif.348.1543883723458; Mon, 03 Dec 2018 16:35:23 -0800 (PST) MIME-Version: 1.0 References: <20181128193636.254378-1-brendanhiggins@google.com> <20181128193636.254378-4-brendanhiggins@google.com> <20181130032924.GH18410@garbanzo.do-not-panic.com> <20181203105517.vbedwygttxxbdtan@pathway.suse.cz> In-Reply-To: <20181203105517.vbedwygttxxbdtan@pathway.suse.cz> From: Brendan Higgins Date: Mon, 3 Dec 2018 16:35:12 -0800 Message-ID: Subject: Re: [RFC v3 03/19] kunit: test: add string_stream a std::stream like string builder To: Petr Mladek Cc: mcgrof@kernel.org, Greg KH , Kees Cook , shuah@kernel.org, Joel Stanley , mpe@ellerman.id.au, joe@perches.com, brakmo@fb.com, rostedt@goodmis.org, Tim.Bird@sony.com, khilman@baylibre.com, Julia Lawall , linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, Linux Kernel Mailing List , jdike@addtoit.com, richard@nod.at, linux-um@lists.infradead.org, Daniel Vetter , dri-devel@lists.freedesktop.org, Rob Herring , dan.j.williams@intel.com, linux-nvdimm@lists.01.org, kieran.bingham@ideasonboard.com, Frank Rowand , Knut Omang 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 On Mon, Dec 3, 2018 at 2:55 AM Petr Mladek wrote: > > On Thu 2018-11-29 19:29:24, Luis Chamberlain wrote: > > On Wed, Nov 28, 2018 at 11:36:20AM -0800, Brendan Higgins wrote: > > > A number of test features need to do pretty complicated string printing > > > where it may not be possible to rely on a single preallocated string > > > with parameters. > > > > > > So provide a library for constructing the string as you go similar to > > > C++'s std::string. > > > > Hrm, what's the potential for such thing actually being eventually > > generically useful for printk folks, I wonder? Petr? > > printk() is a bit tricky: > > + It should work in any context. Any additional lock adds risk of a > deadlock. Especially the NMI and scheduler contexts are problematic. > There are problems with any other code that might be called > from console drivers and calls printk() under a lock. > > + It should work also when the system is out of memory. Especially > atomic context is problematic because we could not wait for > memory reclaim or swap. > > + We also do to the best effort to get the message out on the > console. It is important when the system is about to die. > Any extra buffering layer might cause delay and avoid seeing the > message. > > From this point of views, this API is not generally usable with printk(). Yeah, that makes sense. I wouldn't really expect this to work well in those cases. > Now, the question is how many of the above fits also for unit testing. > At least, you might need to be careful when allocating memory in > atomic context. True, but this is only supposed to be used for constructing expectation failure messages which should only happen from a non-atomic context. > > BTW: There are more existing printk APIs: Well, I admit the they are > not easily reusable in unit testing: > > + printk() is old, crappy code, complicated with all the > cornercases and consoles. > > + include/linux/seq_buf.h is simple buffering. It is used primary > for sysfs output. It might be usable if you add support for > loglevel and use big enough buffer. I quess that you should > flush the buffer regularly anyway. > > + trace_printk() uses lockless per-CPU buffers. It currently does not > support loglevels. But it might be pretty interesting choice as well. > > > I do not say that you have to use one of the existing API. But you > might consider them if you encouter any problems and maintaining > your variant gets complicated. Alright, I will take a look. Thanks!