Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp622387pxa; Tue, 4 Aug 2020 13:49:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQJNodYHDID1q0Rhw3Sdnv136lY0VfjTzn8vw2TkNcDRdQPR3zc2oZ84APIQh+ua4hIHIp X-Received: by 2002:a50:da04:: with SMTP id z4mr21777917edj.375.1596574149324; Tue, 04 Aug 2020 13:49:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596574149; cv=none; d=google.com; s=arc-20160816; b=wpN5Q+eXFx7TIJih2slUNdOwvGY7eHjD+XIb/95NZ8rdGn1PxY9VJuRA9z1Rgzmrkv 3ZaKopBkwEPjNutiXAwYPUAUACAb3ZuR+fS2XIPRsg6+lEMHPBXYffYhgBKGoz+lZqVA tuP1iGl/e20t7jeglRHIowKiNfp6/J0ifhXvO7WRYSc219TziYZqX0RYQv7/8lFSp/bS zNt/vFDsQXmMhujr7zzJl6oII6nJuMFrR3oEXoyvgeCNTJIeg7UkFRNiDChXXPwuqRGS YeZmtin0FWpmOamLRwgZgFAgzFM1VFxryX/dVDhIkDsvbejniGJjcYb0rqQSbz3zI60u E20w== 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:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=y+u4fKeYaqBEutQX9Z0HQ6z4AVHLFsJy68c6azG+EzI=; b=aDpCYm7cYNtIPE61Fsshvjhvp9itAMNgmJa6gwFzzXRjpl7FK3HasU8pZaBBar7kF3 /9nUYttpjPGCAZVXY4rdmxbVoegpXrzrd6UE5FC2vvhMtU6TQEnBEvrEuEWX5ygY6RtD hTCHfCypNokFoMN+FbqYKRjUSdPSGkhvNk08FfbRILoLX0/8YOQ5eQdEh7cYPUeRTNgC nJiHbIMrZWvN0Zi4BIUTOq3RZm33XeVyk4G0Y/iHTheArAUzUFlw6RlShaThpQ49A2DH BoN+2rumysQ3uIjXkhoGlUIWST7sGHrhTUWhjhYZvhIBrzzI8/2LWz95AyiuabMzD0Cz X4fQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="mmVoL/AM"; 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 i7si6390780ejo.230.2020.08.04.13.48.46; Tue, 04 Aug 2020 13:49:09 -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="mmVoL/AM"; 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 S1728156AbgHDUsE (ORCPT + 99 others); Tue, 4 Aug 2020 16:48:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728146AbgHDUr7 (ORCPT ); Tue, 4 Aug 2020 16:47:59 -0400 Received: from mail-qt1-x84a.google.com (mail-qt1-x84a.google.com [IPv6:2607:f8b0:4864:20::84a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA6BCC06174A for ; Tue, 4 Aug 2020 13:47:58 -0700 (PDT) Received: by mail-qt1-x84a.google.com with SMTP id k1so16304428qtp.20 for ; Tue, 04 Aug 2020 13:47:58 -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=y+u4fKeYaqBEutQX9Z0HQ6z4AVHLFsJy68c6azG+EzI=; b=mmVoL/AM2WzN83wudXZcQBbAARV3/CCAsweI2kvE34swVGEjEGDTyGhs8TzIqLB2Jy J9ABiX5LWXRTIPPouIHnVNKoYjuyneQCYAgTO8KCID1l2KHt6VpCwyEzaiH8GMYHHSAP pAKKxa6sHVCqjWlYiJDPfltmJlj9UARbuMIfuynhlkZCTu3T2byGo6yjWRh7wYptj6+F mxLVmMmQ1JcXWjY9BlBuvIqBQTAQ5Qns34/Ua/GQqqfrrwC70rdtH+cE2oUv5YMBChi8 q0GDV3HsB+RnB1CaxSgFWDfYEZTZRgyIfKv99NnIUyGt7dQ+fLYy0HlBAl7VvqYdxVrd X3pw== 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=y+u4fKeYaqBEutQX9Z0HQ6z4AVHLFsJy68c6azG+EzI=; b=a1WDX4EkBt15/mSDuiHTa06EOc3UU0VubV2wlWHen0N4SRGDA90+gyV2JmWy/ATrlX dq5yoG3Z8Xxu1cRzqw/rfJ/SabeI5PzMSqaBbM28UaVOPxyXDx8vglr4gkbYj9oICMIW 2Bynrc4PDICVW0Xucmb/lMsmcInXd5ATMtX3MwXJqJPKL786aytyRee1SLOMyjJrmJnj MM5/9M0qM9ddFo2v5gpboj7dIH6XAxcU5fxKZGNCo6sxxUIXYfpM7mKRpHI3GmSYzpkk ME7KzatiAHjDB3CGSrstaw0iD04J5/szqpmavJ05WxwNUoOyhgohDzjBZTLS56fFFYwg XSSQ== X-Gm-Message-State: AOAM533RfRtpKatDGoei67jHvtinqQ4dPyGyj5exnkEM6nP3HfQuMTin oAFyciHiVmAq52k5QUvlk4Rlx9UnXCRAhYNhIQ8QFQ== X-Received: by 2002:a0c:806b:: with SMTP id 98mr238468qva.38.1596574077956; Tue, 04 Aug 2020 13:47:57 -0700 (PDT) Date: Tue, 4 Aug 2020 13:47:43 -0700 In-Reply-To: <20200804204745.987648-1-brendanhiggins@google.com> Message-Id: <20200804204745.987648-4-brendanhiggins@google.com> Mime-Version: 1.0 References: <20200804204745.987648-1-brendanhiggins@google.com> X-Mailer: git-send-email 2.28.0.163.g6104cc2f0b6-goog Subject: [PATCH v6 3/5] init: main: add KUnit to kernel init From: Brendan Higgins To: jdike@addtoit.com, richard@nod.at, anton.ivanov@cambridgegreys.com, arnd@arndb.de, keescook@chromium.org, skhan@linuxfoundation.org, alan.maguire@oracle.com, yzaikin@google.com, davidgow@google.com, akpm@linux-foundation.org, rppt@linux.ibm.com, frowand.list@gmail.com Cc: gregkh@linuxfoundation.org, sboyd@kernel.org, logang@deltatee.com, mcgrof@kernel.org, linux-arch@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Brendan Higgins 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 Although we have not seen any actual examples where KUnit doesn't work because it runs in the late init phase of the kernel, it has been a concern for some time that this could potentially be an issue in the future. So, remove KUnit from init calls entirely, instead call directly from kernel_init() so that KUnit runs after late init. Co-developed-by: Alan Maguire Signed-off-by: Alan Maguire Signed-off-by: Brendan Higgins Reviewed-by: Stephen Boyd Reviewed-by: Kees Cook Reviewed-by: Luis Chamberlain --- include/kunit/test.h | 9 +++++++++ init/main.c | 4 ++++ lib/kunit/executor.c | 4 +--- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/include/kunit/test.h b/include/kunit/test.h index f3e86c3953a2b..795039d9f1917 100644 --- a/include/kunit/test.h +++ b/include/kunit/test.h @@ -228,6 +228,15 @@ int __kunit_test_suites_init(struct kunit_suite * const * const suites); void __kunit_test_suites_exit(struct kunit_suite **suites); +#if IS_BUILTIN(CONFIG_KUNIT) +int kunit_run_all_tests(void); +#else +static inline int kunit_run_all_tests(void) +{ + return 0; +} +#endif /* IS_BUILTIN(CONFIG_KUNIT) */ + /** * kunit_test_suites() - used to register one or more &struct kunit_suite * with KUnit. diff --git a/init/main.c b/init/main.c index 0ead83e86b5aa..d3101d8874dea 100644 --- a/init/main.c +++ b/init/main.c @@ -106,6 +106,8 @@ #define CREATE_TRACE_POINTS #include +#include + static int kernel_init(void *); extern void init_IRQ(void); @@ -1504,6 +1506,8 @@ static noinline void __init kernel_init_freeable(void) do_basic_setup(); + kunit_run_all_tests(); + console_on_rootfs(); /* diff --git a/lib/kunit/executor.c b/lib/kunit/executor.c index 7015e7328dce7..4aab7f70a88c3 100644 --- a/lib/kunit/executor.c +++ b/lib/kunit/executor.c @@ -11,7 +11,7 @@ extern struct kunit_suite * const * const __kunit_suites_end[]; #if IS_BUILTIN(CONFIG_KUNIT) -static int kunit_run_all_tests(void) +int kunit_run_all_tests(void) { struct kunit_suite * const * const *suites; @@ -23,6 +23,4 @@ static int kunit_run_all_tests(void) return 0; } -late_initcall(kunit_run_all_tests); - #endif /* IS_BUILTIN(CONFIG_KUNIT) */ -- 2.28.0.163.g6104cc2f0b6-goog