Debian Codegraph @

test/ioctl/mock.h

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3 #ifndef _LIBNVME_TEST_IOCTL_MOCK_H
4 #define _LIBNVME_TEST_IOCTL_MOCK_H
5
6 #include <stddef.h>
7 #include <stdint.h>
8
9 /**
10 * struct mock_cmd - a mock NVMe passthru ioctl() invocation
11 * @opcode: the expected `opcode` passed to ioctl()
12 * @flags: the expected `flags` passed to ioctl()
13 * @nsid: the expected `nsid` passed to ioctl()
14 * @cdw2: the expected `cdw2` passed to ioctl()
15 * @cdw3: the expected `cdw3` passed to ioctl()
16 * @metadata: the expected `metadata` of length `metadata_len` passed to ioctl()
17 * @in_data: the expected `addr` of length `data_len` passed to ioctl().
18 * Set this to NULL to skip checking the data,
19 * for example if the command is in the read direction.
20 * @metadata_len: the expected `metadata_len` passed to ioctl()
21 * @data_len: the expected `data_len` passed to ioctl()
22 * @cdw10: the expected `cdw10` passed to ioctl()
23 * @cdw11: the expected `cdw11` passed to ioctl()
24 * @cdw12: the expected `cdw12` passed to ioctl()
25 * @cdw13: the expected `cdw13` passed to ioctl()
26 * @cdw14: the expected `cdw14` passed to ioctl()
27 * @cdw15: the expected `cdw15` passed to ioctl()
28 * @timeout_ms: the expected `timeout_ms` passed to ioctl()
29 * @out_data: if not NULL, bytes to copy to the caller's `addr`
30 * @out_data_len: length of `out_data` buffer to return.
31 * If 0, `data_len` is used instead.
32 * @result: copied to the caller's `result`.
33 * If `result` doesn't fit in a u32, the ioctl() must be the 64-bit one.
34 * @err: If negative, ioctl() returns -1 and sets `errno` to `-err`.
35 * Otherwise, ioctl() returns `err`, representing a NVMe status code.
36 */
37 struct mock_cmd {
38 uint8_t opcode;
39 uint8_t flags;
40 uint32_t nsid;
41 uint32_t cdw2;
42 uint32_t cdw3;
43 const void *metadata;
44 const void *in_data;
45 uint32_t metadata_len;
46 uint32_t data_len;
47 uint32_t cdw10;
48 uint32_t cdw11;
49 uint32_t cdw12;
50 uint32_t cdw13;
51 uint32_t cdw14;
52 uint32_t cdw15;
53 uint32_t timeout_ms;
54 const void *out_data;
55 uint32_t out_data_len;
56 uint64_t result;
57 int err;
58 };
59
60 /**
61 * set_mock_fd() - sets the expected file descriptor for NVMe passthru ioctls()
62 * @fd: file descriptor expected to be passed to ioctl()
63 */
64 void set_mock_fd(int fd);
65
66 /**
67 * set_mock_admin_cmds() - mocks NVMe admin passthru ioctl() invocations
68 * @cmds: pointer to start of the mock_cmd slice
69 * @len: length of the mock_cmd slice (number of ioctl() invocations)
70 *
71 * Provides a sequence of mocks for NVMe admin passthru ioctl() invocations.
72 * Each ioctl() consumes the next mock from the sequence.
73 * Its arguments are checked against the mock's expected arguments,
74 * aborting the process if unexpected arguments are passed.
75 * The mock results (return value, NVMe result and data)
76 * are returned from the ioctl().
77 *
78 * Analogous to set_mock_io_cmds(), but for admin commands.
79 * Both admin and IO mocks can be active at the same time.
80 */
81 void set_mock_admin_cmds(const struct mock_cmd *cmds, size_t len);
82
83 /**
84 * set_mock_io_cmds() - mocks NVMe IO passthru ioctl() invocations
85 * @cmds: pointer to start of the mock_cmd slice
86 * @len: length of the mock_cmd slice (number of ioctl() invocations)
87 *
88 * Provides a sequence of mocks for NVMe IO passthru ioctl() invocations.
89 * Each ioctl() consumes the next mock from the sequence.
90 * Its arguments are checked against the mock's expected arguments,
91 * aborting the process if unexpected arguments are passed.
92 * The mock results (return value, NVMe result and data)
93 * are returned from the ioctl().
94 *
95 * Analogous to set_mock_admin_cmds(), but for IO commands.
96 * Both admin and IO mocks can be active at the same time.
97 */
98 void set_mock_io_cmds(const struct mock_cmd *cmds, size_t len);
99
100 /**
101 * end_mock_cmds() - finishes mocking NVMe passthru ioctl() invocations
102 *
103 * Checks that all mock ioctl() invocations were performed.
104 */
105 void end_mock_cmds(void);
106
107 #endif /* #ifndef _LIBNVME_TEST_IOCTL_MOCK_H */