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 | |
| 44 | void *talloc_asn1_ctx; |
| 45 | |
| 46 | static const struct log_info_cat log_cat[] = { |
| 47 | [DMAIN] = { |
| 48 | .name = "DMAIN", .loglevel = LOGL_INFO, .enabled = 1, |
| 49 | .color = "", |
| 50 | .description = "Main program", |
| 51 | }, |
| 52 | [DHNBAP] = { |
| 53 | .name = "DHNBAP", .loglevel = LOGL_DEBUG, .enabled = 1, |
| 54 | .color = "", |
| 55 | .description = "Home Node B Application Part", |
| 56 | }, |
| 57 | [DRANAP] = { |
| 58 | .name = "RANAP", .loglevel = LOGL_DEBUG, .enabled = 1, |
| 59 | .color = "", |
| 60 | .description = "RAN Application Part", |
| 61 | }, |
| 62 | [DRUA] = { |
| 63 | .name = "RUA", .loglevel = LOGL_DEBUG, .enabled = 1, |
| 64 | .color = "", |
| 65 | .description = "RANAP User Adaptation", |
| 66 | }, |
Harald Welte | 87ffeb9 | 2015-12-25 15:34:22 +0100 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | static const struct log_info test_log_info = { |
| 70 | .cat = log_cat, |
| 71 | .num_cat = ARRAY_SIZE(log_cat), |
| 72 | }; |
| 73 | |
Neels Hofmeyr | d9cb19a | 2017-11-18 18:47:55 +0100 | [diff] [blame] | 74 | static void *msgb_ctx; |
| 75 | |
Harald Welte | 87ffeb9 | 2015-12-25 15:34:22 +0100 | [diff] [blame] | 76 | int test_common_init(void) |
| 77 | { |
| 78 | int rc; |
| 79 | |
Neels Hofmeyr | d9cb19a | 2017-11-18 18:47:55 +0100 | [diff] [blame] | 80 | msgb_ctx = msgb_talloc_ctx_init(NULL, 0); |
Harald Welte | 87ffeb9 | 2015-12-25 15:34:22 +0100 | [diff] [blame] | 81 | talloc_asn1_ctx = talloc_named_const(NULL, 0, "asn1_context"); |
| 82 | |
| 83 | rc = osmo_init_logging(&test_log_info); |
| 84 | if (rc < 0) |
| 85 | exit(1); |
| 86 | |
Harald Welte | bdf3fd1 | 2016-01-03 17:04:09 +0100 | [diff] [blame] | 87 | ranap_set_log_area(DRANAP); |
Neels Hofmeyr | 52c6ae2 | 2016-08-26 14:08:51 +0200 | [diff] [blame] | 88 | |
| 89 | log_set_print_filename(osmo_stderr_target, 0); |
| 90 | log_set_use_color(osmo_stderr_target, 0); |
Harald Welte | 87ffeb9 | 2015-12-25 15:34:22 +0100 | [diff] [blame] | 91 | } |
Neels Hofmeyr | d9cb19a | 2017-11-18 18:47:55 +0100 | [diff] [blame] | 92 | |
| 93 | void test_common_cleanup(void) |
| 94 | { |
| 95 | if (talloc_total_blocks(msgb_ctx) != 1 |
| 96 | || talloc_total_size(msgb_ctx) != 0) |
| 97 | talloc_report_full(msgb_ctx, stderr); |
| 98 | |
| 99 | OSMO_ASSERT(talloc_total_blocks(msgb_ctx) == 1); |
| 100 | OSMO_ASSERT(talloc_total_size(msgb_ctx) == 0); |
| 101 | talloc_free(msgb_ctx); |
| 102 | |
| 103 | if (talloc_total_blocks(talloc_asn1_ctx) != 1 |
| 104 | || talloc_total_size(talloc_asn1_ctx) != 0) |
| 105 | talloc_report_full(talloc_asn1_ctx, stderr); |
| 106 | |
| 107 | OSMO_ASSERT(talloc_total_blocks(talloc_asn1_ctx) == 1); |
| 108 | OSMO_ASSERT(talloc_total_size(talloc_asn1_ctx) == 0); |
| 109 | talloc_free(talloc_asn1_ctx); |
| 110 | } |