* [PATCH 0/3] Simplify and improve fpga test suites using deferred actions
@ 2024-07-25 12:50 Marco Pagani
2024-07-25 12:50 ` [PATCH 1/3] Simplify and improve the fpga manager test suite " Marco Pagani
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Marco Pagani @ 2024-07-25 12:50 UTC (permalink / raw)
To: Moritz Fischer, Wu Hao, Xu Yilun, Tom Rix
Cc: Marco Pagani, linux-kernel, linux-fpga
Use deferred actions to simplify fpga test suites and avoid potential
memory leaks when test cases fail. Deferred actions are executed when a
test is completed either successfully or unsuccessfully (e.g., due to a
failed assertion).
Marco Pagani (3):
Simplify and improve the fpga manager test suite using deferred
actions
Simplify and improve the fpga bridge test suite using deferred actions
Simplify and improve the fpga region test suite using deferred actions
drivers/fpga/tests/fpga-bridge-test.c | 25 +++++++---------
drivers/fpga/tests/fpga-mgr-test.c | 28 +++++++++++-------
drivers/fpga/tests/fpga-region-test.c | 41 ++++++++++++++++-----------
3 files changed, 52 insertions(+), 42 deletions(-)
base-commit: 3a0fa8e97d3024de199634667900b6a90bbe43d0
--
2.45.2
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/3] Simplify and improve the fpga manager test suite using deferred actions
2024-07-25 12:50 [PATCH 0/3] Simplify and improve fpga test suites using deferred actions Marco Pagani
@ 2024-07-25 12:50 ` Marco Pagani
2024-07-25 12:50 ` [PATCH 2/3] Simplify and improve the fpga bridge " Marco Pagani
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Marco Pagani @ 2024-07-25 12:50 UTC (permalink / raw)
To: Moritz Fischer, Wu Hao, Xu Yilun, Tom Rix
Cc: Marco Pagani, linux-kernel, linux-fpga
Use deferred actions to simplify the test suite and avoid potential memory
leaks when test cases fail. Remove unnecessary calls to
kunit_device_unregister() since kunit devices are tied to the test context
and released by a deferred action when the test is completed.
Signed-off-by: Marco Pagani <marpagan@redhat.com>
---
drivers/fpga/tests/fpga-mgr-test.c | 28 +++++++++++++++++-----------
1 file changed, 17 insertions(+), 11 deletions(-)
diff --git a/drivers/fpga/tests/fpga-mgr-test.c b/drivers/fpga/tests/fpga-mgr-test.c
index 125b3a4d43c6..9cb37aefbac4 100644
--- a/drivers/fpga/tests/fpga-mgr-test.c
+++ b/drivers/fpga/tests/fpga-mgr-test.c
@@ -44,6 +44,16 @@ struct mgr_ctx {
struct mgr_stats stats;
};
+/*
+ * Wrappers to avoid cast warnings when passing action functions directly
+ * to kunit_add_action().
+ */
+KUNIT_DEFINE_ACTION_WRAPPER(sg_free_table_wrapper, sg_free_table,
+ struct sg_table *);
+
+KUNIT_DEFINE_ACTION_WRAPPER(fpga_image_info_free_wrapper, fpga_image_info_free,
+ struct fpga_image_info *);
+
/**
* init_test_buffer() - Allocate and initialize a test image in a buffer.
* @test: KUnit test context object.
@@ -257,6 +267,9 @@ static void fpga_mgr_test_img_load_sgt(struct kunit *test)
KUNIT_ASSERT_EQ(test, ret, 0);
sg_init_one(sgt->sgl, img_buf, IMAGE_SIZE);
+ ret = kunit_add_action_or_reset(test, sg_free_table_wrapper, sgt);
+ KUNIT_ASSERT_EQ(test, ret, 0);
+
ctx->img_info->sgt = sgt;
ret = fpga_mgr_load(ctx->mgr, ctx->img_info);
@@ -273,13 +286,12 @@ static void fpga_mgr_test_img_load_sgt(struct kunit *test)
KUNIT_EXPECT_EQ(test, ctx->stats.op_write_init_seq, ctx->stats.op_parse_header_seq + 1);
KUNIT_EXPECT_EQ(test, ctx->stats.op_write_sg_seq, ctx->stats.op_parse_header_seq + 2);
KUNIT_EXPECT_EQ(test, ctx->stats.op_write_complete_seq, ctx->stats.op_parse_header_seq + 3);
-
- sg_free_table(ctx->img_info->sgt);
}
static int fpga_mgr_test_init(struct kunit *test)
{
struct mgr_ctx *ctx;
+ int ret;
ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx);
@@ -294,19 +306,14 @@ static int fpga_mgr_test_init(struct kunit *test)
ctx->img_info = fpga_image_info_alloc(ctx->dev);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx->img_info);
+ ret = kunit_add_action_or_reset(test, fpga_image_info_free_wrapper, ctx->img_info);
+ KUNIT_ASSERT_EQ(test, ret, 0);
+
test->priv = ctx;
return 0;
}
-static void fpga_mgr_test_exit(struct kunit *test)
-{
- struct mgr_ctx *ctx = test->priv;
-
- fpga_image_info_free(ctx->img_info);
- kunit_device_unregister(test, ctx->dev);
-}
-
static struct kunit_case fpga_mgr_test_cases[] = {
KUNIT_CASE(fpga_mgr_test_get),
KUNIT_CASE(fpga_mgr_test_lock),
@@ -318,7 +325,6 @@ static struct kunit_case fpga_mgr_test_cases[] = {
static struct kunit_suite fpga_mgr_suite = {
.name = "fpga_mgr",
.init = fpga_mgr_test_init,
- .exit = fpga_mgr_test_exit,
.test_cases = fpga_mgr_test_cases,
};
--
2.45.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/3] Simplify and improve the fpga bridge test suite using deferred actions
2024-07-25 12:50 [PATCH 0/3] Simplify and improve fpga test suites using deferred actions Marco Pagani
2024-07-25 12:50 ` [PATCH 1/3] Simplify and improve the fpga manager test suite " Marco Pagani
@ 2024-07-25 12:50 ` Marco Pagani
2024-07-25 12:50 ` [PATCH 3/3] Simplify and improve the fpga region " Marco Pagani
2024-08-15 3:01 ` [PATCH 0/3] Simplify and improve fpga test suites " Xu Yilun
3 siblings, 0 replies; 5+ messages in thread
From: Marco Pagani @ 2024-07-25 12:50 UTC (permalink / raw)
To: Moritz Fischer, Wu Hao, Xu Yilun, Tom Rix
Cc: Marco Pagani, linux-kernel, linux-fpga
Use deferred actions to simplify the test suite and avoid potential memory
leaks when test cases fail. Remove unnecessary calls to
kunit_device_unregister() since kunit devices are tied to the test context
and released by a deferred action when the test is completed.
Signed-off-by: Marco Pagani <marpagan@redhat.com>
---
drivers/fpga/tests/fpga-bridge-test.c | 25 +++++++++++--------------
1 file changed, 11 insertions(+), 14 deletions(-)
diff --git a/drivers/fpga/tests/fpga-bridge-test.c b/drivers/fpga/tests/fpga-bridge-test.c
index 2f7a24f23808..b9ab29809e96 100644
--- a/drivers/fpga/tests/fpga-bridge-test.c
+++ b/drivers/fpga/tests/fpga-bridge-test.c
@@ -23,6 +23,13 @@ struct bridge_ctx {
struct bridge_stats stats;
};
+/*
+ * Wrapper to avoid a cast warning when passing the action function directly
+ * to kunit_add_action().
+ */
+KUNIT_DEFINE_ACTION_WRAPPER(fpga_bridge_unregister_wrapper, fpga_bridge_unregister,
+ struct fpga_bridge *);
+
static int op_enable_set(struct fpga_bridge *bridge, bool enable)
{
struct bridge_stats *stats = bridge->priv;
@@ -50,6 +57,7 @@ static const struct fpga_bridge_ops fake_bridge_ops = {
static struct bridge_ctx *register_test_bridge(struct kunit *test, const char *dev_name)
{
struct bridge_ctx *ctx;
+ int ret;
ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx);
@@ -61,13 +69,10 @@ static struct bridge_ctx *register_test_bridge(struct kunit *test, const char *d
&ctx->stats);
KUNIT_ASSERT_FALSE(test, IS_ERR_OR_NULL(ctx->bridge));
- return ctx;
-}
+ ret = kunit_add_action_or_reset(test, fpga_bridge_unregister_wrapper, ctx->bridge);
+ KUNIT_ASSERT_EQ(test, ret, 0);
-static void unregister_test_bridge(struct kunit *test, struct bridge_ctx *ctx)
-{
- fpga_bridge_unregister(ctx->bridge);
- kunit_device_unregister(test, ctx->dev);
+ return ctx;
}
static void fpga_bridge_test_get(struct kunit *test)
@@ -141,8 +146,6 @@ static void fpga_bridge_test_get_put_list(struct kunit *test)
fpga_bridges_put(&bridge_list);
KUNIT_EXPECT_TRUE(test, list_empty(&bridge_list));
-
- unregister_test_bridge(test, ctx_1);
}
static int fpga_bridge_test_init(struct kunit *test)
@@ -152,11 +155,6 @@ static int fpga_bridge_test_init(struct kunit *test)
return 0;
}
-static void fpga_bridge_test_exit(struct kunit *test)
-{
- unregister_test_bridge(test, test->priv);
-}
-
static struct kunit_case fpga_bridge_test_cases[] = {
KUNIT_CASE(fpga_bridge_test_get),
KUNIT_CASE(fpga_bridge_test_toggle),
@@ -167,7 +165,6 @@ static struct kunit_case fpga_bridge_test_cases[] = {
static struct kunit_suite fpga_bridge_suite = {
.name = "fpga_bridge",
.init = fpga_bridge_test_init,
- .exit = fpga_bridge_test_exit,
.test_cases = fpga_bridge_test_cases,
};
--
2.45.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/3] Simplify and improve the fpga region test suite using deferred actions
2024-07-25 12:50 [PATCH 0/3] Simplify and improve fpga test suites using deferred actions Marco Pagani
2024-07-25 12:50 ` [PATCH 1/3] Simplify and improve the fpga manager test suite " Marco Pagani
2024-07-25 12:50 ` [PATCH 2/3] Simplify and improve the fpga bridge " Marco Pagani
@ 2024-07-25 12:50 ` Marco Pagani
2024-08-15 3:01 ` [PATCH 0/3] Simplify and improve fpga test suites " Xu Yilun
3 siblings, 0 replies; 5+ messages in thread
From: Marco Pagani @ 2024-07-25 12:50 UTC (permalink / raw)
To: Moritz Fischer, Wu Hao, Xu Yilun, Tom Rix
Cc: Marco Pagani, linux-kernel, linux-fpga
Use deferred actions to simplify the test suite and avoid potential memory
leaks when test cases fail. Remove unnecessary calls to
kunit_device_unregister() since kunit devices are tied to the test context
and released by a deferred action when the test is completed.
Other changes: fix a typo by changing the test suite name to fpga_region in
the kunit_suite struct.
Signed-off-by: Marco Pagani <marpagan@redhat.com>
---
drivers/fpga/tests/fpga-region-test.c | 41 ++++++++++++++++-----------
1 file changed, 24 insertions(+), 17 deletions(-)
diff --git a/drivers/fpga/tests/fpga-region-test.c b/drivers/fpga/tests/fpga-region-test.c
index bcf0651df261..6a108cafded8 100644
--- a/drivers/fpga/tests/fpga-region-test.c
+++ b/drivers/fpga/tests/fpga-region-test.c
@@ -35,6 +35,19 @@ struct test_ctx {
struct mgr_stats mgr_stats;
};
+/*
+ * Wrappers to avoid cast warnings when passing action functions directly
+ * to kunit_add_action().
+ */
+KUNIT_DEFINE_ACTION_WRAPPER(fpga_image_info_free_wrapper, fpga_image_info_free,
+ struct fpga_image_info *);
+
+KUNIT_DEFINE_ACTION_WRAPPER(fpga_bridge_unregister_wrapper, fpga_bridge_unregister,
+ struct fpga_bridge *);
+
+KUNIT_DEFINE_ACTION_WRAPPER(fpga_region_unregister_wrapper, fpga_region_unregister,
+ struct fpga_region *);
+
static int op_write(struct fpga_manager *mgr, const char *buf, size_t count)
{
struct mgr_stats *stats = mgr->priv;
@@ -111,6 +124,9 @@ static void fpga_region_test_program_fpga(struct kunit *test)
img_info = fpga_image_info_alloc(ctx->mgr_dev);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, img_info);
+ ret = kunit_add_action_or_reset(test, fpga_image_info_free_wrapper, img_info);
+ KUNIT_ASSERT_EQ(test, ret, 0);
+
img_info->buf = img_buf;
img_info->count = sizeof(img_buf);
@@ -130,8 +146,6 @@ static void fpga_region_test_program_fpga(struct kunit *test)
KUNIT_EXPECT_EQ(test, 2, ctx->bridge_stats.cycles_count);
fpga_bridges_put(&ctx->region->bridge_list);
-
- fpga_image_info_free(img_info);
}
/*
@@ -144,6 +158,7 @@ static int fpga_region_test_init(struct kunit *test)
{
struct test_ctx *ctx;
struct fpga_region_info region_info = { 0 };
+ int ret;
ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx);
@@ -164,6 +179,9 @@ static int fpga_region_test_init(struct kunit *test)
ctx->bridge_stats.enable = true;
+ ret = kunit_add_action_or_reset(test, fpga_bridge_unregister_wrapper, ctx->bridge);
+ KUNIT_ASSERT_EQ(test, ret, 0);
+
ctx->region_dev = kunit_device_register(test, "fpga-region-test-dev");
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx->region_dev);
@@ -174,24 +192,14 @@ static int fpga_region_test_init(struct kunit *test)
ctx->region = fpga_region_register_full(ctx->region_dev, ®ion_info);
KUNIT_ASSERT_FALSE(test, IS_ERR_OR_NULL(ctx->region));
+ ret = kunit_add_action_or_reset(test, fpga_region_unregister_wrapper, ctx->region);
+ KUNIT_ASSERT_EQ(test, ret, 0);
+
test->priv = ctx;
return 0;
}
-static void fpga_region_test_exit(struct kunit *test)
-{
- struct test_ctx *ctx = test->priv;
-
- fpga_region_unregister(ctx->region);
- kunit_device_unregister(test, ctx->region_dev);
-
- fpga_bridge_unregister(ctx->bridge);
- kunit_device_unregister(test, ctx->bridge_dev);
-
- kunit_device_unregister(test, ctx->mgr_dev);
-}
-
static struct kunit_case fpga_region_test_cases[] = {
KUNIT_CASE(fpga_region_test_class_find),
KUNIT_CASE(fpga_region_test_program_fpga),
@@ -199,9 +207,8 @@ static struct kunit_case fpga_region_test_cases[] = {
};
static struct kunit_suite fpga_region_suite = {
- .name = "fpga_mgr",
+ .name = "fpga_region",
.init = fpga_region_test_init,
- .exit = fpga_region_test_exit,
.test_cases = fpga_region_test_cases,
};
--
2.45.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 0/3] Simplify and improve fpga test suites using deferred actions
2024-07-25 12:50 [PATCH 0/3] Simplify and improve fpga test suites using deferred actions Marco Pagani
` (2 preceding siblings ...)
2024-07-25 12:50 ` [PATCH 3/3] Simplify and improve the fpga region " Marco Pagani
@ 2024-08-15 3:01 ` Xu Yilun
3 siblings, 0 replies; 5+ messages in thread
From: Xu Yilun @ 2024-08-15 3:01 UTC (permalink / raw)
To: Marco Pagani
Cc: Moritz Fischer, Wu Hao, Xu Yilun, Tom Rix, linux-kernel,
linux-fpga
On Thu, Jul 25, 2024 at 02:50:28PM +0200, Marco Pagani wrote:
> Use deferred actions to simplify fpga test suites and avoid potential
> memory leaks when test cases fail. Deferred actions are executed when a
> test is completed either successfully or unsuccessfully (e.g., due to a
> failed assertion).
>
> Marco Pagani (3):
> Simplify and improve the fpga manager test suite using deferred
> actions
> Simplify and improve the fpga bridge test suite using deferred actions
> Simplify and improve the fpga region test suite using deferred actions
Don't forget the prefix in shortlog. I added "fpga: " for them.
Others look good to me.
Acked-by: Xu Yilun <yilun.xu@intel.com>
Applied this series to for-next.
Thanks,
Yilun
>
> drivers/fpga/tests/fpga-bridge-test.c | 25 +++++++---------
> drivers/fpga/tests/fpga-mgr-test.c | 28 +++++++++++-------
> drivers/fpga/tests/fpga-region-test.c | 41 ++++++++++++++++-----------
> 3 files changed, 52 insertions(+), 42 deletions(-)
>
>
> base-commit: 3a0fa8e97d3024de199634667900b6a90bbe43d0
> --
> 2.45.2
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-08-15 3:04 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-25 12:50 [PATCH 0/3] Simplify and improve fpga test suites using deferred actions Marco Pagani
2024-07-25 12:50 ` [PATCH 1/3] Simplify and improve the fpga manager test suite " Marco Pagani
2024-07-25 12:50 ` [PATCH 2/3] Simplify and improve the fpga bridge " Marco Pagani
2024-07-25 12:50 ` [PATCH 3/3] Simplify and improve the fpga region " Marco Pagani
2024-08-15 3:01 ` [PATCH 0/3] Simplify and improve fpga test suites " Xu Yilun
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).