summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2024-08-22 11:30:19 (GMT)
committerThomas Haller <thaller@redhat.com>2024-08-22 11:37:45 (GMT)
commit1aa16ea9d99e935d28e9f3f56c080dcfc4499689 (patch)
treea8796e4f79d8bf8ec7db480328fe5ba7ac012170
parent7f099cf01ce37093f6a908282bb61fa4e63c07c0 (diff)
downloadlibnl-1aa16ea9d99e935d28e9f3f56c080dcfc4499689.zip
libnl-1aa16ea9d99e935d28e9f3f56c080dcfc4499689.tar.gz
libnl-1aa16ea9d99e935d28e9f3f56c080dcfc4499689.tar.bz2
tests: print route list before failure in _nltst_assert_route_list()
It's hard to debug a failure. Print what we were comparing before crashing.
-rw-r--r--tests/nl-test-util.c42
1 files changed, 34 insertions, 8 deletions
diff --git a/tests/nl-test-util.c b/tests/nl-test-util.c
index 27cbb14..fefc662 100644
--- a/tests/nl-test-util.c
+++ b/tests/nl-test-util.c
@@ -936,9 +936,7 @@ bool _nltst_select_route_match(struct nl_object *route,
ck_assert_ptr_nonnull(route);
ck_assert_str_eq(nl_object_get_type(route), "route/route");
-
- if (!select_route)
- return true;
+ ck_assert_ptr_nonnull(select_route);
route_ = (struct rtnl_route *)route;
@@ -1033,7 +1031,7 @@ bool _nltst_select_route_match(struct nl_object *route,
#undef _check
- return false;
+ return true;
}
/*****************************************************************************/
@@ -1052,16 +1050,44 @@ void _nltst_assert_route_list(struct nl_object *const *objs, ssize_t len,
0
};
_nl_auto_free char *s = _nltst_object_to_string(route);
+ bool good;
+
+ if (!expected_routes[i]) {
+ good = false;
+ } else {
+ _nltst_select_route_parse(expected_routes[i],
+ &select_route);
+ good = _nltst_select_route_match(route, &select_route,
+ false);
+ }
+
+ if (!good) {
+ _nl_auto_free char *s2 =
+ _nltst_objects_to_string("route-list", objs, l);
+ size_t l_expected =
+ _nl_ptrarray_len(expected_routes, -1);
+ size_t j;
+
+ printf("route content: %s", s2);
+ printf("expected routes: %zu\n", l_expected);
+ for (j = 0; j < l_expected; j++) {
+ printf("expected route: [%zu] %s %s\n", j,
+ i == j ? "-->" : " ",
+ expected_routes[j]);
+ }
+ printf("ip-route:>>>\n");
+ _nltst_system("ip -d -4 addr show");
+ _nltst_system("ip -d -6 addr show");
+ printf("<<<\n");
+ }
if (!expected_routes[i]) {
ck_abort_msg(
"No more expected route, but have route %zu (of %zu) as %s",
i + 1, l, s);
+ } else {
+ _nltst_select_route_match(route, &select_route, true);
}
-
- _nltst_select_route_parse(expected_routes[i], &select_route);
-
- _nltst_select_route_match(route, &select_route, true);
}
}