From: David Gow <davidgow@google.com>
To: Matti Vaittinen <mazziesaccount@gmail.com>,
Daniel Latypov <dlatypov@google.com>,
Maxime Ripard <maxime@cerno.tech>,
Benjamin Berg <benjamin@sipsolutions.net>,
Brendan Higgins <brendan.higgins@linux.dev>,
Stephen Boyd <sboyd@kernel.org>,
Shuah Khan <skhan@linuxfoundation.org>,
Rae Moar <rmoar@google.com>
Cc: David Gow <davidgow@google.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Rafael J . Wysocki" <rafael@kernel.org>,
Heikki Krogerus <heikki.krogerus@linux.intel.com>,
Jonathan Cameron <jic23@kernel.org>,
Sadiya Kazi <sadiyakazi@google.com>,
Jonathan Corbet <corbet@lwn.net>,
linux-doc@vger.kernel.org, kunit-dev@googlegroups.com,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
Benjamin Berg <benjamin.berg@intel.com>
Subject: [PATCH v2 2/4] kunit: executor_test: Use kunit_add_action()
Date: Thu, 18 May 2023 16:38:44 +0800 [thread overview]
Message-ID: <20230518083849.2631178-2-davidgow@google.com> (raw)
In-Reply-To: <20230518083849.2631178-1-davidgow@google.com>
Now we have the kunit_add_action() function, we can use it to implement
kfree_at_end() and free_subsuite_at_end() without the need for extra
helper functions.
Reviewed-by: Benjamin Berg <benjamin.berg@intel.com>
Reviewed-by: Maxime Ripard <maxime@cerno.tech>
Tested-by: Maxime Ripard <maxime@cerno.tech>
Signed-off-by: David Gow <davidgow@google.com>
---
Changes since v1:
https://lore.kernel.org/linux-kselftest/20230421084226.2278282-3-davidgow@google.com/
- Use the kunit_action_t typedef
Changes since RFCv2:
https://lore.kernel.org/linux-kselftest/20230331080411.981038-3-davidgow@google.com/
- Don't use the no-longer-extant kunit_defer_func_t typedef.
- Don't pass a GFP pointer in.
---
lib/kunit/executor_test.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/lib/kunit/executor_test.c b/lib/kunit/executor_test.c
index 0cea31c27b23..ce6749af374d 100644
--- a/lib/kunit/executor_test.c
+++ b/lib/kunit/executor_test.c
@@ -125,11 +125,6 @@ kunit_test_suites(&executor_test_suite);
/* Test helpers */
-static void kfree_res_free(struct kunit_resource *res)
-{
- kfree(res->data);
-}
-
/* Use the resource API to register a call to kfree(to_free).
* Since we never actually use the resource, it's safe to use on const data.
*/
@@ -138,8 +133,10 @@ static void kfree_at_end(struct kunit *test, const void *to_free)
/* kfree() handles NULL already, but avoid allocating a no-op cleanup. */
if (IS_ERR_OR_NULL(to_free))
return;
- kunit_alloc_resource(test, NULL, kfree_res_free, GFP_KERNEL,
- (void *)to_free);
+
+ kunit_add_action(test,
+ (kunit_action_t *)kfree,
+ (void *)to_free);
}
static struct kunit_suite *alloc_fake_suite(struct kunit *test,
--
2.40.1.698.g37aff9b760-goog
next prev parent reply other threads:[~2023-05-18 8:39 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-18 8:38 [PATCH v2 1/4] kunit: Add kunit_add_action() to defer a call until test exit David Gow
2023-05-18 8:38 ` David Gow [this message]
2023-05-18 8:38 ` [PATCH v2 3/4] kunit: kmalloc_array: Use kunit_add_action() David Gow
2023-05-18 8:38 ` [PATCH v2 4/4] Documentation: kunit: Add usage notes for kunit_add_action() David Gow
2023-05-19 8:30 ` Bagas Sanjaya
2023-05-24 21:22 ` Rae Moar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230518083849.2631178-2-davidgow@google.com \
--to=davidgow@google.com \
--cc=benjamin.berg@intel.com \
--cc=benjamin@sipsolutions.net \
--cc=brendan.higgins@linux.dev \
--cc=corbet@lwn.net \
--cc=dlatypov@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=heikki.krogerus@linux.intel.com \
--cc=jic23@kernel.org \
--cc=kunit-dev@googlegroups.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=maxime@cerno.tech \
--cc=mazziesaccount@gmail.com \
--cc=rafael@kernel.org \
--cc=rmoar@google.com \
--cc=sadiyakazi@google.com \
--cc=sboyd@kernel.org \
--cc=skhan@linuxfoundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).