summaryrefstree
path: root/kernel/include/linux/platform_device_mock.h
blob: ca3a9d5d5706011d33dffbc71457c9c2d6f2b287 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Fake platform device API for unit testing platform drivers.
 *
 * Copyright (C) 2018, Google LLC.
 * Author: Brendan Higgins <brendanhiggins@google.com>
 */

#include <linux/platform_device.h>
#include <kunit/mock.h>

static inline struct platform_driver *platform_driver_find(const char *name)
{
	struct device_driver *driver;

	driver = driver_find(name, &platform_bus_type);
	if (!driver)
		return NULL;

	return to_platform_driver(driver);
}

/**
 * of_fake_node()
 * @test: the test to associate node with
 * @name: name of the node
 *
 * The &struct device_node returned is allocated as a root node with the given
 * name and otherwise behaves as a real &struct device_node.
 *
 * Returns: the faked &struct device_node
 */
struct device_node *of_fake_node(struct test *test, const char *name);

/**
 * of_fake_probe_platform()
 * @test: the test to associate the fake platform device with
 * @driver: driver to probe
 * @node_name: name of the device node created
 *
 * Creates a &struct platform_device and an associated &struct device_node,
 * probes the provided &struct platform_driver with the &struct platform_device.
 *
 * Returns: the &struct platform_device that was created
 */
struct platform_device *
of_fake_probe_platform(struct test *test,
		       struct platform_driver *driver,
		       const char *node_name);

/**
 * of_fake_probe_platform_by_name()
 * @test: the test to associate the fake platform device with
 * @driver_name: name of the driver to probe
 * @node_name: name of the device node created
 *
 * Same as of_fake_probe_platform() but looks up the &struct platform_driver by
 * the provided name.
 *
 * Returns: the &struct platform_device that was created
 */
struct platform_device *of_fake_probe_platform_by_name(struct test *test,
						       const char *driver_name,
						       const char *node_name);