From 81c40cbb904fb4844411cc660eaa0fd1d5d9f5f3 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 22 Aug 2024 18:36:06 +0200 Subject: [PATCH] tests: optimize _nltst_assert_route_list_permutate() to short cut search through permutations --- tests/nl-test-util.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/tests/nl-test-util.c b/tests/nl-test-util.c index 9fd6c8b6..dc8dc5ad 100644 --- a/tests/nl-test-util.c +++ b/tests/nl-test-util.c @@ -1085,12 +1085,16 @@ _nltst_assert_route_list_permutate(const NltstAssertRouteListPermData *data, { size_t i; - if (idx + 1 == num) { - return _nltst_assert_route_list_equal( - objs, data->expected_route_selects, num); - } + if (idx + 1 == num) + return true; for (i = idx; i < num; i++) { + if (!_nltst_select_route_match( + objs[i], &data->expected_route_selects[idx], + false)) { + /* This entry does not match. We can shortcut this permutation. */ + continue; + } _nl_swap(&objs[idx], &objs[i]); if (_nltst_assert_route_list_permutate(data, objs, idx + 1, num)) { @@ -1137,6 +1141,14 @@ void _nltst_assert_route_list(struct nl_object *const *objs, ssize_t len, objs2, 0, l_objs)) goto out_fail; + if (!_nltst_assert_route_list_equal(objs2, expected_route_selects, + len)) { + _nltst_assert_route_list_print(objs, l_objs, expected_routes, + l_expected); + ck_abort_msg( + "there is a in _nltst_assert_route_list_permutate(), the permutation should now match"); + } + goto out_free; out_fail: