@@ -148,14 +148,15 @@ int main(int argc, const char* argv[]) {
148
148
149
149
if (argc == 1 || argc == 2 ) {
150
150
printf (" usage 1: %s [-v] [-save_output] generate <nr_elements> <nr_inputs>\n " , argv[0 ]);
151
- printf (" usage 2: %s [-v] [-save_output] <file_num_hashes> <file_num_hashes_arr> <file_num_elems>\n " , argv[0 ]);
151
+ printf (" usage 2: %s [-v] [-save_output] [-check_result] <file_num_hashes> <file_num_hashes_arr> <file_num_elems>\n " , argv[0 ]);
152
152
printf (" usage: argc is %i \n " , argc);
153
153
return 1 ;
154
154
}
155
155
156
156
int arg = 1 ;
157
157
bool verbose = false ;
158
158
bool save_output_file = false ;
159
+ bool check_result = false ;
159
160
if (0 == strcmp (argv[arg], " -v" )) {
160
161
verbose = true ;
161
162
arg++;
@@ -164,14 +165,18 @@ int main(int argc, const char* argv[]) {
164
165
save_output_file = true ;
165
166
arg++;
166
167
}
168
+ if (0 == strcmp (argv[arg], " -check_result" )) {
169
+ check_result = true ;
170
+ arg++;
171
+ }
167
172
168
173
poh_verify_many_set_verbose (verbose);
169
174
170
175
if (0 == strcmp (argv[arg], " generate" )) {
171
176
++arg;
172
177
if ((argc - arg) != 2 ) {
173
178
printf (" usage 1: %s [-v] [-save_output] generate <nr_elements> <nr_inputs>\n " , argv[0 ]);
174
- printf (" usage 2: %s [-v] [-save_output] <file_num_hashes> <file_num_hashes_arr> <file_num_elems>\n " , argv[0 ]);
179
+ printf (" usage 2: %s [-v] [-save_output] [-check_result] <file_num_hashes> <file_num_hashes_arr> <file_num_elems>\n " , argv[0 ]);
175
180
printf (" usage: argc is %i \n " , argc);
176
181
return 1 ;
177
182
}
@@ -251,7 +256,7 @@ int main(int argc, const char* argv[]) {
251
256
else {
252
257
if ((argc - arg) != 3 ) {
253
258
printf (" usage 1: %s [-v] [-save_output] generate <nr_elements>\n " , argv[0 ]);
254
- printf (" usage 2: %s [-v] [-save_output] <file_num_hashes> <file_num_hashes_arr> <file_num_elems>\n " , argv[0 ]);
259
+ printf (" usage 2: %s [-v] [-save_output] [-check_result] <file_num_hashes> <file_num_hashes_arr> <file_num_elems> \n " , argv[0 ]);
255
260
printf (" usage: argc is %i \n " , argc);
256
261
return 1 ;
257
262
}
@@ -269,6 +274,57 @@ int main(int argc, const char* argv[]) {
269
274
if (save_output_file) {
270
275
save_out (input_result->hashes , input_result->num_elems , 0 );
271
276
}
277
+
278
+ if (check_result) {
279
+ FILE * fp;
280
+ fp = fopen (argv[arg+2 ], " r" );
281
+
282
+ if (fp == NULL ) {
283
+ fprintf (stderr, " Could not open file %s\n " , argv[arg+2 ]);
284
+ exit (-1 );
285
+ }
286
+
287
+ FILE * fp2;
288
+ const char * file_with_results = " ..//poh-verify-test//test_hashes_output_332" ;
289
+ fp2 = fopen (file_with_results, " r" );
290
+
291
+ if (fp2 == NULL ) {
292
+ fprintf (stderr, " Could not open file %s\n " , file_with_results);
293
+ exit (-1 );
294
+ }
295
+
296
+ size_t num_elems;
297
+ DIE ( 0 == fscanf (fp, " %zu" , &num_elems), " Error while reading num_elems from file" );
298
+ fprintf (stderr, " num_elems read from file %s is %zu\n " , argv[arg+2 ], num_elems);
299
+
300
+ uint8_t * test_result_hashes = (uint8_t *)calloc (input_result->num_elems , sizeof (uint8_t ));
301
+ DIE (test_result_hashes == NULL , " Error while allocating test_result_hashes" );
302
+
303
+ size_t i = 0 ;
304
+ for (i=0 ; i < num_elems; ++i) {
305
+ if ( 0 == fscanf (fp2, " %hhu" , &test_result_hashes[i])) {
306
+ fprintf (stderr, " Error while reading hashes from file %s at index %lu \n " , file_with_results, i);
307
+ exit (-2 );
308
+ }
309
+ }
310
+
311
+ for (i=0 ; i < num_elems; ++i) {
312
+ if (test_result_hashes[i] != input_result->hashes [i]) {
313
+ fprintf (stderr, " Different result detected at index %lu of %lu actual result: %hhu expected: %hhu \n TEST FAILED" ,
314
+ i, num_elems, input_result->hashes [i], test_result_hashes[i]);
315
+ break ;
316
+ }
317
+ }
318
+
319
+ if (num_elems == i) {
320
+ printf (" TEST PASSED num_elems %lu\n " , num_elems);
321
+ }
322
+ free (test_result_hashes);
323
+ fclose (fp);
324
+ fclose (fp2);
325
+ }
326
+
327
+
272
328
free_input_poh (&input_result);
273
329
}
274
330
0 commit comments