]> git.proxmox.com Git - efi-boot-shim.git/blob - include/test.mk
New upstream version 15.5
[efi-boot-shim.git] / include / test.mk
1 # SPDX-License-Identifier: BSD-2-Clause-Patent
2 #
3 # test.mk - makefile to make local test programs
4 #
5
6 .SUFFIXES:
7
8 include Make.defaults
9
10 CC = gcc
11 VALGRIND ?=
12 DEBUG_PRINTS ?= 0
13 OPTIMIZATIONS=-O2 -ggdb
14 CFLAGS_LTO =
15 CFLAGS_GCOV =
16 CFLAGS = $(OPTIMIZATIONS) -std=gnu11 \
17 -isystem $(TOPDIR)/include/system \
18 $(EFI_INCLUDES) \
19 -Iinclude -iquote . \
20 -isystem /usr/include \
21 -isystem $(shell $(CC) $(ARCH_CFLAGS) -print-file-name=include) \
22 $(ARCH_CFLAGS) \
23 $(CFLAGS_LTO) \
24 $(CFLAGS_GCOV) \
25 -fshort-wchar \
26 -fno-builtin \
27 -rdynamic \
28 -fno-inline \
29 -fno-eliminate-unused-debug-types \
30 -fno-eliminate-unused-debug-symbols \
31 -gpubnames \
32 -grecord-gcc-switches \
33 $(if $(findstring clang,$(CC)),-Wno-unknown-warning-option) \
34 $(DEFAULT_WARNFLAGS) \
35 -Wsign-compare \
36 -Wno-deprecated-declarations \
37 $(if $(findstring gcc,$(CC)),-Wno-unused-but-set-variable) \
38 -Wno-unused-variable \
39 -Wno-pointer-sign \
40 $(DEFAULT_WERRFLAGS) \
41 -Werror=nonnull \
42 $(shell $(CC) -Werror=nonnull-compare -E -x c /dev/null >/dev/null 2>&1 && echo -Werror=nonnull-compare) \
43 $(ARCH_DEFINES) \
44 -DEFI_FUNCTION_WRAPPER \
45 -DGNU_EFI_USE_MS_ABI -DPAGE_SIZE=4096 \
46 -DSHIM_UNIT_TEST \
47 "-DDEFAULT_DEBUG_PRINT_STATE=$(DEBUG_PRINTS)"
48
49 # On some systems (e.g. Arch Linux), limits.h is in the "include-fixed" instead
50 # of the "include" directory
51 CFLAGS += -isystem $(shell $(CC) $(ARCH_CFLAGS) -print-file-name=include-fixed)
52
53 export CFLAGS_LTO CFLAGS_GCOV
54
55 libefi-test.a :
56 $(MAKE) -C gnu-efi \
57 COMPILER="$(COMPILER)" \
58 CC="$(CC)" \
59 ARCH=$(ARCH_GNUEFI) \
60 TOPDIR=$(TOPDIR)/gnu-efi \
61 CFLAGS_LTO="$(CFLAGS_LTO)" \
62 CFLAGS_GCOV="$(CFLAGS_GCOV)" \
63 -f $(TOPDIR)/gnu-efi/Makefile \
64 clean lib
65 mv gnu-efi/$(ARCH)/lib/libefi.a $@
66 $(MAKE) -C gnu-efi \
67 COMPILER="$(COMPILER)" \
68 ARCH=$(ARCH_GNUEFI) \
69 TOPDIR=$(TOPDIR)/gnu-efi \
70 CFLAGS_LTO="$(CFLAGS_LTO)" \
71 CFLAGS_GCOV="$(CFLAGS_GCOV)" \
72 -f $(TOPDIR)/gnu-efi/Makefile \
73 clean
74
75 test-random.h:
76 dd if=/dev/urandom bs=512 count=17 of=random.bin
77 xxd -i random.bin test-random.h
78
79 $(wildcard test-*.c) :: %.c : test-random.h
80 $(patsubst %.c,%,$(wildcard test-*.c)) :: | test-random.h
81 $(patsubst %.c,%.o,$(wildcard test-*.c)) : | test-random.h
82
83 test-load-options_FILES = lib/guid.c
84 test-load-options : CFLAGS+=-DHAVE_SHIM_LOCK_GUID
85
86 test-mock-variables_FILES = mok.c globals.c tpm.c lib/guid.c lib/variables.c mock-variables.c
87 test-mock-variables: CFLAGS+=-DHAVE_SHIM_LOCK_GUID
88
89 test-mok-mirror_FILES = mok.c globals.c tpm.c lib/guid.c lib/variables.c mock-variables.c
90 test-mok-mirror: CFLAGS+=-DHAVE_START_IMAGE -DHAVE_SHIM_LOCK_GUID
91
92 test-sbat_FILES = csv.c lib/variables.c lib/guid.c
93 test-sbat :: CFLAGS+=-DHAVE_GET_VARIABLE -DHAVE_GET_VARIABLE_ATTR -DHAVE_SHIM_LOCK_GUID
94
95 test-str_FILES = lib/string.c
96
97 tests := $(patsubst %.c,%,$(wildcard test-*.c))
98
99 $(tests) :: test-% : | libefi-test.a
100
101 $(tests) :: test-% : test.c test-%.c $(test-%_FILES)
102 $(CC) $(CFLAGS) -o $@ $(sort $^ $(wildcard $*.c) $(test-$*_FILES)) libefi-test.a -lefivar
103 $(VALGRIND) ./$@
104
105 test : $(tests)
106 $(MAKE) -f include/test.mk test-clean
107
108 test-lto : CFLAGS_LTO+=-flto
109 test-lto : $(tests)
110 $(MAKE) -f include/test.mk test-clean
111
112 test-coverage : CFLAGS_GCOV+=--coverage
113 test-coverage : $(tests)
114
115 test-clean :
116 @rm -vf test-random.h random.bin libefi-test.a
117 @rm -vf *.gcda *.gcno *.gcov vgcore.*
118
119 clean : test-clean
120
121 all : test-clean test
122
123 .PHONY: $(tests) all test clean
124 .SECONDARY: random.bin
125
126 # vim:ft=make