]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
dm: test: Add a test driver for devres
authorSimon Glass <sjg@chromium.org>
Mon, 30 Dec 2019 04:19:25 +0000 (21:19 -0700)
committerSimon Glass <sjg@chromium.org>
Tue, 7 Jan 2020 23:02:39 +0000 (16:02 -0700)
Add a driver which does devres allocations so that we can write tests for
devres.

Signed-off-by: Simon Glass <sjg@chromium.org>
arch/sandbox/dts/test.dts
include/dm/uclass-id.h
include/test/test.h
test/dm/test-fdt.c

index 57513a449fab24c5169ddfffe4a685cf7f523eb6..3aef40d5ca135022495f7bc9ce713bbd63945641 100644 (file)
                compatible = "denx,u-boot-fdt-test1";
        };
 
+       devres-test {
+               compatible = "denx,u-boot-devres-test";
+       };
+
        clocks {
                clk_fixed: clk-fixed {
                        compatible = "fixed-clock";
index c1bab17ad115149d67b16c0051496fb3a5ace78e..c9f49df3f2683b9eab7a14f84b6507824ec2f4e9 100644 (file)
@@ -19,6 +19,7 @@ enum uclass_id {
        UCLASS_TEST_BUS,
        UCLASS_TEST_PROBE,
        UCLASS_TEST_DUMMY,
+       UCLASS_TEST_DEVRES,
        UCLASS_SPI_EMUL,        /* sandbox SPI device emulator */
        UCLASS_I2C_EMUL,        /* sandbox I2C device emulator */
        UCLASS_I2C_EMUL_PARENT, /* parent for I2C device emulators */
index 98fbcd11f6ffed8dcd55a7b2c27061f060e25022..5977c59d3f78fd55257a92c88b12e38a2c86cf5c 100644 (file)
@@ -46,5 +46,14 @@ struct unit_test {
                .func = _name,                                          \
        }
 
+/* Sizes for devres tests */
+enum {
+       TEST_DEVRES_SIZE        = 100,
+       TEST_DEVRES_COUNT       = 10,
+       TEST_DEVRES_TOTAL       = TEST_DEVRES_SIZE * TEST_DEVRES_COUNT,
+
+       /* A different size */
+       TEST_DEVRES_SIZE2       = 15,
+};
 
 #endif /* __TEST_TEST_H */
index 1fb8b5c248d346f9903663b7727b5e375dae0638..bbac37761d438bfd1eb7ee13656a63e005a26957 100644 (file)
@@ -153,6 +153,53 @@ UCLASS_DRIVER(testprobe) = {
        .flags          = DM_UC_FLAG_SEQ_ALIAS,
 };
 
+struct dm_testdevres_pdata {
+       void *ptr;
+};
+
+struct dm_testdevres_priv {
+       void *ptr;
+};
+
+static int testdevres_drv_bind(struct udevice *dev)
+{
+       struct dm_testdevres_pdata *pdata = dev_get_platdata(dev);
+
+       pdata->ptr = devm_kmalloc(dev, TEST_DEVRES_SIZE, 0);
+
+       return 0;
+}
+
+static int testdevres_drv_probe(struct udevice *dev)
+{
+       struct dm_testdevres_priv *priv = dev_get_priv(dev);
+
+       priv->ptr = devm_kmalloc(dev, TEST_DEVRES_SIZE2, 0);
+
+       return 0;
+}
+
+static const struct udevice_id testdevres_ids[] = {
+       { .compatible = "denx,u-boot-devres-test" },
+       { }
+};
+
+U_BOOT_DRIVER(testdevres_drv) = {
+       .name   = "testdevres_drv",
+       .of_match       = testdevres_ids,
+       .id     = UCLASS_TEST_DEVRES,
+       .bind   = testdevres_drv_bind,
+       .probe  = testdevres_drv_probe,
+       .platdata_auto_alloc_size       = sizeof(struct dm_testdevres_pdata),
+       .priv_auto_alloc_size   = sizeof(struct dm_testdevres_priv),
+};
+
+UCLASS_DRIVER(testdevres) = {
+       .name           = "testdevres",
+       .id             = UCLASS_TEST_DEVRES,
+       .flags          = DM_UC_FLAG_SEQ_ALIAS,
+};
+
 int dm_check_devices(struct unit_test_state *uts, int num_devices)
 {
        struct udevice *dev;