t38_non_ecm_buffer_tests.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. /*
  2. * SpanDSP - a series of DSP components for telephony
  3. *
  4. * t38_non_ecm_buffer_tests.c - Tests for the T.38 non-ECM image data buffer module.
  5. *
  6. * Written by Steve Underwood <steveu@coppice.org>
  7. *
  8. * Copyright (C) 2008 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. /*! \file */
  26. /*! \page t38_non_ecm_buffer_tests_page T.38 non-ECM buffer tests
  27. \section t38_non_ecm_buffer_tests_page_sec_1 What does it do?
  28. These tests exercise the flow controlling non-ECM image data buffer
  29. module, used for T.38 gateways.
  30. */
  31. #if defined(HAVE_CONFIG_H)
  32. #include "config.h"
  33. #endif
  34. #include <stdlib.h>
  35. #include <stdio.h>
  36. #include <fcntl.h>
  37. #include <string.h>
  38. #include <assert.h>
  39. #include <errno.h>
  40. #define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
  41. #include "spandsp.h"
  42. /* A pattern of widening gaps between ones, until at 11 apart an
  43. EOL should be registered */
  44. static const uint8_t spreader[] =
  45. {
  46. 0x55,
  47. 0x55,
  48. 0x55,
  49. 0x55,
  50. 0x55,
  51. 0x55,
  52. 0x55,
  53. 0x55, /* 1 apart */
  54. 0x22, /* 2 and 3 apart */
  55. 0x10, /* 4 apart */
  56. 0x40, /* 5 apart */
  57. 0x80, /* 6 apart */
  58. 0x80, /* 7 apart */
  59. 0x40, /* 8 apart */
  60. 0x10, /* 9 apart */
  61. 0x02, /* 10 apart */
  62. 0x00,
  63. 0x25 /* 11 apart */
  64. };
  65. static int bit_no;
  66. static int xxx(t38_non_ecm_buffer_state_t *s, logging_state_t *l, int log_bits, int n, int expected)
  67. {
  68. int i;
  69. int j;
  70. int bit;
  71. t38_non_ecm_buffer_inject(s, &spreader[n], 1);
  72. if (expected >= 0)
  73. {
  74. for (i = 0; i < 128; i++)
  75. {
  76. bit = t38_non_ecm_buffer_get_bit((void *) s);
  77. if (log_bits)
  78. printf("Rx bit %d - %d\n", bit_no, bit);
  79. if (bit != expected)
  80. {
  81. printf("Tests failed - %d %d %d\n", bit_no, bit, expected);
  82. exit(2);
  83. }
  84. bit_no++;
  85. }
  86. }
  87. else
  88. {
  89. j = -1;
  90. for (i = 0; i < 256; i++)
  91. {
  92. bit = t38_non_ecm_buffer_get_bit((void *) s);
  93. if (log_bits)
  94. printf("Rx bit %d - %d\n", bit_no, bit);
  95. if (j < 0)
  96. {
  97. if (bit == 1)
  98. j = 18*8 - 5;
  99. }
  100. else
  101. {
  102. expected = (spreader[j >> 3] >> (7 - (j & 7))) & 1;
  103. if (bit != expected)
  104. {
  105. printf("Tests failed - %d %d %d\n", bit_no, bit, expected);
  106. exit(2);
  107. }
  108. j++;
  109. if (j >= 18*8)
  110. j = 0;
  111. }
  112. bit_no++;
  113. if (j == 17*8)
  114. return 0;
  115. }
  116. }
  117. return 0;
  118. }
  119. /*- End of function --------------------------------------------------------*/
  120. int main(int argc, char *argv[])
  121. {
  122. t38_non_ecm_buffer_state_t buffer;
  123. logging_state_t logging;
  124. uint8_t buf[1024];
  125. int bit;
  126. int n;
  127. int log_bits;
  128. int i;
  129. log_bits = (argc > 1);
  130. printf("T.38 non-ECM rate adapting buffer tests.\n");
  131. span_log_init(&logging, SPAN_LOG_FLOW, NULL);
  132. span_log_set_protocol(&logging, "Buffer");
  133. printf("1 - Impose no minimum for the bits per row\n");
  134. t38_non_ecm_buffer_init(&buffer, true, 0);
  135. n = 0;
  136. bit_no = 0;
  137. /* We should get ones until the buffers recognises an EOL */
  138. printf(" We should get ones here\n");
  139. for (i = 0; i < 17; i++)
  140. xxx(&buffer, &logging, log_bits, i, 1);
  141. printf(" We should change to zeros here\n");
  142. xxx(&buffer, &logging, log_bits, i, 0);
  143. for (i = 0; i < 17; i++)
  144. xxx(&buffer, &logging, log_bits, i, 0);
  145. printf(" We should get the first row here\n");
  146. xxx(&buffer, &logging, log_bits, i, -1);
  147. for (i = 0; i < 17; i++)
  148. xxx(&buffer, &logging, log_bits, i, 0);
  149. printf(" We should get the second row here\n");
  150. xxx(&buffer, &logging, log_bits, i, -1);
  151. for (i = 0; i < 17; i++)
  152. xxx(&buffer, &logging, log_bits, i, 0);
  153. printf(" We should get the third row here\n");
  154. xxx(&buffer, &logging, log_bits, i, -1);
  155. printf(" Done\n");
  156. t38_non_ecm_buffer_report_input_status(&buffer, &logging);
  157. t38_non_ecm_buffer_report_output_status(&buffer, &logging);
  158. t38_non_ecm_buffer_release(&buffer);
  159. printf("2 - Impose no minimum for the bits per row, different alignment\n");
  160. t38_non_ecm_buffer_init(&buffer, true, 0);
  161. n = 0;
  162. memset(buf, 0, sizeof(buf));
  163. /* The first one in this should be seen as the first EOL */
  164. memset(buf + 10, 0x55, 10);
  165. /* EOL 2 */
  166. buf[25] = 0x20;
  167. /* EOL 3 */
  168. memset(buf + 30, 0x55, 10);
  169. /* EOL 4 */
  170. buf[45] = 0x10;
  171. t38_non_ecm_buffer_inject(&buffer, buf, 50);
  172. t38_non_ecm_buffer_push(&buffer);
  173. for (;;)
  174. {
  175. bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
  176. if (log_bits)
  177. printf("Rx bit %d - %d\n", n, bit);
  178. n++;
  179. if (bit == SIG_STATUS_END_OF_DATA)
  180. {
  181. if (n != 337)
  182. {
  183. printf("Tests failed\n");
  184. exit(2);
  185. }
  186. break;
  187. }
  188. if (n >= 18 && n <= 96)
  189. {
  190. if (bit == (n & 1))
  191. {
  192. printf("Tests failed\n");
  193. exit(2);
  194. }
  195. }
  196. else if (n >= 178 && n <= 256)
  197. {
  198. if (bit == (n & 1))
  199. {
  200. printf("Tests failed\n");
  201. exit(2);
  202. }
  203. }
  204. else if (n == 139 || n == 300)
  205. {
  206. if (bit != 1)
  207. {
  208. printf("Tests failed\n");
  209. exit(2);
  210. }
  211. }
  212. else
  213. {
  214. if (bit != 0)
  215. {
  216. printf("Tests failed\n");
  217. exit(2);
  218. }
  219. }
  220. }
  221. t38_non_ecm_buffer_report_input_status(&buffer, &logging);
  222. t38_non_ecm_buffer_report_output_status(&buffer, &logging);
  223. t38_non_ecm_buffer_release(&buffer);
  224. printf("3 - Demand a fairly high minimum for the bits per row\n");
  225. t38_non_ecm_buffer_init(&buffer, true, 400);
  226. n = 0;
  227. memset(buf, 0, sizeof(buf));
  228. /* The first one in this should be seen as the first EOL */
  229. memset(buf + 10, 0x55, 10);
  230. /* EOL 2 */
  231. buf[25] = 0x08;
  232. /* EOL 3 */
  233. memset(buf + 30, 0x55, 10);
  234. /* EOL 4 */
  235. buf[45] = 0x04;
  236. t38_non_ecm_buffer_inject(&buffer, buf, 50);
  237. t38_non_ecm_buffer_push(&buffer);
  238. for (;;)
  239. {
  240. bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
  241. if (log_bits)
  242. printf("Rx bit %d - %d\n", n, bit);
  243. n++;
  244. if (bit == SIG_STATUS_END_OF_DATA)
  245. {
  246. if (n != 1273)
  247. {
  248. printf("Tests failed\n");
  249. exit(2);
  250. }
  251. break;
  252. }
  253. if (n >= 18 && n <= 96)
  254. {
  255. if (bit == (n & 1))
  256. {
  257. printf("Tests failed\n");
  258. exit(2);
  259. }
  260. }
  261. else if (n >= 834 && n <= 912)
  262. {
  263. if (bit == (n & 1))
  264. {
  265. printf("Tests failed\n");
  266. exit(2);
  267. }
  268. }
  269. else if (n == 429 || n == 1238)
  270. {
  271. if (bit != 1)
  272. {
  273. printf("Tests failed\n");
  274. exit(2);
  275. }
  276. }
  277. else
  278. {
  279. if (bit != 0)
  280. {
  281. printf("Tests failed\n");
  282. exit(2);
  283. }
  284. }
  285. }
  286. t38_non_ecm_buffer_report_input_status(&buffer, &logging);
  287. t38_non_ecm_buffer_report_output_status(&buffer, &logging);
  288. t38_non_ecm_buffer_release(&buffer);
  289. printf("4 - Take some time to get to the first row of the image, output ahead\n");
  290. t38_non_ecm_buffer_init(&buffer, true, 400);
  291. n = 0;
  292. /* Get some initial bits from an empty buffer. These should be ones */
  293. for (i = 0; i < 1000; i++)
  294. {
  295. bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
  296. if (log_bits)
  297. printf("Rx bit %d - %d\n", n++, bit);
  298. if (bit != 1)
  299. {
  300. printf("Tests failed\n");
  301. exit(2);
  302. }
  303. }
  304. printf(" Initial ones OK\n");
  305. /* Now put some zeros into the buffer, but no EOL. We should continue
  306. getting ones out. */
  307. memset(buf, 0, sizeof(buf));
  308. t38_non_ecm_buffer_inject(&buffer, buf, 20);
  309. for (i = 0; i < 1000; i++)
  310. {
  311. bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
  312. if (log_bits)
  313. printf("Rx bit %d - %d\n", n++, bit);
  314. if (bit != 1)
  315. {
  316. printf("Tests failed\n");
  317. exit(2);
  318. }
  319. }
  320. printf(" Continuing initial ones OK\n");
  321. /* Now add a one, to make an EOL. We should see the zeros come out. */
  322. buf[0] = 0x01;
  323. t38_non_ecm_buffer_inject(&buffer, buf, 1);
  324. for (i = 0; i < 1000; i++)
  325. {
  326. bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
  327. if (log_bits)
  328. printf("Rx bit %d - %d\n", n++, bit);
  329. if (bit != 0)
  330. {
  331. printf("Tests failed\n");
  332. exit(2);
  333. }
  334. }
  335. printf(" First EOL caused zeros to output OK\n");
  336. /* Now add another line. We should see the first line come out. This means just the
  337. 23rd bit from now will be a one. */
  338. buf[0] = 0x00;
  339. buf[4] = 0x01;
  340. t38_non_ecm_buffer_inject(&buffer, buf, 5);
  341. for (i = 0; i < 1000; i++)
  342. {
  343. bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
  344. if (log_bits)
  345. printf("Rx bit %d - %d\n", n++, bit);
  346. if ((i == 23 && bit == 0) || (i != 23 && bit != 0))
  347. {
  348. printf("Tests failed (%d)\n", i);
  349. exit(2);
  350. }
  351. }
  352. printf(" Second EOL caused the first row to output OK\n");
  353. /* Now inject an RTC - 6 EOLs */
  354. memset(buf, 0, sizeof(buf));
  355. /* T.4 1D style */
  356. for (i = 10; i < 19; i += 3)
  357. {
  358. buf[i] = 0x00;
  359. buf[i + 1] = 0x10;
  360. buf[i + 2] = 0x01;
  361. }
  362. /* T.4 2D style */
  363. buf[25 + 0] = 0x00;
  364. buf[25 + 1] = 0x18;
  365. buf[25 + 2] = 0x00;
  366. buf[25 + 3] = 0xC0;
  367. buf[25 + 4] = 0x06;
  368. buf[25 + 5] = 0x00;
  369. buf[25 + 6] = 0x30;
  370. buf[25 + 7] = 0x01;
  371. buf[25 + 8] = 0x80;
  372. buf[25 + 9] = 0x0C;
  373. t38_non_ecm_buffer_inject(&buffer, buf, 50);
  374. t38_non_ecm_buffer_push(&buffer);
  375. for (i = 0; i < 1000; i++)
  376. {
  377. bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
  378. if (log_bits)
  379. printf("Rx bit %d - %d\n", n++, bit);
  380. if (i == 7
  381. ||
  382. i == 400 + 11 + 0*12
  383. ||
  384. i == 400 + 11 + 1*12
  385. ||
  386. i == 400 + 11 + 2*12
  387. ||
  388. i == 400 + 11 + 3*12
  389. ||
  390. i == 400 + 11 + 4*12
  391. ||
  392. i == 400 + 11 + 5*12
  393. ||
  394. i == 400 + 11 + 60 + 400 + 4 + 0*13
  395. ||
  396. i == 400 + 11 + 60 + 400 + 4 + 0*13 + 1
  397. ||
  398. i == 400 + 11 + 60 + 400 + 4 + 1*13
  399. ||
  400. i == 400 + 11 + 60 + 400 + 4 + 1*13 + 1
  401. ||
  402. i == 400 + 11 + 60 + 400 + 4 + 2*13
  403. ||
  404. i == 400 + 11 + 60 + 400 + 4 + 2*13 + 1
  405. ||
  406. i == 400 + 11 + 60 + 400 + 4 + 3*13
  407. ||
  408. i == 400 + 11 + 60 + 400 + 4 + 3*13 + 1
  409. ||
  410. i == 400 + 11 + 60 + 400 + 4 + 4*13
  411. ||
  412. i == 400 + 11 + 60 + 400 + 4 + 4*13 + 1
  413. ||
  414. i == 400 + 11 + 60 + 400 + 4 + 5*13
  415. ||
  416. i == 400 + 11 + 60 + 400 + 4 + 5*13 + 1)
  417. {
  418. if (bit == 0)
  419. {
  420. printf("Tests failed (%d)\n", i);
  421. exit(2);
  422. }
  423. }
  424. else
  425. {
  426. if (bit == 1)
  427. {
  428. printf("Tests failed (%d)\n", i);
  429. exit(2);
  430. }
  431. }
  432. }
  433. printf(" RTC output OK\n");
  434. t38_non_ecm_buffer_report_input_status(&buffer, &logging);
  435. t38_non_ecm_buffer_report_output_status(&buffer, &logging);
  436. t38_non_ecm_buffer_release(&buffer);
  437. printf("5 - Take some time to get to the first row of the image, output behind\n");
  438. t38_non_ecm_buffer_init(&buffer, true, 400);
  439. n = 0;
  440. /* Inject some ones. */
  441. memset(buf, 0xFF, 100);
  442. t38_non_ecm_buffer_inject(&buffer, buf, 100);
  443. /* Inject some zeros */
  444. memset(buf, 0, sizeof(buf));
  445. t38_non_ecm_buffer_inject(&buffer, buf, 100);
  446. for (i = 0; i < 1000; i++)
  447. {
  448. bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
  449. if (log_bits)
  450. printf("Rx bit %d - %d\n", n++, bit);
  451. if (bit != 1)
  452. {
  453. printf("Tests failed\n");
  454. exit(2);
  455. }
  456. }
  457. printf(" Initial ones OK\n");
  458. /* Now add a one, to make an EOL. We should see the zeros come out. */
  459. buf[0] = 0x01;
  460. t38_non_ecm_buffer_inject(&buffer, buf, 1);
  461. for (i = 0; i < 1000; i++)
  462. {
  463. bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
  464. if (log_bits)
  465. printf("Rx bit %d - %d\n", n++, bit);
  466. if (bit != 0)
  467. {
  468. printf("Tests failed\n");
  469. exit(2);
  470. }
  471. }
  472. printf(" First EOL caused zeros to output OK\n");
  473. /* Now add another line. We should see the first line come out. This means just the
  474. 23rd bit from now will be a one. */
  475. buf[0] = 0x00;
  476. buf[4] = 0x01;
  477. t38_non_ecm_buffer_inject(&buffer, buf, 5);
  478. for (i = 0; i < 1000; i++)
  479. {
  480. bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
  481. if (log_bits)
  482. printf("Rx bit %d - %d\n", n++, bit);
  483. if ((i == 23 && bit == 0) || (i != 23 && bit != 0))
  484. {
  485. printf("Tests failed (%d)\n", i);
  486. exit(2);
  487. }
  488. }
  489. printf(" Second EOL caused the first row to output OK\n");
  490. /* Now inject an RTC - 6 EOLs */
  491. memset(buf, 0, sizeof(buf));
  492. /* T.4 1D style */
  493. for (i = 10; i < 19; i += 3)
  494. {
  495. buf[i] = 0x00;
  496. buf[i + 1] = 0x10;
  497. buf[i + 2] = 0x01;
  498. }
  499. /* T.4 2D style */
  500. buf[25 + 0] = 0x00;
  501. buf[25 + 1] = 0x18;
  502. buf[25 + 2] = 0x00;
  503. buf[25 + 3] = 0xC0;
  504. buf[25 + 4] = 0x06;
  505. buf[25 + 5] = 0x00;
  506. buf[25 + 6] = 0x30;
  507. buf[25 + 7] = 0x01;
  508. buf[25 + 8] = 0x80;
  509. buf[25 + 9] = 0x0C;
  510. t38_non_ecm_buffer_inject(&buffer, buf, 50);
  511. t38_non_ecm_buffer_push(&buffer);
  512. for (i = 0; i < 1000; i++)
  513. {
  514. bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
  515. if (log_bits)
  516. printf("Rx bit %d - %d\n", n++, bit);
  517. if (i == 7
  518. ||
  519. i == 400 + 11 + 0*12
  520. ||
  521. i == 400 + 11 + 1*12
  522. ||
  523. i == 400 + 11 + 2*12
  524. ||
  525. i == 400 + 11 + 3*12
  526. ||
  527. i == 400 + 11 + 4*12
  528. ||
  529. i == 400 + 11 + 5*12
  530. ||
  531. i == 400 + 11 + 60 + 400 + 4 + 0*13
  532. ||
  533. i == 400 + 11 + 60 + 400 + 4 + 0*13 + 1
  534. ||
  535. i == 400 + 11 + 60 + 400 + 4 + 1*13
  536. ||
  537. i == 400 + 11 + 60 + 400 + 4 + 1*13 + 1
  538. ||
  539. i == 400 + 11 + 60 + 400 + 4 + 2*13
  540. ||
  541. i == 400 + 11 + 60 + 400 + 4 + 2*13 + 1
  542. ||
  543. i == 400 + 11 + 60 + 400 + 4 + 3*13
  544. ||
  545. i == 400 + 11 + 60 + 400 + 4 + 3*13 + 1
  546. ||
  547. i == 400 + 11 + 60 + 400 + 4 + 4*13
  548. ||
  549. i == 400 + 11 + 60 + 400 + 4 + 4*13 + 1
  550. ||
  551. i == 400 + 11 + 60 + 400 + 4 + 5*13
  552. ||
  553. i == 400 + 11 + 60 + 400 + 4 + 5*13 + 1)
  554. {
  555. if (bit == 0)
  556. {
  557. printf("Tests failed (%d)\n", i);
  558. exit(2);
  559. }
  560. }
  561. else
  562. {
  563. if (bit == 1)
  564. {
  565. printf("Tests failed (%d)\n", i);
  566. exit(2);
  567. }
  568. }
  569. }
  570. printf(" RTC output OK\n");
  571. t38_non_ecm_buffer_report_input_status(&buffer, &logging);
  572. t38_non_ecm_buffer_report_output_status(&buffer, &logging);
  573. t38_non_ecm_buffer_release(&buffer);
  574. printf("6 - TCF without leading ones\n");
  575. t38_non_ecm_buffer_init(&buffer, false, 400);
  576. n = 0;
  577. /* Get some initial bits from an empty buffer. These should be ones */
  578. for (i = 0; i < 1000; i++)
  579. {
  580. bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
  581. if (log_bits)
  582. printf("Rx bit %d - %d\n", n++, bit);
  583. if (bit != 1)
  584. {
  585. printf("Tests failed\n");
  586. exit(2);
  587. }
  588. }
  589. printf(" Initial ones from an empty TCF buffer OK\n");
  590. /* Now send some TCF through, and see that it comes out */
  591. memset(buf, 0x00, sizeof(buf));
  592. t38_non_ecm_buffer_inject(&buffer, buf, 500);
  593. t38_non_ecm_buffer_push(&buffer);
  594. for (i = 0; i < 500*8; i++)
  595. {
  596. bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
  597. if (log_bits)
  598. printf("Rx bit %d - %d\n", n++, bit);
  599. if (bit != 0)
  600. {
  601. printf("Tests failed\n");
  602. exit(2);
  603. }
  604. }
  605. printf(" Passthrough of TCF OK\n");
  606. /* Check the right number of bits was buffered */
  607. bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
  608. if (log_bits)
  609. printf("Rx bit %d - %d\n", n++, bit);
  610. if (bit != SIG_STATUS_END_OF_DATA)
  611. {
  612. printf("Tests failed\n");
  613. exit(2);
  614. }
  615. printf(" End of data seen OK\n");
  616. t38_non_ecm_buffer_report_input_status(&buffer, &logging);
  617. t38_non_ecm_buffer_report_output_status(&buffer, &logging);
  618. t38_non_ecm_buffer_release(&buffer);
  619. printf("7 - TCF with leading ones\n");
  620. t38_non_ecm_buffer_init(&buffer, false, 400);
  621. n = 0;
  622. /* Get some initial bits from an empty buffer. These should be ones */
  623. for (i = 0; i < 1000; i++)
  624. {
  625. bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
  626. if (log_bits)
  627. printf("Rx bit %d - %d\n", n++, bit);
  628. if (bit != 1)
  629. {
  630. printf("Tests failed\n");
  631. exit(2);
  632. }
  633. }
  634. printf(" Initial ones from an empty TCF buffer OK\n");
  635. /* Now send some initial ones, and see that we continue to get all ones
  636. as the stuffing. */
  637. memset(buf, 0xFF, 500);
  638. t38_non_ecm_buffer_inject(&buffer, buf, 500);
  639. for (i = 0; i < 500*8; i++)
  640. {
  641. bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
  642. if (log_bits)
  643. printf("Rx bit %d - %d\n", n++, bit);
  644. if (bit != 1)
  645. {
  646. printf("Tests failed\n");
  647. exit(2);
  648. }
  649. }
  650. printf(" Sustaining ones OK\n");
  651. /* Now send some initial ones, and some TCF through, and see that only
  652. the TCF comes out */
  653. memset(buf, 0x00, sizeof(buf));
  654. memset(buf, 0xFF, 100);
  655. /* End the ones mid byte */
  656. buf[100] = 0xF0;
  657. t38_non_ecm_buffer_inject(&buffer, buf, 500);
  658. t38_non_ecm_buffer_push(&buffer);
  659. for (i = 0; i < 400*8; i++)
  660. {
  661. bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
  662. if (log_bits)
  663. printf("Rx bit %d - %d\n", n++, bit);
  664. if ((i < 4 && bit == 0) || (i >= 4 && bit != 0))
  665. {
  666. printf("Tests failed\n");
  667. exit(2);
  668. }
  669. }
  670. printf(" Passthrough of TCF OK\n");
  671. /* Check the right number of bits was buffered */
  672. bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
  673. if (log_bits)
  674. printf("Rx bit %d - %d\n", n++, bit);
  675. if (bit != SIG_STATUS_END_OF_DATA)
  676. {
  677. printf("Tests failed\n");
  678. exit(2);
  679. }
  680. printf(" End of data seen OK\n");
  681. t38_non_ecm_buffer_report_input_status(&buffer, &logging);
  682. t38_non_ecm_buffer_report_output_status(&buffer, &logging);
  683. t38_non_ecm_buffer_release(&buffer);
  684. printf("Tests passed\n");
  685. return 0;
  686. }
  687. /*- End of function --------------------------------------------------------*/
  688. /*- End of file ------------------------------------------------------------*/