1 /* SPDX-License-Identifier: GPL-2.0-only */
12 * Get the file size of a given file
14 * @params fname name of the file relative to the __TEST_DATA_DIR__ directory
16 * @return On success file size in bytes is returned. On failure -1 is returned.
18 int test_get_file_size(const char *fname
)
20 char path
[strlen(__TEST_DATA_DIR__
) + strlen(fname
) + 2];
21 sprintf(path
, "%s/%s", __TEST_DATA_DIR__
, fname
);
24 if (stat(path
, &st
) == -1)
30 * Read a file and write its contents into a buffer
32 * @params fname name of the file relative to the __TEST_DATA_DIR__ directory
33 * @params buf buffer to write file contents into
34 * @params size size of buf
36 * @return On success number of bytes read is returned. On failure -1 is returned.
38 int test_read_file(const char *fname
, uint8_t *buf
, size_t size
)
40 char path
[strlen(__TEST_DATA_DIR__
) + strlen(fname
) + 2];
41 sprintf(path
, "%s/%s", __TEST_DATA_DIR__
, fname
);
43 int f
= open(path
, O_RDONLY
);
47 int read_size
= read(f
, buf
, size
);