Imported Upstream version 3.0
[debian/gnuradio] / gnuradio-core / src / lib / reed-solomon / rstest.c
1 /* Test the Reed-Solomon codecs
2  * for various block sizes and with random data and random error patterns
3  *
4  * Copyright 2002 Phil Karn, KA9Q
5  * May be used under the terms of the GNU General Public License (GPL)
6  */
7
8 #ifdef HAVE_CONFIG_H
9 #include <config.h>
10 #endif
11
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <time.h>
15 #include "rs.h"
16
17 int exercise_char(void *,int);
18
19 #ifdef ALL_VERSIONS
20 int exercise_int(void *,int);
21 int exercise_8(int);
22 int exercise_ccsds(int);
23 #endif
24
25 struct {
26   int symsize;
27   int genpoly;
28   int fcs;
29   int prim;
30   int nroots;
31   int ntrials;
32 } Tab[] = {
33   {2, 0x7,     1,   1, 1, 10 },
34   {3, 0xb,     1,   1, 2, 10 },
35   {4, 0x13,    1,   1, 4, 10 },
36   {5, 0x25,    1,   1, 6, 10 },
37   {6, 0x43,    1,   1, 8, 10 },
38   {7, 0x89,    1,   1, 10, 10 },
39   {8, 0x11d,   1,   1, 32, 10 },
40   {8, 0x187,   112,11, 32, 10 }, /* Duplicates CCSDS codec */
41 #ifdef ALL_VESIONS
42   {9, 0x211,   1,   1, 32, 10 },
43   {10,0x409,   1,   1, 32, 10 },
44   {11,0x805,   1,   1, 32, 10 },
45   {12,0x1053,  1,   1, 32, 5 },
46   {13,0x201b,  1,   1, 32, 2 },
47   {14,0x4443,  1,   1, 32, 1 },
48   {15,0x8003,  1,   1, 32, 1 },
49   {16,0x1100b, 1,   1, 32, 1 },
50 #endif
51   {0, 0, 0, 0, 0},
52 };
53
54 int main(){
55   void *handle;
56   int errs,terrs;
57   int i;
58
59   terrs = 0;
60   srandom(time(NULL));
61
62 #ifdef ALL_VERSIONS
63   printf("Testing fixed (255,223) RS codec...");
64   fflush(stdout);
65   errs = exercise_8(10);
66   terrs += errs;
67   if(errs == 0){
68     printf("OK\n");
69   }
70   printf("Testing CCSDS standard (255,223) RS codec...");
71   fflush(stdout);
72   errs = exercise_ccsds(10);
73   terrs += errs;
74   if(errs == 0){
75     printf("OK\n");
76   }
77 #endif
78
79   for(i=0;Tab[i].symsize != 0;i++){
80     int nn,kk;
81
82     nn = (1<<Tab[i].symsize) - 1;
83     kk = nn - Tab[i].nroots;
84     printf("Testing (%d,%d) RS codec...",nn,kk);
85     fflush(stdout);
86     if(Tab[i].symsize <= 8){
87       if((handle = init_rs_char(Tab[i].symsize,Tab[i].genpoly,Tab[i].fcs,Tab[i].prim,Tab[i].nroots)) == NULL){
88         printf("init_rs_char failed!\n");
89         continue;
90       }
91       errs = exercise_char(handle,Tab[i].ntrials);
92     } else {
93 #ifdef ALL_VERSIONS
94       if((handle = init_rs_int(Tab[i].symsize,Tab[i].genpoly,Tab[i].fcs,Tab[i].prim,Tab[i].nroots)) == NULL){
95         printf("init_rs_int failed!\n");
96         continue;
97       }
98       errs = exercise_int(handle,Tab[i].ntrials);
99 #else
100       printf ("init_rs_init support is not enabled\n");
101       exit (1);
102 #endif
103
104     }
105     terrs += errs;
106     if(errs == 0){
107       printf("OK\n");
108     }
109     free_rs_char(handle);
110   }
111   if(terrs == 0)
112     printf("All codec tests passed!\n");
113
114   exit(0);
115 }
116
117