Harald Welte | 87ffeb9 | 2015-12-25 15:34:22 +0100 | [diff] [blame] | 1 | /* 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 Hofmeyr | c6ed1c3 | 2017-11-20 22:41:21 +0100 | [diff] [blame] | 40 | #include <osmocom/ranap/ranap_common.h> |
| 41 | |
Neels Hofmeyr | df63de2 | 2016-08-18 13:13:55 +0200 | [diff] [blame] | 42 | #include <osmocom/iuh/hnbgw.h> |
Harald Welte | 87ffeb9 | 2015-12-25 15:34:22 +0100 | [diff] [blame] | 43 | |
Harald Welte | 87ffeb9 | 2015-12-25 15:34:22 +0100 | [diff] [blame] | 44 | static 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 Welte | 87ffeb9 | 2015-12-25 15:34:22 +0100 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | static const struct log_info test_log_info = { |
| 68 | .cat = log_cat, |
| 69 | .num_cat = ARRAY_SIZE(log_cat), |
| 70 | }; |
| 71 | |
Neels Hofmeyr | d9cb19a | 2017-11-18 18:47:55 +0100 | [diff] [blame] | 72 | static void *msgb_ctx; |
| 73 | |
Harald Welte | 87ffeb9 | 2015-12-25 15:34:22 +0100 | [diff] [blame] | 74 | int test_common_init(void) |
| 75 | { |
| 76 | int rc; |
| 77 | |
Neels Hofmeyr | d9cb19a | 2017-11-18 18:47:55 +0100 | [diff] [blame] | 78 | msgb_ctx = msgb_talloc_ctx_init(NULL, 0); |
Harald Welte | 87ffeb9 | 2015-12-25 15:34:22 +0100 | [diff] [blame] | 79 | 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 Welte | bdf3fd1 | 2016-01-03 17:04:09 +0100 | [diff] [blame] | 85 | ranap_set_log_area(DRANAP); |
Neels Hofmeyr | 52c6ae2 | 2016-08-26 14:08:51 +0200 | [diff] [blame] | 86 | |
Pau Espin Pedrol | a94752e | 2021-02-19 13:19:01 +0100 | [diff] [blame] | 87 | log_set_print_filename2(osmo_stderr_target, LOG_FILENAME_NONE); |
Neels Hofmeyr | 52c6ae2 | 2016-08-26 14:08:51 +0200 | [diff] [blame] | 88 | log_set_use_color(osmo_stderr_target, 0); |
Pau Espin Pedrol | 2c6aed3 | 2021-02-19 13:18:42 +0100 | [diff] [blame] | 89 | log_set_print_category(osmo_stderr_target, 0); |
| 90 | log_set_print_category_hex(osmo_stderr_target, 0); |
Martin Hauke | c593da5 | 2020-02-15 23:01:39 +0100 | [diff] [blame] | 91 | return rc; |
Harald Welte | 87ffeb9 | 2015-12-25 15:34:22 +0100 | [diff] [blame] | 92 | } |
Neels Hofmeyr | d9cb19a | 2017-11-18 18:47:55 +0100 | [diff] [blame] | 93 | |
| 94 | void 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 | } |