fpga: tests: use KUnit devices instead of platform devices
PATCH v2 1/1 fpga: tests: use KUnit devices instead of platform devices
KUnit now provides helper functions to create fake devices, so use them instead of relying on platform devices.
Other changes: remove an unnecessary white space in the fpga region suite.
---
v2:
- Add reviewed-by Russ Weight
--- drivers/fpga/tests/fpga-bridge-test.c | 33 ++++++++++----------- drivers/fpga/tests/fpga-mgr-test.c | 16 +++++------ drivers/fpga/tests/fpga-region-test.c | 41 +++++++++++++-------------- 3 files changed, 44 insertions(+), 46 deletions(-)
drivers/fpga/tests/fpga-bridge-test.c +17 -16
@@ -7,8 +7,8 @@* Author: Marco Pagani <[email protected]> */ +#include <kunit/device.h> #include <kunit/test.h> -#include <linux/device.h> #include <linux/fpga/fpga-bridge.h> #include <linux/module.h> #include <linux/types.h>
@@ -19,7 +19,7 @@ struct bridge_stats {struct bridge_ctx {struct fpga_bridge *bridge; -struct platform_device *pdev; +struct device *dev;struct bridge_stats stats; };
@@ -43,30 +43,31 @@ static const struct fpga_bridge_ops fake_bridge_ops = {/** * register_test_bridge() - Register a fake FPGA bridge for testing. * @test: KUnit test context object. +* @dev_name: name of the kunit device to be registered * * Return: Context of the newly registered FPGA bridge. */ -static struct bridge_ctx *register_test_bridge (struct kunit *test) +static struct bridge_ctx *register_test_bridge (struct kunit *test,const char *dev_name) {struct bridge_ctx *ctx; ctx =kunit_kzalloc (test,sizeof (*ctx),GFP_KERNEL );KUNIT_ASSERT_NOT_ERR_OR_NULL (test, ctx); - ctx->pdev =platform_device_register_simple ("bridge_pdev" ,PLATFORM_DEVID_AUTO ,NULL ,0 ); -KUNIT_ASSERT_NOT_ERR_OR_NULL (test, ctx->pdev); + ctx->dev =kunit_device_register (test, dev_name); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, ctx->dev); - ctx->bridge =fpga_bridge_register (&ctx->pdev->dev,"Fake FPGA bridge" , &fake_bridge_ops, + ctx->bridge =fpga_bridge_register (ctx->dev,"Fake FPGA bridge" , &fake_bridge_ops, &ctx->stats);KUNIT_ASSERT_FALSE (test,IS_ERR_OR_NULL (ctx->bridge));return ctx; } -static void unregister_test_bridge (struct bridge_ctx *ctx) +static void unregister_test_bridge (struct kunit *test,struct bridge_ctx *ctx) {fpga_bridge_unregister (ctx->bridge); -platform_device_unregister (ctx->pdev); +kunit_device_unregister (test, ctx->dev); }static void fpga_bridge_test_get (struct kunit *test)
@@ -74,10 +75,10 @@ static void fpga_bridge_test_get(struct kunit *test)struct bridge_ctx *ctx = test->priv;struct fpga_bridge *bridge; - bridge =fpga_bridge_get (&ctx->pdev->dev,NULL ); + bridge =fpga_bridge_get (ctx->dev,NULL );KUNIT_EXPECT_PTR_EQ (test, bridge, ctx->bridge); - bridge =fpga_bridge_get (&ctx->pdev->dev,NULL ); + bridge =fpga_bridge_get (ctx->dev,NULL );KUNIT_EXPECT_EQ (test,PTR_ERR (bridge), -EBUSY );fpga_bridge_put (ctx->bridge);
@@ -105,19 +106,19 @@ static void fpga_bridge_test_get_put_list(struct kunit *test)int ret; ctx_0 = test->priv; - ctx_1 =register_test_bridge (test); + ctx_1 =register_test_bridge (test,"fpga-bridge-test-dev-1" );INIT_LIST_HEAD (&bridge_list);/* Get bridge 0 and add it to the list */ - ret =fpga_bridge_get_to_list (&ctx_0->pdev->dev,NULL , &bridge_list); + ret =fpga_bridge_get_to_list (ctx_0->dev,NULL , &bridge_list);KUNIT_EXPECT_EQ (test, ret,0 );KUNIT_EXPECT_PTR_EQ (test, ctx_0->bridge, list_first_entry_or_null(&bridge_list, struct fpga_bridge, node));/* Get bridge 1 and add it to the list */ - ret =fpga_bridge_get_to_list (&ctx_1->pdev->dev,NULL , &bridge_list); + ret =fpga_bridge_get_to_list (ctx_1->dev,NULL , &bridge_list);KUNIT_EXPECT_EQ (test, ret,0 ); KUNIT_EXPECT_PTR_EQ(test, ctx_1->bridge,
@@ -141,19 +142,19 @@ static void fpga_bridge_test_get_put_list(struct kunit *test)KUNIT_EXPECT_TRUE (test,list_empty (&bridge_list)); -unregister_test_bridge (ctx_1); +unregister_test_bridge (test, ctx_1); }static int fpga_bridge_test_init (struct kunit *test) { - test->priv =register_test_bridge (test); + test->priv =register_test_bridge (test,"fpga-bridge-test-dev-0" );return 0 ; }static void fpga_bridge_test_exit (struct kunit *test) { -unregister_test_bridge (test->priv); +unregister_test_bridge (test, test->priv); }static struct kunit_case fpga_bridge_test_cases[] = {
drivers/fpga/tests/fpga-mgr-test.c +8 -8
@@ -7,8 +7,8 @@* Author: Marco Pagani <[email protected]> */ +#include <kunit/device.h> #include <kunit/test.h> -#include <linux/device.h> #include <linux/fpga/fpga-mgr.h> #include <linux/module.h> #include <linux/scatterlist.h>
@@ -40,7 +40,7 @@ struct mgr_stats {struct mgr_ctx {struct fpga_image_info *img_info;struct fpga_manager *mgr; -struct platform_device *pdev; +struct device *dev;struct mgr_stats stats; };
@@ -194,7 +194,7 @@ static void fpga_mgr_test_get(struct kunit *test)struct mgr_ctx *ctx = test->priv;struct fpga_manager *mgr; - mgr =fpga_mgr_get (&ctx->pdev->dev); + mgr =fpga_mgr_get (ctx->dev);KUNIT_EXPECT_PTR_EQ (test, mgr, ctx->mgr);fpga_mgr_put (ctx->mgr);
@@ -284,14 +284,14 @@ static int fpga_mgr_test_init(struct kunit *test) ctx =kunit_kzalloc (test,sizeof (*ctx),GFP_KERNEL );KUNIT_ASSERT_NOT_ERR_OR_NULL (test, ctx); - ctx->pdev =platform_device_register_simple ("mgr_pdev" ,PLATFORM_DEVID_AUTO ,NULL ,0 ); -KUNIT_ASSERT_NOT_ERR_OR_NULL (test, ctx->pdev); + ctx->dev =kunit_device_register (test,"fpga-manager-test-dev" ); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, ctx->dev); - ctx->mgr =devm_fpga_mgr_register (&ctx->pdev->dev,"Fake FPGA Manager" , &fake_mgr_ops, + ctx->mgr =devm_fpga_mgr_register (ctx->dev,"Fake FPGA Manager" , &fake_mgr_ops, &ctx->stats);KUNIT_ASSERT_FALSE (test,IS_ERR_OR_NULL (ctx->mgr)); - ctx->img_info =fpga_image_info_alloc (&ctx->pdev->dev); + ctx->img_info =fpga_image_info_alloc (ctx->dev);KUNIT_ASSERT_NOT_ERR_OR_NULL (test, ctx->img_info); test->priv = ctx;
@@ -304,7 +304,7 @@ static void fpga_mgr_test_exit(struct kunit *test)struct mgr_ctx *ctx = test->priv;fpga_image_info_free (ctx->img_info); -platform_device_unregister (ctx->pdev); +kunit_device_unregister (test, ctx->dev); }static struct kunit_case fpga_mgr_test_cases[] = {
drivers/fpga/tests/fpga-region-test.c +19 -22
106 lines not on this page · raw message
base-commit: b1a91ca25f15b6d7b311de4465854a5981dee3d3
Signature · 1 line
2.44.0
Quoted 7 lines · Marco Pagani
KUnit now provides helper functions to create fake devices, so use them instead of relying on platform devices.
Other changes: remove an unnecessary white space in the fpga region suite.
Reviewed-by Russ Weight <[email protected]>Signed-off-by Marco Pagani <[email protected]>
Does this patch has dependency on module owner changes for fpga-mgr/bridge/region?
Thanks,
Yilun
Quoted 4 lines · Xu Yilun
Quoted 3 lines · Marco Pagani
KUnit now provides helper functions to create fake devices, so use them instead of relying on platform devices.
Quoted 8 lines
Quoted 4 lines
Other changes: remove an unnecessary white space in the fpga region suite.
Reviewed-by Russ Weight <[email protected]>Signed-off-by Marco Pagani <[email protected]>Acked-by Xu Yilun <[email protected]>Does this patch has dependency on module owner changes for fpga-mgr/bridge/region?
There is no dependency on module owner changes for mgr/bridge/region.
Thanks,
Marco
Quoted 9 lines · Marco Pagani
Quoted 6 lines · Xu Yilun
Quoted 5 lines · Marco Pagani
KUnit now provides helper functions to create fake devices, so use them instead of relying on platform devices.
Other changes: remove an unnecessary white space in the fpga region suite.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Reviewed-by Russ Weight <[email protected]>Signed-off-by Marco Pagani <[email protected]>Acked-by Xu Yilun <[email protected]>Does this patch has dependency on module owner changes for fpga-mgr/bridge/region?
There is no dependency on module owner changes for mgr/bridge/region.
Fine. Applied to for-next.
Quoted 4 lines
Thanks,
Marco