Mercurial > hg > audiostuff
comparison spandsp-0.0.6pre17/tests/crc_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 * crc_tests.c | |
| 5 * | |
| 6 * Written by Steve Underwood <steveu@coppice.org> | |
| 7 * | |
| 8 * Copyright (C) 2003 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: crc_tests.c,v 1.6 2008/05/13 13:17:25 steveu Exp $ | |
| 26 */ | |
| 27 | |
| 28 /*! \file */ | |
| 29 | |
| 30 /*! \page crc_tests_page CRC tests | |
| 31 \section crc_tests_page_sec_1 What does it do? | |
| 32 The CRC tests exercise the ITU-16 and ITU-32 CRC module, and verifies | |
| 33 correct operation. | |
| 34 */ | |
| 35 | |
| 36 #if defined(HAVE_CONFIG_H) | |
| 37 #include "config.h" | |
| 38 #endif | |
| 39 | |
| 40 #include <stdio.h> | |
| 41 #include <stdlib.h> | |
| 42 #include <string.h> | |
| 43 | |
| 44 #include "spandsp.h" | |
| 45 | |
| 46 int ref_len; | |
| 47 uint8_t buf[1000]; | |
| 48 | |
| 49 /* Use a local random generator, so the results are consistent across platforms. We have hard coded | |
| 50 correct results for a message sequence generated by this particular PRNG. */ | |
| 51 static int my_rand(void) | |
| 52 { | |
| 53 static int rndnum = 1234567; | |
| 54 | |
| 55 return (rndnum = 1664525U*rndnum + 1013904223U) >> 8; | |
| 56 } | |
| 57 /*- End of function --------------------------------------------------------*/ | |
| 58 | |
| 59 static int cook_up_msg(uint8_t *buf) | |
| 60 { | |
| 61 int i; | |
| 62 int len; | |
| 63 | |
| 64 /* Use medium length messages, with some randomised length variation. */ | |
| 65 /* TODO: this doesn't exercise extremely short or long messages. */ | |
| 66 len = (my_rand() & 0x3F) + 100; | |
| 67 for (i = 0; i < len; i++) | |
| 68 buf[i] = my_rand(); | |
| 69 return len; | |
| 70 } | |
| 71 /*- End of function --------------------------------------------------------*/ | |
| 72 | |
| 73 int main(int argc, char *argv[]) | |
| 74 { | |
| 75 int i; | |
| 76 int len; | |
| 77 | |
| 78 printf("HDLC module tests\n"); | |
| 79 | |
| 80 /* TODO: This doesn't check every function in the module */ | |
| 81 | |
| 82 /* Try a few random messages through the CRC logic. */ | |
| 83 printf("Testing the CRC-16 routines\n"); | |
| 84 for (i = 0; i < 100; i++) | |
| 85 { | |
| 86 ref_len = cook_up_msg(buf); | |
| 87 len = crc_itu16_append(buf, ref_len); | |
| 88 if (!crc_itu16_check(buf, len)) | |
| 89 { | |
| 90 printf("CRC-16 failure\n"); | |
| 91 exit(2); | |
| 92 } | |
| 93 } | |
| 94 printf("Test passed.\n\n"); | |
| 95 | |
| 96 printf("Testing the CRC-32 routines\n"); | |
| 97 for (i = 0; i < 100; i++) | |
| 98 { | |
| 99 ref_len = cook_up_msg(buf); | |
| 100 len = crc_itu32_append(buf, ref_len); | |
| 101 if (!crc_itu32_check(buf, len)) | |
| 102 { | |
| 103 printf("CRC-32 failure\n"); | |
| 104 exit(2); | |
| 105 } | |
| 106 } | |
| 107 printf("Test passed.\n"); | |
| 108 return 0; | |
| 109 } | |
| 110 /*- End of function --------------------------------------------------------*/ | |
| 111 /*- End of file ------------------------------------------------------------*/ |
