blob: 9663157ffa210a53c594f143b5ededebc4a55448 [file] [log] [blame]
Harald Welte87ffeb92015-12-25 15:34:22 +01001/* Common osmo-iuh test stub code */
2
3/* (C) 2015 by Sysmocom s.f.m.c. GmbH
4 * Author: Daniel Willmann <dwillmann@sysmocom.de>
5 * All Rights Reserved
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#include <unistd.h>
23#include <stdio.h>
24#include <stdlib.h>
25#include <string.h>
26#include <getopt.h>
27#include <errno.h>
28#include <signal.h>
29
30#include <sys/types.h>
31#include <sys/socket.h>
32#include <netinet/in.h>
33#include <netinet/sctp.h>
34#include <arpa/inet.h>
35
36#include <osmocom/core/application.h>
37#include <osmocom/core/talloc.h>
38#include <osmocom/core/logging.h>
39
Neels Hofmeyrc6ed1c32017-11-20 22:41:21 +010040#include <osmocom/ranap/ranap_common.h>
41
Neels Hofmeyrdf63de22016-08-18 13:13:55 +020042#include <osmocom/iuh/hnbgw.h>
Harald Welte87ffeb92015-12-25 15:34:22 +010043
Harald Welte87ffeb92015-12-25 15:34:22 +010044static const struct log_info_cat log_cat[] = {
45 [DMAIN] = {
46 .name = "DMAIN", .loglevel = LOGL_INFO, .enabled = 1,
47 .color = "",
48 .description = "Main program",
49 },
50 [DHNBAP] = {
51 .name = "DHNBAP", .loglevel = LOGL_DEBUG, .enabled = 1,
52 .color = "",
53 .description = "Home Node B Application Part",
54 },
55 [DRANAP] = {
56 .name = "RANAP", .loglevel = LOGL_DEBUG, .enabled = 1,
57 .color = "",
58 .description = "RAN Application Part",
59 },
60 [DRUA] = {
61 .name = "RUA", .loglevel = LOGL_DEBUG, .enabled = 1,
62 .color = "",
63 .description = "RANAP User Adaptation",
64 },
Harald Welte87ffeb92015-12-25 15:34:22 +010065};
66
67static const struct log_info test_log_info = {
68 .cat = log_cat,
69 .num_cat = ARRAY_SIZE(log_cat),
70};
71
Neels Hofmeyrd9cb19a2017-11-18 18:47:55 +010072static void *msgb_ctx;
73
Harald Welte87ffeb92015-12-25 15:34:22 +010074int test_common_init(void)
75{
76 int rc;
77
Neels Hofmeyrd9cb19a2017-11-18 18:47:55 +010078 msgb_ctx = msgb_talloc_ctx_init(NULL, 0);
Harald Welte87ffeb92015-12-25 15:34:22 +010079 talloc_asn1_ctx = talloc_named_const(NULL, 0, "asn1_context");
80
81 rc = osmo_init_logging(&test_log_info);
82 if (rc < 0)
83 exit(1);
84
Harald Weltebdf3fd12016-01-03 17:04:09 +010085 ranap_set_log_area(DRANAP);
Neels Hofmeyr52c6ae22016-08-26 14:08:51 +020086
Pau Espin Pedrola94752e2021-02-19 13:19:01 +010087 log_set_print_filename2(osmo_stderr_target, LOG_FILENAME_NONE);
Neels Hofmeyr52c6ae22016-08-26 14:08:51 +020088 log_set_use_color(osmo_stderr_target, 0);
Pau Espin Pedrol2c6aed32021-02-19 13:18:42 +010089 log_set_print_category(osmo_stderr_target, 0);
90 log_set_print_category_hex(osmo_stderr_target, 0);
Martin Haukec593da52020-02-15 23:01:39 +010091 return rc;
Harald Welte87ffeb92015-12-25 15:34:22 +010092}
Neels Hofmeyrd9cb19a2017-11-18 18:47:55 +010093
94void test_common_cleanup(void)
95{
96 if (talloc_total_blocks(msgb_ctx) != 1
97 || talloc_total_size(msgb_ctx) != 0)
98 talloc_report_full(msgb_ctx, stderr);
99
100 OSMO_ASSERT(talloc_total_blocks(msgb_ctx) == 1);
101 OSMO_ASSERT(talloc_total_size(msgb_ctx) == 0);
102 talloc_free(msgb_ctx);
103
104 if (talloc_total_blocks(talloc_asn1_ctx) != 1
105 || talloc_total_size(talloc_asn1_ctx) != 0)
106 talloc_report_full(talloc_asn1_ctx, stderr);
107
108 OSMO_ASSERT(talloc_total_blocks(talloc_asn1_ctx) == 1);
109 OSMO_ASSERT(talloc_total_size(talloc_asn1_ctx) == 0);
110 talloc_free(talloc_asn1_ctx);
111}