-/* $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 <claudio@openbsd.org>
#include <sys/types.h>
#include <sys/queue.h>
-#include <stdio.h>
#include <err.h>
+#include <stdio.h>
+#include <stdlib.h>
#include "rde.h"
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;
}
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);
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]))
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;
-/* $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 <claudio@openbsd.org>
{
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;
}
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);