Skip to content

Commit

Permalink
tests: optimize _nltst_assert_route_list_permutate() to short cut sea…
Browse files Browse the repository at this point in the history
…rch through permutations
  • Loading branch information
thom311 committed Aug 22, 2024
1 parent 9f5fac7 commit 81c40cb
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions tests/nl-test-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 81c40cb

Please sign in to comment.