From patchwork Tue Jan 30 22:31:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuah Khan X-Patchwork-Id: 194353 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1534850dyb; Tue, 30 Jan 2024 14:31:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IGCeP7tNkW31p3GKzrzAkMHYz4RC6o3Lla8NgXTFNyNmbWVYWqy/lbn7gslG2SwdVZVgiOg X-Received: by 2002:a05:6a20:a808:b0:19c:5d8a:d028 with SMTP id cb8-20020a056a20a80800b0019c5d8ad028mr605090pzb.57.1706653916653; Tue, 30 Jan 2024 14:31:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706653916; cv=pass; d=google.com; s=arc-20160816; b=Q2QkmILxrt2pOdvvzNYjOfPY0ZST5RSY/61DLh1zg2sMFOIO/C+hU9FXmVBqLrNXJd 7qcWaienq849OkiAvws46FcOBdfxWJHvBTu7g5YjmtPJhfU6AHqaxQvfkBLwfRRLeEzB DmRlI/S4B8c1RMI4IE1NElsNMtuq0S0/zMPZ3G3/tsWxbjm32sN7BHp5CD4iRAEcE15y iiNqA3asuNdSJI+u5SdY6AtMZ5r9B8HF/UhD/IjcOk4fv1JG+L1jqYQYj1N+6/TjaAi0 bMu7GZ+hN0LfD4L/6HPhhqMNEl+WCq4F8LmIE2WEerJpRrIttqDdUc4UVVp2AOOf/FjC OMPg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=subject:from:cc:to:content-language:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=nsdCrxbJMkHWE2IVMxvoEl76crbHFHMA88l9bGpCqFs=; fh=e8HLdo2QUSI2wjL1r3Ylm0LbueIJJ9sFPiD5Q6fxMLw=; b=cFsMhEwPsWAykBngwTpGLjnaOKFp20SIO9RKHH20lrHQomKVys/nhVKw9H4p5ZxgeB cvKGsZs15FPGVUiOQgQJ4PJckpIA5+TMvrmSBAFnV/BqxF6ocm/H3VsDSxPVBYXDiWtS Kbq+Ov/0HinewdU51Ibw4B8z892l22WmOaL0UVb9Zc2nexiltyWkM+FWm6kkVQiNIfs+ lPrDLFTxSYTvzaYyhX8gwvP3aegIQDcTzW8XQS3FP0RublslGFNZKJBAYtlT5Chhy5s2 5JOnYRgnfCk/+vP4w4nx1+emV32vSaw0Mt41MKtK/lZFeHHStSNCZTaaTNqcex6NIlfZ 4L5Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=google header.b=ef6fvhgU; arc=pass (i=1 spf=pass spfdomain=linuxfoundation.org dkim=pass dkdomain=linuxfoundation.org dmarc=pass fromdomain=linuxfoundation.org); spf=pass (google.com: domain of linux-kernel+bounces-45401-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45401-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id s32-20020a17090a69a300b00295b47aaff5si1643853pjj.162.2024.01.30.14.31.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 14:31:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45401-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=google header.b=ef6fvhgU; arc=pass (i=1 spf=pass spfdomain=linuxfoundation.org dkim=pass dkdomain=linuxfoundation.org dmarc=pass fromdomain=linuxfoundation.org); spf=pass (google.com: domain of linux-kernel+bounces-45401-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45401-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 684732855F5 for ; Tue, 30 Jan 2024 22:31:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 210A278661; Tue, 30 Jan 2024 22:31:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="ef6fvhgU" Received: from mail-io1-f44.google.com (mail-io1-f44.google.com [209.85.166.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C290C78677 for ; Tue, 30 Jan 2024 22:31:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706653866; cv=none; b=t5tmKTIxjB8m6RqMpOAt5JKPXiBf2D/j775m+rQ788QaIxp6WlQdphcc09n2hqL3rUcwut/0dABhOvY2woJiKVTHRYKs391Ps3JqRtgUl6Rl687rCT8Ex5hZrayAzSJStqljGAB5Mu6+15ta7PDME8Q2aPfYzyFilDG3e7KB+Cg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706653866; c=relaxed/simple; bh=cAKvGryUinyz1i8lgKU0z1MgcOvnbLrOQy0WnM5M21c=; h=Content-Type:Message-ID:Date:MIME-Version:To:Cc:From:Subject; b=K/drdG7IndnLsPufWv5ebTV+BmhDdLBD6631q5Uu7dyD5qhUrb5rYT3DjzcIu5Xee7xCwO7QoYd0bJNJ/TC0+IL72aOSOX8T1SVS6qfPUEQRU42gjme/NR+oNNBRFje94QamqvSD036wyC3C7Ff6/7FiWyKOMEXML/xdvXGBIgg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linuxfoundation.org; spf=pass smtp.mailfrom=linuxfoundation.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=ef6fvhgU; arc=none smtp.client-ip=209.85.166.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linuxfoundation.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linuxfoundation.org Received: by mail-io1-f44.google.com with SMTP id ca18e2360f4ac-7bbdd28a52aso56425739f.1 for ; Tue, 30 Jan 2024 14:31:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; t=1706653862; x=1707258662; darn=vger.kernel.org; h=subject:from:cc:to:content-language:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=nsdCrxbJMkHWE2IVMxvoEl76crbHFHMA88l9bGpCqFs=; b=ef6fvhgUK7CQj/75J5XzjB0Ywb80WrRd5tFVoXjDKVLLrZLQOr3trZ/oOwa/P5evWD KYtxCUgHe5qkpJSMueGeScjQREfO8xuN2RnfLoBuDzx+dq2JrNe040yaTaHhF1sU7dLl 4EU94Sxms6rzlZBqTniZcoScl8o1yYkpL1btQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706653862; x=1707258662; h=subject:from:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=nsdCrxbJMkHWE2IVMxvoEl76crbHFHMA88l9bGpCqFs=; b=h2lTsLW9dHVEgHjFKlz21dBBfOIWvNuT7AjDAAtpSUfrJcOf6Ar5vtVgLlRqatJKEd VWvTCJB0j5rFc1P+XJAGKSaGejxbAYX9SvGueks3OPlEe0HWIi5ooHwinz/xxL1qa4KI 6w4eix+Lf8/ytv7xsJR00aD0POkRhr1470vDahzCu4pKUfZ4Q/AI4DJw7PFUmR5cF6n/ U5IRW5f/Y4PbjP83S6PN8A7MzU0lZs4x7+WiTBPr1q3lM0LwCdSw6HsiWygIGrRbh9hX qm3nCn1ud2kGKwjYWF2Zli3jvNoH4rU2XQ8NCqpwhyDDrikgs2gylyn8l5gUZMMAdUwG D0qg== X-Forwarded-Encrypted: i=0; AJvYcCU7JyHNWLNLO9Rh4zoQLbR2S40fxXChmU6nzldL3N98X70/resNhAuFsttxKUhGTsOJB5bKDuIET7tCXO/caECn4g+dJq3smjxb1w12 X-Gm-Message-State: AOJu0YzHdvJq7geYUitzXca8YMB0GZ78L1YNWzwnojyeg07mYs+QXb+h LQOsFXYinLaUtFGQ6YNMz/BELcxv8F9INmgY1vxWiGfOT9BnCzIINcuJxFRsbL0= X-Received: by 2002:a6b:c8d0:0:b0:7bc:207d:5178 with SMTP id y199-20020a6bc8d0000000b007bc207d5178mr11750991iof.2.1706653861907; Tue, 30 Jan 2024 14:31:01 -0800 (PST) Received: from [192.168.1.128] ([38.175.170.29]) by smtp.gmail.com with ESMTPSA id l14-20020a056638220e00b0046e1f0f6d92sm2481719jas.76.2024.01.30.14.31.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 30 Jan 2024 14:31:01 -0800 (PST) Message-ID: <697a06c6-03a7-4939-9821-392239b3d5b2@linuxfoundation.org> Date: Tue, 30 Jan 2024 15:31:00 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: Linus Torvalds Cc: Brendan Higgins , David Gow , shuah , Shuah Khan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org From: Shuah Khan Subject: [GIT PULL] KUnit fixes update for Linux 6.8-rc3 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789556336926154298 X-GMAIL-MSGID: 1789556336926154298 Hi Linus, Please pull the following KUnit fixes update for Linux 6.8-rc3. This kunit fixes update for Linux 6.8-rc3 consists of NULL vs IS_ERR() bug fixes, documentation update, MAINTAINERS file update to add Rae Moar as a reviewer, and a fix to run test suites only after module initialization completes. diff is attached. thanks, -- Shuah ---------------------------------------------------------------- The following changes since commit 6613476e225e090cc9aad49be7fa504e290dd33d: Linux 6.8-rc1 (2024-01-21 14:11:32 -0800) are available in the Git repository at: git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest tags/linux_kselftest-kunit-fixes-6.8-rc3 for you to fetch changes up to 1a9f2c776d1416c4ea6cb0d0b9917778c41a1a7d: Documentation: KUnit: Update the instructions on how to test static functions (2024-01-22 07:59:03 -0700) ---------------------------------------------------------------- linux_kselftest-kunit-fixes-6.8-rc3 This kunit fixes update for Linux 6.8-rc3 consists of NULL vs IS_ERR() bug fixes, documentation update, MAINTAINERS file update to add Rae Moar as a reviewer, and a fix to run test suites only after module initialization completes. ---------------------------------------------------------------- Arthur Grillo (1): Documentation: KUnit: Update the instructions on how to test static functions Dan Carpenter (2): kunit: Fix a NULL vs IS_ERR() bug kunit: device: Fix a NULL vs IS_ERR() check in init() David Gow (1): MAINTAINERS: kunit: Add Rae Moar as a reviewer Marco Pagani (1): kunit: run test suites only after module initialization completes Documentation/dev-tools/kunit/usage.rst | 19 +++++++++++++++++-- MAINTAINERS | 1 + lib/kunit/device.c | 4 ++-- lib/kunit/executor.c | 4 ++++ lib/kunit/kunit-test.c | 2 +- lib/kunit/test.c | 14 +++++++++++--- 6 files changed, 36 insertions(+), 8 deletions(-) ---------------------------------------------------------------- diff --git a/Documentation/dev-tools/kunit/usage.rst b/Documentation/dev-tools/kunit/usage.rst index a9efab50eed8..22955d56b379 100644 --- a/Documentation/dev-tools/kunit/usage.rst +++ b/Documentation/dev-tools/kunit/usage.rst @@ -671,8 +671,23 @@ Testing Static Functions ------------------------ If we do not want to expose functions or variables for testing, one option is to -conditionally ``#include`` the test file at the end of your .c file. For -example: +conditionally export the used symbol. For example: + +.. code-block:: c + + /* In my_file.c */ + + VISIBLE_IF_KUNIT int do_interesting_thing(); + EXPORT_SYMBOL_IF_KUNIT(do_interesting_thing); + + /* In my_file.h */ + + #if IS_ENABLED(CONFIG_KUNIT) + int do_interesting_thing(void); + #endif + +Alternatively, you could conditionally ``#include`` the test file at the end of +your .c file. For example: .. code-block:: c diff --git a/MAINTAINERS b/MAINTAINERS index 8d1052fa6a69..354d993bc2cf 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -11724,6 +11724,7 @@ F: fs/smb/server/ KERNEL UNIT TESTING FRAMEWORK (KUnit) M: Brendan Higgins M: David Gow +R: Rae Moar L: linux-kselftest@vger.kernel.org L: kunit-dev@googlegroups.com S: Maintained diff --git a/lib/kunit/device.c b/lib/kunit/device.c index f5371287b375..074c6dd2e36a 100644 --- a/lib/kunit/device.c +++ b/lib/kunit/device.c @@ -45,8 +45,8 @@ int kunit_bus_init(void) int error; kunit_bus_device = root_device_register("kunit"); - if (!kunit_bus_device) - return -ENOMEM; + if (IS_ERR(kunit_bus_device)) + return PTR_ERR(kunit_bus_device); error = bus_register(&kunit_bus_type); if (error) diff --git a/lib/kunit/executor.c b/lib/kunit/executor.c index 717b9599036b..689fff2b2b10 100644 --- a/lib/kunit/executor.c +++ b/lib/kunit/executor.c @@ -146,6 +146,10 @@ void kunit_free_suite_set(struct kunit_suite_set suite_set) kfree(suite_set.start); } +/* + * Filter and reallocate test suites. Must return the filtered test suites set + * allocated at a valid virtual address or NULL in case of error. + */ struct kunit_suite_set kunit_filter_suites(const struct kunit_suite_set *suite_set, const char *filter_glob, diff --git a/lib/kunit/kunit-test.c b/lib/kunit/kunit-test.c index c4259d910356..f7980ef236a3 100644 --- a/lib/kunit/kunit-test.c +++ b/lib/kunit/kunit-test.c @@ -720,7 +720,7 @@ static void kunit_device_cleanup_test(struct kunit *test) long action_was_run = 0; test_device = kunit_device_register(test, "my_device"); - KUNIT_ASSERT_NOT_NULL(test, test_device); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, test_device); /* Add an action to verify cleanup. */ devm_add_action(test_device, test_dev_action, &action_was_run); diff --git a/lib/kunit/test.c b/lib/kunit/test.c index f95d2093a0aa..31a5a992e646 100644 --- a/lib/kunit/test.c +++ b/lib/kunit/test.c @@ -17,6 +17,7 @@ #include #include #include +#include #include "debugfs.h" #include "device-impl.h" @@ -801,12 +802,19 @@ static void kunit_module_exit(struct module *mod) }; const char *action = kunit_action(); + /* + * Check if the start address is a valid virtual address to detect + * if the module load sequence has failed and the suite set has not + * been initialized and filtered. + */ + if (!suite_set.start || !virt_addr_valid(suite_set.start)) + return; + if (!action) __kunit_test_suites_exit(mod->kunit_suites, mod->num_kunit_suites); - if (suite_set.start) - kunit_free_suite_set(suite_set); + kunit_free_suite_set(suite_set); } static int kunit_module_notify(struct notifier_block *nb, unsigned long val, @@ -816,12 +824,12 @@ static int kunit_module_notify(struct notifier_block *nb, unsigned long val, switch (val) { case MODULE_STATE_LIVE: + kunit_module_init(mod); break; case MODULE_STATE_GOING: kunit_module_exit(mod); break; case MODULE_STATE_COMING: - kunit_module_init(mod); break; case MODULE_STATE_UNFORMED: break;