2
0

queue_tests.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  1. /*
  2. * SpanDSP - a series of DSP components for telephony
  3. *
  4. * queue_tests.c
  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. /*! \page queue_tests_page Queue tests
  26. \section queue_tests_page_sec_1 What does it do?
  27. */
  28. #if defined(HAVE_CONFIG_H)
  29. #include "config.h"
  30. #endif
  31. #include <stdlib.h>
  32. #include <stdio.h>
  33. #include <unistd.h>
  34. #include <string.h>
  35. #include <assert.h>
  36. #include <pthread.h>
  37. #include <sched.h>
  38. #define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
  39. #include "spandsp.h"
  40. #define BUF_LEN 10000
  41. #define MSG_LEN 17
  42. pthread_t thread[2];
  43. queue_state_t *queue;
  44. volatile int put_oks;
  45. volatile int put_misses;
  46. volatile int got_oks;
  47. volatile int got_misses;
  48. int total_in;
  49. int total_out;
  50. static void tests_failed(void)
  51. {
  52. printf("Tests failed\n");
  53. exit(2);
  54. }
  55. /*- End of function --------------------------------------------------------*/
  56. static void display_queue_pointers(void)
  57. {
  58. printf("Pointers %d %d %d\n", queue->iptr, queue->optr, queue->len);
  59. }
  60. /*- End of function --------------------------------------------------------*/
  61. static void *run_stream_write(void *arg)
  62. {
  63. uint8_t buf[MSG_LEN];
  64. int i;
  65. int next;
  66. printf("Write thread\n");
  67. next = 0;
  68. for (i = 0; i < MSG_LEN; i++)
  69. buf[i] = next;
  70. next = (next + 1) & 0xFF;
  71. put_oks = 0;
  72. put_misses = 0;
  73. for (;;)
  74. {
  75. if (queue_write(queue, buf, MSG_LEN) == MSG_LEN)
  76. {
  77. for (i = 0; i < MSG_LEN; i++)
  78. buf[i] = next;
  79. next = (next + 1) & 0xFF;
  80. put_oks++;
  81. if (put_oks%1000000 == 0)
  82. printf("%d puts, %d misses\n", put_oks, put_misses);
  83. }
  84. else
  85. {
  86. sched_yield();
  87. put_misses++;
  88. }
  89. }
  90. return NULL;
  91. }
  92. /*- End of function --------------------------------------------------------*/
  93. static void *run_stream_read(void *arg)
  94. {
  95. uint8_t buf[MSG_LEN];
  96. int i;
  97. int len;
  98. int next;
  99. printf("Read thread\n");
  100. next = 0;
  101. got_oks = 0;
  102. got_misses = 0;
  103. for (;;)
  104. {
  105. if ((len = queue_read(queue, buf, MSG_LEN)) >= 0)
  106. {
  107. if (len != MSG_LEN)
  108. {
  109. printf("AHH! - len %d\n", len);
  110. tests_failed();
  111. }
  112. for (i = 0; i < len; i++)
  113. {
  114. if (buf[i] != next)
  115. {
  116. printf("AHH! - 0x%X 0x%X\n", buf[i], next);
  117. tests_failed();
  118. }
  119. }
  120. next = (next + 1) & 0xFF;
  121. got_oks++;
  122. if (got_oks%1000000 == 0)
  123. printf("%d gots, %d misses\n", got_oks, got_misses);
  124. }
  125. else
  126. {
  127. sched_yield();
  128. got_misses++;
  129. }
  130. }
  131. return NULL;
  132. }
  133. /*- End of function --------------------------------------------------------*/
  134. static void threaded_stream_tests(void)
  135. {
  136. pthread_attr_t attr;
  137. if ((queue = queue_init(NULL, BUF_LEN, QUEUE_READ_ATOMIC | QUEUE_WRITE_ATOMIC)) == NULL)
  138. {
  139. printf("Failed to create the queue\n");
  140. tests_failed();
  141. }
  142. pthread_attr_init(&attr);
  143. pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
  144. if (pthread_create(&thread[0], &attr, run_stream_write, NULL))
  145. {
  146. printf("Failed to create thread\n");
  147. tests_failed();
  148. }
  149. if (pthread_create(&thread[1], &attr, run_stream_read, NULL))
  150. {
  151. printf("Failed to create thread\n");
  152. tests_failed();
  153. }
  154. for (;;)
  155. {
  156. sleep(5);
  157. printf("Main thread - %d %d\n", put_oks, got_oks);
  158. }
  159. queue_free(queue);
  160. }
  161. /*- End of function --------------------------------------------------------*/
  162. static void *run_message_write(void *arg)
  163. {
  164. uint8_t buf[MSG_LEN];
  165. int i;
  166. int next;
  167. printf("Write thread\n");
  168. next = 0;
  169. for (i = 0; i < MSG_LEN; i++)
  170. buf[i] = next;
  171. next = (next + 1) & 0xFF;
  172. put_oks = 0;
  173. put_misses = 0;
  174. for (;;)
  175. {
  176. if (queue_write_msg(queue, buf, MSG_LEN) == MSG_LEN)
  177. {
  178. for (i = 0; i < MSG_LEN; i++)
  179. buf[i] = next;
  180. next = (next + 1) & 0xFF;
  181. put_oks++;
  182. if (put_oks%1000000 == 0)
  183. printf("%d puts, %d misses\n", put_oks, put_misses);
  184. }
  185. else
  186. {
  187. sched_yield();
  188. put_misses++;
  189. }
  190. }
  191. return NULL;
  192. }
  193. /*- End of function --------------------------------------------------------*/
  194. static void *run_message_read(void *arg)
  195. {
  196. uint8_t buf[1024];
  197. int i;
  198. int len;
  199. int next;
  200. printf("Read thread\n");
  201. next = 0;
  202. got_oks = 0;
  203. got_misses = 0;
  204. for (;;)
  205. {
  206. if ((len = queue_read_msg(queue, buf, 1024)) >= 0)
  207. {
  208. if (len != MSG_LEN)
  209. {
  210. printf("AHH! - len %d\n", len);
  211. tests_failed();
  212. }
  213. for (i = 0; i < len; i++)
  214. {
  215. if (buf[i] != next)
  216. {
  217. printf("AHH! - 0x%X 0x%X\n", buf[i], next);
  218. tests_failed();
  219. }
  220. }
  221. next = (next + 1) & 0xFF;
  222. got_oks++;
  223. if (got_oks%1000000 == 0)
  224. printf("%d gots, %d misses\n", got_oks, got_misses);
  225. }
  226. else
  227. {
  228. sched_yield();
  229. got_misses++;
  230. }
  231. }
  232. return NULL;
  233. }
  234. /*- End of function --------------------------------------------------------*/
  235. static void threaded_message_tests(void)
  236. {
  237. pthread_attr_t attr;
  238. if ((queue = queue_init(NULL, BUF_LEN, QUEUE_READ_ATOMIC | QUEUE_WRITE_ATOMIC)) == NULL)
  239. {
  240. printf("Failed to create the queue\n");
  241. tests_failed();
  242. }
  243. pthread_attr_init(&attr);
  244. pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
  245. if (pthread_create(&thread[0], &attr, run_message_write, NULL))
  246. {
  247. printf("Failed to create thread\n");
  248. tests_failed();
  249. }
  250. if (pthread_create(&thread[1], &attr, run_message_read, NULL))
  251. {
  252. printf("Failed to create thread\n");
  253. tests_failed();
  254. }
  255. for (;;)
  256. {
  257. sleep(5);
  258. printf("Main thread - %d %d\n", put_oks, got_oks);
  259. }
  260. queue_free(queue);
  261. }
  262. /*- End of function --------------------------------------------------------*/
  263. static void check_contents(int total_in, int total_out)
  264. {
  265. if (queue_contents(queue) != (total_in - total_out))
  266. {
  267. printf("Contents = %d (%d)\n", queue_contents(queue), (total_in - total_out));
  268. display_queue_pointers();
  269. tests_failed();
  270. }
  271. if (queue_free_space(queue) != BUF_LEN - (total_in - total_out))
  272. {
  273. printf("Free space = %d (%d)\n", queue_free_space(queue), BUF_LEN - (total_in - total_out));
  274. display_queue_pointers();
  275. tests_failed();
  276. }
  277. }
  278. /*- End of function --------------------------------------------------------*/
  279. static int monitored_queue_write(const uint8_t buf[], int len)
  280. {
  281. int lenx;
  282. lenx = queue_write(queue, buf, len);
  283. if (lenx >= 0)
  284. total_in += lenx;
  285. check_contents(total_in, total_out);
  286. return lenx;
  287. }
  288. /*- End of function --------------------------------------------------------*/
  289. static int monitored_queue_write_byte(const uint8_t buf)
  290. {
  291. int res;
  292. if ((res = queue_write_byte(queue, buf)) >= 0)
  293. total_in++;
  294. check_contents(total_in, total_out);
  295. return res;
  296. }
  297. /*- End of function --------------------------------------------------------*/
  298. static int monitored_queue_read(uint8_t buf[], int len)
  299. {
  300. int lenx;
  301. lenx = queue_read(queue, buf, len);
  302. if (lenx >= 0)
  303. total_out += lenx;
  304. check_contents(total_in, total_out);
  305. return lenx;
  306. }
  307. /*- End of function --------------------------------------------------------*/
  308. static int monitored_queue_read_byte(void)
  309. {
  310. int res;
  311. if ((res = queue_read_byte(queue)) >= 0)
  312. total_out++;
  313. check_contents(total_in, total_out);
  314. return res;
  315. }
  316. /*- End of function --------------------------------------------------------*/
  317. static void functional_stream_tests(void)
  318. {
  319. uint8_t buf[MSG_LEN];
  320. int i;
  321. int res;
  322. total_in = 0;
  323. total_out = 0;
  324. for (i = 0; i < MSG_LEN; i++)
  325. buf[i] = i;
  326. if ((queue = queue_init(NULL, BUF_LEN, QUEUE_READ_ATOMIC | QUEUE_WRITE_ATOMIC)) == NULL)
  327. {
  328. printf("Failed to create the queue\n");
  329. tests_failed();
  330. }
  331. check_contents(total_in, total_out);
  332. /* Half fill the buffer, and check we can get out what we put in. */
  333. for (i = 1; i < 5000; i++)
  334. {
  335. if (monitored_queue_write_byte(i & 0xFF) != 1)
  336. {
  337. printf("Byte by byte full at %d/%d\n", i, BUF_LEN);
  338. tests_failed();
  339. }
  340. }
  341. for (i = 1; i < 5001; i++)
  342. {
  343. if ((res = monitored_queue_read_byte()) != (i & 0xFF))
  344. break;
  345. }
  346. printf("Byte by byte read breaks at %d (expected %d) - %d\n", i, 5000, res);
  347. if (i != 5000)
  348. tests_failed();
  349. /* Now completely fill the buffer, and we should roll around the end. Check we can
  350. get out what we put in. */
  351. for (i = 1; i < 20000; i++)
  352. {
  353. if (monitored_queue_write_byte(i & 0xFF) != 1)
  354. break;
  355. }
  356. printf("Byte by byte full at %d (expected %d)\n", i, 10001);
  357. if (i != 10001)
  358. tests_failed();
  359. for (i = 1; i < 20000; i++)
  360. {
  361. if ((res = monitored_queue_read_byte()) != (i & 0xFF))
  362. break;
  363. }
  364. printf("Byte by byte read breaks at %d (expected %d) - %d\n", i, 10001, res);
  365. if (i != 10001)
  366. tests_failed();
  367. /* Fill the buffer, checking the contents grow correctly */
  368. for (i = 1; i < 1000; i++)
  369. {
  370. if (monitored_queue_write(buf, MSG_LEN) != MSG_LEN)
  371. break;
  372. }
  373. printf("Full at chunk %d (expected %d)\n", i, BUF_LEN/MSG_LEN + 1);
  374. if (i != BUF_LEN/MSG_LEN + 1)
  375. tests_failed();
  376. if (monitored_queue_write(buf, 5) == 5)
  377. {
  378. printf("Write of 5 succeeded\n");
  379. tests_failed();
  380. }
  381. if (monitored_queue_write(buf, 4) != 4)
  382. {
  383. printf("Write of 4 failed\n");
  384. tests_failed();
  385. }
  386. /* Now full. Empty a little, and refill around the end */
  387. if (monitored_queue_read(buf, MSG_LEN) != MSG_LEN)
  388. {
  389. printf("Read failed\n");
  390. tests_failed();
  391. }
  392. if (monitored_queue_write(buf, MSG_LEN) != MSG_LEN)
  393. {
  394. printf("Write failed\n");
  395. tests_failed();
  396. }
  397. /* Empty completely, checking the contents shrink correctly */
  398. for (;;)
  399. {
  400. if (monitored_queue_read(buf, MSG_LEN) != MSG_LEN)
  401. break;
  402. }
  403. if (monitored_queue_read(buf, 4) != 4)
  404. {
  405. printf("Read failed\n");
  406. tests_failed();
  407. }
  408. /* Nudge around the buffer */
  409. for (i = 1; i < 588; i++)
  410. {
  411. if (monitored_queue_write(buf, MSG_LEN) != MSG_LEN)
  412. {
  413. printf("Write failed\n");
  414. tests_failed();
  415. }
  416. if (monitored_queue_read(buf, MSG_LEN) != MSG_LEN)
  417. {
  418. printf("Read failed\n");
  419. tests_failed();
  420. }
  421. }
  422. /* Fill the buffer, checking the contents grow correctly */
  423. for (i = 1; i < 1000; i++)
  424. {
  425. if (monitored_queue_write(buf, MSG_LEN) != MSG_LEN)
  426. break;
  427. }
  428. printf("Full at chunk %d (expected %d)\n", i, BUF_LEN/MSG_LEN + 1);
  429. if (i != BUF_LEN/MSG_LEN + 1)
  430. tests_failed();
  431. display_queue_pointers();
  432. if (monitored_queue_read(buf, MSG_LEN) != MSG_LEN)
  433. {
  434. printf("Read failed\n");
  435. tests_failed();
  436. }
  437. if (monitored_queue_write(buf, MSG_LEN) != MSG_LEN)
  438. {
  439. printf("Write failed\n");
  440. tests_failed();
  441. }
  442. display_queue_pointers();
  443. for (i = 1; i < 5000; i++)
  444. {
  445. if (monitored_queue_read(buf, MSG_LEN) != MSG_LEN)
  446. {
  447. printf("Read failed\n");
  448. tests_failed();
  449. }
  450. if (monitored_queue_write(buf, MSG_LEN) != MSG_LEN)
  451. {
  452. printf("Write failed\n");
  453. tests_failed();
  454. }
  455. }
  456. display_queue_pointers();
  457. if (monitored_queue_write(buf, 5) == 5)
  458. {
  459. printf("Write of 5 succeeded\n");
  460. tests_failed();
  461. }
  462. if (monitored_queue_write(buf, 4) != 4)
  463. {
  464. printf("Write of 4 failed\n");
  465. tests_failed();
  466. }
  467. display_queue_pointers();
  468. for (i = 1; i < 5000; i++)
  469. {
  470. if (monitored_queue_read(buf, MSG_LEN) != MSG_LEN)
  471. {
  472. printf("Read failed\n");
  473. tests_failed();
  474. }
  475. if (monitored_queue_write(buf, MSG_LEN) != MSG_LEN)
  476. {
  477. printf("Write failed\n");
  478. tests_failed();
  479. }
  480. }
  481. display_queue_pointers();
  482. queue_free(queue);
  483. }
  484. /*- End of function --------------------------------------------------------*/
  485. static int monitored_queue_write_msg(const uint8_t buf[], int len)
  486. {
  487. int lenx;
  488. lenx = queue_write_msg(queue, buf, len);
  489. if (lenx >= 0)
  490. total_in += lenx + sizeof(uint16_t);
  491. check_contents(total_in, total_out);
  492. return lenx;
  493. }
  494. /*- End of function --------------------------------------------------------*/
  495. static int monitored_queue_read_msg(uint8_t buf[], int len)
  496. {
  497. int lenx;
  498. lenx = queue_read_msg(queue, buf, len);
  499. if (lenx >= 0)
  500. total_out += lenx + sizeof(uint16_t);
  501. check_contents(total_in, total_out);
  502. return lenx;
  503. }
  504. /*- End of function --------------------------------------------------------*/
  505. static void functional_message_tests(void)
  506. {
  507. uint8_t buf[MSG_LEN];
  508. int i;
  509. int len;
  510. total_in = 0;
  511. total_out = 0;
  512. for (i = 0; i < MSG_LEN; i++)
  513. buf[i] = i;
  514. if ((queue = queue_init(NULL, BUF_LEN, QUEUE_READ_ATOMIC | QUEUE_WRITE_ATOMIC)) == NULL)
  515. {
  516. printf("Failed to create the queue\n");
  517. tests_failed();
  518. }
  519. check_contents(total_in, total_out);
  520. /* Fill the buffer, checking the contents grow correctly */
  521. for (i = 1; i < 1000; i++)
  522. {
  523. if (monitored_queue_write_msg(buf, MSG_LEN) != MSG_LEN)
  524. break;
  525. }
  526. printf("Full at chunk %d (expected %lu)\n", i, (unsigned long int) BUF_LEN/(MSG_LEN + sizeof(uint16_t)) + 1);
  527. if (i != BUF_LEN/(MSG_LEN + sizeof(uint16_t)) + 1)
  528. tests_failed();
  529. if ((len = monitored_queue_write_msg(buf, 5)) == 5)
  530. {
  531. printf("Write of 5 succeeded\n");
  532. tests_failed();
  533. }
  534. if ((len = monitored_queue_write_msg(buf, 4)) != 4)
  535. {
  536. printf("Write of 4 failed\n");
  537. tests_failed();
  538. }
  539. /* Now full. Empty a little, and refill around the end */
  540. if ((len = monitored_queue_read_msg(buf, MSG_LEN)) != MSG_LEN)
  541. {
  542. printf("Read failed - %d\n", len);
  543. tests_failed();
  544. }
  545. if ((len = monitored_queue_write_msg(buf, MSG_LEN)) != MSG_LEN)
  546. {
  547. printf("Write failed - %d\n", len);
  548. tests_failed();
  549. }
  550. /* Empty completely, checking the contents shrink correctly */
  551. for (;;)
  552. {
  553. if ((len = monitored_queue_read_msg(buf, MSG_LEN)) != MSG_LEN)
  554. break;
  555. }
  556. if (len != 4)
  557. {
  558. printf("Read failed - %d\n", len);
  559. tests_failed();
  560. }
  561. /* We should now have one MSG_LEN message in the buffer */
  562. /* Nudge around the buffer */
  563. for (i = 1; i < 527; i++)
  564. {
  565. if ((len = monitored_queue_write_msg(buf, MSG_LEN)) != MSG_LEN)
  566. {
  567. printf("Write failed - %d\n", len);
  568. tests_failed();
  569. }
  570. if ((len = monitored_queue_read_msg(buf, MSG_LEN)) != MSG_LEN)
  571. {
  572. printf("Read failed - %d\n", len);
  573. tests_failed();
  574. }
  575. }
  576. /* Fill the buffer, checking the contents grow correctly */
  577. for (i = 1; i < 1000; i++)
  578. {
  579. if ((len = monitored_queue_write_msg(buf, MSG_LEN)) != MSG_LEN)
  580. break;
  581. }
  582. printf("Free space = %d (%d)\n", queue_free_space(queue), BUF_LEN - (total_in - total_out));
  583. display_queue_pointers();
  584. printf("Full at chunk %d (expected %lu)\n", i, (unsigned long int) BUF_LEN/(MSG_LEN + sizeof(uint16_t)));
  585. if (i != BUF_LEN/(MSG_LEN + sizeof(uint16_t)))
  586. tests_failed();
  587. display_queue_pointers();
  588. if ((len = monitored_queue_read_msg(buf, MSG_LEN)) != MSG_LEN)
  589. {
  590. printf("Read failed - %d\n", len);
  591. tests_failed();
  592. }
  593. if ((len = monitored_queue_write_msg(buf, MSG_LEN)) != MSG_LEN)
  594. {
  595. printf("Write failed - %d\n", len);
  596. tests_failed();
  597. }
  598. display_queue_pointers();
  599. for (i = 1; i < 5000; i++)
  600. {
  601. if ((len = monitored_queue_read_msg(buf, MSG_LEN)) != MSG_LEN)
  602. {
  603. printf("Read failed - %d\n", len);
  604. tests_failed();
  605. }
  606. if ((len = monitored_queue_write_msg(buf, MSG_LEN)) != MSG_LEN)
  607. {
  608. printf("Write failed - %d\n", len);
  609. tests_failed();
  610. }
  611. }
  612. display_queue_pointers();
  613. if ((len = monitored_queue_write_msg(buf, 5)) == 5)
  614. {
  615. printf("Write of 5 succeeded\n");
  616. tests_failed();
  617. }
  618. if ((len = monitored_queue_write_msg(buf, 4)) != 4)
  619. {
  620. printf("Write of 4 failed\n");
  621. tests_failed();
  622. }
  623. display_queue_pointers();
  624. for (i = 1; i < 5000; i++)
  625. {
  626. if (i == 527)
  627. {
  628. if ((len = monitored_queue_read_msg(buf, MSG_LEN)) != 4)
  629. {
  630. printf("Read failed - %d\n", len);
  631. tests_failed();
  632. }
  633. }
  634. if ((len = monitored_queue_read_msg(buf, MSG_LEN)) != MSG_LEN)
  635. {
  636. printf("Read failed - %d\n", len);
  637. tests_failed();
  638. }
  639. if ((len = monitored_queue_write_msg(buf, MSG_LEN)) != MSG_LEN)
  640. {
  641. printf("Write failed - %d\n", len);
  642. tests_failed();
  643. }
  644. }
  645. display_queue_pointers();
  646. queue_free(queue);
  647. }
  648. /*- End of function --------------------------------------------------------*/
  649. int main(int argc, char *argv[])
  650. {
  651. bool threaded_messages;
  652. bool threaded_streams;
  653. int opt;
  654. threaded_messages = false;
  655. threaded_streams = false;
  656. while ((opt = getopt(argc, argv, "ms")) != -1)
  657. {
  658. switch (opt)
  659. {
  660. case 'm':
  661. threaded_messages = true;
  662. break;
  663. case 's':
  664. threaded_streams = true;
  665. break;
  666. }
  667. }
  668. /* Test the basic functionality of the queueing code in stream and message modes */
  669. printf("Stream mode functional tests\n");
  670. functional_stream_tests();
  671. printf("Message mode functional tests\n");
  672. functional_message_tests();
  673. /* Run separate write and read threads for a while, to verify there are no locking
  674. issues. */
  675. if (threaded_streams)
  676. {
  677. printf("Stream mode threaded tests\n");
  678. threaded_stream_tests();
  679. }
  680. if (threaded_messages)
  681. {
  682. printf("Message mode threaded tests\n");
  683. threaded_message_tests();
  684. }
  685. return 0;
  686. }
  687. /*- End of function --------------------------------------------------------*/
  688. /*- End of file ------------------------------------------------------------*/