dm: test: Add tests for device's uclass platform data
[platform/kernel/u-boot.git] / include / dm / test.h
index 7b04850..f03fbcb 100644 (file)
@@ -8,6 +8,7 @@
 #define __DM_TEST_H
 
 #include <dm.h>
+#include <malloc.h>
 
 /**
  * struct dm_test_cdata - configuration data for test instance
@@ -43,6 +44,7 @@ enum {
        /* For uclass */
        DM_TEST_OP_POST_BIND,
        DM_TEST_OP_PRE_UNBIND,
+       DM_TEST_OP_PRE_PROBE,
        DM_TEST_OP_POST_PROBE,
        DM_TEST_OP_PRE_REMOVE,
        DM_TEST_OP_INIT,
@@ -66,6 +68,8 @@ enum {
 struct dm_test_priv {
        int ping_total;
        int op_count[DM_TEST_OP_COUNT];
+       int uclass_flag;
+       int uclass_total;
 };
 
 /**
@@ -86,9 +90,32 @@ struct dm_test_uclass_priv {
  * struct dm_test_parent_data - parent's information on each child
  *
  * @sum: Test value used to check parent data works correctly
+ * @flag: Used to track calling of parent operations
+ * @uclass_flag: Used to track calling of parent operations by uclass
  */
 struct dm_test_parent_data {
        int sum;
+       int flag;
+};
+
+/* Test values for test device's uclass platform data */
+enum {
+       TEST_UC_PDATA_INTVAL1 = 2,
+       TEST_UC_PDATA_INTVAL2 = 334,
+       TEST_UC_PDATA_INTVAL3 = 789452,
+};
+
+/**
+ * struct dm_test_uclass_platda - uclass's information on each device
+ *
+ * @intval1: set to TEST_UC_PDATA_INTVAL1 in .post_bind method of test uclass
+ * @intval2: set to TEST_UC_PDATA_INTVAL2 in .post_bind method of test uclass
+ * @intval3: set to TEST_UC_PDATA_INTVAL3 in .post_bind method of test uclass
+ */
+struct dm_test_perdev_uc_pdata {
+       int intval1;
+       int intval2;
+       int intval3;
 };
 
 /*
@@ -109,6 +136,7 @@ extern struct dm_test_state global_test_state;
  * @fail_count: Number of tests that failed
  * @force_fail_alloc: Force all memory allocs to fail
  * @skip_post_probe: Skip uclass post-probe processing
+ * @removed: Used to keep track of a device that was removed
  */
 struct dm_test_state {
        struct udevice *root;
@@ -116,6 +144,8 @@ struct dm_test_state {
        int fail_count;
        int force_fail_alloc;
        int skip_post_probe;
+       struct udevice *removed;
+       struct mallinfo start;
 };
 
 /* Test flags for each test */
@@ -174,12 +204,34 @@ int dm_check_operations(struct dm_test_state *dms, struct udevice *dev,
 int dm_check_devices(struct dm_test_state *dms, int num_devices);
 
 /**
- * dm_test_main() - Run all the tests
+ * dm_leak_check_start() - Prepare to check for a memory leak
+ *
+ * Call this before allocating memory to record the amount of memory being
+ * used.
+ *
+ * @dms: Overall test state
+ */
+void dm_leak_check_start(struct dm_test_state *dms);
+
+/**
+ * dm_leak_check_end() - Check that no memory has leaked
+ *
+ * Call this after dm_leak_check_start() and after you have hopefuilly freed
+ * all the memory that was allocated. This function will print an error if
+ * it sees a different amount of total memory allocated than before.
+ *
+ * @dms: Overall test state
+ */int dm_leak_check_end(struct dm_test_state *dms);
+
+
+/**
+ * dm_test_main() - Run all or one of the tests
  *
- * This runs all available driver model tests
+ * This runs all available driver model tests, or a selected one
  *
+ * @test_name: Name of test to run, or NULL for all
  * @return 0 if OK, -ve on error
  */
-int dm_test_main(void);
+int dm_test_main(const char *test_name);
 
 #endif