Jacob Erlbeck | 0acc001 | 2014-12-03 13:05:16 +0100 | [diff] [blame] | 1 | /* (C) 2008 by Jan Luebbe <jluebbe@debian.org> |
| 2 | * (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.org> |
| 3 | * (C) 2014 by Alexander Chemeris <Alexander.Chemeris@fairwaves.co> |
| 4 | * All Rights Reserved |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU Affero General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Affero General Public License |
| 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | */ |
| 20 | |
| 21 | #include <openbsc/debug.h> |
| 22 | #include <openbsc/db.h> |
| 23 | #include <openbsc/gsm_subscriber.h> |
| 24 | #include <openbsc/gsm_04_11.h> |
| 25 | |
| 26 | #include <osmocom/core/application.h> |
| 27 | |
| 28 | #include <stdio.h> |
| 29 | #include <string.h> |
| 30 | #include <stdlib.h> |
| 31 | #include <inttypes.h> |
| 32 | |
| 33 | static struct gsm_network dummy_net; |
| 34 | static struct gsm_subscriber_group dummy_sgrp; |
| 35 | |
| 36 | static void test_subscr(void) |
| 37 | { |
Jacob Erlbeck | 0acc001 | 2014-12-03 13:05:16 +0100 | [diff] [blame] | 38 | struct gsm_subscriber *subscr; |
| 39 | const char *imsi = "1234567890"; |
| 40 | |
| 41 | printf("Test subscriber allocation and deletion\n"); |
| 42 | |
| 43 | /* Don't keep subscr */ |
| 44 | |
| 45 | dummy_sgrp.keep_subscr = 0; |
| 46 | |
| 47 | OSMO_ASSERT(llist_empty(&active_subscribers)); |
| 48 | |
| 49 | subscr = subscr_get_or_create(&dummy_sgrp, imsi); |
| 50 | |
| 51 | OSMO_ASSERT(!llist_empty(&active_subscribers)); |
| 52 | OSMO_ASSERT(subscr->use_count == 1); |
| 53 | |
| 54 | subscr_put(subscr); |
| 55 | |
| 56 | OSMO_ASSERT(llist_empty(&active_subscribers)); |
| 57 | |
| 58 | /* Keep subscr */ |
| 59 | |
| 60 | dummy_sgrp.keep_subscr = 1; |
| 61 | |
| 62 | subscr = subscr_get_or_create(&dummy_sgrp, imsi); |
| 63 | |
| 64 | OSMO_ASSERT(!llist_empty(&active_subscribers)); |
| 65 | OSMO_ASSERT(subscr->use_count == 1); |
| 66 | |
| 67 | subscr_put(subscr); |
| 68 | OSMO_ASSERT(!llist_empty(&active_subscribers)); |
| 69 | OSMO_ASSERT(subscr->use_count == 0); |
| 70 | |
| 71 | subscr_get(subscr); |
| 72 | OSMO_ASSERT(subscr->use_count == 1); |
| 73 | |
| 74 | subscr_purge_inactive(&dummy_sgrp); |
| 75 | |
| 76 | OSMO_ASSERT(!llist_empty(&active_subscribers)); |
| 77 | OSMO_ASSERT(subscr->use_count == 1); |
| 78 | |
| 79 | subscr_put(subscr); |
| 80 | OSMO_ASSERT(!llist_empty(&active_subscribers)); |
| 81 | OSMO_ASSERT(subscr->use_count == 0); |
| 82 | |
| 83 | subscr_purge_inactive(&dummy_sgrp); |
| 84 | |
| 85 | OSMO_ASSERT(llist_empty(&active_subscribers)); |
| 86 | } |
| 87 | |
| 88 | int main() |
| 89 | { |
Jacob Erlbeck | 0acc001 | 2014-12-03 13:05:16 +0100 | [diff] [blame] | 90 | printf("Testing subscriber core code.\n"); |
| 91 | osmo_init_logging(&log_info); |
| 92 | log_set_print_filename(osmo_stderr_target, 0); |
| 93 | |
| 94 | dummy_net.subscr_group = &dummy_sgrp; |
| 95 | dummy_sgrp.net = &dummy_net; |
| 96 | |
| 97 | test_subscr(); |
| 98 | |
| 99 | printf("Done\n"); |
| 100 | return 0; |
| 101 | } |