2018-05-14 13:03:37 +00:00
|
|
|
COMPONENTS_DIR=../..
|
2020-07-23 13:16:15 +00:00
|
|
|
COMPILER_ICLUDE_DIR=$(shell echo `which xtensa-esp32-elf-gcc | xargs dirname | xargs dirname`/xtensa-esp32-elf)
|
|
|
|
CFLAGS=-std=gnu99 -Og -ggdb -ffunction-sections -fdata-sections -nostdlib -Wall -Werror=all -Wno-int-to-pointer-cast -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wno-macro-redefined -Wno-constant-conversion -Wno-incompatible-pointer-types-discards-qualifiers -Wno-typedef-redefinition -Wno-incompatible-pointer-types -Wextra \
|
2019-06-28 12:12:10 +00:00
|
|
|
-Wno-unused-parameter -Wno-sign-compare -Wno-address -Wno-unused-variable -DESP_PLATFORM -D IDF_VER=\"v3.1\" -MMD -MP -DWITH_POSIX -DLWIP_NO_CTYPE_H=1
|
2021-09-20 06:07:03 +00:00
|
|
|
INC_DIRS=-I . -I ./build/config -I $(COMPONENTS_DIR)/newlib/platform_include -I $(COMPONENTS_DIR)/newlib/include -I $(COMPONENTS_DIR)/driver/include -I $(COMPONENTS_DIR)/esp32/include -I $(COMPONENTS_DIR)/ethernet/include -I $(COMPONENTS_DIR)/freertos/esp_additions/include -I $(COMPONENTS_DIR)/freertos/esp_additions/include/freertos -I $(COMPONENTS_DIR)/freertos/FreeRTOS-Kernel/include -I $(COMPONENTS_DIR)/heap/include -I $(COMPONENTS_DIR)/lwip/lwip/src/include -I $(COMPONENTS_DIR)/lwip/include/apps -I $(COMPONENTS_DIR)/lwip/lwip/src/include/netif -I $(COMPONENTS_DIR)/lwip/lwip/src/include/posix -I $(COMPONENTS_DIR)/lwip/port/esp32/include -I $(COMPONENTS_DIR)/lwip/lwip/src/include/posix -I $(COMPONENTS_DIR)/lwip/include/apps/ping -I $(COMPONENTS_DIR)/lwip/include/apps/sntp -I $(COMPONENTS_DIR)/soc/esp32/include -I $(COMPONENTS_DIR)/soc/include -I $(COMPONENTS_DIR)/tcpip_adapter/include -I $(COMPONENTS_DIR)/esp_rom/include -I $(COMPONENTS_DIR)/esp_common/include -I $(COMPONENTS_DIR)/esp_hw_support/include -I $(COMPONENTS_DIR)/xtensa/include -I $(COMPONENTS_DIR)/xtensa/esp32/include -I $(COMPONENTS_DIR)/esp_wifi/include -I $(COMPONENTS_DIR)/esp_event/include -I $(COMPONENTS_DIR)/freertos/FreeRTOS-Kernel/portable/xtensa/include -I $(COMPONENTS_DIR)/esp_system/include -I $(COMPONENTS_DIR)/esp_timer/include -I $(COMPONENTS_DIR)/soc/include -I $(COMPONENTS_DIR)/soc/include -I $(COMPONENTS_DIR)/soc/src/esp32/include -I $(COMPONENTS_DIR)/soc/esp32/include -I $(COMPONENTS_DIR)/esp_netif/include -I $(COMPONENTS_DIR)/esp_eth/include -I $(COMPONENTS_DIR)/esp_netif/lwip -I $(COMPONENTS_DIR)/hal/include -I $(COMPONENTS_DIR)/hal/esp32/include -I $(COMPILER_ICLUDE_DIR)/include
|
2018-05-14 13:03:37 +00:00
|
|
|
TEST_NAME=test
|
|
|
|
FUZZ=afl-fuzz
|
2018-09-14 12:30:03 +00:00
|
|
|
GEN_CFG=generate_config
|
2018-05-14 13:03:37 +00:00
|
|
|
LD=$(CC)
|
2018-05-18 13:54:08 +00:00
|
|
|
ifeq ($(MODE),dhcp_client)
|
|
|
|
DEPENDENCY_INJECTION=-include dhcp_di.h
|
2018-09-14 12:30:03 +00:00
|
|
|
OBJECTS=dhcp.o def.o network_mock.o test_dhcp_client.o
|
2018-05-18 13:54:08 +00:00
|
|
|
SAMPLE_PACKETS=in_dhcp_client
|
|
|
|
else ifeq ($(MODE),dhcp_server)
|
|
|
|
DEPENDENCY_INJECTION=-include dhcpserver_di.h
|
2020-07-23 13:16:15 +00:00
|
|
|
OBJECTS=dhcpserver.o def.o test_dhcp_server.o network_mock.o esp_netif_loopback_mock.o
|
2018-05-18 13:54:08 +00:00
|
|
|
SAMPLE_PACKETS=in_dhcp_server
|
|
|
|
else ifeq ($(MODE),dns)
|
|
|
|
CFLAGS+=-DNOT_MOCK_DNS
|
|
|
|
DEPENDENCY_INJECTION=-include dns_di.h
|
2018-09-14 12:30:03 +00:00
|
|
|
OBJECTS=dns.o def.o test_dns.o network_mock.o
|
2018-05-18 13:54:08 +00:00
|
|
|
SAMPLE_PACKETS=in_dns
|
|
|
|
else
|
|
|
|
$(error Please specify MODE: dhcp_server, dhcp_client, dns)
|
2018-05-15 13:49:10 +00:00
|
|
|
endif
|
2018-05-14 13:03:37 +00:00
|
|
|
|
2018-05-15 13:49:10 +00:00
|
|
|
ifeq ($(INSTR),off)
|
2018-05-14 13:03:37 +00:00
|
|
|
CC=gcc
|
2018-05-15 13:49:10 +00:00
|
|
|
CFLAGS+=-DINSTR_IS_OFF
|
2018-05-14 13:03:37 +00:00
|
|
|
TEST_NAME=test_sim
|
|
|
|
else
|
|
|
|
CC=afl-clang-fast
|
|
|
|
endif
|
|
|
|
|
|
|
|
CFLAGS+=$(INC_DIRS)
|
|
|
|
|
|
|
|
all: $(TEST_NAME)
|
|
|
|
|
2018-09-14 12:30:03 +00:00
|
|
|
def.o: ../lwip/src/core/def.c $(GEN_CFG)
|
|
|
|
@echo "[CC] $<"
|
|
|
|
@$(CC) $(CFLAGS) -D BUILDING_DEF $(DEPENDENCY_INJECTION) -c $< -o $@
|
|
|
|
|
|
|
|
dns.o: ../lwip/src/core/dns.c $(GEN_CFG)
|
2018-05-18 13:54:08 +00:00
|
|
|
@echo "[CC] $<"
|
|
|
|
@$(CC) $(CFLAGS) $(DEPENDENCY_INJECTION) -c $< -o $@
|
|
|
|
|
2018-09-14 12:30:03 +00:00
|
|
|
dhcp.o: ../lwip/src/core/ipv4/dhcp.c $(GEN_CFG)
|
2018-05-15 13:49:10 +00:00
|
|
|
@echo "[CC] $<"
|
2018-05-18 13:54:08 +00:00
|
|
|
@$(CC) $(CFLAGS) $(DEPENDENCY_INJECTION) -c $< -o $@
|
2018-05-15 13:49:10 +00:00
|
|
|
|
2018-09-14 12:30:03 +00:00
|
|
|
dhcpserver.o: ../apps/dhcpserver/dhcpserver.c $(GEN_CFG)
|
2018-05-14 13:03:37 +00:00
|
|
|
@echo "[CC] $<"
|
2018-05-18 13:54:08 +00:00
|
|
|
@$(CC) $(CFLAGS) $(DEPENDENCY_INJECTION) -c $< -o $@
|
2018-05-14 13:03:37 +00:00
|
|
|
|
2018-09-14 12:30:03 +00:00
|
|
|
%.o: %.c $(GEN_CFG)
|
2018-05-14 13:03:37 +00:00
|
|
|
@echo "[CC] $<"
|
|
|
|
@$(CC) $(CFLAGS) -c $< -o $@
|
|
|
|
|
2018-09-14 12:30:03 +00:00
|
|
|
.PHONY: $(GEN_CFG)
|
|
|
|
$(GEN_CFG):
|
|
|
|
$(IDF_PATH)/tools/idf.py reconfigure
|
|
|
|
|
2018-05-14 13:03:37 +00:00
|
|
|
$(TEST_NAME): $(OBJECTS)
|
|
|
|
@echo "[LD] $@"
|
|
|
|
@$(LD) $(OBJECTS) -o $@ $(LDLIBS)
|
|
|
|
|
|
|
|
fuzz: $(TEST_NAME)
|
2018-07-27 07:26:51 +00:00
|
|
|
@$(FUZZ) -t 5000+ -i "$(SAMPLE_PACKETS)" -o "out" -- ./$(TEST_NAME)
|