summaryrefslogtreecommitdiff
path: root/tests/lib
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib')
-rw-r--r--tests/lib/Makefile.mk1
-rw-r--r--tests/lib/lzma-test.c35
2 files changed, 8 insertions, 28 deletions
diff --git a/tests/lib/Makefile.mk b/tests/lib/Makefile.mk
index 01777171c9..7fc5471529 100644
--- a/tests/lib/Makefile.mk
+++ b/tests/lib/Makefile.mk
@@ -234,6 +234,7 @@ lzma-test-srcs += tests/lib/lzma-test.c
lzma-test-srcs += tests/stubs/console.c
lzma-test-srcs += src/lib/lzma.c
lzma-test-srcs += src/lib/lzmadecode.c
+lzma-test-syssrcs += tests/helpers/file.c
ux_locales-test-srcs += tests/lib/ux_locales-test.c
ux_locales-test-srcs += tests/stubs/console.c
diff --git a/tests/lib/lzma-test.c b/tests/lib/lzma-test.c
index b68d38e122..48d629a179 100644
--- a/tests/lib/lzma-test.c
+++ b/tests/lib/lzma-test.c
@@ -1,6 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#include <fcntl.h>
+#include <helpers/file.h>
#include <lib.h>
#include <lib/lzmadecode.h>
#include <stdlib.h>
@@ -10,7 +11,6 @@
#include <tests/test.h>
#include <unistd.h>
-
struct lzma_test_state {
char *raw_filename;
size_t raw_file_sz;
@@ -18,14 +18,6 @@ struct lzma_test_state {
size_t comp_file_sz;
};
-static int get_file_size(const char *fname)
-{
- struct stat st;
- if (stat(fname, &st) == -1)
- return -1;
- return st.st_size;
-}
-
static int teardown_ulzman_file(void **state)
{
struct lzma_test_state *s = *state;
@@ -42,7 +34,7 @@ static int setup_ulzman_file(void **state)
{
int ret = 0;
const char *fname_base = *state;
- const char path_prefix[] = __TEST_DATA_DIR__ "/lib/lzma-test/%s%s";
+ const char path_prefix[] = "lib/lzma-test/%s%s";
const char raw_file_suffix[] = ".bin";
const char comp_file_suffix[] = ".lzma.bin";
struct lzma_test_state *s = test_malloc(sizeof(*s));
@@ -69,8 +61,8 @@ static int setup_ulzman_file(void **state)
snprintf(s->comp_filename, comp_filename_size, path_prefix, fname_base,
comp_file_suffix);
- s->raw_file_sz = get_file_size(s->raw_filename);
- s->comp_file_sz = get_file_size(s->comp_filename);
+ s->raw_file_sz = test_get_file_size(s->raw_filename);
+ s->comp_file_sz = test_get_file_size(s->comp_filename);
if (s->raw_file_sz == -1) {
print_error("Unable to open file: %s\n", s->raw_filename);
@@ -91,20 +83,6 @@ error:
return ret;
}
-static int read_file(const char *fname, uint8_t *buf, size_t sz)
-{
- int f = open(fname, O_RDONLY);
- int read_sz = 0;
-
- if (f == -1)
- return -1;
-
- read_sz = read(f, buf, sz);
-
- close(f);
- return read_sz;
-}
-
static void test_ulzman_correct_file(void **state)
{
struct lzma_test_state *s = *state;
@@ -115,9 +93,10 @@ static void test_ulzman_correct_file(void **state)
assert_non_null(raw_buf);
assert_non_null(decomp_buf);
assert_non_null(comp_buf);
- assert_int_equal(s->raw_file_sz, read_file(s->raw_filename, raw_buf, s->raw_file_sz));
+ assert_int_equal(s->raw_file_sz,
+ test_read_file(s->raw_filename, raw_buf, s->raw_file_sz));
assert_int_equal(s->comp_file_sz,
- read_file(s->comp_filename, comp_buf, s->comp_file_sz));
+ test_read_file(s->comp_filename, comp_buf, s->comp_file_sz));
assert_int_equal(s->raw_file_sz,
ulzman(comp_buf, s->comp_file_sz, decomp_buf, s->raw_file_sz));