• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) 2019 Cyril Hrubis <chrubis@suse.cz>
4  */
5 
6 #ifndef TST_BUFFERS_H__
7 #define TST_BUFFERS_H__
8 
9 /*
10  * Buffer description consist of a pointer to a pointer and buffer type/size
11  * encoded as a different structure members.
12  *
13  * Only one of the size and iov_sizes can be set at a time.
14  */
15 struct tst_buffers {
16 	/*
17 	 * This pointer points to a buffer pointer.
18 	 */
19 	void *ptr;
20 	/*
21 	 * Buffer size.
22 	 */
23 	size_t size;
24 	/*
25 	 * Array of iov buffer sizes terminated by -1.
26 	 */
27 	int *iov_sizes;
28 	/*
29 	 * If size and iov_sizes is NULL this is the string we want to strdup()
30 	 * into the buffer.
31 	 */
32 	char *str;
33 };
34 
35 /*
36  * Allocates buffers based on the tst_buffers structure.
37  *
38  * @bufs NULL terminated array of test buffer descriptions.
39  *
40  * This is called from the test library if the tst_test->bufs pointer is set.
41  */
42 void tst_buffers_alloc(struct tst_buffers bufs[]);
43 
44 /*
45  * strdup() that callls tst_alloc().
46  */
47 char *tst_strdup(const char *str);
48 
49 /*
50  * Allocates size bytes, returns pointer to the allocated buffer.
51  */
52 void *tst_alloc(size_t size);
53 
54 /*
55  * Printf into a guarded buffer.
56  */
57 char *tst_aprintf(const char *fmt, ...)
58       __attribute__((format (printf, 1, 2)));
59 
60 /*
61  * Allocates iovec structure including the buffers.
62  *
63  * @sizes -1 terminated array of buffer sizes.
64  */
65 struct iovec *tst_iovec_alloc(int sizes[]);
66 
67 /*
68  * Frees all allocated buffers.
69  *
70  * This is called at the end of the test automatically.
71  */
72 void tst_free_all(void);
73 
74 #endif	/* TST_BUFFERS_H__ */
75