summaryrefslogtreecommitdiffstats
path: root/test/ext/Makefile
blob: d7acb7bc2b289db0b31dcae7084f1ec75834bb50 (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
TEST_EXT_DIR=$(TEST_DIR)/ext
VAPI_BINDIR = $(TEST_BR)/vapi_test
VAPI_CBIN = $(addprefix $(VAPI_BINDIR), /vapi_c_test)
VAPI_CPPBIN = $(addprefix $(VAPI_BINDIR), /vapi_cpp_test)
VOM_BINDIR = $(TEST_BR)/vom_test

VAPI_LIBS = \
  -L$(VPP_INSTALL_PATH)/vpp/lib \
  -lvppinfra -lvlibmemoryclient -lsvm -lpthread -lcheck -lrt -lm -lvapiclient

ifneq ($(filter centos opensuse opensuse-tumbleweed opensuse-leap,$(OS_ID)),$(OS_ID))
VAPI_LIBS += -lsubunit
endif

FLAGS = -g -Wall -lstdc++ -pthread -I$(WS_ROOT)/src -I$(VPP_INSTALL_PATH)/vpp/include -I$(VAPI_BINDIR)
CFLAGS = -std=gnu99 $(FLAGS)
CPPFLAGS = -std=c++11 $(FLAGS) -I$(WS_ROOT)/extras/vom

$(VAPI_BINDIR):
	@mkdir -p $(VAPI_BINDIR)

CSRC = $(TEST_EXT_DIR)/vapi_c_test.c

$(VAPI_BINDIR)/fake.api.vapi.h: fake.api.json $(WS_ROOT)/src/vpp-api/vapi/vapi_c_gen.py | $(VAPI_BINDIR)
	$(WS_ROOT)/src/vpp-api/vapi/vapi_c_gen.py --prefix $(VAPI_BINDIR) $<

$(VAPI_BINDIR)/fake.api.vapi.hpp: fake.api.json $(WS_ROOT)/src/vpp-api/vapi/vapi_cpp_gen.py | $(VAPI_BINDIR)
	$(WS_ROOT)/src/vpp-api/vapi/vapi_cpp_gen.py --prefix $(VAPI_BINDIR) $<

$(VAPI_CBIN): $(CSRC) $(VAPI_BINDIR)/fake.api.vapi.h | $(VAPI_BINDIR)
	$(CC) -o $@ $(CFLAGS) $(CSRC) $(VAPI_LIBS)

$(VAPI_CBIN).d: $(CSRC) $(VAPI_BINDIR)/fake.api.vapi.h
	$(CC) -o $@ $(CFLAGS) -MM -MT '$(VAPI_CBIN)' $(CSRC) > $@


ifeq ($(filter rhel centos,$(OS_ID)),$(OS_ID))
VAPI_CPPBIN=
else
CPPSRC = $(TEST_EXT_DIR)/vapi_cpp_test.cpp

$(VAPI_CPPBIN): $(CPPSRC) $(VAPI_BINDIR)/fake.api.vapi.hpp | $(VAPI_BINDIR)
	$(CXX) -o $@ $(CPPFLAGS) $(CPPSRC) $(VAPI_LIBS)

$(VAPI_CPPBIN).d: $(CPPSRC) $(VAPI_BINDIR)/fake.api.vapi.hpp
	$(CXX) -o $@ $(CPPFLAGS) -MM -MT '$(VAPI_CPPBIN)' $(CPPSRC) > $@
endif

ifneq ($(EXTENDED_TESTS),)
ifeq ($(filter yes y 1,$(EXTENDED_TESTS)),$(EXTENDED_TESTS))
VOM_BIN = $(addprefix $(VOM_BINDIR), /vom_test)
VOM_CPPSRC = $(TEST_EXT_DIR)/vom_test.cpp

$(VOM_BINDIR):
	@mkdir -p $(VOM_BINDIR)

LIB_VOM = -lvom
VOM_LIBS = \
	-L$(VPP_INSTALL_PATH)/vom/lib \
	-lvom						\
	-lboost_thread					\
	-lboost_system					\
	-lboost_filesystem				\
	-lboost_unit_test_framework			\
	$(VAPI_LIBS)

VOM_CPPFLAGS = \
	-I $(WS_ROOT)/src/vpp-api/ \
	-DBOOST_LOG_DYN_LINK \
	$(CPPFLAGS)

$(VOM_BIN): $(VOM_CPPSRC) $(VOM_BINDIR)
	$(CXX) -o $@ $(VOM_CPPFLAGS) -O0 -g $(VOM_CPPSRC) $(VOM_LIBS) -Wl,-rpath,$(VPP_INSTALL_PATH)/vom/lib

$(VOM_BIN).d: $(VOM_CPPSRC) $(VOM_BINDIR)
	$(CXX) -o $@ $(VOM_CPPFLAGS) -MM -MT '$(VOM_BIN)' $(VOM_CPPSRC) > $@
endif
endif

.PHONY: test-apps
test-apps: $(VAPI_CBIN) $(VAPI_CPPBIN) $(VOM_BIN)

.PHONY: clean
clean:
	@rm -rf $(VAPI_BINDIR) $(VOM_BINDIR)

ifneq ($(MAKECMDGOALS),clean)
-include $(VAPI_CBIN).d
ifneq ($(VAPI_CPPBIN),)
-include $(VAPI_CPPBIN).d
endif
ifneq ($(VOM_BIN),)
-include $(VOM_BIN).d
endif
endif
class="p">) % 26]; return s; } void exit (int); int test_pfhash_main (unformat_input_t * input) { u32 seed = 0xdeaddabe; int i, iter; u32 nkeys = 4; u32 niter = 1; u32 nbuckets = 1; u32 bucket; u32 sizes[3] = { 16, 8, 4 }, this_size, size; u8 **keys = 0; pfhash_t _rec, *p = &_rec; while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { if (unformat (input, "seed %d", &seed)) ; else if (unformat (input, "niter %d", &niter)) ; else if (unformat (input, "nkeys %d", &nkeys)) ; else if (unformat (input, "nbuckets %d", &nbuckets)) ; else if (unformat (input, "verbose %d", &verbose)) ; else if (unformat (input, "verbose")) verbose = 1; else clib_error ("unknown input `%U'", format_unformat_error, input); } vec_validate (keys, nkeys - 1); for (i = 0; i < nkeys; i++) { int j, k; again: keys[i] = random_aligned_string (&seed, 16); for (j = 0; j < (i - 1); j++) { /* Make sure we don't have a dup key in the min key size */ for (k = 0; k < 4; k++) { if (keys[i][k] != keys[j][k]) goto check_next_key; } vec_free (keys[i]); goto again; check_next_key: ; } } /* test 8 byte key, 8 byte value case separately */ for (size = 8; size < 9; size++) { this_size = 8; fformat (stdout, "%d-byte key 8 byte value test\n", this_size); pfhash_init (p, "test", 8 /* key size */ , 8 /* value size */ , nbuckets + 1); for (iter = 0; iter < niter; iter++) { bucket = 0; for (i = 0; i < nkeys; i++) { bucket = (i % nbuckets) + 1; pfhash_set (p, bucket, keys[i], (void *) (u64) 0x100000000ULL + i + 1); } for (i = 0; i < nkeys; i++) { bucket = (i % nbuckets) + 1; if (pfhash_get (p, bucket, keys[i]) != (u64) 0x100000000ULL + i + 1) { clib_warning ("key %d bucket %d lookup FAIL\n", i, bucket); (void) pfhash_get (p, bucket, keys[i]); } } /* test inline functions */ for (i = 0; i < nkeys; i++) { u32 bucket_contents; u64 value = 0xdeadbeef; bucket = (i % nbuckets) + 1; pfhash_prefetch_bucket (p, bucket); bucket_contents = pfhash_read_bucket_prefetch_kv (p, bucket); value = pfhash_search_kv_8v8 (p, bucket_contents, (u64 *) keys[i]); if (value != (u64) 0x100000000ULL + i + 1) clib_warning ("key %d bucket %d lookup FAIL\n", i, bucket); } if (verbose) fformat (stdout, "%U\n", format_pfhash, p, verbose > 1); for (i = 0; i < nkeys; i++) { bucket = (i % nbuckets) + 1; pfhash_unset (p, bucket, keys[i]); } for (i = 0; i < nkeys; i++) { bucket = (i % nbuckets) + 1; if (pfhash_get (p, bucket, keys[i]) != (u64) ~ 0) { clib_warning ("key %d bucket %d lookup FAIL\n", i, bucket); (void) pfhash_get (p, bucket, keys[i]); } } /* test inline functions */ for (i = 0; i < nkeys; i++) { u32 bucket_contents; u64 value = 0xdeadbeef; bucket = (i % nbuckets) + 1; pfhash_prefetch_bucket (p, bucket); bucket_contents = pfhash_read_bucket_prefetch_kv (p, bucket); value = pfhash_search_kv_8v8 (p, bucket_contents, (u64 *) keys[i]); if (value != (u64) ~ 0) clib_warning ("key %d bucket %d lookup FAIL\n", i, bucket); } } pfhash_free (p); } /* test other cases */ for (size = 0; size < ARRAY_LEN (sizes); size++) { this_size = sizes[size]; fformat (stdout, "%d-byte key test\n", this_size); pfhash_init (p, "test", this_size, 4 /* value size */ , nbuckets + 1); for (iter = 0; iter < niter; iter++) { bucket = 0; for (i = 0; i < nkeys; i++) { bucket = (i % nbuckets) + 1; pfhash_set (p, bucket, keys[i], (void *) (u64) i + 1); } for (i = 0; i < nkeys; i++) { bucket = (i % nbuckets) + 1; if (pfhash_get (p, bucket, keys[i]) != i + 1) { clib_warning ("key %d bucket %d lookup FAIL\n", i, bucket); (void) pfhash_get (p, bucket, keys[i]); } } /* test inline functions */ for (i = 0; i < nkeys; i++) { u32 bucket_contents; u32 value = 0xdeadbeef; bucket = (i % nbuckets) + 1; pfhash_prefetch_bucket (p, bucket); bucket_contents = pfhash_read_bucket_prefetch_kv (p, bucket); switch (p->key_size) { case 16: value = pfhash_search_kv_16 (p, bucket_contents, (u32x4 *) keys[i]); break; case 8: value = pfhash_search_kv_8 (p, bucket_contents, (u64 *) keys[i]); break; case 4: value = pfhash_search_kv_4 (p, bucket_contents, (u32 *) keys[i]); break; } if (value != (i + 1)) clib_warning ("key %d bucket %d lookup FAIL\n", i, bucket); } if (verbose) fformat (stdout, "%U\n", format_pfhash, p, verbose > 1); for (i = 0; i < nkeys; i++) { bucket = (i % nbuckets) + 1; pfhash_unset (p, bucket, keys[i]); } for (i = 0; i < nkeys; i++) { bucket = (i % nbuckets) + 1; if (pfhash_get (p, bucket, keys[i]) != (u64) ~ 0) { clib_warning ("key %d bucket %d lookup FAIL\n", i, bucket); (void) pfhash_get (p, bucket, keys[i]); } } /* test inline functions */ for (i = 0; i < nkeys; i++) { u32 bucket_contents; u32 value = 0xdeadbeef; bucket = (i % nbuckets) + 1; pfhash_prefetch_bucket (p, bucket); bucket_contents = pfhash_read_bucket_prefetch_kv (p, bucket); switch (p->key_size) { case 16: value = pfhash_search_kv_16 (p, bucket_contents, (u32x4 *) keys[i]); break; case 8: value = pfhash_search_kv_8 (p, bucket_contents, (u64 *) keys[i]); break; case 4: value = pfhash_search_kv_4 (p, bucket_contents, (u32 *) keys[i]); break; } if (value != (u32) ~ 0) clib_warning ("key %d bucket %d lookup FAIL\n", i, bucket); } } pfhash_free (p); } exit (0); } #else int test_pfhash_main (unformat_input_t * input) { clib_warning ("MMX unit not available"); return 0; } #endif #ifdef CLIB_UNIX int main (int argc, char *argv[]) { unformat_input_t i; int ret; unformat_init_command_line (&i, argv); ret = test_pfhash_main (&i); unformat_free (&i); return ret; } #endif /* CLIB_UNIX */ /* * fd.io coding-style-patch-verification: ON * * Local Variables: * eval: (c-set-style "gnu") * End: */