summaryrefslogtreecommitdiff
path: root/tools/net/ynl/tests/Makefile
blob: 40827ca8e579d3cb13056a5f4bb8e7ed1d94ea1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# SPDX-License-Identifier: GPL-2.0
# Makefile for YNL tests

include ../Makefile.deps

CC=gcc
CFLAGS += -std=gnu11 -O2 -W -Wall -Wextra -Wno-unused-parameter -Wshadow \
	-I../lib/ -I../generated/ -I../../../testing/selftests/ \
	-idirafter $(UAPI_PATH)
ifneq ("$(NDEBUG)","1")
  CFLAGS += -g -fsanitize=address -fsanitize=leak -static-libasan
endif

LDLIBS=../lib/ynl.a ../generated/protos.a

TEST_PROGS := \
	devlink.sh \
	ethtool.sh \
	rt-addr.sh \
	rt-route.sh \
	test_ynl_cli.sh \
	test_ynl_ethtool.sh \
# end of TEST_PROGS

TEST_GEN_PROGS := \
	netdev \
	ovs \
	rt-link \
	tc \
# end of TEST_GEN_PROGS

TEST_GEN_FILES := \
	devlink \
	ethtool \
	rt-addr \
	rt-route \
# end of TEST_GEN_FILES

TEST_FILES := \
	ethtool.py \
	ynl_nsim_lib.sh \
# end of TEST_FILES

CFLAGS_netdev:=$(CFLAGS_netdev) $(CFLAGS_rt-link)
CFLAGS_ovs:=$(CFLAGS_ovs_datapath)

include $(wildcard *.d)

INSTALL_PATH ?= $(DESTDIR)/usr/share/kselftest

all: $(TEST_GEN_PROGS) $(TEST_GEN_FILES)

../lib/ynl.a:
	@$(MAKE) -C ../lib

../generated/protos.a:
	@$(MAKE) -C ../generated

$(TEST_GEN_PROGS) $(TEST_GEN_FILES): %: %.c ../lib/ynl.a ../generated/protos.a
	@echo -e '\tCC test $@'
	@$(COMPILE.c) $(CFLAGS_$@) $@.c -o $@.o
	@$(LINK.c) $@.o -o $@  $(LDLIBS)

run_tests:
	@for test in $(TEST_PROGS); do \
		./$$test; \
	done

install: $(TEST_GEN_PROGS) $(TEST_GEN_FILES)
	@mkdir -p $(INSTALL_PATH)/ynl
	@cp ../../../testing/selftests/kselftest/ktap_helpers.sh $(INSTALL_PATH)/
	@for test in $(TEST_PROGS); do \
		name=$$(basename $$test); \
		sed -e 's|^ynl=.*|ynl="ynl"|' \
		    -e 's|^ynl_ethtool=.*|ynl_ethtool="ynl-ethtool"|' \
		    -e 's|KSELFTEST_KTAP_HELPERS=.*|KSELFTEST_KTAP_HELPERS="$(INSTALL_PATH)/ktap_helpers.sh"|' \
		    $$test > $(INSTALL_PATH)/ynl/$$name; \
		chmod +x $(INSTALL_PATH)/ynl/$$name; \
	done
	@for file in $(TEST_FILES); do \
		cp $$file $(INSTALL_PATH)/ynl/$$file; \
	done
	@for bin in $(TEST_GEN_PROGS) $(TEST_GEN_FILES); do \
		cp $$bin $(INSTALL_PATH)/ynl/$$bin; \
	done
	@for test in $(TEST_PROGS) $(TEST_GEN_PROGS); do \
		echo "ynl:$$test"; \
	done > $(INSTALL_PATH)/kselftest-list.txt

clean:
	rm -f *.o *.d *~

distclean: clean
	rm -f $(TEST_GEN_PROGS) $(TEST_GEN_FILES)

.PHONY: all install clean distclean run_tests
.DEFAULT_GOAL=all