bool bib_assert(l4_protocol l4_proto, struct bib_entry **expected_bibs) { int expected_count = 0; int actual_count = 0; if (is_error(bib_for_each(l4_proto, count_bibs, &actual_count))) { log_warning("Could not count the BIB entries in the database for some reason."); return false; } while (expected_bibs[expected_count] != NULL) { struct bib_entry *expected = expected_bibs[expected_count]; struct bib_entry *actual; int error; error = bib_get_by_ipv6(&expected->ipv6, l4_proto, &actual); if (error) { log_warning("Error %d while trying to find BIB entry [%pI6c#%u, %pI4#%u] in the DB.", error, &expected->ipv6.address, expected->ipv6.l4_id, &expected->ipv4.address, expected->ipv4.l4_id); return false; } expected_count++; } if (expected_count != actual_count) { log_warning("Expected %d BIB entries in the database. Found %d.", expected_count, actual_count); return false; } return true; }
bool test_for_each(void) { struct bib_entry *bib1, *bib2; struct loop_summary summary = { .bib1 = NULL, .bib2 = NULL }; bool success = true; bib1 = create_and_insert_bib(0, 0, IPPROTO_UDP); if (!bib1) return false; bib2 = create_and_insert_bib(1, 1, IPPROTO_UDP); if (!bib2) return false; success &= assert_equals_int(0, bib_for_each(IPPROTO_UDP, for_each_func, &summary), ""); success &= assert_true(bib_entry_equals(bib1, summary.bib1) || bib_entry_equals(bib1, summary.bib2), ""); success &= assert_true(bib_entry_equals(bib2, summary.bib2) || bib_entry_equals(bib2, summary.bib2), ""); return success; }
int print_bibs(l4_protocol l4_proto) { log_debug("BIB:"); return bib_for_each(l4_proto, print_bibs_aux, NULL); }