1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
/* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only */
/* Copyright (c) 2023-2025 Brett Sheffield <bacs@librecast.net> */
#ifndef _TESTDATA_H
#define _TESTDATA_H 1
#include <fcntl.h>
#ifdef HAVE_LIBLIBRECAST
#include <librecast/crypto.h>
#endif
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <unistd.h>
enum {
TEST_TMP = 1,
TEST_RND = 2,
};
/* write sz random bytes to ptr */
int test_random_bytes(void *ptr, size_t sz);
/* create test file with of sz bytes at path filename
*
* flags:
* TEST_TMP - if set, a temp file is created using filename as the template.
* TEST_RND - fill the file with sz random bytes
*
* if sz > 0 but TEST_RND is not set, a sparse file is created.
*/
int test_data_file(char *filename, size_t sz, int flags);
/* verify filename is a regular file and is correct size
* return 0 if correct, -1 on error */
int test_data_size(char *filename, size_t sz);
/* hash file
* filename - file to hash
* hash - buffer to return hash in
* hashlen - length of hash buffer
* buf - either NULL or a pointer to a preallocated buffer for file I/O
* buflen - length of buf in bytes
* returns 0 on success, -1 on error, setting errno
*/
int test_hash_file(const char *filename, unsigned char *hash, size_t hashlen, char *buf, size_t buflen);
/* hash files and confirm data matches, return 0 on match, nonzero fail */
int test_file_match(const char *file1, const char *file2);
/* write len random bytes to file, starting at offset off
* returns 0 on success, -1 on error, setting errno */
int test_file_scratch(const char *filename, long offset, size_t len);
/* extend file sparsely to sz bytes */
int test_sparsify_fd(int fd, size_t sz);
#endif /* _TESTDATA_H */
|