summaryrefslogtreecommitdiff
path: root/gnuradio-core/src/lib/reed-solomon/rstest.c
blob: d8fc5448a70d0fedfe3251dc952971be41729396 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/* Test the Reed-Solomon codecs
 * for various block sizes and with random data and random error patterns
 *
 * Copyright 2002 Phil Karn, KA9Q
 * May be used under the terms of the GNU General Public License (GPL)
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "rs.h"

int exercise_char(void *,int);

#ifdef ALL_VERSIONS
int exercise_int(void *,int);
int exercise_8(int);
int exercise_ccsds(int);
#endif

struct {
  int symsize;
  int genpoly;
  int fcs;
  int prim;
  int nroots;
  int ntrials;
} Tab[] = {
  {2, 0x7,     1,   1, 1, 10 },
  {3, 0xb,     1,   1, 2, 10 },
  {4, 0x13,    1,   1, 4, 10 },
  {5, 0x25,    1,   1, 6, 10 },
  {6, 0x43,    1,   1, 8, 10 },
  {7, 0x89,    1,   1, 10, 10 },
  {8, 0x11d,   1,   1, 32, 10 },
  {8, 0x187,   112,11, 32, 10 }, /* Duplicates CCSDS codec */
#ifdef ALL_VESIONS
  {9, 0x211,   1,   1, 32, 10 },
  {10,0x409,   1,   1, 32, 10 },
  {11,0x805,   1,   1, 32, 10 },
  {12,0x1053,  1,   1, 32, 5 },
  {13,0x201b,  1,   1, 32, 2 },
  {14,0x4443,  1,   1, 32, 1 },
  {15,0x8003,  1,   1, 32, 1 },
  {16,0x1100b, 1,   1, 32, 1 },
#endif
  {0, 0, 0, 0, 0},
};

int main(){
  void *handle;
  int errs,terrs;
  int i;

  terrs = 0;
  srandom(time(NULL));

#ifdef ALL_VERSIONS
  printf("Testing fixed (255,223) RS codec...");
  fflush(stdout);
  errs = exercise_8(10);
  terrs += errs;
  if(errs == 0){
    printf("OK\n");
  }
  printf("Testing CCSDS standard (255,223) RS codec...");
  fflush(stdout);
  errs = exercise_ccsds(10);
  terrs += errs;
  if(errs == 0){
    printf("OK\n");
  }
#endif

  for(i=0;Tab[i].symsize != 0;i++){
    int nn,kk;

    nn = (1<<Tab[i].symsize) - 1;
    kk = nn - Tab[i].nroots;
    printf("Testing (%d,%d) RS codec...",nn,kk);
    fflush(stdout);
    if(Tab[i].symsize <= 8){
      if((handle = init_rs_char(Tab[i].symsize,Tab[i].genpoly,Tab[i].fcs,Tab[i].prim,Tab[i].nroots)) == NULL){
	printf("init_rs_char failed!\n");
	continue;
      }
      errs = exercise_char(handle,Tab[i].ntrials);
    } else {
#ifdef ALL_VERSIONS
      if((handle = init_rs_int(Tab[i].symsize,Tab[i].genpoly,Tab[i].fcs,Tab[i].prim,Tab[i].nroots)) == NULL){
	printf("init_rs_int failed!\n");
	continue;
      }
      errs = exercise_int(handle,Tab[i].ntrials);
#else
      printf ("init_rs_init support is not enabled\n");
      exit (1);
#endif

    }
    terrs += errs;
    if(errs == 0){
      printf("OK\n");
    }
    free_rs_char(handle);
  }
  if(terrs == 0)
    printf("All codec tests passed!\n");

  exit(0);
}