devlink.sh \
ethtool.sh \
rt-addr.sh \
+ rt-route.sh \
test_ynl_cli.sh \
test_ynl_ethtool.sh \
# end of TEST_PROGS
devlink \
ethtool \
rt-addr \
-# end of TEST_GEN_FILES
-
-BINS := \
rt-route \
-# end of BINS
+# end of TEST_GEN_FILES
TEST_FILES := ynl_nsim_lib.sh
INSTALL_PATH ?= $(DESTDIR)/usr/share/kselftest
-all: $(TEST_GEN_PROGS) $(TEST_GEN_FILES) $(BINS)
+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) $(BINS): %: %.c ../lib/ynl.a ../generated/protos.a
+$(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)
./$$test; \
done
-install: $(TEST_GEN_PROGS) $(TEST_GEN_FILES) $(BINS)
+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 \
@for file in $(TEST_FILES); do \
cp $$file $(INSTALL_PATH)/ynl/$$file; \
done
- @for bin in $(TEST_GEN_PROGS) $(TEST_GEN_FILES) $(BINS); do \
+ @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 \
rm -f *.o *.d *~
distclean: clean
- rm -f $(TEST_GEN_PROGS) $(TEST_GEN_FILES) $(BINS)
+ rm -f $(TEST_GEN_PROGS) $(TEST_GEN_FILES)
.PHONY: all install clean distclean run_tests
.DEFAULT_GOAL=all
#include <arpa/inet.h>
#include <net/if.h>
+#include <kselftest_harness.h>
+
#include "rt-route-user.h"
-static void rt_route_print(struct rt_route_getroute_rsp *r)
+static void rt_route_print(struct __test_metadata *_metadata,
+ struct rt_route_getroute_rsp *r)
{
char ifname[IF_NAMESIZE];
char route_str[64];
if (r->_present.oif) {
name = if_indextoname(r->oif, ifname);
+ EXPECT_NE(NULL, name);
if (name)
- printf("oif: %-16s ", name);
+ ksft_print_msg("oif: %-16s ", name);
}
if (r->_len.dst) {
printf("\n");
}
-int main(int argc, char **argv)
+FIXTURE(rt_route)
+{
+ struct ynl_sock *ys;
+};
+
+FIXTURE_SETUP(rt_route)
+{
+ struct ynl_error yerr;
+
+ self->ys = ynl_sock_create(&ynl_rt_route_family, &yerr);
+ ASSERT_NE(NULL, self->ys)
+ TH_LOG("failed to create rt-route socket: %s", yerr.msg);
+}
+
+FIXTURE_TEARDOWN(rt_route)
+{
+ ynl_sock_destroy(self->ys);
+}
+
+TEST_F(rt_route, dump)
{
struct rt_route_getroute_req_dump *req;
struct rt_route_getroute_list *rsp;
- struct ynl_error yerr;
- struct ynl_sock *ys;
+ struct in6_addr v6_expected;
+ struct in_addr v4_expected;
+ bool found_v4 = false;
+ bool found_v6 = false;
- ys = ynl_sock_create(&ynl_rt_route_family, &yerr);
- if (!ys) {
- fprintf(stderr, "YNL: %s\n", yerr.msg);
- return 1;
- }
+ /* The bash wrapper configures 192.168.1.1/24 and 2001:db8::1/64,
+ * make sure we can find the connected routes in the dump.
+ */
+ inet_pton(AF_INET, "192.168.1.0", &v4_expected);
+ inet_pton(AF_INET6, "2001:db8::", &v6_expected);
req = rt_route_getroute_req_dump_alloc();
- if (!req)
- goto err_destroy;
+ ASSERT_NE(NULL, req);
- rsp = rt_route_getroute_dump(ys, req);
+ rsp = rt_route_getroute_dump(self->ys, req);
rt_route_getroute_req_dump_free(req);
- if (!rsp)
- goto err_close;
+ ASSERT_NE(NULL, rsp) {
+ TH_LOG("dump failed: %s", self->ys->err.msg);
+ }
- if (ynl_dump_empty(rsp))
- fprintf(stderr, "Error: no routeesses reported\n");
- ynl_dump_foreach(rsp, route)
- rt_route_print(route);
- rt_route_getroute_list_free(rsp);
+ ASSERT_FALSE(ynl_dump_empty(rsp)) {
+ rt_route_getroute_list_free(rsp);
+ TH_LOG("no routes reported");
+ }
- ynl_sock_destroy(ys);
- return 0;
+ ynl_dump_foreach(rsp, route) {
+ rt_route_print(_metadata, route);
-err_close:
- fprintf(stderr, "YNL: %s\n", ys->err.msg);
-err_destroy:
- ynl_sock_destroy(ys);
- return 2;
+ if (route->_hdr.rtm_table == RT_TABLE_LOCAL)
+ continue;
+
+ if (route->_len.dst == 4 && route->_hdr.rtm_dst_len == 24)
+ found_v4 |= !memcmp(route->dst, &v4_expected, 4);
+ if (route->_len.dst == 16 && route->_hdr.rtm_dst_len == 64)
+ found_v6 |= !memcmp(route->dst, &v6_expected, 16);
+ }
+ rt_route_getroute_list_free(rsp);
+
+ EXPECT_TRUE(found_v4);
+ EXPECT_TRUE(found_v6);
}
+
+TEST_HARNESS_MAIN