platform/chrome: kunit: make EC protocol tests independent
authorTzung-Bi Shih <tzungbi@kernel.org>
Tue, 3 Oct 2023 08:05:15 +0000 (08:05 +0000)
committerTzung-Bi Shih <tzungbi@kernel.org>
Thu, 5 Oct 2023 10:11:36 +0000 (18:11 +0800)
Remove CONFIG_CROS_KUNIT and common code concept for ChromeOS Kunit but
make it bundle to ChromeOS EC protocol tests.

Reviewed-by: Guenter Roeck <groeck@chromium.org>
Link: https://lore.kernel.org/r/20231003080515.4011374-1-tzungbi@kernel.org
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
drivers/platform/chrome/Kconfig
drivers/platform/chrome/Makefile
drivers/platform/chrome/cros_ec_proto_test.c
drivers/platform/chrome/cros_ec_proto_test_util.c [new file with mode: 0644]
drivers/platform/chrome/cros_ec_proto_test_util.h [new file with mode: 0644]
drivers/platform/chrome/cros_kunit_util.c [deleted file]
drivers/platform/chrome/cros_kunit_util.h [deleted file]

index 7d82a0946e1c8beccb058d13e92d773764c65796..7a83346bfa53d5346ab3cdaa57669883ea31ed8f 100644 (file)
@@ -299,12 +299,12 @@ config CROS_TYPEC_SWITCH
 source "drivers/platform/chrome/wilco_ec/Kconfig"
 
 # Kunit test cases
-config CROS_KUNIT
-       tristate "Kunit tests for ChromeOS" if !KUNIT_ALL_TESTS
+config CROS_KUNIT_EC_PROTO_TEST
+       tristate "Kunit tests for ChromeOS EC protocol" if !KUNIT_ALL_TESTS
        depends on KUNIT && CROS_EC
        default KUNIT_ALL_TESTS
        select CROS_EC_PROTO
        help
-         ChromeOS Kunit tests.
+         Kunit tests for ChromeOS EC protocol.
 
 endif # CHROMEOS_PLATFORMS
index 9e26e45c4a375882e3de36ae4c6b5d62d8d6abb9..2dcc6ccc23022b18f2743b786ac4535d1b435e0e 100644 (file)
@@ -36,6 +36,5 @@ obj-$(CONFIG_CROS_USBPD_NOTIFY)               += cros_usbpd_notify.o
 obj-$(CONFIG_WILCO_EC)                 += wilco_ec/
 
 # Kunit test cases
-obj-$(CONFIG_CROS_KUNIT)               += cros_kunit.o
-cros_kunit-objs                                := cros_kunit_util.o
-cros_kunit-objs                                += cros_ec_proto_test.o
+obj-$(CONFIG_CROS_KUNIT_EC_PROTO_TEST) += cros_kunit_proto_test.o
+cros_kunit_proto_test-objs             := cros_ec_proto_test_util.o cros_ec_proto_test.o
index 63e38671e95a648a3aba1c01a68ed40a084a1d6c..b6169d6f2467775040c5486eafb480b964395ce4 100644 (file)
@@ -11,7 +11,7 @@
 #include <linux/platform_data/cros_ec_proto.h>
 
 #include "cros_ec.h"
-#include "cros_kunit_util.h"
+#include "cros_ec_proto_test_util.h"
 
 #define BUFSIZE 512
 
