drivers/platform/chrome/cros_ec_proto_test_util.c
Source file repositories/reference/linux-study-clean/drivers/platform/chrome/cros_ec_proto_test_util.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/platform/chrome/cros_ec_proto_test_util.c- Extension
.c- Size
- 3346 bytes
- Lines
- 129
- Domain
- Driver Families
- Bucket
- drivers/platform
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
kunit/test.hlinux/list.hlinux/minmax.hlinux/platform_data/cros_ec_commands.hlinux/platform_data/cros_ec_proto.hcros_ec.hcros_ec_proto_test_util.h
Detected Declarations
function cros_kunit_ec_xfer_mockfunction cros_kunit_ec_cmd_xfer_mockfunction cros_kunit_ec_pkt_xfer_mockfunction cros_kunit_readmem_mockfunction cros_kunit_mock_reset
Annotated Snippet
// 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;
}
Annotation
- Immediate include surface: `kunit/test.h`, `linux/list.h`, `linux/minmax.h`, `linux/platform_data/cros_ec_commands.h`, `linux/platform_data/cros_ec_proto.h`, `cros_ec.h`, `cros_ec_proto_test_util.h`.
- Detected declarations: `function cros_kunit_ec_xfer_mock`, `function cros_kunit_ec_cmd_xfer_mock`, `function cros_kunit_ec_pkt_xfer_mock`, `function cros_kunit_readmem_mock`, `function cros_kunit_mock_reset`.
- Atlas domain: Driver Families / drivers/platform.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.