File: test.c

package info (click to toggle)
libzn-poly 0.9.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 904 kB
  • sloc: ansic: 10,736; python: 124; makefile: 12; sh: 6
file content (257 lines) | stat: -rw-r--r-- 6,237 bytes parent folder | download | duplicates (3)
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
/*
   test.c:  command line program for running test routines
   
   Copyright (C) 2007, 2008, David Harvey
   
   This file is part of the zn_poly library (version 0.9).
   
   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 2 of the License, or
   (at your option) version 3 of the License.

   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, see <http://www.gnu.org/licenses/>.

*/


#include <string.h>
#include "support.h"
#include "zn_poly_internal.h"


typedef struct
{
   // function name to print
   char* name;
   
   // pointer to actual test function; should return 1 if test passes
   // parameter quick is 1 if only a quick test is wanted
   int (*func)(int quick);

}
test_target_t;


extern int test_zn_array_mul_KS1 (int quick);
extern int test_zn_array_mul_KS2 (int quick);
extern int test_zn_array_mul_KS3 (int quick);
extern int test_zn_array_mul_KS4 (int quick);
extern int test_zn_array_sqr_KS1 (int quick);
extern int test_zn_array_sqr_KS2 (int quick);
extern int test_zn_array_sqr_KS3 (int quick);
extern int test_zn_array_sqr_KS4 (int quick);
extern int test_zn_array_mulmid_KS1 (int quick);
extern int test_zn_array_mulmid_KS2 (int quick);
extern int test_zn_array_mulmid_KS3 (int quick);
extern int test_zn_array_mulmid_KS4 (int quick);
extern int test_zn_array_recover_reduce (int quick);
extern int test_zn_array_pack (int quick);
extern int test_zn_array_unpack (int quick);
extern int test_zn_array_mul_fft (int quick);
extern int test_zn_array_sqr_fft (int quick);
extern int test_zn_array_mul_fft_dft (int quick);
extern int test_zn_array_mulmid_fft (int quick);
extern int test_nuss_mul (int quick);
extern int test_pmfvec_fft_dc (int quick);
extern int test_pmfvec_fft_huge (int quick);
extern int test_pmfvec_ifft_dc (int quick);
extern int test_pmfvec_ifft_huge (int quick);
extern int test_pmfvec_tpfft_dc (int quick);
extern int test_pmfvec_tpfft_huge (int quick);
extern int test_pmfvec_tpifft_dc (int quick);
extern int test_pmfvec_tpifft_huge (int quick);
extern int test_zn_array_invert (int quick);
extern int test_mpn_smp_basecase (int quick);
extern int test_mpn_smp_kara (int quick);
extern int test_mpn_smp (int quick);
extern int test_mpn_mulmid (int quick);


test_target_t targets[] = {
   {"mpn_smp_basecase",
    test_mpn_smp_basecase},

   {"mpn_smp_kara",
    test_mpn_smp_kara},

   {"mpn_smp",
    test_mpn_smp},

   {"mpn_mulmid",
    test_mpn_mulmid},

   {"zn_array_recover_reduce",
    test_zn_array_recover_reduce},
    
   {"zn_array_pack",
    test_zn_array_pack},
    
   {"zn_array_unpack",
    test_zn_array_unpack},
    
   {"zn_array_mul_KS1",
    test_zn_array_mul_KS1},
    
   {"zn_array_mul_KS2",
    test_zn_array_mul_KS2},
    
   {"zn_array_mul_KS3",
    test_zn_array_mul_KS3},
    
   {"zn_array_mul_KS4",
    test_zn_array_mul_KS4},
    
   {"zn_array_sqr_KS1",
    test_zn_array_sqr_KS1},
    
   {"zn_array_sqr_KS2",
    test_zn_array_sqr_KS2},
    
   {"zn_array_sqr_KS3",
    test_zn_array_sqr_KS3},
    
   {"zn_array_sqr_KS4",
    test_zn_array_sqr_KS4},
    
   {"zn_array_mulmid_KS1",
    test_zn_array_mulmid_KS1},
    
   {"zn_array_mulmid_KS2",
    test_zn_array_mulmid_KS2},
    
   {"zn_array_mulmid_KS3",
    test_zn_array_mulmid_KS3},
    
   {"zn_array_mulmid_KS4",
    test_zn_array_mulmid_KS4},
    
   {"nuss_mul",
    test_nuss_mul},

   {"pmfvec_fft_dc",
    test_pmfvec_fft_dc},
    
   {"pmfvec_fft_huge",
    test_pmfvec_fft_huge},
    
   {"pmfvec_ifft_dc",
    test_pmfvec_ifft_dc},
    
   {"pmfvec_ifft_huge",
    test_pmfvec_ifft_huge},

   {"pmfvec_tpfft_dc",
    test_pmfvec_tpfft_dc},
    
   {"pmfvec_tpfft_huge",
    test_pmfvec_tpfft_huge},
    
   {"pmfvec_tpifft_dc",
    test_pmfvec_tpifft_dc},

   {"pmfvec_tpifft_huge",
    test_pmfvec_tpifft_huge},

   {"zn_array_mul_fft",
    test_zn_array_mul_fft},
    
   {"zn_array_sqr_fft",
    test_zn_array_sqr_fft},

   {"zn_array_mulmid_fft",
    test_zn_array_mulmid_fft},
    
   {"zn_array_mul_fft_dft",
    test_zn_array_mul_fft_dft},
    
   {"zn_array_invert",
    test_zn_array_invert},

};

const unsigned num_targets = sizeof (targets) / sizeof (targets[0]);


int
run_test (test_target_t* target, int quick)
{
   printf ("%s()... ", target->name);
   fflush (stdout);
   int success = target->func (quick);
   printf ("%s\n", success ? "ok" : "FAIL!");
   return success;
}


void
usage ()
{
   printf ("usage: test [ -quick ] <target1> <target2> ...\n\n");
   printf ("Available targets:\n\n");
   printf ("   all (runs all tests)\n");
   int i;
   for (i = 0; i < num_targets; i++)
      printf ("   %s\n", targets[i].name);
}


int
main (int argc, char* argv[])
{
   gmp_randinit_default (randstate);
   
   int all_success = 1, any_targets = 0, quick = 0, success, i, j;

   for (j = 1; j < argc; j++)
   {
      if (!strcmp (argv[j], "-quick"))
         quick = 1;
      else if (!strcmp (argv[j], "all"))
      {
         any_targets = 1;
         for (i = 0; i < num_targets; i++)
            all_success = all_success && run_test (&targets[i], quick);
      }
      else
      {
         int found = -1;
         for (i = 0; i < num_targets; i++)
            if (!strcmp (argv[j], targets[i].name))
               found = i;
         if (found == -1)
         {
            printf ("unknown target string \"%s\"\n", argv[j]);
            return 0;
         }

         any_targets = 1;
         all_success = all_success && run_test (&targets[found], quick);
      }
   }
   
   if (!any_targets)
   {
      usage ();
      return 0;
   }

   printf("\n");
   if (all_success)
      printf ("All tests passed.\n");
   else
      printf ("At least one test FAILED!\n");
   
   gmp_randclear (randstate);

   return !all_success;
}


// end of file ****************************************************************