From 97774ff6df667cd0f61fa760680d23734ce595c8 Mon Sep 17 00:00:00 2001 From: claudio Date: Thu, 20 Sep 2018 11:47:50 +0000 Subject: [PATCH] Adjust unittests to the adjustments done to the as_set code. OK benno@ --- .../usr.sbin/bgpd/unittests/rde_sets_test.c | 39 ++++++++++--------- .../usr.sbin/bgpd/unittests/rde_trie_test.c | 21 +++++----- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/regress/usr.sbin/bgpd/unittests/rde_sets_test.c b/regress/usr.sbin/bgpd/unittests/rde_sets_test.c index 0535723d25f..a1082f4a8d2 100644 --- a/regress/usr.sbin/bgpd/unittests/rde_sets_test.c +++ b/regress/usr.sbin/bgpd/unittests/rde_sets_test.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde_sets_test.c,v 1.3 2018/09/14 10:23:42 claudio Exp $ */ +/* $OpenBSD: rde_sets_test.c,v 1.4 2018/09/20 11:47:50 claudio Exp $ */ /* * Copyright (c) 2018 Claudio Jeker @@ -18,8 +18,9 @@ #include #include -#include #include +#include +#include #include "rde.h" @@ -28,17 +29,19 @@ u_int32_t vaa[] = { 125, 14, 76, 32, 19 }; u_int32_t vb[] = { 256, 1024, 512, 4096, 2048, 512 }; u_int32_t vc[] = { 42 }; +struct as_set_head *as_sets; + static struct as_set * build_set(const char *name, u_int32_t *mem, size_t nmemb, size_t initial) { struct as_set *a; - a = as_set_new(name, initial, sizeof(*mem)); + a = as_sets_new(as_sets, name, initial, sizeof(*mem)); if (a == NULL) err(1, "as_set_new %s", name); - if (as_set_add(a, mem, nmemb) != 0) + if (set_add(a->set, mem, nmemb) != 0) err(1, "as_set_add %s", name); - as_set_prep(a); + set_prep(a->set); return a; } @@ -49,6 +52,10 @@ main(int argc, char **argv) struct as_set *a, *aa, *b, *c, *empty; size_t i; + if ((as_sets = malloc(sizeof(*as_sets))) == NULL) + err(1, NULL); + SIMPLEQ_INIT(as_sets); + a = build_set("a", va, sizeof(va) / sizeof(va[0]), sizeof(va) / sizeof(va[0])); aa = build_set("aa", vaa, sizeof(vaa) / sizeof(vaa[0]), 0); @@ -56,12 +63,12 @@ main(int argc, char **argv) c = build_set("c", vc, sizeof(vc) / sizeof(vc[0]), 1); empty = build_set("empty", NULL, 0, 0); - if (!as_set_equal(a, a)) - errx(1, "as_set_equal(a, a) non equal"); - if (!as_set_equal(a, aa)) - errx(1, "as_set_equal(a, aa) non equal"); - if (as_set_equal(a, b)) - errx(1, "as_set_equal(a, b) equal"); + if (!set_equal(a->set, a->set)) + errx(1, "set_equal(a, a) non equal"); + if (!set_equal(a->set, aa->set)) + errx(1, "set_equal(a, aa) non equal"); + if (set_equal(a->set, b->set)) + errx(1, "set_equal(a, b) equal"); for (i = 0; i < sizeof(va) / sizeof(va[0]); i++) if (!as_set_match(a, va[i])) @@ -75,16 +82,12 @@ main(int argc, char **argv) if (as_set_match(c, 7)) errx(1, "as_set_match(c, %u) matched but should not", 7); - if (!as_set_equal(empty, empty)) - errx(1, "as_set_equal(empty, empty) non equal"); + if (!set_equal(empty->set, empty->set)) + errx(1, "set_equal(empty, empty) non equal"); if (as_set_match(empty, 42)) errx(1, "as_set_match(empty, %u) matched but should not", 42); - as_set_free(a); - as_set_free(aa); - as_set_free(b); - as_set_free(c); - as_set_free(empty); + as_sets_free(as_sets); printf("OK\n"); return 0; diff --git a/regress/usr.sbin/bgpd/unittests/rde_trie_test.c b/regress/usr.sbin/bgpd/unittests/rde_trie_test.c index af039276bfe..3862e38a676 100644 --- a/regress/usr.sbin/bgpd/unittests/rde_trie_test.c +++ b/regress/usr.sbin/bgpd/unittests/rde_trie_test.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde_trie_test.c,v 1.5 2018/09/18 15:15:32 claudio Exp $ */ +/* $OpenBSD: rde_trie_test.c,v 1.6 2018/09/20 11:47:50 claudio Exp $ */ /* * Copyright (c) 2018 Claudio Jeker @@ -176,7 +176,7 @@ parse_roa_file(FILE *in, struct trie_head *th) { const char *errstr; char *line, *s; - struct as_set *aset = NULL; + struct set_table *set = NULL; struct roa_set rs; struct bgpd_addr prefix; u_int8_t plen; @@ -224,21 +224,20 @@ parse_roa_file(FILE *in, struct trie_head *th) } if (state == 0) { - as_set_prep(aset); - if (trie_roa_add(th, &prefix, plen, aset) != 0) + set_prep(set); + if (trie_roa_add(th, &prefix, plen, set) != 0) errx(1, "trie_roa_add(%s, %u) failed", print_prefix(&prefix), plen); - aset = NULL; + set = NULL; } else { - if (aset == NULL) { - if ((aset = as_set_new("", 1, sizeof(rs))) == - NULL) - err(1, "as_set_new"); + if (set == NULL) { + if ((set = set_new(1, sizeof(rs))) == NULL) + err(1, "set_new"); } rs.as = as; rs.maxlen = max; - if (as_set_add(aset, &rs, 1) != 0) - err(1, "as_set_add"); + if (set_add(set, &rs, 1) != 0) + err(1, "set_add"); } free(line); -- 2.20.1