Neels Hofmeyr | 6bd5447 | 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 | |
Philipp Maier | efe85d3 | 2017-04-09 12:32:51 +0200 | [diff] [blame^] | 82 | extern bool iu_release_expected; |
| 83 | extern bool iu_release_sent; |
| 84 | extern bool bssap_clear_expected; |
| 85 | extern bool bssap_clear_sent; |
| 86 | |
| 87 | static inline void expect_iu_release() |
| 88 | { |
| 89 | iu_release_expected = true; |
| 90 | iu_release_sent = false; |
| 91 | } |
| 92 | |
| 93 | static inline void expect_bssap_clear() |
| 94 | { |
| 95 | bssap_clear_expected = true; |
| 96 | bssap_clear_sent = false; |
| 97 | } |
| 98 | |
| 99 | static inline void expect_release_clear(enum ran_type via_ran) |
| 100 | { |
| 101 | switch (via_ran) { |
| 102 | case RAN_GERAN_A: |
| 103 | expect_bssap_clear(); |
| 104 | return; |
| 105 | case RAN_UTRAN_IU: |
| 106 | expect_iu_release(); |
| 107 | return; |
| 108 | default: |
| 109 | OSMO_ASSERT(false); |
| 110 | break; |
| 111 | } |
| 112 | } |
| 113 | |
Neels Hofmeyr | 6bd5447 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 114 | struct msc_vlr_test_cmdline_opts { |
| 115 | bool verbose; |
| 116 | int run_test_nr; |
| 117 | }; |
| 118 | |
| 119 | typedef void (* msc_vlr_test_func_t )(void); |
| 120 | extern msc_vlr_test_func_t msc_vlr_tests[]; |
| 121 | |
| 122 | struct msgb *msgb_from_hex(const char *label, uint16_t size, const char *hex); |
| 123 | |
| 124 | void clear_vlr(); |
| 125 | bool conn_exists(struct gsm_subscriber_connection *conn); |
| 126 | |
| 127 | void dtap_expect_tx(const char *hex); |
| 128 | void dtap_expect_tx_ussd(char *ussd_text); |
| 129 | void paging_expect_imsi(const char *imsi); |
| 130 | void paging_expect_tmsi(uint32_t tmsi); |
| 131 | |
| 132 | void ms_sends_msg(const char *hex); |
Neels Hofmeyr | 2188a77 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 133 | void ms_sends_security_mode_complete(); |
Neels Hofmeyr | 6bd5447 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 134 | void gsup_rx(const char *rx_hex, const char *expect_tx_hex); |
| 135 | void send_sms(struct vlr_subscr *receiver, |
| 136 | struct vlr_subscr *sender, |
| 137 | char *str); |
| 138 | |
| 139 | void thwart_rx_non_initial_requests(); |
| 140 | |
| 141 | void check_talloc(void *msgb_ctx, void *tall_bsc_ctx, int expected_blocks); |
| 142 | |
| 143 | #define EXPECT_ACCEPTED(expect_accepted) do { \ |
| 144 | if (g_conn) \ |
| 145 | OSMO_ASSERT(conn_exists(g_conn)); \ |
| 146 | bool accepted = msc_subscr_conn_is_accepted(g_conn); \ |
| 147 | fprintf(stderr, "msc_subscr_conn_is_accepted() == %s\n", \ |
| 148 | accepted ? "true" : "false"); \ |
| 149 | OSMO_ASSERT(accepted == expect_accepted); \ |
| 150 | } while (false) |
| 151 | |
| 152 | #define VERBOSE_ASSERT(val, expect_op, fmt) \ |
| 153 | do { \ |
| 154 | log(#val " == " fmt, (val)); \ |
| 155 | OSMO_ASSERT((val) expect_op); \ |
| 156 | } while (0); |
| 157 | |
| 158 | #define EXPECT_CONN_COUNT(N) VERBOSE_ASSERT(llist_count(&net->subscr_conns), == N, "%d") |
| 159 | |
| 160 | #define gsup_expect_tx(hex) do \ |
| 161 | { \ |
Neels Hofmeyr | 2188a77 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 162 | if (gsup_tx_expected) { \ |
| 163 | log("Previous expected GSUP tx was not confirmed!"); \ |
| 164 | OSMO_ASSERT(!gsup_tx_expected); \ |
| 165 | } \ |
Neels Hofmeyr | 6bd5447 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 166 | if (!hex) \ |
| 167 | break; \ |
| 168 | gsup_tx_expected = hex; \ |
| 169 | gsup_tx_confirmed = false; \ |
| 170 | } while (0) |
| 171 | |
| 172 | void fake_time_start(); |
| 173 | |
| 174 | /* as macro to get the test file's source line number */ |
| 175 | #define fake_time_passes(secs, usecs) do \ |
| 176 | { \ |
| 177 | struct timeval diff; \ |
| 178 | osmo_gettimeofday_override_add(secs, usecs); \ |
| 179 | timersub(&osmo_gettimeofday_override_time, &fake_time_start_time, &diff); \ |
| 180 | btw("Total time passed: %d.%06d s", \ |
| 181 | (int)diff.tv_sec, (int)diff.tv_usec); \ |
| 182 | osmo_timers_prepare(); \ |
| 183 | osmo_timers_update(); \ |
| 184 | } while (0) |
| 185 | |
| 186 | extern const struct timeval fake_time_start_time; |