Debian Codegraph @

unit-test/pqos/Makefile

raw
1 ###############################################################################
2 # Makefile script for PQoS library and sample application
3 #
4 # @par
5 # BSD LICENSE
6 #
7 # Copyright(c) 2022-2026 Intel Corporation. All rights reserved.
8 #
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions
11 # are met:
12 #
13 # * Redistributions of source code must retain the above copyright
14 # notice, this list of conditions and the following disclaimer.
15 # * Redistributions in binary form must reproduce the above copyright
16 # notice, this list of conditions and the following disclaimer in
17 # the documentation and/or other materials provided with the
18 # distribution.
19 # * Neither the name of Intel Corporation nor the names of its
20 # contributors may be used to endorse or promote products derived
21 # from this software without specific prior written permission.
22 #
23 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 ###############################################################################
35
36 include ../../pre-build.mk
37
38 PQOS_DIR = ../../pqos
39 LIB_DIR = ../../lib
40 OBJ_DIR = ./obj
41 BIN_DIR = ./bin
42 MOCK_DIR = ../mock
43 APP_MOCK_DIR = ./mock
44 OBJ_APP_MOCK_DIR = $(APP_MOCK_DIR)/obj
45 GRAB_OUTPUT_DIR = ../output
46 PQOS_SRCS = $(sort $(wildcard $(PQOS_DIR)/*.c))
47 PQOS_OBJS = $(PQOS_SRCS:$(PQOS_DIR)/%.c=$(OBJ_DIR)/%.o)
48 APP_MOCK_SRCS = $(sort $(wildcard $(APP_MOCK_DIR)/*.c))
49 APP_MOCK_OBJS = $(APP_MOCK_SRCS:$(APP_MOCK_DIR)/%.c=$(OBJ_APP_MOCK_DIR)/%.o)
50
51 TESTS_SRCS = $(sort $(wildcard test_*.c))
52 TESTS = $(TESTS_SRCS:%.c=$(BIN_DIR)/%)
53
54 LDFLAGS = -L$(LIB_DIR) -L$(MOCK_DIR) -L$(GRAB_OUTPUT_DIR) -lpqos -lcmocka -lpqosmock -lgraboutput\
55 -z noexecstack -z relro -z now
56 CFLAGS = -I$(LIB_DIR) -I$(PQOS_DIR) -I$(MOCK_DIR) -I$(GRAB_OUTPUT_DIR) -I$(APP_MOCK_DIR)\
57 -W -Wall -Wextra -Wstrict-prototypes -Wmissing-prototypes \
58 -Wmissing-declarations -Wold-style-definition -Wpointer-arith \
59 -Wcast-qual -Wundef -Wwrite-strings \
60 -Wformat -Wformat-security -fstack-protector-strong \
61 -Wunreachable-code -Wsign-compare -Wno-endif-labels
62
63
64 IS_GCC = $(shell $(CC) -v 2>&1 | grep -c "^gcc version ")
65 IS_CLANG = $(shell $(CC) -v 2>&1 | grep -c "^clang version ")
66
67 # GCC-only options
68 ifeq ($(IS_GCC),1)
69 CFLAGS += -fno-strict-overflow \
70 -fno-delete-null-pointer-checks \
71 -fwrapv \
72 -fstack-clash-protection \
73 -fcf-protection=full
74 endif
75
76 CFLAGS += -g -ggdb -O0
77
78 all: $(TESTS)
79
80 $(OBJ_DIR)/main.o: $(PQOS_DIR)/main.c
81 mkdir -p $(OBJ_DIR)
82 $(CC) $(CFLAGS) -c $< -o $@
83 objcopy $@ --redefine-sym main=appmain $@
84
85 $(OBJ_DIR)/%.o: $(PQOS_DIR)/%.c
86 mkdir -p $(OBJ_DIR)
87 $(CC) $(CFLAGS) -c $< -o $@
88
89 $(OBJ_APP_MOCK_DIR)/%.o: $(APP_MOCK_DIR)/%.c
90 mkdir -p $(OBJ_APP_MOCK_DIR)
91 $(CC) $(CFLAGS) -c $< -o $@
92
93 $(BIN_DIR)/test_alloc: ./test_alloc.c $(PQOS_OBJS)
94 mkdir -p $(BIN_DIR)
95 $(CC) $(CFLAGS) \
96 -Wl,--wrap=puts \
97 -Wl,--wrap=printf \
98 -Wl,--wrap=putchar \
99 -Wl,--wrap=exit \
100 -Wl,--wrap=pqos_l3ca_get \
101 -Wl,--wrap=pqos_l2ca_get \
102 -Wl,--wrap=pqos_mba_get \
103 -Wl,--wrap=pqos_pid_get_pid_assoc \
104 -Wl,--wrap=pqos_alloc_assoc_get \
105 -Wl,--wrap=pqos_mon_assoc_get \
106 -Wl,--wrap=pqos_inter_get \
107 -Wl,--wrap=pqos_mba_set \
108 -Wl,--wrap=pqos_l3ca_set \
109 -Wl,--wrap=pqos_l2ca_set \
110 -Wl,--wrap=pqos_alloc_assoc_set \
111 -Wl,--wrap=pqos_alloc_assoc_set_pid \
112 -Wl,--start-group \
113 $(LDFLAGS) $(filter-out ./obj/alloc.o,$(PQOS_OBJS)) $< -Wl,--end-group -o $@
114
115 $(BIN_DIR)/test_profiles: ./test_profiles.c $(PQOS_OBJS) $(APP_MOCK_OBJS)
116 mkdir -p $(BIN_DIR)
117 $(CC) $(CFLAGS) \
118 -Wl,--wrap=puts \
119 -Wl,--wrap=printf \
120 -Wl,--wrap=putchar \
121 -Wl,--wrap=exit \
122 -Wl,--wrap=selfn_allocation_class \
123 -Wl,--start-group \
124 $(LDFLAGS) $(filter-out ./obj/profiles.o,$(PQOS_OBJS)) $(APP_MOCK_OBJS) $< -Wl,--end-group -o $@
125
126 $(BIN_DIR)/test_main: ./test_main.c $(PQOS_OBJS)
127 mkdir -p $(BIN_DIR)
128 $(CC) $(CFLAGS) \
129 -Wl,--wrap=puts \
130 -Wl,--wrap=printf \
131 -Wl,--wrap=putchar \
132 -Wl,--wrap=exit \
133 -Wl,--start-group \
134 $(LDFLAGS) $(PQOS_OBJS) $< -Wl,--end-group -o $@
135
136 $(BIN_DIR)/test_iface_select: ./test_iface_select.c $(PQOS_OBJS)
137 mkdir -p $(BIN_DIR)
138 $(CC) $(CFLAGS) \
139 -Wl,--start-group \
140 $(LDFLAGS) $(PQOS_OBJS) $< -Wl,--end-group -o $@
141
142
143 .PHONY: run
144 run: $(TESTS)
145 @echo "Running pqos Unit Tests"
146 @for test in $(TESTS); do \
147 bash -c "LD_LIBRARY_PATH=$(MOCK_DIR):$(LIB_DIR):$(GRAB_OUTPUT_DIR) ./$$test" || true; \
148 done;
149
150 CLANGFORMAT?=clang-format
151 .PHONY: clang-format
152 clang-format:
153 @for file in $(wildcard *.[ch]) $(wildcard $(APP_MOCK_DIR)/*.[ch]); do \
154 echo "Checking style $$file"; \
155 $(CLANGFORMAT) -style=file "$$file" | diff "$$file" - | tee /dev/stderr | [ $$(wc -c) -eq 0 ] || \
156 { echo "ERROR: $$file has style problems"; exit 1; } \
157 done
158
159 CODESPELL?=codespell
160 .PHONY: codespell
161 codespell:
162 $(CODESPELL) . --skip $(OBJ_DIR) -q 2
163
164 CHECKPATCH?=checkpatch.pl
165 .PHONY: checkpatch
166 checkpatch:
167 $(CHECKPATCH) --no-tree --no-signoff --emacs \
168 --ignore CODE_INDENT,INITIALISED_STATIC,LEADING_SPACE,SPLIT_STRING,\
169 NEW_TYPEDEFS,UNSPECIFIED_INT,BLOCK_COMMENT_STYLE,\
170 SPDX_LICENSE_TAG,ARRAY_SIZE,EMBEDDED_FUNCTION_NAME,\
171 SYMBOLIC_PERMS,CONST_STRUCT,SPACING \
172 -f test_alloc.c \
173 -f test_main.c \
174 -f test_iface_select.c \
175 -f test_profiles.c \
176 -f mock/mock_alloc.c \
177 -f mock/mock_alloc.h \
178
179 .PHONY: style
180 style:
181 $(MAKE) checkpatch
182 $(MAKE) clang-format
183 $(MAKE) codespell
184
185 clean:
186 rm -rf $(BIN_DIR)
187 rm -rf $(OBJ_DIR)
188 rm -rf $(OBJ_APP_MOCK_DIR)