From patchwork Thu Oct 15 22:13:52 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neels Hofmeyr X-Patchwork-Id: 530947 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.osmocom.org (unknown [IPv6:2a01:4f8:191:444b::2:7]) by ozlabs.org (Postfix) with ESMTP id C67721402D0 for ; Fri, 16 Oct 2015 09:14:30 +1100 (AEDT) Received: from lists.osmocom.org (lists.osmocom.org [144.76.43.76]) by lists.osmocom.org (Postfix) with ESMTP id 9E9D389DD; Thu, 15 Oct 2015 22:14:29 +0000 (UTC) X-Original-To: openbsc@lists.osmocom.org Delivered-To: openbsc@lists.osmocom.org Received: from mail.sysmocom.de (mail.sysmocom.de [IPv6:2a01:4f8:191:444c::2:4]) by lists.osmocom.org (Postfix) with ESMTP id 3B7E48907 for ; Thu, 15 Oct 2015 22:14:17 +0000 (UTC) Received: from localhost.localdomain (unknown [37.120.3.39]) by mail.sysmocom.de (Postfix) with ESMTPSA id 247551BEEBE for ; Thu, 15 Oct 2015 22:14:17 +0000 (UTC) From: Neels Hofmeyr To: openbsc@lists.osmocom.org Subject: [PATCH 08/15] gtphub: add TEI map test Date: Fri, 16 Oct 2015 00:13:52 +0200 Message-Id: <1444947239-17582-9-git-send-email-nhofmeyr@sysmocom.de> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1444947239-17582-1-git-send-email-nhofmeyr@sysmocom.de> References: <1444947239-17582-1-git-send-email-nhofmeyr@sysmocom.de> X-BeenThere: openbsc@lists.osmocom.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Development of the OpenBSC GSM base station controller List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openbsc-bounces@lists.osmocom.org Sender: "OpenBSC" Sponsored-by: On-Waves ehi diff --git a/openbsc/tests/gtphub/Makefile.am b/openbsc/tests/gtphub/Makefile.am index 7cc3ac9..5347811 100644 --- a/openbsc/tests/gtphub/Makefile.am +++ b/openbsc/tests/gtphub/Makefile.am @@ -9,6 +9,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 +#include + 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);