From 1c90b19aa381588dc4f53047a950fda2ddf5feeb Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Wed, 30 Mar 2022 11:33:23 -0600 Subject: helpers: add file creation with pattern Signed-off-by: Jens Axboe --- test/helpers.c | 14 ++++++++++++-- test/helpers.h | 6 ++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/test/helpers.c b/test/helpers.c index 975e7cb..491822e 100644 --- a/test/helpers.c +++ b/test/helpers.c @@ -49,14 +49,14 @@ void *t_calloc(size_t nmemb, size_t size) /* * Helper for creating file and write @size byte buf with 0xaa value in the file. */ -void t_create_file(const char *file, size_t size) +static void __t_create_file(const char *file, size_t size, char pattern) { ssize_t ret; char *buf; int fd; buf = t_malloc(size); - memset(buf, 0xaa, size); + memset(buf, pattern, size); fd = open(file, O_WRONLY | O_CREAT, 0644); assert(fd >= 0); @@ -68,6 +68,16 @@ void t_create_file(const char *file, size_t size) assert(ret == size); } +void t_create_file(const char *file, size_t size) +{ + __t_create_file(file, size, 0xaa); +} + +void t_create_file_pattern(const char *file, size_t size, char pattern) +{ + __t_create_file(file, size, pattern); +} + /* * Helper for creating @buf_num number of iovec * with @buf_size bytes buffer of each iovec. diff --git a/test/helpers.h b/test/helpers.h index 7526d46..d0beb93 100644 --- a/test/helpers.h +++ b/test/helpers.h @@ -40,6 +40,12 @@ void *t_calloc(size_t nmemb, size_t size); */ void t_create_file(const char *file, size_t size); +/* + * Helper for creating file and write @size byte buf with @pattern value in + * the file. + */ +void t_create_file_pattern(const char *file, size_t size, char pattern); + /* * Helper for creating @buf_num number of iovec * with @buf_size bytes buffer of each iovec. -- cgit v1.2.3