xref: /linux/drivers/platform/chrome/cros_ec_proto_test_util.h (revision 3bf3e21c15d4386a5f15118ec39bbc1b67ea5759)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * CrOS Kunit tests utilities.
4  */
5 
6 #ifndef _CROS_KUNIT_UTIL_H_
7 #define _CROS_KUNIT_UTIL_H_
8 
9 #include <linux/platform_data/cros_ec_proto.h>
10 
11 struct ec_xfer_mock {
12 	struct list_head list;
13 	struct kunit *test;
14 
15 	/* input */
16 	struct cros_ec_command msg;
17 	void *i_data;
18 
19 	/* output */
20 	int ret;
21 	int result;
22 	void *o_data;
23 	u32 o_data_len;
24 };
25 
26 extern int cros_kunit_ec_xfer_mock_default_result;
27 extern int cros_kunit_ec_xfer_mock_default_ret;
28 extern int cros_kunit_ec_cmd_xfer_mock_called;
29 extern int cros_kunit_ec_pkt_xfer_mock_called;
30 
31 int cros_kunit_ec_xfer_mock(struct cros_ec_device *ec_dev, struct cros_ec_command *msg);
32 int cros_kunit_ec_cmd_xfer_mock(struct cros_ec_device *ec_dev, struct cros_ec_command *msg);
33 int cros_kunit_ec_pkt_xfer_mock(struct cros_ec_device *ec_dev, struct cros_ec_command *msg);
34 struct ec_xfer_mock *cros_kunit_ec_xfer_mock_add(struct kunit *test, size_t size);
35 struct ec_xfer_mock *cros_kunit_ec_xfer_mock_addx(struct kunit *test,
36 						  int ret, int result, size_t size);
37 struct ec_xfer_mock *cros_kunit_ec_xfer_mock_next(void);
38 
39 extern int cros_kunit_readmem_mock_offset;
40 extern u8 *cros_kunit_readmem_mock_data;
41 extern int cros_kunit_readmem_mock_ret;
42 
43 int cros_kunit_readmem_mock(struct cros_ec_device *ec_dev, unsigned int offset,
44 			    unsigned int bytes, void *dest);
45 
46 void cros_kunit_mock_reset(void);
47 
48 #endif
49