• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Description: Helpers for tests.
4  */
5 #ifndef LIBURING_HELPERS_H
6 #define LIBURING_HELPERS_H
7 
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 
12 #include "liburing.h"
13 
14 enum t_setup_ret {
15 	T_SETUP_OK	= 0,
16 	T_SETUP_SKIP,
17 };
18 
19 /*
20  * Helper for allocating memory in tests.
21  */
22 void *t_malloc(size_t size);
23 
24 
25 /*
26  * Helper for allocating size bytes aligned on a boundary.
27  */
28 void t_posix_memalign(void **memptr, size_t alignment, size_t size);
29 
30 
31 /*
32  * Helper for allocating space for an array of nmemb elements
33  * with size bytes for each element.
34  */
35 void *t_calloc(size_t nmemb, size_t size);
36 
37 
38 /*
39  * Helper for creating file and write @size byte buf with 0xaa value in the file.
40  */
41 void t_create_file(const char *file, size_t size);
42 
43 /*
44  * Helper for creating file and write @size byte buf with @pattern value in
45  * the file.
46  */
47 void t_create_file_pattern(const char *file, size_t size, char pattern);
48 
49 /*
50  * Helper for creating @buf_num number of iovec
51  * with @buf_size bytes buffer of each iovec.
52  */
53 struct iovec *t_create_buffers(size_t buf_num, size_t buf_size);
54 
55 /*
56  * Helper for setting up a ring and checking for user privs
57  */
58 enum t_setup_ret t_create_ring_params(int depth, struct io_uring *ring,
59 				      struct io_uring_params *p);
60 enum t_setup_ret t_create_ring(int depth, struct io_uring *ring,
61 			       unsigned int flags);
62 
63 enum t_setup_ret t_register_buffers(struct io_uring *ring,
64 				    const struct iovec *iovecs,
65 				    unsigned nr_iovecs);
66 
67 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
68 
69 #ifdef __cplusplus
70 }
71 #endif
72 
73 #endif
74