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 30 /* 31 * Allocates buffers based on the tst_buffers structure. 32 * 33 * @bufs NULL terminated array of test buffer descriptions. 34 * 35 * This is called from the test library if the tst_test->bufs pointer is set. 36 */ 37 void tst_buffers_alloc(struct tst_buffers bufs[]); 38 39 /* 40 * strdup() that callls tst_alloc(). 41 */ 42 char *tst_strdup(const char *str); 43 44 /* 45 * Allocates size bytes, returns pointer to the allocated buffer. 46 */ 47 void *tst_alloc(size_t size); 48 49 /* 50 * Allocates iovec structure including the buffers. 51 * 52 * @sizes -1 terminated array of buffer sizes. 53 */ 54 struct iovec *tst_iovec_alloc(int sizes[]); 55 56 /* 57 * Frees all allocated buffers. 58 * 59 * This is called at the end of the test automatically. 60 */ 61 void tst_free_all(void); 62 63 #endif /* TST_BUFFERS_H__ */ 64