]> git.proxmox.com Git - efi-boot-shim.git/blame - include/test.mk
New upstream version 15.5
[efi-boot-shim.git] / include / test.mk
CommitLineData
031e5cce
SM
1# SPDX-License-Identifier: BSD-2-Clause-Patent
2#
3# test.mk - makefile to make local test programs
4#
5
6.SUFFIXES:
7
8529e0f7
SM
8include Make.defaults
9
031e5cce
SM
10CC = gcc
11VALGRIND ?=
12DEBUG_PRINTS ?= 0
8529e0f7
SM
13OPTIMIZATIONS=-O2 -ggdb
14CFLAGS_LTO =
15CFLAGS_GCOV =
16CFLAGS = $(OPTIMIZATIONS) -std=gnu11 \
031e5cce
SM
17 -isystem $(TOPDIR)/include/system \
18 $(EFI_INCLUDES) \
19 -Iinclude -iquote . \
8529e0f7
SM
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) \
031e5cce
SM
35 -Wsign-compare \
36 -Wno-deprecated-declarations \
8529e0f7
SM
37 $(if $(findstring gcc,$(CC)),-Wno-unused-but-set-variable) \
38 -Wno-unused-variable \
031e5cce 39 -Wno-pointer-sign \
8529e0f7 40 $(DEFAULT_WERRFLAGS) \
031e5cce
SM
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
8529e0f7
SM
49# On some systems (e.g. Arch Linux), limits.h is in the "include-fixed" instead
50# of the "include" directory
51CFLAGS += -isystem $(shell $(CC) $(ARCH_CFLAGS) -print-file-name=include-fixed)
52
53export CFLAGS_LTO CFLAGS_GCOV
54
55libefi-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
031e5cce
SM
74
75test-random.h:
76 dd if=/dev/urandom bs=512 count=17 of=random.bin
77 xxd -i random.bin test-random.h
78
8529e0f7
SM
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
83test-load-options_FILES = lib/guid.c
84test-load-options : CFLAGS+=-DHAVE_SHIM_LOCK_GUID
85
86test-mock-variables_FILES = mok.c globals.c tpm.c lib/guid.c lib/variables.c mock-variables.c
87test-mock-variables: CFLAGS+=-DHAVE_SHIM_LOCK_GUID
88
89test-mok-mirror_FILES = mok.c globals.c tpm.c lib/guid.c lib/variables.c mock-variables.c
90test-mok-mirror: CFLAGS+=-DHAVE_START_IMAGE -DHAVE_SHIM_LOCK_GUID
91
92test-sbat_FILES = csv.c lib/variables.c lib/guid.c
93test-sbat :: CFLAGS+=-DHAVE_GET_VARIABLE -DHAVE_GET_VARIABLE_ATTR -DHAVE_SHIM_LOCK_GUID
94
031e5cce
SM
95test-str_FILES = lib/string.c
96
97tests := $(patsubst %.c,%,$(wildcard test-*.c))
98
8529e0f7
SM
99$(tests) :: test-% : | libefi-test.a
100
031e5cce 101$(tests) :: test-% : test.c test-%.c $(test-%_FILES)
8529e0f7 102 $(CC) $(CFLAGS) -o $@ $(sort $^ $(wildcard $*.c) $(test-$*_FILES)) libefi-test.a -lefivar
031e5cce
SM
103 $(VALGRIND) ./$@
104
105test : $(tests)
8529e0f7
SM
106 $(MAKE) -f include/test.mk test-clean
107
108test-lto : CFLAGS_LTO+=-flto
109test-lto : $(tests)
110 $(MAKE) -f include/test.mk test-clean
111
112test-coverage : CFLAGS_GCOV+=--coverage
113test-coverage : $(tests)
114
115test-clean :
116 @rm -vf test-random.h random.bin libefi-test.a
117 @rm -vf *.gcda *.gcno *.gcov vgcore.*
031e5cce 118
8529e0f7 119clean : test-clean
031e5cce 120
8529e0f7 121all : test-clean test
031e5cce
SM
122
123.PHONY: $(tests) all test clean
124.SECONDARY: random.bin
125
126# vim:ft=make