summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorPeter Jones <pjones@redhat.com>2021-02-23 15:01:38 -0500
committerPeter Jones <pjones@redhat.com>2021-02-25 10:15:14 -0500
commit615e701d53383a67131e9082d1c7329b69aa9f5d (patch)
treeb1812d45294c94410753b528baa9d7c5d6affe56 /include
parent8766d64a70b91dfadd5bf348a5c3d471761ef784 (diff)
downloadefi-boot-shim-615e701d53383a67131e9082d1c7329b69aa9f5d.tar.gz
efi-boot-shim-615e701d53383a67131e9082d1c7329b69aa9f5d.zip
Add test cases for our CSV parser.
This does a couple of straightforward tests on our CSV parser, and then for good measure it does two with random data - one that's just random data, one that's had all the zeros changed to nonzero values. Note that building and running this test does not quite work yet /on this branch/. In order to do that, we need some cleanups and reorganizing that I don't want to push just yet, which can be found on https://github.com/rhboot/shim/tree/test-reorg Signed-off-by: Peter Jones <pjones@redhat.com>
Diffstat (limited to 'include')
-rw-r--r--include/str.h5
-rw-r--r--include/test.mk12
2 files changed, 15 insertions, 2 deletions
diff --git a/include/str.h b/include/str.h
index 91f05dc6..c4d12113 100644
--- a/include/str.h
+++ b/include/str.h
@@ -256,4 +256,9 @@ EFI_STATUS parse_csv_data(char *data, char *end, size_t n_columns,
list_t *list);
void free_csv_list(list_t *list);
+#ifdef SHIM_UNIT_TEST
+void NONNULL(1, 3, 4)
+parse_csv_line(char * line, size_t max, size_t *n_columns, const char *columns[]);
+#endif
+
#endif /* SHIM_STR_H */
diff --git a/include/test.mk b/include/test.mk
index f70fdaa9..8cdcc332 100644
--- a/include/test.mk
+++ b/include/test.mk
@@ -28,6 +28,12 @@ CFLAGS = -O2 -ggdb -std=gnu11 \
-DSHIM_UNIT_TEST \
"-DDEFAULT_DEBUG_PRINT_STATE=$(DEBUG_PRINTS)"
+$(wildcard test-*.c) :: %.c : test-random.h
+
+test-random.h:
+ dd if=/dev/urandom bs=512 count=17 of=random.bin
+ xxd -i random.bin test-random.h
+
tests := $(patsubst %.c,%,$(wildcard test-*.c))
$(tests) :: test-% : test.c test-%.c $(test-%_FILES)
@@ -36,10 +42,12 @@ $(tests) :: test-% : test.c test-%.c $(test-%_FILES)
test : $(tests)
-all : test
-
clean :
+ @rm -vf test-random.h random.bin
+
+all : clean test
.PHONY: $(tests) all test clean
+.SECONDARY: random.bin
# vim:ft=make