Neels Hofmeyr | f817814 | 2017-01-25 15:04:16 +0100 | [diff] [blame^] | 1 | /* Osmocom MSC+VLR end-to-end tests */ |
| 2 | |
| 3 | /* (C) 2017 by sysmocom s.f.m.c. GmbH <info@sysmocom.de> |
| 4 | * |
| 5 | * All Rights Reserved |
| 6 | * |
| 7 | * Author: Neels Hofmeyr <nhofmeyr@sysmocom.de> |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU Affero General Public License as published by |
| 11 | * the Free Software Foundation; either version 3 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU Affero General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU Affero General Public License |
| 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | #pragma once |
| 25 | |
| 26 | #include <stdbool.h> |
| 27 | #include <stdio.h> |
| 28 | |
| 29 | #include <openbsc/gsm_data.h> |
| 30 | #include <openbsc/osmo_msc.h> |
| 31 | #include <openbsc/vlr.h> |
| 32 | |
| 33 | extern bool _log_lines; |
| 34 | #define _log(fmt, args...) do { \ |
| 35 | if (_log_lines) \ |
| 36 | fprintf(stderr, " %4d:%s: " fmt "\n", \ |
| 37 | __LINE__, __FILE__, ## args ); \ |
| 38 | else \ |
| 39 | fprintf(stderr, fmt "\n", ## args ); \ |
| 40 | } while (false) |
| 41 | |
| 42 | /* btw means "by the way", the test tells the log what's happening. |
| 43 | * BTW() marks a larger section, btw() is the usual logging. */ |
| 44 | #define BTW(fmt, args...) _log("---\n- " fmt, ## args ) |
| 45 | #define btw(fmt, args...) _log("- " fmt, ## args ) |
| 46 | #define log(fmt, args...) _log(" " fmt, ## args ) |
| 47 | |
| 48 | #define comment_start() fprintf(stderr, "===== %s\n", __func__); |
| 49 | #define comment_end() fprintf(stderr, "===== %s: SUCCESS\n\n", __func__); |
| 50 | |
| 51 | extern struct gsm_subscriber_connection *g_conn; |
| 52 | extern struct gsm_network *net; |
| 53 | extern struct gsm_bts *the_bts; |
| 54 | extern void *msgb_ctx; |
| 55 | |
| 56 | extern enum ran_type rx_from_ran; |
| 57 | |
| 58 | extern const char *gsup_tx_expected; |
| 59 | extern bool gsup_tx_confirmed; |
| 60 | |
| 61 | extern struct msgb *dtap_tx_expected; |
| 62 | extern bool dtap_tx_confirmed; |
| 63 | |
| 64 | enum result_sent { |
| 65 | RES_NONE = 0, |
| 66 | RES_ACCEPT = 1, |
| 67 | RES_REJECT = 2, |
| 68 | }; |
| 69 | extern enum result_sent lu_result_sent; |
| 70 | extern enum result_sent cm_service_result_sent; |
| 71 | |
| 72 | extern bool auth_request_sent; |
| 73 | extern const char *auth_request_expect_rand; |
| 74 | extern const char *auth_request_expect_autn; |
| 75 | |
| 76 | extern bool cipher_mode_cmd_sent; |
| 77 | extern bool cipher_mode_cmd_sent_with_imeisv; |
| 78 | |
| 79 | extern bool paging_sent; |
| 80 | extern bool paging_stopped; |
| 81 | |
| 82 | struct msc_vlr_test_cmdline_opts { |
| 83 | bool verbose; |
| 84 | int run_test_nr; |
| 85 | }; |
| 86 | |
| 87 | typedef void (* msc_vlr_test_func_t )(void); |
| 88 | extern msc_vlr_test_func_t msc_vlr_tests[]; |
| 89 | |
| 90 | struct msgb *msgb_from_hex(const char *label, uint16_t size, const char *hex); |
| 91 | |
| 92 | void clear_vlr(); |
| 93 | bool conn_exists(struct gsm_subscriber_connection *conn); |
| 94 | |
| 95 | void dtap_expect_tx(const char *hex); |
| 96 | void dtap_expect_tx_ussd(char *ussd_text); |
| 97 | void paging_expect_imsi(const char *imsi); |
| 98 | void paging_expect_tmsi(uint32_t tmsi); |
| 99 | |
| 100 | void ms_sends_msg(const char *hex); |
| 101 | void gsup_rx(const char *rx_hex, const char *expect_tx_hex); |
| 102 | void send_sms(struct vlr_subscr *receiver, |
| 103 | struct vlr_subscr *sender, |
| 104 | char *str); |
| 105 | |
| 106 | void thwart_rx_non_initial_requests(); |
| 107 | |
| 108 | void check_talloc(void *msgb_ctx, void *tall_bsc_ctx, int expected_blocks); |
| 109 | |
| 110 | #define EXPECT_ACCEPTED(expect_accepted) do { \ |
| 111 | if (g_conn) \ |
| 112 | OSMO_ASSERT(conn_exists(g_conn)); \ |
| 113 | bool accepted = msc_subscr_conn_is_accepted(g_conn); \ |
| 114 | fprintf(stderr, "msc_subscr_conn_is_accepted() == %s\n", \ |
| 115 | accepted ? "true" : "false"); \ |
| 116 | OSMO_ASSERT(accepted == expect_accepted); \ |
| 117 | } while (false) |
| 118 | |
| 119 | #define VERBOSE_ASSERT(val, expect_op, fmt) \ |
| 120 | do { \ |
| 121 | log(#val " == " fmt, (val)); \ |
| 122 | OSMO_ASSERT((val) expect_op); \ |
| 123 | } while (0); |
| 124 | |
| 125 | #define EXPECT_CONN_COUNT(N) VERBOSE_ASSERT(llist_count(&net->subscr_conns), == N, "%d") |
| 126 | |
| 127 | #define gsup_expect_tx(hex) do \ |
| 128 | { \ |
| 129 | OSMO_ASSERT(!gsup_tx_expected); \ |
| 130 | if (!hex) \ |
| 131 | break; \ |
| 132 | gsup_tx_expected = hex; \ |
| 133 | gsup_tx_confirmed = false; \ |
| 134 | } while (0) |
| 135 | |
| 136 | void fake_time_start(); |
| 137 | |
| 138 | /* as macro to get the test file's source line number */ |
| 139 | #define fake_time_passes(secs, usecs) do \ |
| 140 | { \ |
| 141 | struct timeval diff; \ |
| 142 | osmo_gettimeofday_override_add(secs, usecs); \ |
| 143 | timersub(&osmo_gettimeofday_override_time, &fake_time_start_time, &diff); \ |
| 144 | btw("Total time passed: %d.%06d s", \ |
| 145 | (int)diff.tv_sec, (int)diff.tv_usec); \ |
| 146 | osmo_timers_prepare(); \ |
| 147 | osmo_timers_update(); \ |
| 148 | } while (0) |
| 149 | |
| 150 | extern const struct timeval fake_time_start_time; |