comparison spandsp-0.0.6pre17/tests/t38_core_tests.c @ 4:26cd8f1ef0b1

import spandsp-0.0.6pre17
author Peter Meerwald <pmeerw@cosy.sbg.ac.at>
date Fri, 25 Jun 2010 15:50:58 +0200
parents
children
comparison
equal deleted inserted replaced
3:c6c5a16ce2f2 4:26cd8f1ef0b1
1 /*
2 * SpanDSP - a series of DSP components for telephony
3 *
4 * t38_core_tests.c - Tests for the T.38 FoIP core module.
5 *
6 * Written by Steve Underwood <steveu@coppice.org>
7 *
8 * Copyright (C) 2007 Steve Underwood
9 *
10 * All rights reserved.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2, as
14 * published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 *
25 * $Id: t38_core_tests.c,v 1.16 2009/07/14 13:54:22 steveu Exp $
26 */
27
28 /*! \file */
29
30 /*! \page t38_core_tests_page T.38 core tests
31 \section t38_core_tests_page_sec_1 What does it do?
32 These tests exercise the T.38 core ASN.1 processing code.
33 */
34
35 #if defined(HAVE_CONFIG_H)
36 #include <config.h>
37 #endif
38
39 #include <stdlib.h>
40 #include <stdio.h>
41 #include <fcntl.h>
42 #include <string.h>
43 #include <assert.h>
44 #include <errno.h>
45
46 //#if defined(WITH_SPANDSP_INTERNALS)
47 #define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
48 //#endif
49
50 #include "spandsp.h"
51
52 #define MAX_FIELDS 42
53 #define MAX_FIELD_LEN 8192
54
55 int t38_version;
56 int succeeded = TRUE;
57 int ok_indicator_packets;
58 int bad_indicator_packets;
59 int ok_data_packets;
60 int bad_data_packets;
61 int missing_packets;
62
63 int current_indicator;
64 int current_data_type;
65 int current_field_type;
66 int skip;
67
68 uint8_t field_body[MAX_FIELDS][MAX_FIELD_LEN];
69 int field_len[MAX_FIELDS];
70
71 static int rx_missing_handler(t38_core_state_t *s, void *user_data, int rx_seq_no, int expected_seq_no)
72 {
73 missing_packets++;
74 //printf("Hit missing\n");
75 return 0;
76 }
77 /*- End of function --------------------------------------------------------*/
78
79 static int rx_indicator_handler(t38_core_state_t *s, void *user_data, int indicator)
80 {
81 if (indicator == current_indicator)
82 ok_indicator_packets++;
83 else
84 bad_indicator_packets++;
85 //printf("Hit indicator %d\n", indicator);
86 return 0;
87 }
88 /*- End of function --------------------------------------------------------*/
89
90 static int rx_data_handler(t38_core_state_t *s, void *user_data, int data_type, int field_type, const uint8_t *buf, int len)
91 {
92 if (--skip >= 0)
93 {
94 if (data_type == current_data_type && field_type == current_field_type)
95 ok_data_packets++;
96 else
97 bad_data_packets++;
98 }
99 else
100 {
101 if (data_type == current_data_type && field_type == T38_FIELD_T4_NON_ECM_SIG_END)
102 ok_data_packets++;
103 else
104 bad_data_packets++;
105 }
106 //printf("Hit data %d, field %d\n", data_type, field_type);
107 return 0;
108 }
109 /*- End of function --------------------------------------------------------*/
110
111 static int tx_packet_handler(t38_core_state_t *s, void *user_data, const uint8_t *buf, int len, int count)
112 {
113 t38_core_state_t *t;
114 static int seq_no = 0;
115
116 t = (t38_core_state_t *) user_data;
117 span_log(&s->logging, SPAN_LOG_FLOW, "Send seq %d, len %d, count %d\n", s->tx_seq_no, len, count);
118 if (t38_core_rx_ifp_packet(t, buf, len, seq_no) < 0)
119 succeeded = FALSE;
120 seq_no++;
121 return 0;
122 }
123 /*- End of function --------------------------------------------------------*/
124
125 static int encode_decode_tests(t38_core_state_t *a, t38_core_state_t *b)
126 {
127 t38_data_field_t field[MAX_FIELDS];
128 int i;
129 int j;
130
131 ok_indicator_packets = 0;
132 bad_indicator_packets = 0;
133 ok_data_packets = 0;
134 bad_data_packets = 0;
135 missing_packets = 0;
136
137 /* Try all the indicator types */
138 for (i = 0; i < 100; i++)
139 {
140 current_indicator = i;
141 if (t38_core_send_indicator(a, i) < 0)
142 break;
143 }
144
145 /* Try all the data types, as single field messages with no data */
146 for (i = 0; i < 100; i++)
147 {
148 for (j = 0; j < 100; j++)
149 {
150 current_data_type = i;
151 current_field_type = j;
152 skip = 99;
153 if (t38_core_send_data(a, i, j, (uint8_t *) "", 0, T38_PACKET_CATEGORY_CONTROL_DATA) < 0)
154 break;
155 }
156 if (j == 0)
157 break;
158 }
159
160 /* Try all the data types and field types, as single field messages with data */
161 for (i = 0; i < 100; i++)
162 {
163 for (j = 0; j < 100; j++)
164 {
165 current_data_type = i;
166 current_field_type = j;
167 skip = 99;
168 if (t38_core_send_data(a, i, j, (uint8_t *) "ABCD", 4, T38_PACKET_CATEGORY_CONTROL_DATA) < 0)
169 break;
170 }
171 if (j == 0)
172 break;
173 }
174
175 /* Try all the data types and field types, as multi-field messages */
176 for (i = 0; i < 100; i++)
177 {
178 for (j = 0; j < 100; j++)
179 {
180 current_data_type = i;
181 current_field_type = j;
182 skip = 1;
183
184 field_len[0] = 444;
185 field_len[1] = 333;
186
187 field[0].field_type = j;
188 field[0].field = field_body[0];
189 field[0].field_len = field_len[0];
190 field[1].field_type = T38_FIELD_T4_NON_ECM_SIG_END;
191 field[1].field = field_body[1];
192 field[1].field_len = field_len[1];
193 if (t38_core_send_data_multi_field(a, i, field, 2, T38_PACKET_CATEGORY_CONTROL_DATA) < 0)
194 break;
195 }
196 if (j == 0)
197 break;
198 }
199 printf("Indicator packets: OK = %d, bad = %d\n", ok_indicator_packets, bad_indicator_packets);
200 printf("Data packets: OK = %d, bad = %d\n", ok_data_packets, bad_data_packets);
201 printf("Missing packets = %d\n", missing_packets);
202 if (t38_version == 0)
203 {
204 if (ok_indicator_packets != 16 || bad_indicator_packets != 0)
205 {
206 printf("Tests failed\n");
207 return -1;
208 }
209 if (ok_data_packets != 288 || bad_data_packets != 0)
210 {
211 printf("Tests failed\n");
212 return -1;
213 }
214 }
215 else
216 {
217 if (ok_indicator_packets != 23 || bad_indicator_packets != 0)
218 {
219 printf("Tests failed\n");
220 return -1;
221 }
222 if (ok_data_packets != 720 || bad_data_packets != 0)
223 {
224 printf("Tests failed\n");
225 return -1;
226 }
227 }
228 if (missing_packets > 0)
229 {
230 printf("Tests failed\n");
231 return -1;
232 }
233 return 0;
234 }
235 /*- End of function --------------------------------------------------------*/
236
237 static int attack_tests(t38_core_state_t *s)
238 {
239 return 0;
240 }
241 /*- End of function --------------------------------------------------------*/
242
243 int main(int argc, char *argv[])
244 {
245 t38_core_state_t t38_core_a;
246 t38_core_state_t t38_core_b;
247
248 for (t38_version = 0; t38_version < 2; t38_version++)
249 {
250 printf("Using T.38 version %d\n", t38_version);
251
252 if (t38_core_init(&t38_core_a,
253 rx_indicator_handler,
254 rx_data_handler,
255 rx_missing_handler,
256 &t38_core_b,
257 tx_packet_handler,
258 &t38_core_b) == NULL)
259 {
260 fprintf(stderr, "Cannot start the T.38 core\n");
261 exit(2);
262 }
263 if (t38_core_init(&t38_core_b,
264 rx_indicator_handler,
265 rx_data_handler,
266 rx_missing_handler,
267 &t38_core_a,
268 tx_packet_handler,
269 &t38_core_a) == NULL)
270 {
271 fprintf(stderr, "Cannot start the T.38 core\n");
272 exit(2);
273 }
274
275 t38_set_t38_version(&t38_core_a, t38_version);
276 t38_set_t38_version(&t38_core_b, t38_version);
277
278 span_log_set_level(&t38_core_a.logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG);
279 span_log_set_tag(&t38_core_a.logging, "T.38-A");
280 span_log_set_level(&t38_core_b.logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG);
281 span_log_set_tag(&t38_core_b.logging, "T.38-B");
282
283 if (encode_decode_tests(&t38_core_a, &t38_core_b))
284 {
285 printf("Encode/decode tests failed\n");
286 exit(2);
287 }
288 if (attack_tests(&t38_core_a))
289 {
290 printf("Attack tests failed\n");
291 exit(2);
292 }
293 }
294 if (!succeeded)
295 {
296 printf("Tests failed\n");
297 exit(2);
298 }
299 printf("Tests passed\n");
300 return 0;
301 }
302 /*- End of function --------------------------------------------------------*/
303 /*- End of file ------------------------------------------------------------*/

Repositories maintained by Peter Meerwald, pmeerw@pmeerw.net.