diff --git a/drivers/platform/chrome/cros_ec_proto_test_util.c b/drivers/platform/chrome/cros_ec_proto_test_util.c
new file mode 100644 (file)
index 0000000..65d328b
--- /dev/null
@@ -0,0 +1,128 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * CrOS Kunit tests utilities.
+ */
+
+#include <kunit/test.h>
+
+#include <linux/list.h>
+#include <linux/minmax.h>
+#include <linux/platform_data/cros_ec_commands.h>
+#include <linux/platform_data/cros_ec_proto.h>
+
+#include "cros_ec.h"
+#include "cros_ec_proto_test_util.h"
+
+int cros_kunit_ec_xfer_mock_default_result;
+int cros_kunit_ec_xfer_mock_default_ret;
+int cros_kunit_ec_cmd_xfer_mock_called;
+int cros_kunit_ec_pkt_xfer_mock_called;
+
+static struct list_head cros_kunit_ec_xfer_mock_in;
+static struct list_head cros_kunit_ec_xfer_mock_out;
+
+int cros_kunit_ec_xfer_mock(struct cros_ec_device *ec_dev, struct cros_ec_command *msg)
+{
+       struct ec_xfer_mock *mock;
+
+       mock = list_first_entry_or_null(&cros_kunit_ec_xfer_mock_in, struct ec_xfer_mock, list);
+       if (!mock) {
+               msg->result = cros_kunit_ec_xfer_mock_default_result;
+               return cros_kunit_ec_xfer_mock_default_ret;
+       }
+
+       list_del(&mock->list);
+
+       memcpy(&mock->msg, msg, sizeof(*msg));
+       if (msg->outsize) {
+               mock->i_data = kunit_kzalloc(mock->test, msg->outsize, GFP_KERNEL);
+               if (mock->i_data)
+                       memcpy(mock->i_data, msg->data, msg->outsize);
+       }
+
+       msg->result = mock->result;
+       if (msg->insize)
+               memcpy(msg->data, mock->o_data, min(msg->insize, mock->o_data_len));
+
+       list_add_tail(&mock->list, &cros_kunit_ec_xfer_mock_out);
+
+       return mock->ret;
+}
+
+int cros_kunit_ec_cmd_xfer_mock(struct cros_ec_device *ec_dev, struct cros_ec_command *msg)
+{
+       ++cros_kunit_ec_cmd_xfer_mock_called;
+       return cros_kunit_ec_xfer_mock(ec_dev, msg);
+}
+
+int cros_kunit_ec_pkt_xfer_mock(struct cros_ec_device *ec_dev, struct cros_ec_command *msg)
+{
+       ++cros_kunit_ec_pkt_xfer_mock_called;
+       return cros_kunit_ec_xfer_mock(ec_dev, msg);
+}
+
+struct ec_xfer_mock *cros_kunit_ec_xfer_mock_add(struct kunit *test, size_t size)
+{
+       return cros_kunit_ec_xfer_mock_addx(test, size, EC_RES_SUCCESS, size);
+}
+
+struct ec_xfer_mock *cros_kunit_ec_xfer_mock_addx(struct kunit *test,
+                                                 int ret, int result, size_t size)
+{
+       struct ec_xfer_mock *mock;
+
+       mock = kunit_kzalloc(test, sizeof(*mock), GFP_KERNEL);
+       if (!mock)
+               return NULL;
+
+       list_add_tail(&mock->list, &cros_kunit_ec_xfer_mock_in);
+       mock->test = test;
+
+       mock->ret = ret;
+       mock->result = result;
+       mock->o_data = kunit_kzalloc(test, size, GFP_KERNEL);
+       if (!mock->o_data)
+               return NULL;
+       mock->o_data_len = size;
+
+       return mock;
+}
+
+struct ec_xfer_mock *cros_kunit_ec_xfer_mock_next(void)
+{
+       struct ec_xfer_mock *mock;
+
+       mock = list_first_entry_or_null(&cros_kunit_ec_xfer_mock_out, struct ec_xfer_mock, list);
+       if (mock)
+               list_del(&mock->list);
+
+       return mock;
+}
+
+int cros_kunit_readmem_mock_offset;
+u8 *cros_kunit_readmem_mock_data;
+int cros_kunit_readmem_mock_ret;
+
+int cros_kunit_readmem_mock(struct cros_ec_device *ec_dev, unsigned int offset,
+                           unsigned int bytes, void *dest)
+{
+       cros_kunit_readmem_mock_offset = offset;
+
+       memcpy(dest, cros_kunit_readmem_mock_data, bytes);
+
+       return cros_kunit_readmem_mock_ret;
+}
+
+void cros_kunit_mock_reset(void)
+{
+       cros_kunit_ec_xfer_mock_default_result = 0;
+       cros_kunit_ec_xfer_mock_default_ret = 0;
+       cros_kunit_ec_cmd_xfer_mock_called = 0;
+       cros_kunit_ec_pkt_xfer_mock_called = 0;
+       INIT_LIST_HEAD(&cros_kunit_ec_xfer_mock_in);
+       INIT_LIST_HEAD(&cros_kunit_ec_xfer_mock_out);
+
+       cros_kunit_readmem_mock_offset = 0;
+       cros_kunit_readmem_mock_data = NULL;
+       cros_kunit_readmem_mock_ret = 0;
+}
diff --git a/drivers/platform/chrome/cros_ec_proto_test_util.h b/drivers/platform/chrome/cros_ec_proto_test_util.h
new file mode 100644 (file)
index 0000000..4140022
--- /dev/null
@@ -0,0 +1,48 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * CrOS Kunit tests utilities.
+ */
+
+#ifndef _CROS_KUNIT_UTIL_H_
+#define _CROS_KUNIT_UTIL_H_
+
+#include <linux/platform_data/cros_ec_proto.h>
+
+struct ec_xfer_mock {
+       struct list_head list;
+       struct kunit *test;
+
+       /* input */
+       struct cros_ec_command msg;
+       void *i_data;
+
+       /* output */
+       int ret;
+       int result;
+       void *o_data;
+       u32 o_data_len;
+};
+
+extern int cros_kunit_ec_xfer_mock_default_result;
+extern int cros_kunit_ec_xfer_mock_default_ret;
+extern int cros_kunit_ec_cmd_xfer_mock_called;
+extern int cros_kunit_ec_pkt_xfer_mock_called;
+
+int cros_kunit_ec_xfer_mock(struct cros_ec_device *ec_dev, struct cros_ec_command *msg);
+int cros_kunit_ec_cmd_xfer_mock(struct cros_ec_device *ec_dev, struct cros_ec_command *msg);
+int cros_kunit_ec_pkt_xfer_mock(struct cros_ec_device *ec_dev, struct cros_ec_command *msg);
+struct ec_xfer_mock *cros_kunit_ec_xfer_mock_add(struct kunit *test, size_t size);
+struct ec_xfer_mock *cros_kunit_ec_xfer_mock_addx(struct kunit *test,
+                                                 int ret, int result, size_t size);
+struct ec_xfer_mock *cros_kunit_ec_xfer_mock_next(void);
+
+extern int cros_kunit_readmem_mock_offset;
+extern u8 *cros_kunit_readmem_mock_data;
+extern int cros_kunit_readmem_mock_ret;
+
+int cros_kunit_readmem_mock(struct cros_ec_device *ec_dev, unsigned int offset,
+                           unsigned int bytes, void *dest);
+
+void cros_kunit_mock_reset(void);
+
+#endif
diff --git a/drivers/platform/chrome/cros_kunit_util.c b/drivers/platform/chrome/cros_kunit_util.c
deleted file mode 100644 (file)
index f0fda96..0000000
+++ /dev/null
@@ -1,130 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-/*
- * CrOS Kunit tests utilities.
- */
-
-#include <kunit/test.h>
-
-#include <linux/list.h>
-#include <linux/minmax.h>
-#include <linux/platform_data/cros_ec_commands.h>
-#include <linux/platform_data/cros_ec_proto.h>
-
-#include "cros_ec.h"
-#include "cros_kunit_util.h"
-
-int cros_kunit_ec_xfer_mock_default_result;
-int cros_kunit_ec_xfer_mock_default_ret;
-int cros_kunit_ec_cmd_xfer_mock_called;
-int cros_kunit_ec_pkt_xfer_mock_called;
-
-static struct list_head cros_kunit_ec_xfer_mock_in;
-static struct list_head cros_kunit_ec_xfer_mock_out;
-
-int cros_kunit_ec_xfer_mock(struct cros_ec_device *ec_dev, struct cros_ec_command *msg)
-{
-       struct ec_xfer_mock *mock;
-
-       mock = list_first_entry_or_null(&cros_kunit_ec_xfer_mock_in, struct ec_xfer_mock, list);
-       if (!mock) {
-               msg->result = cros_kunit_ec_xfer_mock_default_result;
-               return cros_kunit_ec_xfer_mock_default_ret;
-       }
-
-       list_del(&mock->list);
-
-       memcpy(&mock->msg, msg, sizeof(*msg));
-       if (msg->outsize) {
-               mock->i_data = kunit_kzalloc(mock->test, msg->outsize, GFP_KERNEL);
-               if (mock->i_data)
-                       memcpy(mock->i_data, msg->data, msg->outsize);
-       }
-
-       msg->result = mock->result;
-       if (msg->insize)
-               memcpy(msg->data, mock->o_data, min(msg->insize, mock->o_data_len));
-
-       list_add_tail(&mock->list, &cros_kunit_ec_xfer_mock_out);
-
-       return mock->ret;
-}
-
-int cros_kunit_ec_cmd_xfer_mock(struct cros_ec_device *ec_dev, struct cros_ec_command *msg)
-{
-       ++cros_kunit_ec_cmd_xfer_mock_called;
-       return cros_kunit_ec_xfer_mock(ec_dev, msg);
-}
-
-int cros_kunit_ec_pkt_xfer_mock(struct cros_ec_device *ec_dev, struct cros_ec_command *msg)
-{
-       ++cros_kunit_ec_pkt_xfer_mock_called;
-       return cros_kunit_ec_xfer_mock(ec_dev, msg);
-}
-
-struct ec_xfer_mock *cros_kunit_ec_xfer_mock_add(struct kunit *test, size_t size)
-{
-       return cros_kunit_ec_xfer_mock_addx(test, size, EC_RES_SUCCESS, size);
-}
-
-struct ec_xfer_mock *cros_kunit_ec_xfer_mock_addx(struct kunit *test,
-                                                 int ret, int result, size_t size)
-{
-       struct ec_xfer_mock *mock;
-
-       mock = kunit_kzalloc(test, sizeof(*mock), GFP_KERNEL);
-       if (!mock)
-               return NULL;
-
-       list_add_tail(&mock->list, &cros_kunit_ec_xfer_mock_in);
-       mock->test = test;
-
-       mock->ret = ret;
-       mock->result = result;
-       mock->o_data = kunit_kzalloc(test, size, GFP_KERNEL);
-       if (!mock->o_data)
-               return NULL;
-       mock->o_data_len = size;
-
-       return mock;
-}
-
-struct ec_xfer_mock *cros_kunit_ec_xfer_mock_next(void)
-{
-       struct ec_xfer_mock *mock;
-
-       mock = list_first_entry_or_null(&cros_kunit_ec_xfer_mock_out, struct ec_xfer_mock, list);
-       if (mock)
-               list_del(&mock->list);
-
-       return mock;
-}
-
-int cros_kunit_readmem_mock_offset;
-u8 *cros_kunit_readmem_mock_data;
-int cros_kunit_readmem_mock_ret;
-
-int cros_kunit_readmem_mock(struct cros_ec_device *ec_dev, unsigned int offset,
-                           unsigned int bytes, void *dest)
-{
-       cros_kunit_readmem_mock_offset = offset;
-
-       memcpy(dest, cros_kunit_readmem_mock_data, bytes);
-
-       return cros_kunit_readmem_mock_ret;
-}
-
-void cros_kunit_mock_reset(void)
-{
-       cros_kunit_ec_xfer_mock_default_result = 0;
-       cros_kunit_ec_xfer_mock_default_ret = 0;
-       cros_kunit_ec_cmd_xfer_mock_called = 0;
-       cros_kunit_ec_pkt_xfer_mock_called = 0;
-       INIT_LIST_HEAD(&cros_kunit_ec_xfer_mock_in);
-       INIT_LIST_HEAD(&cros_kunit_ec_xfer_mock_out);
-
-       cros_kunit_readmem_mock_offset = 0;
-       cros_kunit_readmem_mock_data = NULL;
-       cros_kunit_readmem_mock_ret = 0;
-}
-
-MODULE_LICENSE("GPL");
diff --git a/drivers/platform/chrome/cros_kunit_util.h b/drivers/platform/chrome/cros_kunit_util.h
deleted file mode 100644 (file)
index 4140022..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/*
- * CrOS Kunit tests utilities.
- */
-
-#ifndef _CROS_KUNIT_UTIL_H_
-#define _CROS_KUNIT_UTIL_H_
-
-#include <linux/platform_data/cros_ec_proto.h>
-
-struct ec_xfer_mock {
-       struct list_head list;
-       struct kunit *test;
-
-       /* input */
-       struct cros_ec_command msg;
-       void *i_data;
-
-       /* output */
-       int ret;
-       int result;
-       void *o_data;
-       u32 o_data_len;
-};
-
-extern int cros_kunit_ec_xfer_mock_default_result;
-extern int cros_kunit_ec_xfer_mock_default_ret;
-extern int cros_kunit_ec_cmd_xfer_mock_called;
-extern int cros_kunit_ec_pkt_xfer_mock_called;
-
-int cros_kunit_ec_xfer_mock(struct cros_ec_device *ec_dev, struct cros_ec_command *msg);
-int cros_kunit_ec_cmd_xfer_mock(struct cros_ec_device *ec_dev, struct cros_ec_command *msg);
-int cros_kunit_ec_pkt_xfer_mock(struct cros_ec_device *ec_dev, struct cros_ec_command *msg);
-struct ec_xfer_mock *cros_kunit_ec_xfer_mock_add(struct kunit *test, size_t size);
-struct ec_xfer_mock *cros_kunit_ec_xfer_mock_addx(struct kunit *test,
-                                                 int ret, int result, size_t size);
-struct ec_xfer_mock *cros_kunit_ec_xfer_mock_next(void);
-
-extern int cros_kunit_readmem_mock_offset;
-extern u8 *cros_kunit_readmem_mock_data;
-extern int cros_kunit_readmem_mock_ret;
-
-int cros_kunit_readmem_mock(struct cros_ec_device *ec_dev, unsigned int offset,
-                           unsigned int bytes, void *dest);
-
-void cros_kunit_mock_reset(void);
-
-#endif