comparison spandsp-0.0.6pre17/tests/v18_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 * v18_tests.c
5 *
6 * Written by Steve Underwood <steveu@coppice.org>
7 *
8 * Copyright (C) 2004-2009 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: v18_tests.c,v 1.8 2009/05/30 15:23:14 steveu Exp $
26 */
27
28 /*! \page v18_tests_page V.18 tests
29 \section v18_tests_page_sec_1 What does it do?
30 */
31
32 /* Enable the following definition to enable direct probing into the spandsp structures */
33 //#define WITH_SPANDSP_INTERNALS
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 <unistd.h>
43 #include <string.h>
44 #include <sndfile.h>
45
46 //#if defined(WITH_SPANDSP_INTERNALS)
47 #define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
48 //#endif
49
50 #include "spandsp.h"
51 #include "spandsp-sim.h"
52
53 #define FALSE 0
54 #define TRUE (!FALSE)
55
56 #define OUTPUT_FILE_NAME "v18.wav"
57
58 #define SAMPLES_PER_CHUNK 160
59
60 int log_audio = FALSE;
61 SNDFILE *outhandle = NULL;
62
63 char *decode_test_file = NULL;
64
65 int good_message_received;
66
67 const char *qbf_tx = "The quick Brown Fox Jumps Over The Lazy dog 0123456789!@#$%^&*()'";
68 const char *qbf_rx = "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG 0123456789!X$$/'+.()'";
69 const char *full_baudot_rx =
70 "\b \n\n\n\r?\n\n\n !\"$$/+'().+,-./"
71 "0123456789:;(=)?"
72 "XABCDEFGHIJKLMNOPQRSTUVWXYZ(/)' "
73 "'ABCDEFGHIJKLMNOPQRSTUVWXYZ(!) ";
74
75 #if 1
76 static void put_text_msg(void *user_data, const uint8_t *msg, int len)
77 {
78 if (strcmp((const char *) msg, qbf_rx))
79 {
80 printf("Result:\n%s\n", msg);
81 printf("Reference result:\n%s\n", qbf_rx);
82 }
83 else
84 {
85 good_message_received = TRUE;
86 }
87 }
88 /*- End of function --------------------------------------------------------*/
89
90 static void basic_tests(int mode)
91 {
92 int16_t amp[SAMPLES_PER_CHUNK];
93 int outframes;
94 int len;
95 int push;
96 int i;
97 v18_state_t *v18_a;
98 v18_state_t *v18_b;
99
100 printf("Testing %s\n", v18_mode_to_str(mode));
101 v18_a = v18_init(NULL, TRUE, mode, put_text_msg, NULL);
102 v18_b = v18_init(NULL, FALSE, mode, put_text_msg, NULL);
103
104 /* Fake an OK condition for the first message test */
105 good_message_received = TRUE;
106 push = 0;
107 if (v18_put(v18_a, qbf_tx, -1) != strlen(qbf_tx))
108 {
109 printf("V.18 put failed\n");
110 exit(2);
111 }
112 for (i = 0; i < 100000; i++)
113 {
114 if (push == 0)
115 {
116 if ((len = v18_tx(v18_a, amp, SAMPLES_PER_CHUNK)) == 0)
117 push = 10;
118 }
119 else
120 {
121 len = 0;
122 /* Push a little silence through, to flush things out */
123 if (--push == 0)
124 {
125 if (!good_message_received)
126 {
127 printf("No message received\n");
128 exit(2);
129 }
130 good_message_received = FALSE;
131 if (v18_put(v18_a, qbf_tx, -1) != strlen(qbf_tx))
132 {
133 printf("V.18 put failed\n");
134 exit(2);
135 }
136 }
137 }
138 if (len < SAMPLES_PER_CHUNK)
139 {
140 memset(&amp[len], 0, sizeof(int16_t)*(SAMPLES_PER_CHUNK - len));
141 len = SAMPLES_PER_CHUNK;
142 }
143 if (log_audio)
144 {
145 outframes = sf_writef_short(outhandle, amp, len);
146 if (outframes != len)
147 {
148 fprintf(stderr, " Error writing audio file\n");
149 exit(2);
150 }
151 }
152 v18_rx(v18_b, amp, len);
153 }
154 v18_free(v18_a);
155 v18_free(v18_b);
156 }
157 /*- End of function --------------------------------------------------------*/
158 #endif
159
160 static int test_x_01(void)
161 {
162 /* III.5.4.5.1 Baudot carrier timing and receiver disabling */
163 printf("Test not yet implemented\n");
164 return 1;
165 }
166 /*- End of function --------------------------------------------------------*/
167
168 static int test_x_02(void)
169 {
170 /* III.5.4.5.2 Baudot bit rate confirmation */
171 printf("Test not yet implemented\n");
172 return 1;
173 }
174 /*- End of function --------------------------------------------------------*/
175
176 static int test_x_03(void)
177 {
178 /* III.5.4.5.3 Baudot probe bit rate confirmation */
179 printf("Test not yet implemented\n");
180 return 1;
181 }
182 /*- End of function --------------------------------------------------------*/
183
184 static int test_x_04(void)
185 {
186 char result[1024];
187 char *t;
188 int ch;
189 int xx;
190 int yy;
191 int i;
192 v18_state_t *v18_state;
193
194 /* III.5.4.5.4 5 Bit to T.50 character conversion */
195 v18_state = v18_init(NULL, TRUE, V18_MODE_5BIT_45, NULL, NULL);
196 printf("Original:\n");
197 t = result;
198 for (i = 0; i < 127; i++)
199 {
200 ch = i;
201 printf("%c", ch);
202 xx = v18_encode_baudot(v18_state, ch);
203 if (xx)
204 {
205 if ((xx & 0x3E0))
206 {
207 yy = v18_decode_baudot(v18_state, (xx >> 5) & 0x1F);
208 if (yy)
209 *t++ = yy;
210 }
211 yy = v18_decode_baudot(v18_state, xx & 0x1F);
212 if (yy)
213 *t++ = yy;
214 }
215 }
216 printf("\n");
217 *t = '\0';
218 v18_free(v18_state);
219 printf("Result:\n%s\n", result);
220 printf("Reference result:\n%s\n", full_baudot_rx);
221 if (strcmp(result, full_baudot_rx) != 0)
222 return -1;
223 return 0;
224 }
225 /*- End of function --------------------------------------------------------*/
226
227 static int test_x_06(void)
228 {
229 char msg[128];
230 char dtmf[1024];
231 char result[1024];
232 const char *ref;
233 int len;
234 int i;
235
236 /* III.5.4.5.6 DTMF character conversion */
237 for (i = 0; i < 127; i++)
238 msg[i] = i + 1;
239 msg[127] = '\0';
240 printf("%s\n", msg);
241
242 len = v18_encode_dtmf(NULL, dtmf, msg);
243 printf("%s\n", dtmf);
244
245 len = v18_decode_dtmf(NULL, result, dtmf);
246
247 ref = "\b \n\n\n?\n\n\n %+().+,-.0123456789:;(=)"
248 "?XABCDEFGHIJKLMNOPQRSTUVWXYZĈĜĊ"
249 " abcdefghijklmnopqrstuvwxyzĉĝċ \b";
250
251 printf("Result:\n%s\n", result);
252 printf("Reference result:\n%s\n", ref);
253 if (strcmp(result, ref) != 0)
254 return -1;
255 return 0;
256 }
257 /*- End of function --------------------------------------------------------*/
258
259 static int test_unimplemented(void)
260 {
261 printf("Test not yet implemented\n");
262 return 1;
263 }
264 /*- End of function --------------------------------------------------------*/
265
266 static void put_v18_msg(void *user_data, const uint8_t *msg, int len)
267 {
268 char buf[1024];
269
270 memcpy(buf, msg, len);
271 buf[len] = '\0';
272 printf("Received (%d bytes) '%s'\n", len, buf);
273 }
274 /*- End of function --------------------------------------------------------*/
275
276 static int decode_test_data_file(int mode, const char *filename)
277 {
278 v18_state_t *v18_state;
279 int16_t amp[SAMPLES_PER_CHUNK];
280 SNDFILE *inhandle;
281 int len;
282
283 printf("Decoding as '%s'\n", v18_mode_to_str(mode));
284 /* We will decode the audio from a file. */
285 if ((inhandle = sf_open_telephony_read(decode_test_file, 1)) == NULL)
286 {
287 fprintf(stderr, " Cannot open audio file '%s'\n", decode_test_file);
288 exit(2);
289 }
290 v18_state = v18_init(NULL, FALSE, mode, put_v18_msg, NULL);
291 for (;;)
292 {
293 len = sf_readf_short(inhandle, amp, SAMPLES_PER_CHUNK);
294 if (len == 0)
295 break;
296 v18_rx(v18_state, amp, len);
297 }
298 if (sf_close(inhandle) != 0)
299 {
300 fprintf(stderr, " Cannot close audio file '%s'\n", decode_test_file);
301 exit(2);
302 }
303 v18_free(v18_state);
304 return 0;
305 }
306 /*- End of function --------------------------------------------------------*/
307
308 const struct
309 {
310 const char *title;
311 int (*func)(void);
312 } test_list[] =
313 {
314 {"III.3.2.1 Operational requirements tests", NULL},
315 {"MISC-01 4 (1) No Disconnection Test", test_unimplemented},
316 {"MISC-02 4 (2) Automatic resumption of automoding", test_unimplemented},
317 {"MISC-03 4 (2) Retention of selected mode on loss of signal", test_unimplemented},
318 {"MISC-04 4 (4) Detection of BUSY tone", test_unimplemented},
319 {"MISC-05 4 (4) Detection of RINGING", test_unimplemented},
320 {"MISC-06 4 (4) LOSS OF CARRIER indication", test_unimplemented},
321 {"MISC-07 4 (4) Call progress indication", test_unimplemented},
322 {"MISC-08 4 (5) Circuit 135 test", test_unimplemented},
323 {"MISC-09 Connection Procedures", test_unimplemented},
324
325 {"III.3.2.2 Automode originate tests", NULL},
326 {"ORG-01 5.1.1 CI & XCI Signal coding and cadence", test_unimplemented},
327 {"ORG-02 5.1.3 ANS Signal Detection", test_unimplemented},
328 {"ORG-03 5.2.3.1 End of ANS signal detection", test_unimplemented},
329 {"ORG-04 5.1.3.2 ANS tone followed by TXP", test_unimplemented},
330 {"ORG-05 5.1.3.3 ANS tone followed by 1650Hz", test_unimplemented},
331 {"ORG-06 5.1.3.4 ANS tone followed by 1300Hz", test_unimplemented},
332 {"ORG-07 5.1.3 ANS tone followed by no tone", test_unimplemented},
333 {"ORG-08 5.1.4 Bell 103 (2225Hz Signal) Detection", test_unimplemented},
334 {"ORG-09 5.1.5 V.21 (1650Hz Signal) Detection", test_unimplemented},
335 {"ORG-10 5.1.6 V.23 (1300Hz Signal) Detection", test_unimplemented},
336 {"ORG-11 5.1.7 V.23 (390Hz Signal) Detection", test_unimplemented},
337 {"ORG-12a to d 5.1.8 5 Bit Mode (Baudot) Detection Tests", test_unimplemented},
338 {"ORG-13 5.1.9 DTMF signal detection", test_unimplemented},
339 {"ORG-14 5.1.10 EDT Rate Detection", test_unimplemented},
340 {"ORG-15 5.1.10.1 Rate Detection Test", test_unimplemented},
341 {"ORG-16 5.1.10.2 980Hz Detection", test_unimplemented},
342 {"ORG-17 5.1.10.3 Loss of signal after 980Hz", test_unimplemented},
343 {"ORG-18 5.1.10.3 Tr Timer", test_unimplemented},
344 {"ORG-19 5.1.11 Bell 103 (1270Hz Signal) Detection", test_unimplemented},
345 {"ORG-20 Immunity to Network Tones", test_unimplemented},
346 {"ORG-21a to b Immunity to other non-textphone modems", test_unimplemented},
347 {"ORG-22 Immunity to Fax Tones", test_unimplemented},
348 {"ORG-23 Immunity to Voice", test_unimplemented},
349 {"ORG-24 5.1.2 ANSam detection", test_unimplemented},
350 {"ORG-25 6.1 V.8 originate call", test_unimplemented},
351
352 {"III.3.2.3 Automode answer tests", NULL},
353 {"ANS-01 5.2.1 Ta timer", test_unimplemented},
354 {"ANS-02 5.2.2 CI Signal Detection", test_unimplemented},
355 {"ANS-03 5.2.2.1 Early Termination of ANS tone", test_unimplemented},
356 {"ANS-04 5.2.2.2 Tt Timer", test_unimplemented},
357 {"ANS-05 5.2.3.2 ANS tone followed by 980Hz", test_unimplemented},
358 {"ANS-06 5.2.3.2 ANS tone followed by 1300Hz", test_unimplemented},
359 {"ANS-07 5.2.3.3 ANS tone followed by 1650Hz", test_unimplemented},
360 {"ANS-08 5.2.4.1 980Hz followed by 1650Hz", test_unimplemented},
361 {"ANS-09a to d 5.2.4.2 980Hz calling tone detection", test_unimplemented},
362 {"ANS-10 5.2.4.3 V.21 Detection by Timer", test_unimplemented},
363 {"ANS-11 5.2.4.4.1 EDT Detection by Rate", test_unimplemented},
364 {"ANS-12 5.2.4.4.2 V.21 Detection by Rate", test_unimplemented},
365 {"ANS-13 5.2.4.4.3 Tr Timer", test_unimplemented},
366 {"ANS-14 5.2.4.5 Te Timer", test_unimplemented},
367 {"ANS-15a to d 5.2.5 5 Bit Mode (Baudot) Detection Tests", test_unimplemented},
368 {"ANS-16 5.2.6 DTMF Signal Detection", test_unimplemented},
369 {"ANS-17 5.2.7 Bell 103 (1270Hz signal) detection", test_unimplemented},
370 {"ANS-18 5.2.8 Bell 103 (2225Hz signal) detection", test_unimplemented},
371 {"ANS-19 5.2.9 V.21 Reverse Mode (1650Hz) Detection", test_unimplemented},
372 {"ANS-20a to d 5.2.10 1300Hz Calling Tone Discrimination", test_unimplemented},
373 {"ANS-21 5.2.11 V.23 Reverse Mode (1300Hz) Detection", test_unimplemented},
374 {"ANS-22 1300Hz with XCI Test", test_unimplemented},
375 {"ANS-23 5.2.12 Stimulate Mode Country Settings", test_unimplemented},
376 {"ANS-24 5.2.12.1 Stimulate Carrierless Mode Probe Message", test_unimplemented},
377 {"ANS-25 5.2.12.1.1 Interrupted Carrierless Mode Probe", test_unimplemented},
378 {"ANS-26 5.2.12.2 Stimulate Carrier Mode Probe Time", test_unimplemented},
379 {"ANS-27 5.2.12.2.1 V.23 Mode (390Hz) Detection", test_unimplemented},
380 {"ANS-28 5.2.12.2.2 Interrupted Carrier Mode Probe", test_unimplemented},
381 {"ANS-29 5.2.12.2.2 Stimulate Mode Response During Probe", test_unimplemented},
382 {"ANS-30 Immunity to Network Tones", test_unimplemented},
383 {"ANS-31 Immunity to Fax Calling Tones", test_unimplemented},
384 {"ANS-32 Immunity to Voice", test_unimplemented},
385 {"ANS-33 5.2.2.1 V.8 CM detection and V.8 Answering", test_unimplemented},
386
387 {"III.3.2.4 Automode monitor tests", NULL},
388 {"MON-01 to -20 5.3 Repeat all answer mode tests excluding tests ANS-01, ANS-20 and ANS-23 to ANS-29", test_unimplemented},
389 {"MON-21 5.3 Automode Monitor Ta timer", test_unimplemented},
390 {"MON-22a to d 5.3 Automode Monitor 1300Hz Calling Tone Discrimination", test_unimplemented},
391 {"MON-23a to d 5.3 Automode Monitor 980Hz Calling Tone Discrimination", test_unimplemented},
392
393 {"III.3.2.5 ITU-T V.18 annexes tests", NULL},
394 {"X-01 A.1 Baudot carrier timing and receiver disabling", test_x_01},
395 {"X-02 A.2 Baudot bit rate confirmation", test_x_02},
396 {"X-03 A.3 Baudot probe bit rate confirmation", test_x_03},
397 {"X-04 A.4 5 Bit to T.50 Character Conversion", test_x_04},
398 {"X-05 B.1 DTMF receiver disabling", test_unimplemented},
399 {"X-06 B.2 DTMF character conversion", test_x_06},
400 {"X-07 C.1 EDT carrier timing and receiver disabling", test_unimplemented},
401 {"X-08 C.2-3 EDT bit rate and character structure", test_unimplemented},
402 {"X-09 E V.23 calling mode character format", test_unimplemented},
403 {"X-10 E V.23 answer mode character format", test_unimplemented},
404 {"X-11 F.4-5 V.21 character structure", test_unimplemented},
405 {"X-12 G.1-3 V.18 mode", test_unimplemented},
406
407 {"", NULL}
408 };
409
410 int main(int argc, char *argv[])
411 {
412 int i;
413 int res;
414 int hit;
415 const char *match;
416 int test_standard;
417 int opt;
418
419 match = NULL;
420 test_standard = -1;
421 while ((opt = getopt(argc, argv, "d:ls:")) != -1)
422 {
423 switch (opt)
424 {
425 case 'd':
426 decode_test_file = optarg;
427 break;
428 case 'l':
429 log_audio = TRUE;
430 break;
431 case 's':
432 test_standard = atoi(optarg);
433 break;
434 default:
435 //usage();
436 exit(2);
437 break;
438 }
439 }
440 if (decode_test_file)
441 {
442 decode_test_data_file(test_standard, decode_test_file);
443 exit(0);
444 }
445 argc -= optind;
446 argv += optind;
447 if (argc > 0)
448 match = argv[0];
449
450 outhandle = NULL;
451 if (log_audio)
452 {
453 if ((outhandle = sf_open_telephony_write(OUTPUT_FILE_NAME, 1)) == NULL)
454 {
455 fprintf(stderr, " Cannot create audio file '%s'\n", OUTPUT_FILE_NAME);
456 exit(2);
457 }
458 }
459
460 hit = FALSE;
461 for (i = 0; test_list[i].title[0]; i++)
462 {
463 if (test_list[i].func
464 &&
465 (match == NULL
466 ||
467 (strncmp(match, test_list[i].title, strlen(match)) == 0
468 &&
469 test_list[i].title[strlen(match)] == ' ')))
470 {
471 hit = TRUE;
472 printf("%s\n", test_list[i].title);
473 res = test_list[i].func();
474 if (res < 0)
475 {
476 printf(" Test failed\n");
477 exit(2);
478 }
479 if (res == 0)
480 {
481 printf(" Test passed\n");
482 }
483 }
484 else
485 {
486 if (match == NULL)
487 printf("%s\n", test_list[i].title);
488 }
489 }
490 if (!hit)
491 {
492 printf("Test not found\n");
493 exit(2);
494 }
495 basic_tests(V18_MODE_5BIT_45);
496 if (log_audio)
497 {
498 if (sf_close(outhandle) != 0)
499 {
500 fprintf(stderr, " Cannot close audio file '%s'\n", OUTPUT_FILE_NAME);
501 exit(2);
502 }
503 }
504 printf("Tests passed\n");
505 return 0;
506
507 return 0;
508 }
509 /*- End of function --------------------------------------------------------*/
510 /*- End of file ------------------------------------------------------------*/

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