Skip to content

Commit 615e701

Browse files
committed
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 <[email protected]>
1 parent 8766d64 commit 615e701

File tree

4 files changed

+490
-4
lines changed

4 files changed

+490
-4
lines changed

.gitignore

+4-2
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@
2828
/build*/
2929
/certdb/
3030
/cov-int/
31+
/random.bin
3132
/sbat.*.csv
3233
/scan-results/
3334
[Ss]creenlog*
3435
shim_cert.h
35-
test-*
36-
!test-*.c
36+
/test-*
37+
!/test-*.c
38+
/test-random.h
3739
version.c

include/str.h

+5
Original file line numberDiff line numberDiff line change
@@ -256,4 +256,9 @@ EFI_STATUS parse_csv_data(char *data, char *end, size_t n_columns,
256256
list_t *list);
257257
void free_csv_list(list_t *list);
258258

259+
#ifdef SHIM_UNIT_TEST
260+
void NONNULL(1, 3, 4)
261+
parse_csv_line(char * line, size_t max, size_t *n_columns, const char *columns[]);
262+
#endif
263+
259264
#endif /* SHIM_STR_H */

include/test.mk

+10-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ CFLAGS = -O2 -ggdb -std=gnu11 \
2828
-DSHIM_UNIT_TEST \
2929
"-DDEFAULT_DEBUG_PRINT_STATE=$(DEBUG_PRINTS)"
3030

31+
$(wildcard test-*.c) :: %.c : test-random.h
32+
33+
test-random.h:
34+
dd if=/dev/urandom bs=512 count=17 of=random.bin
35+
xxd -i random.bin test-random.h
36+
3137
tests := $(patsubst %.c,%,$(wildcard test-*.c))
3238

3339
$(tests) :: test-% : test.c test-%.c $(test-%_FILES)
@@ -36,10 +42,12 @@ $(tests) :: test-% : test.c test-%.c $(test-%_FILES)
3642

3743
test : $(tests)
3844

39-
all : test
40-
4145
clean :
46+
@rm -vf test-random.h random.bin
47+
48+
all : clean test
4249

4350
.PHONY: $(tests) all test clean
51+
.SECONDARY: random.bin
4452

4553
# vim:ft=make

0 commit comments

Comments
 (0)