@@ -148,14 +148,15 @@ int main(int argc, const char* argv[]) {
148148
149149 if (argc == 1 || argc == 2 ) {
150150 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 ]);
152152 printf (" usage: argc is %i \n " , argc);
153153 return 1 ;
154154 }
155155
156156 int arg = 1 ;
157157 bool verbose = false ;
158158 bool save_output_file = false ;
159+ bool check_result = false ;
159160 if (0 == strcmp (argv[arg], " -v" )) {
160161 verbose = true ;
161162 arg++;
@@ -164,14 +165,18 @@ int main(int argc, const char* argv[]) {
164165 save_output_file = true ;
165166 arg++;
166167 }
168+ if (0 == strcmp (argv[arg], " -check_result" )) {
169+ check_result = true ;
170+ arg++;
171+ }
167172
168173 poh_verify_many_set_verbose (verbose);
169174
170175 if (0 == strcmp (argv[arg], " generate" )) {
171176 ++arg;
172177 if ((argc - arg) != 2 ) {
173178 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 ]);
175180 printf (" usage: argc is %i \n " , argc);
176181 return 1 ;
177182 }
@@ -251,7 +256,7 @@ int main(int argc, const char* argv[]) {
251256 else {
252257 if ((argc - arg) != 3 ) {
253258 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 ]);
255260 printf (" usage: argc is %i \n " , argc);
256261 return 1 ;
257262 }
@@ -269,6 +274,57 @@ int main(int argc, const char* argv[]) {
269274 if (save_output_file) {
270275 save_out (input_result->hashes , input_result->num_elems , 0 );
271276 }
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+
272328 free_input_poh (&input_result);
273329 }
274330
0 commit comments