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/gerrit-log@lists.osmocom.org/.
Max gerrit-no-reply at lists.osmocom.orgMax has uploaded this change for review. ( https://gerrit.osmocom.org/12556 Change subject: Add tests for transaction routines ...................................................................... Add tests for transaction routines Change-Id: I78dfb7cd35073a305cf668beda7d9d58d5a5a713 --- M configure.ac M tests/Makefile.am M tests/testsuite.at A tests/trans/Makefile.am A tests/trans/trans_test.c A tests/trans/trans_test.err A tests/trans/trans_test.ok 7 files changed, 242 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-msc refs/changes/56/12556/1 diff --git a/configure.ac b/configure.ac index a4979cf..d955187 100644 --- a/configure.ac +++ b/configure.ac @@ -257,6 +257,7 @@ tests/Makefile tests/atlocal tests/smpp/Makefile + tests/trans/Makefile tests/sms_queue/Makefile tests/msc_vlr/Makefile doc/Makefile diff --git a/tests/Makefile.am b/tests/Makefile.am index dc5194c..883df23 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,6 +1,7 @@ SUBDIRS = \ sms_queue \ msc_vlr \ + trans \ $(NULL) if BUILD_SMPP diff --git a/tests/testsuite.at b/tests/testsuite.at index f27b60c..f3cb740 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -9,6 +9,13 @@ AT_CHECK([$abs_top_builddir/tests/smpp/smpp_test], [], [expout], [experr]) AT_CLEANUP +AT_SETUP([trans]) +AT_KEYWORDS([trans]) +cat $abs_srcdir/trans/trans_test.ok > expout +cat $abs_srcdir/trans/trans_test.err > experr +AT_CHECK([$abs_top_builddir/tests/trans/trans_test], [], [expout], [experr]) +AT_CLEANUP + AT_SETUP([sms_queue_test]) AT_KEYWORDS([sms_queue_test]) cat $abs_srcdir/sms_queue/sms_queue_test.ok > expout diff --git a/tests/trans/Makefile.am b/tests/trans/Makefile.am new file mode 100644 index 0000000..1a05307 --- /dev/null +++ b/tests/trans/Makefile.am @@ -0,0 +1,31 @@ +AM_CPPFLAGS = \ + $(all_includes) \ + -I$(top_srcdir)/include \ + -I$(top_srcdir)/src/libmsc \ + $(NULL) + +AM_CFLAGS = \ + -Wall \ + -ggdb3 \ + $(LIBOSMOCORE_CFLAGS) \ + $(LIBOSMOGSM_CFLAGS) \ + $(LIBOSMOSCCP_CFLAGS) \ + $(LIBOSMOABIS_CFLAGS) \ + $(COVERAGE_CFLAGS) \ + $(NULL) + +AM_LDFLAGS = $(COVERAGE_LDFLAGS) + +EXTRA_DIST = trans_test.ok trans_test.err + +trans_test_LDADD = \ + $(top_builddir)/src/libmsc/libmsc.a \ + $(top_builddir)/src/libvlr/libvlr.a \ + $(LIBOSMOCORE_LIBS) \ + $(LIBOSMOGSM_LIBS) \ + $(LIBOSMOABIS_LIBS) \ + $(LIBOSMOSIGTRAN_LIBS) \ + $(LIBOSMOMGCPCLIENT_LIBS) \ + $(LIBOSMOGSUPCLIENT_LIBS) \ + -ldbi \ + $(NULL) diff --git a/tests/trans/trans_test.c b/tests/trans/trans_test.c new file mode 100644 index 0000000..42b39c6 --- /dev/null +++ b/tests/trans/trans_test.c @@ -0,0 +1,184 @@ +/* + * (C) 2019 sysmocom s.f.m.c. GmbH <info at sysmocom.de> + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#include <stdlib.h> +#include <stdio.h> + +#include <osmocom/msc/debug.h> +#include <osmocom/msc/vlr.h> +#include <osmocom/msc/msc_common.h> +#include <osmocom/msc/transaction.h> + +#include <osmocom/core/application.h> +#include <osmocom/core/backtrace.h> +#include <osmocom/core/talloc.h> + + +static bool wrong_tran(const struct gsm_trans *t, uint8_t ref_id) +{ + if (!t) { + printf("Failed to obtain transaction with expected ID %u.\n", ref_id); + return true; + } + + if (t->transaction_id != ref_id) { + printf("Wrong transaction obtained with ID %u != %u (expected)\n", t->transaction_id, ref_id); + return true; + } + + return false; +} + +static struct gsm_trans *make_tran(struct gsm_network *net, struct vlr_subscr *vsub, uint8_t proto, uint32_t callref) +{ + int trans_id = trans_assign_trans_id(net, vsub, proto, 0); + if (trans_id < 0) { + printf("Failed to get next transaction ID.\n"); + return NULL; + } + + return trans_alloc(net, vsub, proto, trans_id, callref); +} + +static struct ran_conn *make_conn(struct gsm_network *net, struct vlr_subscr *vsub) +{ + struct ran_conn *ran_c = ran_conn_alloc(net, OSMO_RAT_UNKNOWN, 69); + if (ran_c) + ran_c->vsub = vlr_subscr_get(vsub); + return ran_c; +} + +static void test_tran_single(struct gsm_network *net, struct vlr_subscr *vsub, uint32_t base_callref) +{ + struct gsm_trans *t, *x; + struct ran_conn *ran_c; + uint8_t p = GSM48_PDISC_GROUP_CC; + int trans_id; + + printf("\nStarting basic transaction test...\n"); + + ran_c = make_conn(net, vsub); + if (!ran_c) + return; + + t = make_tran(net, vsub, p, base_callref); + if (!t) + return; + + printf("Transaction allocation complete: 0x%X CallRef used.\n", t->callref); + + if (trans_has_conn(ran_c)) + return; + + t->conn = ran_conn_get(ran_c, RAN_CONN_USE_SILENT_CALL); + if (!trans_has_conn(ran_c)) + return; + + printf("Connection %s assigned to transaction.\n", vlr_subscr_name(ran_c->vsub)); + + trans_id = trans_assign_trans_id(net, vsub, p, 0); + if (trans_id < 0) { + printf("Failed to allocate next transaction id.\n"); + return; + } + + if (trans_id == t->transaction_id) { + printf("Transaction id allocated twice.\n"); + return; + } + printf("Next transaction ID: %u\n", trans_id); + + printf("Transaction lookup:\n"); + + x = trans_find_by_callref(net, base_callref); + if (wrong_tran(x, t->transaction_id)) + return; + printf("\tCallRef OK.\n"); + + x = trans_find_by_id(ran_c, p, t->transaction_id); + if (wrong_tran(x, t->transaction_id)) + return; + printf("\tID OK.\n"); + + printf("Transaction cleanup.\n"); + trans_free(t); + + printf("Basic transaction test for CallRef 0x%X complete.\n", base_callref); +} + +static void test_tran_overflow(struct gsm_network *net, struct vlr_subscr *vsub, uint32_t base_callref) +{ + unsigned i, max_t = 32, al; + struct gsm_trans *t; + + printf("\nStarting overflow transaction test...\nAllocating: "); + + for (i = 0; i < max_t; i++) { + t = make_tran(net, vsub, GSM48_PDISC_BCAST_CC, base_callref); + if (!t) + break; + printf("."); + } + + al = i; + printf("\tAllocated %u transactions.\n Cleaning: ", al); + + for (i = 0; i < max_t; i++) { + t = trans_find_by_callref(net, base_callref); + if (!t) + break; + trans_free(t); + printf("."); + } + + printf("\n\tCleared %u transactions.\nOverflow transaction test for CallRef 0x%X complete: %s\n", + i, base_callref, (al != i) ? "FAILED" : "OK"); +} + + +int main(int argc, char **argv) +{ + void *ctx = talloc_named_const(NULL, 0, "trans_test"); + struct gsm_network *net; + struct vlr_subscr *v; + + osmo_init_logging2(ctx, NULL); + log_set_use_color(osmo_stderr_target, 0); + log_set_print_filename(osmo_stderr_target, 0); + + net = gsm_network_init(ctx, NULL); + if (!net) { + printf("Failed to allocate network struct\n"); + return 1; + } + + ran_conn_init(); + + if (msc_vlr_alloc(net)) { + printf("Failed to allocate VLR\n"); + return 2; + } + + v = vlr_subscr_alloc(net->vlr); + + test_tran_single(net, v, 1); + test_tran_overflow(net, v, 2); + + return EXIT_SUCCESS; +} diff --git a/tests/trans/trans_test.err b/tests/trans/trans_test.err new file mode 100644 index 0000000..19cfbdb --- /dev/null +++ b/tests/trans/trans_test.err @@ -0,0 +1 @@ +unknown: Unknown RAN type, cannot tx release/clear diff --git a/tests/trans/trans_test.ok b/tests/trans/trans_test.ok new file mode 100644 index 0000000..20622bf --- /dev/null +++ b/tests/trans/trans_test.ok @@ -0,0 +1,17 @@ + +Starting basic transaction test... +Transaction allocation complete: 0x1 CallRef used. +Connection unknown assigned to transaction. +Next transaction ID: 1 +Transaction lookup: + CallRef OK. + ID OK. +Transaction cleanup. +Basic transaction test for CallRef 0x1 complete. + +Starting overflow transaction test... +Allocating: .......Failed to get next transaction ID. + Allocated 7 transactions. + Cleaning: ....... + Cleared 7 transactions. +Overflow transaction test for CallRef 0x2 complete: OK -- To view, visit https://gerrit.osmocom.org/12556 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-msc Gerrit-Branch: master Gerrit-MessageType: newchange Gerrit-Change-Id: I78dfb7cd35073a305cf668beda7d9d58d5a5a713 Gerrit-Change-Number: 12556 Gerrit-PatchSet: 1 Gerrit-Owner: Max <msuraev at sysmocom.de> -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190114/3de7fab0/attachment.htm>