123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482 |
- /*
- * SpanDSP - a series of DSP components for telephony
- *
- * bert_tests.c - Tests for the BER tester.
- *
- * Written by Steve Underwood <steveu@coppice.org>
- *
- * Copyright (C) 2004 Steve Underwood
- *
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2, as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
- /*! \file */
- /*! \page bert_tests_page BERT tests
- \section bert_tests_page_sec_1 What does it do?
- These tests exercise each of the BERT standards supported by the BERT module.
- */
- #if defined(HAVE_CONFIG_H)
- #include "config.h"
- #endif
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <assert.h>
- #include <sndfile.h>
- #define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
- #include "spandsp.h"
- /* Use a local random generator, so the results are consistent across platforms */
- static int my_rand(void)
- {
- static int rndnum = 1234567;
- return (rndnum = 1664525U*rndnum + 1013904223U);
- }
- /*- End of function --------------------------------------------------------*/
- static void reporter(void *user_data, int reason, bert_results_t *results)
- {
- int channel;
- channel = (int) (intptr_t) user_data;
- printf("%d: BERT report '%s' ", channel, bert_event_to_str(reason));
- switch (reason)
- {
- case BERT_REPORT_REGULAR:
- printf("%d bits, %d bad bits, %d resyncs", results->total_bits, results->bad_bits, results->resyncs);
- break;
- }
- printf("\r");
- }
- /*- End of function --------------------------------------------------------*/
- int8_t test[0x800000];
- int main(int argc, char *argv[])
- {
- bert_state_t *tx_bert;
- bert_state_t *rx_bert;
- bert_state_t *bert;
- bert_results_t bert_results;
- int i;
- int bit;
- int zeros;
- int max_zeros;
- int failed;
- tx_bert = bert_init(NULL, 0, BERT_PATTERN_ZEROS, 300, 20);
- rx_bert = bert_init(NULL, 0, BERT_PATTERN_ZEROS, 300, 20);
- for (i = 0; i < 511*2; i++)
- {
- bit = bert_get_bit(tx_bert);
- bert_put_bit(rx_bert, bit);
- }
- bert_result(rx_bert, &bert_results);
- printf("Zeros: Bad bits %d/%d\n", bert_results.bad_bits, bert_results.total_bits);
- if (bert_results.bad_bits || bert_results.total_bits != 950)
- {
- printf("Test failed.\n");
- exit(2);
- }
- bert_free(tx_bert);
- bert_free(rx_bert);
- tx_bert = bert_init(NULL, 0, BERT_PATTERN_ONES, 300, 20);
- rx_bert = bert_init(NULL, 0, BERT_PATTERN_ONES, 300, 20);
- for (i = 0; i < 511*2; i++)
- {
- bit = bert_get_bit(tx_bert);
- bert_put_bit(rx_bert, bit);
- }
- bert_result(rx_bert, &bert_results);
- printf("Ones: Bad bits %d/%d\n", bert_results.bad_bits, bert_results.total_bits);
- if (bert_results.bad_bits || bert_results.total_bits != 950)
- {
- printf("Test failed.\n");
- exit(2);
- }
- bert_free(tx_bert);
- bert_free(rx_bert);
- tx_bert = bert_init(NULL, 0, BERT_PATTERN_1_TO_7, 300, 20);
- rx_bert = bert_init(NULL, 0, BERT_PATTERN_1_TO_7, 300, 20);
- for (i = 0; i < 511*2; i++)
- {
- bit = bert_get_bit(tx_bert);
- bert_put_bit(rx_bert, bit);
- }
- bert_result(rx_bert, &bert_results);
- printf("1 to 7: Bad bits %d/%d\n", bert_results.bad_bits, bert_results.total_bits);
- if (bert_results.bad_bits || bert_results.total_bits != 950)
- {
- printf("Test failed.\n");
- exit(2);
- }
- bert_free(tx_bert);
- bert_free(rx_bert);
- tx_bert = bert_init(NULL, 0, BERT_PATTERN_1_TO_3, 300, 20);
- rx_bert = bert_init(NULL, 0, BERT_PATTERN_1_TO_3, 300, 20);
- for (i = 0; i < 511*2; i++)
- {
- bit = bert_get_bit(tx_bert);
- bert_put_bit(rx_bert, bit);
- }
- bert_result(rx_bert, &bert_results);
- printf("1 to 3: Bad bits %d/%d\n", bert_results.bad_bits, bert_results.total_bits);
- if (bert_results.bad_bits || bert_results.total_bits != 950)
- {
- printf("Test failed.\n");
- exit(2);
- }
- bert_free(tx_bert);
- bert_free(rx_bert);
- tx_bert = bert_init(NULL, 0, BERT_PATTERN_1_TO_1, 300, 20);
- rx_bert = bert_init(NULL, 0, BERT_PATTERN_1_TO_1, 300, 20);
- for (i = 0; i < 511*2; i++)
- {
- bit = bert_get_bit(tx_bert);
- bert_put_bit(rx_bert, bit);
- }
- bert_result(rx_bert, &bert_results);
- printf("1 to 1: Bad bits %d/%d\n", bert_results.bad_bits, bert_results.total_bits);
- if (bert_results.bad_bits || bert_results.total_bits != 950)
- {
- printf("Test failed.\n");
- exit(2);
- }
- bert_free(tx_bert);
- bert_free(rx_bert);
- tx_bert = bert_init(NULL, 0, BERT_PATTERN_3_TO_1, 300, 20);
- rx_bert = bert_init(NULL, 0, BERT_PATTERN_3_TO_1, 300, 20);
- for (i = 0; i < 511*2; i++)
- {
- bit = bert_get_bit(tx_bert);
- bert_put_bit(rx_bert, bit);
- }
- bert_result(rx_bert, &bert_results);
- printf("3 to 1: Bad bits %d/%d\n", bert_results.bad_bits, bert_results.total_bits);
- if (bert_results.bad_bits || bert_results.total_bits != 950)
- {
- printf("Test failed.\n");
- exit(2);
- }
- bert_free(tx_bert);
- bert_free(rx_bert);
- tx_bert = bert_init(NULL, 0, BERT_PATTERN_7_TO_1, 300, 20);
- rx_bert = bert_init(NULL, 0, BERT_PATTERN_7_TO_1, 300, 20);
- for (i = 0; i < 511*2; i++)
- {
- bit = bert_get_bit(tx_bert);
- bert_put_bit(rx_bert, bit);
- }
- bert_result(rx_bert, &bert_results);
- printf("7 to 1: Bad bits %d/%d\n", bert_results.bad_bits, bert_results.total_bits);
- if (bert_results.bad_bits || bert_results.total_bits != 950)
- {
- printf("Test failed.\n");
- exit(2);
- }
- bert_free(tx_bert);
- bert_free(rx_bert);
- tx_bert = bert_init(NULL, 0, BERT_PATTERN_ITU_O153_9, 300, 20);
- rx_bert = bert_init(NULL, 0, BERT_PATTERN_ITU_O153_9, 300, 20);
- for (i = 0; i < 0x200; i++)
- test[i] = 0;
- max_zeros = 0;
- zeros = 0;
- for (i = 0; i < 511*2; i++)
- {
- bit = bert_get_bit(tx_bert);
- if (bit)
- {
- if (zeros > max_zeros)
- max_zeros = zeros;
- zeros = 0;
- }
- else
- {
- zeros++;
- }
- bert_put_bit(rx_bert, bit);
- test[tx_bert->tx.reg]++;
- }
- failed = false;
- if (test[0] != 0)
- {
- printf("XXX %d %d\n", 0, test[0]);
- failed = true;
- }
- for (i = 1; i < 0x200; i++)
- {
- if (test[i] != 2)
- {
- printf("XXX %d %d\n", i, test[i]);
- failed = true;
- }
- }
- bert_result(rx_bert, &bert_results);
- printf("O.153(9): Bad bits %d/%d, max zeros %d\n", bert_results.bad_bits, bert_results.total_bits, max_zeros);
- if (bert_results.bad_bits || bert_results.total_bits != 986 || failed)
- {
- printf("Test failed.\n");
- exit(2);
- }
- bert_free(tx_bert);
- bert_free(rx_bert);
- tx_bert = bert_init(NULL, 0, BERT_PATTERN_ITU_O152_11, 300, 20);
- rx_bert = bert_init(NULL, 0, BERT_PATTERN_ITU_O152_11, 300, 20);
- for (i = 0; i < 0x800; i++)
- test[i] = 0;
- max_zeros = 0;
- zeros = 0;
- for (i = 0; i < 2047*2; i++)
- {
- bit = bert_get_bit(tx_bert);
- if (bit)
- {
- if (zeros > max_zeros)
- max_zeros = zeros;
- zeros = 0;
- }
- else
- {
- zeros++;
- }
- bert_put_bit(rx_bert, bit);
- test[tx_bert->tx.reg]++;
- }
- failed = false;
- if (test[0] != 0)
- {
- printf("XXX %d %d\n", 0, test[0]);
- failed = true;
- }
- for (i = 1; i < 0x800; i++)
- {
- if (test[i] != 2)
- {
- printf("XXX %d %d\n", i, test[i]);
- failed = true;
- }
- }
- bert_result(rx_bert, &bert_results);
- printf("O.152(11): Bad bits %d/%d, max zeros %d\n", bert_results.bad_bits, bert_results.total_bits, max_zeros);
- if (bert_results.bad_bits || bert_results.total_bits != 4052 || failed)
- {
- printf("Test failed.\n");
- exit(2);
- }
- bert_free(tx_bert);
- bert_free(rx_bert);
- tx_bert = bert_init(NULL, 0, BERT_PATTERN_ITU_O151_15, 300, 20);
- rx_bert = bert_init(NULL, 0, BERT_PATTERN_ITU_O151_15, 300, 20);
- for (i = 0; i < 0x8000; i++)
- test[i] = 0;
- max_zeros = 0;
- zeros = 0;
- for (i = 0; i < 32767*2; i++)
- {
- bit = bert_get_bit(tx_bert);
- if (bit)
- {
- if (zeros > max_zeros)
- max_zeros = zeros;
- zeros = 0;
- }
- else
- {
- zeros++;
- }
- bert_put_bit(rx_bert, bit);
- test[tx_bert->tx.reg]++;
- }
- failed = false;
- if (test[0] != 0)
- {
- printf("XXX %d %d\n", 0, test[0]);
- failed = true;
- }
- for (i = 1; i < 0x8000; i++)
- {
- if (test[i] != 2)
- {
- printf("XXX %d %d\n", i, test[i]);
- failed = true;
- }
- }
- bert_result(rx_bert, &bert_results);
- printf("O.151(15): Bad bits %d/%d, max zeros %d\n", bert_results.bad_bits, bert_results.total_bits, max_zeros);
- if (bert_results.bad_bits || bert_results.total_bits != 65480 || failed)
- {
- printf("Test failed.\n");
- exit(2);
- }
- bert_free(tx_bert);
- bert_free(rx_bert);
- tx_bert = bert_init(NULL, 0, BERT_PATTERN_ITU_O151_20, 300, 20);
- rx_bert = bert_init(NULL, 0, BERT_PATTERN_ITU_O151_20, 300, 20);
- for (i = 0; i < 0x100000; i++)
- test[i] = 0;
- max_zeros = 0;
- zeros = 0;
- for (i = 0; i < 1048575*2; i++)
- {
- bit = bert_get_bit(tx_bert);
- if (bit)
- {
- if (zeros > max_zeros)
- max_zeros = zeros;
- zeros = 0;
- }
- else
- {
- zeros++;
- }
- bert_put_bit(rx_bert, bit);
- test[tx_bert->tx.reg]++;
- }
- failed = false;
- if (test[0] != 0)
- {
- printf("XXX %d %d\n", 0, test[0]);
- failed = true;
- }
- for (i = 1; i < 0x100000; i++)
- {
- if (test[i] != 2)
- printf("XXX %d %d\n", i, test[i]);
- }
- bert_result(rx_bert, &bert_results);
- printf("O.151(20): Bad bits %d/%d, max zeros %d\n", bert_results.bad_bits, bert_results.total_bits, max_zeros);
- if (bert_results.bad_bits || bert_results.total_bits != 2097066 || failed)
- {
- printf("Test failed.\n");
- exit(2);
- }
- bert_free(tx_bert);
- bert_free(rx_bert);
- tx_bert = bert_init(NULL, 0, BERT_PATTERN_ITU_O151_23, 300, 20);
- rx_bert = bert_init(NULL, 0, BERT_PATTERN_ITU_O151_23, 300, 20);
- for (i = 0; i < 0x800000; i++)
- test[i] = 0;
- max_zeros = 0;
- zeros = 0;
- for (i = 0; i < 8388607*2; i++)
- {
- bit = bert_get_bit(tx_bert);
- if (bit)
- {
- if (zeros > max_zeros)
- max_zeros = zeros;
- zeros = 0;
- }
- else
- {
- zeros++;
- }
- bert_put_bit(rx_bert, bit);
- test[tx_bert->tx.reg]++;
- }
- failed = false;
- if (test[0] != 0)
- {
- printf("XXX %d %d\n", 0, test[0]);
- failed = true;
- }
- for (i = 1; i < 0x800000; i++)
- {
- if (test[i] != 2)
- printf("XXX %d %d\n", i, test[i]);
- }
- bert_result(rx_bert, &bert_results);
- printf("O.151(23): Bad bits %d/%d, max zeros %d\n", bert_results.bad_bits, bert_results.total_bits, max_zeros);
- if (bert_results.bad_bits || bert_results.total_bits != 16777136 || failed)
- {
- printf("Test failed.\n");
- exit(2);
- }
- bert_free(tx_bert);
- bert_free(rx_bert);
- tx_bert = bert_init(NULL, 0, BERT_PATTERN_QBF, 300, 20);
- rx_bert = bert_init(NULL, 0, BERT_PATTERN_QBF, 300, 20);
- for (i = 0; i < 100000; i++)
- {
- bit = bert_get_bit(tx_bert);
- bert_put_bit(rx_bert, bit);
- }
- bert_result(rx_bert, &bert_results);
- printf("QBF: Bad bits %d/%d\n", bert_results.bad_bits, bert_results.total_bits);
- if (bert_results.bad_bits || bert_results.total_bits != 100000)
- {
- printf("Test failed.\n");
- exit(2);
- }
- bert_free(tx_bert);
- bert_free(rx_bert);
- /* Test the mechanism for categorising the error rate into <10^x bands */
- /* TODO: The result of this test is not checked automatically */
- bert = bert_init(NULL, 15000000, BERT_PATTERN_ITU_O152_11, 300, 20);
- bert_set_report(bert, 100000, reporter, (intptr_t) 0);
- for (;;)
- {
- if ((bit = bert_get_bit(bert)) == SIG_STATUS_END_OF_DATA)
- {
- bert_result(bert, &bert_results);
- printf("Rate test: %d bits, %d bad bits, %d resyncs\n", bert_results.total_bits, bert_results.bad_bits, bert_results.resyncs);
- if (bert_results.total_bits != 15000000 - 42
- ||
- bert_results.bad_bits != 58
- ||
- bert_results.resyncs != 0)
- {
- printf("Tests failed\n");
- exit(2);
- }
- break;
- //bert = bert_init(NULL, 15000000, BERT_PATTERN_ITU_O152_11, 300, 20);
- //bert_set_report(bert, 100000, reporter, (intptr_t) 0);
- //continue;
- }
- if ((my_rand() & 0x3FFFF) == 0)
- bit ^= 1;
- //if ((my_rand() & 0xFFF) == 0)
- // bert_put_bit(bert, bit);
- bert_put_bit(bert, bit);
- }
- bert_free(bert);
- printf("Tests passed.\n");
- return 0;
- }
- /*- End of function --------------------------------------------------------*/
- /*- End of file ------------------------------------------------------------*/
|