This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/OpenBSC@lists.osmocom.org/.
Neels Hofmeyr nhofmeyr at sysmocom.deSponsored-by: On-Waves ehi --- openbsc/tests/gtphub/Makefile.am | 1 + openbsc/tests/gtphub/gtphub_test.c | 60 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/openbsc/tests/gtphub/Makefile.am b/openbsc/tests/gtphub/Makefile.am index c4b3ec1..4b852e4 100644 --- a/openbsc/tests/gtphub/Makefile.am +++ b/openbsc/tests/gtphub/Makefile.am @@ -11,6 +11,7 @@ noinst_PROGRAMS = gtphub_test gtphub_test_SOURCES = gtphub_test.c gtphub_test_LDADD = \ + $(top_builddir)/src/gprs/gtphub.o \ $(LIBOSMOCORE_LIBS) \ -lgtp -lrt diff --git a/openbsc/tests/gtphub/gtphub_test.c b/openbsc/tests/gtphub/gtphub_test.c index 95f82c3..25e51e7 100644 --- a/openbsc/tests/gtphub/gtphub_test.c +++ b/openbsc/tests/gtphub/gtphub_test.c @@ -28,11 +28,65 @@ #include <openbsc/debug.h> +#include <openbsc/gtphub.h> + void *osmo_gtphub_ctx; -static void test_gtphub_api(void) +/* TODO copied from libosmo-abis/src/subchan_demux.c, remove dup */ +static int llist_len(struct llist_head *head) +{ + struct llist_head *entry; + int i = 0; + + llist_for_each(entry, head) + i++; + + return i; +} + +static void test_tei_map(void) { - OSMO_ASSERT(1); + /* Basic */ + struct tei_pool _pool; + struct tei_pool *pool = &_pool; + struct tei_map _map; + struct tei_map *map = &_map; + + tei_pool_init(pool); + tei_map_init(map, pool); + + OSMO_ASSERT(llist_empty(&map->mappings)); + +#define TEST_N 100 +#define TEST_I 123 + uint32_t i, check_i; + uint32_t m[TEST_N]; + + /* create TEST_N mappings */ + for (i = 0; i < TEST_N; i++) { + m[i] = tei_map_get(map, TEST_I + i); + OSMO_ASSERT(m[i] != 0); + OSMO_ASSERT(llist_len(&map->mappings) == (i+1)); + for (check_i = 0; check_i < i; check_i++) + OSMO_ASSERT(m[check_i] != m[i]); + } + OSMO_ASSERT(llist_len(&map->mappings) == TEST_N); + + /* verify mappings */ + for (i = 0; i < TEST_N; i++) { + OSMO_ASSERT(tei_map_get(map, TEST_I + i) == m[i]); + OSMO_ASSERT(tei_map_get_rev(map, m[i]) == (TEST_I + i)); + } + OSMO_ASSERT(llist_len(&map->mappings) == TEST_N); + + /* remove all mappings */ + for (i = 0; i < TEST_N; i++) { + tei_map_del(map, TEST_I + i); + OSMO_ASSERT(llist_len(&map->mappings) == (TEST_N - (i+1))); + } + OSMO_ASSERT(llist_empty(&map->mappings)); +#undef TEST_N +#undef TEST_I } static struct log_info_cat gtphub_categories[] = { @@ -54,7 +108,7 @@ int main(int argc, char **argv) osmo_init_logging(&info); osmo_gtphub_ctx = talloc_named_const(NULL, 0, "osmo_gtphub"); - test_gtphub_api(); + test_tei_map(); printf("Done\n"); talloc_report_full(osmo_gtphub_ctx, stderr); -- 2.1.4