blob: fdd5cd848b55164d6d5cf775dc5fa9a688c20319 [file] [log] [blame]
Jacob Erlbeck0acc0012014-12-03 13:05:16 +01001/* (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
33static struct gsm_network dummy_net;
34static struct gsm_subscriber_group dummy_sgrp;
35
36static void test_subscr(void)
37{
38 int rc;
39 struct gsm_subscriber *subscr;
40 const char *imsi = "1234567890";
41
42 printf("Test subscriber allocation and deletion\n");
43
44 /* Don't keep subscr */
45
46 dummy_sgrp.keep_subscr = 0;
47
48 OSMO_ASSERT(llist_empty(&active_subscribers));
49
50 subscr = subscr_get_or_create(&dummy_sgrp, imsi);
51
52 OSMO_ASSERT(!llist_empty(&active_subscribers));
53 OSMO_ASSERT(subscr->use_count == 1);
54
55 subscr_put(subscr);
56
57 OSMO_ASSERT(llist_empty(&active_subscribers));
58
59 /* Keep subscr */
60
61 dummy_sgrp.keep_subscr = 1;
62
63 subscr = subscr_get_or_create(&dummy_sgrp, imsi);
64
65 OSMO_ASSERT(!llist_empty(&active_subscribers));
66 OSMO_ASSERT(subscr->use_count == 1);
67
68 subscr_put(subscr);
69 OSMO_ASSERT(!llist_empty(&active_subscribers));
70 OSMO_ASSERT(subscr->use_count == 0);
71
72 subscr_get(subscr);
73 OSMO_ASSERT(subscr->use_count == 1);
74
75 subscr_purge_inactive(&dummy_sgrp);
76
77 OSMO_ASSERT(!llist_empty(&active_subscribers));
78 OSMO_ASSERT(subscr->use_count == 1);
79
80 subscr_put(subscr);
81 OSMO_ASSERT(!llist_empty(&active_subscribers));
82 OSMO_ASSERT(subscr->use_count == 0);
83
84 subscr_purge_inactive(&dummy_sgrp);
85
86 OSMO_ASSERT(llist_empty(&active_subscribers));
87}
88
89int main()
90{
91 char scratch_str[256];
92
93 printf("Testing subscriber core code.\n");
94 osmo_init_logging(&log_info);
95 log_set_print_filename(osmo_stderr_target, 0);
96
97 dummy_net.subscr_group = &dummy_sgrp;
98 dummy_sgrp.net = &dummy_net;
99
100 test_subscr();
101
102 printf("Done\n");
103 return 0;
104}