Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2601215pxa; Fri, 7 Aug 2020 15:42:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwpY3Cfg8LFUOm7VGRQtvyBTBfNPt0mXYStrvJ4qSskdxMT6Qwjw1x8qRDrGg9BXWWIPD4d X-Received: by 2002:aa7:c74f:: with SMTP id c15mr11153092eds.331.1596840122112; Fri, 07 Aug 2020 15:42:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596840122; cv=none; d=google.com; s=arc-20160816; b=SI9f52Ro2o7yVjiGlES5/PEDM2CmmpgVdPAkVrPvx7gIQybQMeBzJrgI338UO7u3hF 6WhUhiUPRBY5/Dw0ZdqBJ9w9gMuRumr/oOzFfJ4Fcr2z67At6MrcFMBwGoVvn0JlQgoh Ge8TsvXiugzLuIkOgXPJVYgcOrBGNegxHy72x+OPzt9eN204aWsLF4yAkdz78MSA+RqL DmK7Gnj6Ja1/uccAjrWlGhQfXc8P2gWU+sWw5kQn7DUTYmctuctrQiXv/A7XbQHWa27D U24NfMa/KmYGW+JbZVqqL/fYxKhy2DWaC1noB294kqbsI844uo9WnMxa+WRYmFXBL6mG UShw== 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=c6hoLzC3a/GCKNCcphDjG0464om/VNNdDtUdrarqISg=; b=N5rCr1YiIgiY/NuTnytdaBBJrwJB9zE8gxQuDHnwdKnMtaMHUccNxNGQ0X+YN7RKFi bn1ph3FuTYXu8vdD4tY6J5b7m41W2wAZQE/jwoO90vBh1FSAT9kVeDHj/CFXiNiv4UIu hKNtvNX5e7u/g0gfExesvSDu2xzKDE4dm9G41ROOgIlNa7zej0Qyt6dQDN/ogqd9gA7G b0owUjTM6CiIbHKypQ9uR65mwcx1CXczbkFcL3O+Oz6pKK+maMUSV7VG3VNu4pNByqpd Drj61WYZ2q/4+CeauNxaW5gdVzrrSYKpPXlQrFjzXqJKFjyKd8fWHcQlOdVIy74MyzWW 3tNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=XWqmuEOs; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ce15si6661643edb.291.2020.08.07.15.41.39; Fri, 07 Aug 2020 15:42:02 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=XWqmuEOs; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726186AbgHGWk5 (ORCPT + 99 others); Fri, 7 Aug 2020 18:40:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726045AbgHGWk4 (ORCPT ); Fri, 7 Aug 2020 18:40:56 -0400 Received: from mail-ot1-x344.google.com (mail-ot1-x344.google.com [IPv6:2607:f8b0:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FA0AC061756 for ; Fri, 7 Aug 2020 15:40:56 -0700 (PDT) Received: by mail-ot1-x344.google.com with SMTP id k12so2852096otr.1 for ; Fri, 07 Aug 2020 15:40:56 -0700 (PDT) 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=c6hoLzC3a/GCKNCcphDjG0464om/VNNdDtUdrarqISg=; b=XWqmuEOsFgQl/KW1XFg0sh1mkcTZV+lCf9Km2jxbUnibk7lWts4NReaGkR/UvTRGQs 00p62VfebsT6n/g9aykuVo7Ol+1xtiR2X3LIjW6IrZAwQS1iotmX711XuK0F+QfE33x5 RsRRNX27kjK7iMwcjyKYiD9OFtxAiHkVmRzGAiUeIB859Z6ClGPUd9TCdM3YzcJ5hTJP 7z+JtIvoDfHWjZxzIY25FQ4DJSLptHCO/VYQtA+5JG/Y2D+7uRX+W7sYH/YH4qWnDPeN /Fh385x9FZpPDPB8B8NO+vdHzncxlyooK5Bk0B0tKLw5qXkvOT+lNEbeqndiijbRcZ0Y i3Jg== 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=c6hoLzC3a/GCKNCcphDjG0464om/VNNdDtUdrarqISg=; b=GPIXQNdJnm3YFBmiQIc6XmOetCiDIboXpGxA2qAuRmudTyB0txC8Z39Cu7aiSEYwGp e0jVgh+OJdreD1/KUPWaXp6canjpc+6vH2jm0ygeIJR3DPf/TE4GFXeTg2XEYwxTB958 Y/X/oWm2Y7Tqxss33p+vK6KVsKKKU9Bn9vmH9blafMXxJTGCU+UbflVBhcTeMXGNEGcH sIMFhPg/CUFL8c49SjzEawxrXYZrVjEiIeMe3W0WDg7Qomr43edJtgJyCx3JTY8ndoEL 7s58TLseo7k46dkDcC69DQypc34N3VsJpvpha5b/iGV269R51TtHKit0DY1B7PSOyrxD 4U5g== X-Gm-Message-State: AOAM5316hftym2A6YKcdKo8iEn/aRi0ioTHdsl6S4vEIOPhJuBkWrU14 Og481M+39YGyxnwr08ZHRArY46Z8bW3syvirAOpZDA== X-Received: by 2002:a05:6830:614:: with SMTP id w20mr2624613oti.283.1596840055222; Fri, 07 Aug 2020 15:40:55 -0700 (PDT) MIME-Version: 1.0 References: <20200806174326.3577537-1-urielguajardojr@gmail.com> In-Reply-To: From: Uriel Guajardo Date: Fri, 7 Aug 2020 17:40:43 -0500 Message-ID: Subject: Re: [PATCH 1/2] kunit: support failure from dynamic analysis tools To: Alan Maguire Cc: Uriel Guajardo , Brendan Higgins , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com 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 Fri, Aug 7, 2020 at 9:16 AM Alan Maguire wrote: > > On Thu, 6 Aug 2020, Uriel Guajardo wrote: > > > Adds an API to allow dynamic analysis tools to fail the currently > > running KUnit test case. > > > > - Always places the kunit test in the task_struct to allow other tools > > to access the currently running KUnit test. > > > > - Creates a new header file to avoid circular dependencies that could be > > created from the test.h file. > > > > Requires KASAN-KUnit integration patch to access the kunit test from > > task_struct: > > https://lore.kernel.org/linux-kselftest/20200606040349.246780-2-davidgow@google.com/ > > > > Signed-off-by: Uriel Guajardo > > --- > > include/kunit/test-bug.h | 24 ++++++++++++++++++++++++ > > include/kunit/test.h | 1 + > > lib/kunit/test.c | 10 ++++++---- > > 3 files changed, 31 insertions(+), 4 deletions(-) > > create mode 100644 include/kunit/test-bug.h > > > > diff --git a/include/kunit/test-bug.h b/include/kunit/test-bug.h > > new file mode 100644 > > index 000000000000..283c19ec328f > > --- /dev/null > > +++ b/include/kunit/test-bug.h > > @@ -0,0 +1,24 @@ > > +/* SPDX-License-Identifier: GPL-2.0 */ > > +/* > > + * KUnit API allowing dynamic analysis tools to interact with KUnit tests > > + * > > + * Copyright (C) 2020, Google LLC. > > + * Author: Uriel Guajardo > > + */ > > + > > +#ifndef _KUNIT_TEST_BUG_H > > +#define _KUNIT_TEST_BUG_H > > + > > +#if IS_ENABLED(CONFIG_KUNIT) > > + > > +extern void kunit_fail_current_test(void); > > + > > +#else > > + > > +static inline void kunit_fail_current_test(void) > > +{ > > +} > > + > > +#endif > > + > > +#endif /* _KUNIT_TEST_BUG_H */ > > This is great stuff! > > One thing I wonder though; how obvious will it be to someone > running a KUnit test that the cause of the test failure > is a dynamic analysis tool? Yes we'll see the dmesg logging > from that tool but I don't think there's any context _within_ > KUnit that could clarify the source of the failure. What about > changing the above API to include a string message that KUnit can > log, so it can at least identify the source of the failure > (ubsan, kasan etc). That would alert anyone looking at KUnit > output only that there's an external context to examine. > Good point! You're right: as it stands, there is no context within KUnit indicating the source of the failure, and the tool itself is responsible for logging. This patch is mainly focused on just failing test cases from outside KUnit. I'm actually working on sending a follow-up patch soon that supports the expectation of failures from specific tools. It will introduce something similar to what you are suggesting, so that KUnit can properly distinguish between different failures and log them appropriately. Thanks for the suggestion! > > diff --git a/include/kunit/test.h b/include/kunit/test.h > > index 3391f38389f8..81bf43a1abda 100644 > > --- a/include/kunit/test.h > > +++ b/include/kunit/test.h > > @@ -11,6 +11,7 @@ > > > > #include > > #include > > +#include > > #include > > #include > > #include > > diff --git a/lib/kunit/test.c b/lib/kunit/test.c > > index dcc35fd30d95..d8189d827368 100644 > > --- a/lib/kunit/test.c > > +++ b/lib/kunit/test.c > > @@ -16,6 +16,12 @@ > > #include "string-stream.h" > > #include "try-catch-impl.h" > > > > +void kunit_fail_current_test(void) > > +{ > > + if (current->kunit_test) > > + kunit_set_failure(current->kunit_test); > > +} > > + > > static void kunit_print_tap_version(void) > > { > > static bool kunit_has_printed_tap_version; > > @@ -284,9 +290,7 @@ static void kunit_try_run_case(void *data) > > struct kunit_suite *suite = ctx->suite; > > struct kunit_case *test_case = ctx->test_case; > > > > -#if (IS_ENABLED(CONFIG_KASAN) && IS_ENABLED(CONFIG_KUNIT)) > > current->kunit_test = test; > > -#endif /* IS_ENABLED(CONFIG_KASAN) && IS_ENABLED(CONFIG_KUNIT) */ > > > > /* > > * kunit_run_case_internal may encounter a fatal error; if it does, > > @@ -602,9 +606,7 @@ void kunit_cleanup(struct kunit *test) > > spin_unlock(&test->lock); > > kunit_remove_resource(test, res); > > } > > -#if (IS_ENABLED(CONFIG_KASAN) && IS_ENABLED(CONFIG_KUNIT)) > > current->kunit_test = NULL; > > -#endif /* IS_ENABLED(CONFIG_KASAN) && IS_ENABLED(CONFIG_KUNIT)*/ > > } > > EXPORT_SYMBOL_GPL(kunit_cleanup); > > > > -- > > 2.28.0.163.g6104cc2f0b6-goog > > > >