Debian Codegraph @

Xpjproject/pjsip/src/test/test.h

raw symbols SCIP
1 /*
2 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
3 * Copyright (C) 2003-2008 Benny Prijono <[email protected]>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 #ifndef __TEST_H__
20 #define __TEST_H__
21
22 #include <pjsip/sip_types.h>
23 #include <pjsip/sip_msg.h>
24 #include <pj/string.h>
25
26 extern pjsip_endpoint *endpt;
27 extern pj_caching_pool caching_pool;
28
29 /* Check if we are using ASan */
30 #ifndef __has_feature
31 #define __has_feature(x) 0
32 #endif
33 #if defined(__SANITIZE_ADDRESS__) || __has_feature(address_sanitizer)
34 #define ASAN_ENABLED 1
35 #else
36 #define ASAN_ENABLED 0
37 #endif
38
39 /* Apple Clang ASan crashes on longjmp, see #4846 */
40 #if defined(__APPLE__) && ASAN_ENABLED
41 #define APPLE_ASAN 1
42 #else
43 #define APPLE_ASAN 0
44 #endif
45
46 #define TEST_UDP_PORT 15060
47 #define TEST_UDP_PORT_STR "15060"
48
49 /**
50 * Memory size to use in caching pool.
51 * Default: 2MB
52 */
53 #ifndef PJSIP_TEST_MEM_SIZE
54 # define PJSIP_TEST_MEM_SIZE (2*1024*1024)
55 #endif
56
57 #define INCLUDE_MESSAGING_GROUP 1
58 #define INCLUDE_TRANSPORT_GROUP 1
59 #define INCLUDE_TSX_GROUP 1
60 #define INCLUDE_INV_GROUP 1
61 #define INCLUDE_REGC_GROUP 1
62
63 #define INCLUDE_BENCHMARKS 1
64
65 /*
66 * Include tests that normally would fail under certain gcc
67 * optimization levels.
68 */
69 #ifndef INCLUDE_GCC_TEST
70 # define INCLUDE_GCC_TEST 0
71 #endif
72
73
74 #if defined(PJ_EXCLUDE_BENCHMARK_TESTS) && (PJ_EXCLUDE_BENCHMARK_TESTS==1)
75 # define WITH_BENCHMARK 0
76 #else
77 # define WITH_BENCHMARK 1
78 #endif
79
80 #define INCLUDE_URI_TEST (INCLUDE_MESSAGING_GROUP && !APPLE_ASAN)
81 #define INCLUDE_MSG_TEST (INCLUDE_MESSAGING_GROUP && !APPLE_ASAN)
82 #define INCLUDE_MULTIPART_TEST INCLUDE_MESSAGING_GROUP
83 #define INCLUDE_TXDATA_TEST INCLUDE_MESSAGING_GROUP
84 #define INCLUDE_TSX_BENCH (INCLUDE_MESSAGING_GROUP && WITH_BENCHMARK)
85 #define INCLUDE_UDP_TEST INCLUDE_TRANSPORT_GROUP
86 #define INCLUDE_LOOP_TEST INCLUDE_TRANSPORT_GROUP
87 #define INCLUDE_TCP_TEST INCLUDE_TRANSPORT_GROUP
88 #define INCLUDE_RESOLVE_TEST INCLUDE_TRANSPORT_GROUP
89 #define INCLUDE_TSX_TEST INCLUDE_TSX_GROUP
90 #define INCLUDE_TSX_DESTROY_TEST INCLUDE_TSX_GROUP
91 #define INCLUDE_INV_OA_TEST INCLUDE_INV_GROUP
92 #define INCLUDE_REGC_TEST INCLUDE_REGC_GROUP
93 #define INCLUDE_AUTH_ASYNC_TEST INCLUDE_REGC_GROUP
94 #define INCLUDE_PJSUA_AUTH_TEST INCLUDE_REGC_GROUP
95
96
97 /* The tests */
98 int uri_test(void);
99 int msg_test(void);
100 int msg_err_test(void);
101 int multipart_test(void);
102 int txdata_test(void);
103 int tsx_bench(void);
104 int tsx_destroy_test(void);
105 int transport_udp_test(void);
106 int transport_loop_test(void);
107 int transport_loop_multi_test(void);
108 int transport_loop_resolve_error_test(void);
109 int transport_tcp_test(void);
110 int resolve_test(void);
111 int regc_test(void);
112 int auth_async_test(void);
113 int pjsua_auth_test(void);
114 int inv_offer_answer_test(void);
115
116 #define MAX_TSX_TESTS 10
117
118 struct tsx_test_param
119 {
120 int type;
121 int port;
122 char *tp_type;
123 };
124 extern struct tsx_test_param tsx_test[MAX_TSX_TESTS];
125
126 int tsx_basic_test(unsigned tid);
127 int tsx_uac_test(unsigned tid);
128 int tsx_uas_test(unsigned tid);
129
130 /* Transport test helpers (transport_test.c). */
131 int generic_transport_test(pjsip_transport *tp);
132 int transport_send_recv_test( pjsip_transport_type_e tp_type,
133 pjsip_transport *ref_tp,
134 const char *host_port_transport,
135 int *p_usec_rtt);
136 int transport_rt_test( pjsip_transport_type_e tp_type,
137 pjsip_transport *ref_tp,
138 const char *host_port_transport,
139 int *pkt_lost);
140 int transport_load_test(pjsip_transport_type_e tp_type,
141 const char *host_port_transport);
142
143 /* Test main entry */
144 int test_main(int argc, char *argv[]);
145
146 /* Test utilities. */
147 void app_perror(const char *msg, pj_status_t status);
148 int init_msg_logger(void);
149 int msg_logger_set_enabled(pj_bool_t enabled);
150 void flush_events(unsigned duration);
151 pjsip_transport *wait_loop_transport_clear(int secs);
152
153 void report_ival(const char *name, int value, const char *valname, const char *desc);
154 void report_sval(const char *name, const char* value, const char *valname, const char *desc);
155
156 /* Utility to check if the user part of From/To is equal to the string */
157 PJ_INLINE(pj_bool_t) is_user_equal(const pjsip_fromto_hdr *hdr, const char *user)
158 {
159 const pjsip_sip_uri *sip_uri = (pjsip_sip_uri*)pjsip_uri_get_uri(hdr->uri);
160 const pj_str_t *scheme = pjsip_uri_get_scheme(sip_uri);
161
162 if (pj_stricmp2(scheme, "sip") && pj_stricmp2(scheme, "sips"))
163 return PJ_FALSE;
164
165 return pj_strcmp2(&sip_uri->user, user)==0;
166 }
167
168 /* Settings. */
169 extern int log_level;
170
171 #define UT_MAX_TESTS 32
172 #include "../../../pjlib/src/pjlib-test/test_util.h"
173
174 struct test_app_t
175 {
176 ut_app_t ut_app;
177 };
178 extern struct test_app_t test_app;
179
180 #endif /* __TEST_H__ */