From patchwork Fri Apr 22 12:41:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Kostanbaev X-Patchwork-Id: 613592 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.osmocom.org (lists.osmocom.org [IPv6:2a01:4f8:191:444b::2:7]) by ozlabs.org (Postfix) with ESMTP id 3qrwHR5Z8nz9t3v for ; Fri, 22 Apr 2016 22:42:11 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=0YmIhWNE; dkim-atps=neutral Received: from lists.osmocom.org (lists.osmocom.org [144.76.43.76]) by lists.osmocom.org (Postfix) with ESMTP id 507FD1323C; Fri, 22 Apr 2016 12:42:10 +0000 (UTC) X-Original-To: openbsc@lists.osmocom.org Delivered-To: openbsc@lists.osmocom.org Received: from mail-wm0-x234.google.com (mail-wm0-x234.google.com [IPv6:2a00:1450:400c:c09::234]) by lists.osmocom.org (Postfix) with ESMTP id DC16B1320F for ; Fri, 22 Apr 2016 12:41:59 +0000 (UTC) Received: by mail-wm0-x234.google.com with SMTP id n3so25123047wmn.0 for ; Fri, 22 Apr 2016 05:41:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=0UWBjhpdhP2eTkbfBa1ZIGF7oFqyoSqeC7kDSQpQmdU=; b=0YmIhWNElFwkIX1VTOEF/0vI5BtyqvMYiBwzNec8FN/hM8a6VtmZd/tsJQ32m40S6G aU/vTm2/COxONJ/B2Xr5F9sCw69xUgsqA8Ntiop2pWswnZ5FJfEUvsWIiZ6y9ru8SA1t zTy5Ay1wAlwFhQsIKDdPxsJwA1UsboHVj7BDkx2VzkSw837Q3EqNPkcSsWNvSdz9lTWa vsYG3M1fBempydtBTmNWgrOIqYlPz6p19ebnQ9BBBfFGWFKko4OYM2BcDMzn9xj9rpUH 2TUGz9aMU6G1prGReR3oKpBX/YrHV5DKEVnnS+Xw0/shNKQE4if4ahqUW4PnBk3UQAaq swSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=0UWBjhpdhP2eTkbfBa1ZIGF7oFqyoSqeC7kDSQpQmdU=; b=Y4XgaYMxQ+jMYgIP2//rNQW2Br8Hpb023g5mPscdXyWD6oUq/PlTqEiRc9RP7EKaGh UK2r2VW+i7D/r/P18smosHDKWWcqyI9FxOyda5Yr2LVL7Mx0ou7d2+thqxlaWgQfeprU IBZJL7WbMOD7mQ4siOvgQaLPZPIKoQK4EjCq5kAFUo6Y2MtQCINxRn6yazskvkcauk9k +cTnmbCVJJX/aADKm2ReC5RHMROe1iBdHA9AVEewQ70wdqu6I1gze8+eQACSraLiAeAI gxjJbfvBy4yPvbJu1heekFxJRQ2LlwiegCtYgMS8X541itikwMcD/K8rPHB7tF1xmBme FWFw== X-Gm-Message-State: AOPr4FUEMRS1aLMVN/rhwZ91LXHYSJvAa/DTyuyWWuE7K827JOz/eO9L7lFdJnZSdYaOtQ== X-Received: by 10.28.212.71 with SMTP id l68mr3753880wmg.22.1461328919608; Fri, 22 Apr 2016 05:41:59 -0700 (PDT) Received: from serg-X55SR.in-berlin.de ([185.11.247.108]) by smtp.gmail.com with ESMTPSA id b15sm3224216wmd.1.2016.04.22.05.41.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 22 Apr 2016 05:41:58 -0700 (PDT) From: Sergey Kostanbaev To: openbsc@lists.osmocom.org Subject: [PATCH 9/9] ss: add test Date: Fri, 22 Apr 2016 14:41:38 +0200 Message-Id: <1461328898-8298-9-git-send-email-sergey.kostanbaev@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1461328898-8298-1-git-send-email-sergey.kostanbaev@gmail.com> References: <1461328898-8298-1-git-send-email-sergey.kostanbaev@gmail.com> X-BeenThere: openbsc@lists.osmocom.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "Development of OpenBSC, OsmoBSC, OsmoNITB, OsmoCSCN" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openbsc-bounces@lists.osmocom.org Sender: "OpenBSC" --- openbsc/configure.ac | 1 + openbsc/tests/Makefile.am | 2 +- openbsc/tests/ussd/Makefile.am | 12 +++ openbsc/tests/ussd/ss_test.c | 199 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 213 insertions(+), 1 deletion(-) create mode 100644 openbsc/tests/ussd/Makefile.am create mode 100644 openbsc/tests/ussd/ss_test.c diff --git a/openbsc/configure.ac b/openbsc/configure.ac index b53eca6..6ea83de 100644 --- a/openbsc/configure.ac +++ b/openbsc/configure.ac @@ -229,6 +229,7 @@ AC_OUTPUT( tests/oap/Makefile tests/gtphub/Makefile tests/mm_auth/Makefile + tests/ussd/Makefile doc/Makefile doc/examples/Makefile Makefile) diff --git a/openbsc/tests/Makefile.am b/openbsc/tests/Makefile.am index 09298a3..5732671 100644 --- a/openbsc/tests/Makefile.am +++ b/openbsc/tests/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = gsm0408 db channel mgcp gprs abis gbproxy trau subscr mm_auth +SUBDIRS = gsm0408 db channel mgcp gprs abis gbproxy trau subscr mm_auth ussd if BUILD_NAT SUBDIRS += bsc-nat bsc-nat-trie diff --git a/openbsc/tests/ussd/Makefile.am b/openbsc/tests/ussd/Makefile.am new file mode 100644 index 0000000..ecaa3db --- /dev/null +++ b/openbsc/tests/ussd/Makefile.am @@ -0,0 +1,12 @@ +AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include +AM_CFLAGS=-Wall $(LIBOSMOCORE_CFLAGS) $(LIBOSMOGSM_CFLAGS) $(LIBOSMOABIS_CFLAGS) +noinst_PROGRAMS = ss_test + +# EXTRA_DIST = ss_test.ok + +ss_test_SOURCES = ss_test.c +ss_test_LDADD = $(top_builddir)/src/libbsc/libbsc.a \ + $(top_builddir)/src/libmsc/libmsc.a \ + $(top_builddir)/src/libbsc/libbsc.a \ + $(top_builddir)/src/libcommon/libcommon.a \ + $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) -ldbi diff --git a/openbsc/tests/ussd/ss_test.c b/openbsc/tests/ussd/ss_test.c new file mode 100644 index 0000000..a59bd1b --- /dev/null +++ b/openbsc/tests/ussd/ss_test.c @@ -0,0 +1,199 @@ +/* simple test for the gsm0480 */ +/* + * 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 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 . + * + */ + +#include +#include +#include + +#include + + +#include +#include +#include +#include +#include +#include + +#define COMPARE(result, op, value) \ + if (!((result) op (value))) {\ + fprintf(stderr, "Compare failed. Was %x should be %x in %s:%d\n",result, value, __FILE__, __LINE__); \ + exit(-1); \ + } + +#define COMPARE_STR(result, value) \ + if (strcmp(result, value) != 0) { \ + fprintf(stderr, "Compare failed. Was %s should be %s in %s:%d\n",result, value, __FILE__, __LINE__); \ + exit(-1); \ + } + +#define DBG(...) + +#define VERIFY(res, cmp, wanted) \ + if (!(res cmp wanted)) { \ + printf("ASSERT failed: %s:%d Wanted: %d %s %d\n", \ + __FILE__, __LINE__, res, # cmp, wanted); \ + } + +const uint8_t test_ss_int_01[] = { +0xa1, 0x0e, 0x02, 0x01, 0x00, 0x02, 0x01, 0x0e, 0x30, 0x06, 0x04, 0x01, 0x21, 0x83, 0x01, 0x10 +}; + +const uint8_t test_ss_int_02[] = { +0xa1, 0x0b, 0x02, 0x01, 0x01, 0x02, 0x01, 0x0e, 0x30, 0x03, 0x04, 0x01, 0x21 +}; + +const uint8_t test_ss_int_03[] = { +0xa1, 0x17, 0x02, 0x01, 0x01, 0x02, 0x01, 0x0a, 0x30, 0x0f, 0x04, 0x01, 0x21, +0x83, 0x01, 0x10, 0x84, 0x07, 0x91, 0x52, 0x75, 0x89, 0x46, 0x36, 0x25 +}; + +const uint8_t test_ussd_01[] = { +0xa1, 0x81, 0x83, 0x02, 0x01, 0x01, 0x02, 0x01, 0x3c, 0x30, 0x7b, 0x04, 0x01, +0x0f, 0x04, 0x76, 0xd3, 0x66, 0x50, 0x4a, 0x55, 0xc4, 0x5c, 0x20, 0x6b, 0xda, +0x5c, 0x97, 0xd7, 0xe7, 0xe8, 0x34, 0xc8, 0x9e, 0x0f, 0x83, 0x68, 0x47, 0x50, +0xd2, 0x4d, 0x0f, 0xbb, 0xcb, 0xf4, 0xb4, 0x42, 0xe6, 0x02, 0x59, 0xd3, 0xe6, +0xba, 0xbc, 0x3e, 0x47, 0xa7, 0x41, 0xd6, 0x7c, 0x18, 0x34, 0x6d, 0x06, 0xa9, +0xc9, 0x65, 0x50, 0x31, 0x73, 0x81, 0xac, 0x69, 0x73, 0x5d, 0x5e, 0x9f, 0xa3, +0xd3, 0x20, 0x7b, 0x3e, 0x0c, 0x5a, 0xa7, 0xdb, 0x61, 0x7a, 0x38, 0x6d, 0x0e, +0xbb, 0x14, 0x34, 0x17, 0x68, 0xda, 0x0e, 0xcb, 0xe9, 0xa0, 0x6b, 0xb9, 0xbc, +0x2e, 0xbb, 0xc9, 0x8a, 0x9a, 0x0b, 0xd4, 0x4c, 0xb7, 0xd3, 0x20, 0x77, 0x18, +0x74, 0x2d, 0xdf, 0xcb, 0x20, 0x28, 0xbb, 0x3e, 0x57, 0xd8, 0x5c, 0x20, 0x7d, +0x38, 0x4d, 0x4e, 0x03 +}; + +const uint8_t test_ussd_02[] = { +0xa2, 0x10, 0x02, 0x01, 0x01, 0x30, 0x0b, 0x02, 0x01, 0x3c, 0x30, +0x06, 0x04, 0x01, 0x0f, 0x04, 0x01, 0x34 +}; + +static void test_uss_ser_deser(void) +{ + const uint32_t ref = 1234567890; + const char* ext = "555333444"; + struct msgb *data = msgb_alloc(4000, "test"); + struct ss_header ssh; + + uint32_t r_ref; + struct ss_header r_ssh; + char r_ext_buf[32]; + + int rc; + printf("testing serializing-deserializing\n"); + + ssh.component_length = sizeof(test_ussd_01); + ssh.component_offset = 0; + ssh.message_type = GSM0480_MTYPE_REGISTER; + ssh.transaction_id = 0; + + rc = subscr_uss_message(data, &ssh, ext, ref, test_ussd_01); + OSMO_ASSERT(rc == 0); + + printf("uss len:%d\n", msgb_length(data)); + + rc = rx_uss_message_parse(data->data, msgb_length(data), &r_ssh, &r_ref, r_ext_buf, sizeof(r_ext_buf)); + OSMO_ASSERT(rc == 0); + OSMO_ASSERT(ref == r_ref); + OSMO_ASSERT(ssh.message_type == r_ssh.message_type); + + rc = strcmp(ext, r_ext_buf); + printf("orig_ext:%s decoded_ext:%s\n", ext, r_ext_buf); + OSMO_ASSERT(rc == 0); + + printf("orig_clen:%d decoded_clen:%d\n", ssh.component_length, r_ssh.component_length); + OSMO_ASSERT(ssh.component_length == r_ssh.component_length); + + rc = memcmp(data->data + r_ssh.component_offset, test_ussd_01, sizeof(test_ussd_01)); + OSMO_ASSERT(rc == 0); + + + msgb_reset(data); + memset(&r_ssh, 0, sizeof(r_ssh)); + printf("testing serializing-deserializing small\n"); + + rc = subscr_uss_message(data, &ssh, NULL, ref, NULL); + OSMO_ASSERT(rc == 0); + + printf("uss len:%d\n", msgb_length(data)); + + rc = rx_uss_message_parse(data->data, msgb_length(data), &r_ssh, &r_ref, NULL, 0); + OSMO_ASSERT(rc == 0); + OSMO_ASSERT(ref == r_ref); + OSMO_ASSERT(ssh.message_type == r_ssh.message_type); + +} + +static void test_parse_ss(void) +{ + struct ss_request ss; + int rc; + printf("testing parsing ss\n"); + + // mark as uninitialized + memset(&ss, 0xcc, sizeof(ss)); + rc = gsm0480_parse_ss_facility(test_ussd_01, sizeof(test_ussd_01), &ss); + OSMO_ASSERT(rc == 1); + printf("Sample: test_ussd_01 ctype=%02x invoke_id=%02x opcode=%02x\n", + ss.component_type, ss.invoke_id, ss.opcode); + printf("- USSD: len:%d lang:%d\n", ss.ussd_text_len, ss.ussd_text_language); + + // mark as uninitialized + memset(&ss, 0xcc, sizeof(ss)); + rc = gsm0480_parse_ss_facility(test_ussd_02, sizeof(test_ussd_02), &ss); + OSMO_ASSERT(rc == 1); + printf("Sample: test_ussd_02 ctype=%02x invoke_id=%02x opcode=%02x\n", + ss.component_type, ss.invoke_id, ss.opcode); + + // mark as uninitialized + memset(&ss, 0xcc, sizeof(ss)); + rc = gsm0480_parse_ss_facility(test_ss_int_02, sizeof(test_ss_int_02), &ss); + OSMO_ASSERT(rc == 1); + printf("Sample: test_ss_int_02 ctype=%02x invoke_id=%02x opcode=%02x\n", + ss.component_type, ss.invoke_id, ss.opcode); + printf("- SS: code:%d\n", ss.ss_code); + + // mark as uninitialized + memset(&ss, 0xcc, sizeof(ss)); + rc = gsm0480_parse_ss_facility(test_ss_int_01, sizeof(test_ss_int_01), &ss); + OSMO_ASSERT(rc == 1); + printf("Sample: test_ss_int_01 ctype=%02x invoke_id=%02x opcode=%02x\n", + ss.component_type, ss.invoke_id, ss.opcode); + printf("- SS: code:%d\n", ss.ss_code); + + // mark as uninitialized + memset(&ss, 0xcc, sizeof(ss)); + rc = gsm0480_parse_ss_facility(test_ss_int_03, sizeof(test_ss_int_03), &ss); + OSMO_ASSERT(rc == 1); + printf("Sample: test_ss_int_01 ctype=%02x invoke_id=%02x opcode=%02x\n", + ss.component_type, ss.invoke_id, ss.opcode); + printf("- SS: code:%d\n", ss.ss_code); + +} + +int main(int argc, char **argv) +{ + osmo_init_logging(&log_info); + log_set_log_level(osmo_stderr_target, LOGL_INFO); + + test_uss_ser_deser(); + test_parse_ss(); + + printf("Done.\n"); + return EXIT_SUCCESS; +}