blob: ae0f83c9a52026140963029cfa311dc1bf2f45c1 [file] [log] [blame]
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001/* 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
33extern 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
51extern struct gsm_subscriber_connection *g_conn;
52extern struct gsm_network *net;
53extern struct gsm_bts *the_bts;
54extern void *msgb_ctx;
55
56extern enum ran_type rx_from_ran;
57
58extern const char *gsup_tx_expected;
59extern bool gsup_tx_confirmed;
60
61extern struct msgb *dtap_tx_expected;
62extern bool dtap_tx_confirmed;
63
64enum result_sent {
65 RES_NONE = 0,
66 RES_ACCEPT = 1,
67 RES_REJECT = 2,
68};
69extern enum result_sent lu_result_sent;
70extern enum result_sent cm_service_result_sent;
71
72extern bool auth_request_sent;
73extern const char *auth_request_expect_rand;
74extern const char *auth_request_expect_autn;
75
76extern bool cipher_mode_cmd_sent;
77extern bool cipher_mode_cmd_sent_with_imeisv;
78
79extern bool paging_sent;
80extern bool paging_stopped;
81
82struct msc_vlr_test_cmdline_opts {
83 bool verbose;
84 int run_test_nr;
85};
86
87typedef void (* msc_vlr_test_func_t )(void);
88extern msc_vlr_test_func_t msc_vlr_tests[];
89
90struct msgb *msgb_from_hex(const char *label, uint16_t size, const char *hex);
91
92void clear_vlr();
93bool conn_exists(struct gsm_subscriber_connection *conn);
94
95void dtap_expect_tx(const char *hex);
96void dtap_expect_tx_ussd(char *ussd_text);
97void paging_expect_imsi(const char *imsi);
98void paging_expect_tmsi(uint32_t tmsi);
99
100void ms_sends_msg(const char *hex);
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200101void ms_sends_security_mode_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100102void gsup_rx(const char *rx_hex, const char *expect_tx_hex);
103void send_sms(struct vlr_subscr *receiver,
104 struct vlr_subscr *sender,
105 char *str);
106
107void thwart_rx_non_initial_requests();
108
109void check_talloc(void *msgb_ctx, void *tall_bsc_ctx, int expected_blocks);
110
111#define EXPECT_ACCEPTED(expect_accepted) do { \
112 if (g_conn) \
113 OSMO_ASSERT(conn_exists(g_conn)); \
114 bool accepted = msc_subscr_conn_is_accepted(g_conn); \
115 fprintf(stderr, "msc_subscr_conn_is_accepted() == %s\n", \
116 accepted ? "true" : "false"); \
117 OSMO_ASSERT(accepted == expect_accepted); \
118 } while (false)
119
120#define VERBOSE_ASSERT(val, expect_op, fmt) \
121 do { \
122 log(#val " == " fmt, (val)); \
123 OSMO_ASSERT((val) expect_op); \
124 } while (0);
125
126#define EXPECT_CONN_COUNT(N) VERBOSE_ASSERT(llist_count(&net->subscr_conns), == N, "%d")
127
128#define gsup_expect_tx(hex) do \
129{ \
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200130 if (gsup_tx_expected) { \
131 log("Previous expected GSUP tx was not confirmed!"); \
132 OSMO_ASSERT(!gsup_tx_expected); \
133 } \
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100134 if (!hex) \
135 break; \
136 gsup_tx_expected = hex; \
137 gsup_tx_confirmed = false; \
138} while (0)
139
140void fake_time_start();
141
142/* as macro to get the test file's source line number */
143#define fake_time_passes(secs, usecs) do \
144{ \
145 struct timeval diff; \
146 osmo_gettimeofday_override_add(secs, usecs); \
147 timersub(&osmo_gettimeofday_override_time, &fake_time_start_time, &diff); \
148 btw("Total time passed: %d.%06d s", \
149 (int)diff.tv_sec, (int)diff.tv_usec); \
150 osmo_timers_prepare(); \
151 osmo_timers_update(); \
152} while (0)
153
154extern const struct timeval fake_time_start_time;