44#include <stdio.h>
55#include <string.h>
66
7- #define SET_ARGS (i , C_val , sigma_val ) \
8- { \
9- args[i]->C = (C_val); \
10- args[i]->sigma = (sigma_val); \
11- }
7+ #define SET_ARGS (i , C_val , sigma_val ) \
8+ { \
9+ args[i]->C = (C_val); \
10+ args[i]->sigma = (sigma_val); \
11+ }
1212
1313typedef int (* TestFunc )(void * config , const char * dataDir );
1414
1515typedef struct {
16- const char * name ;
17- TestFunc func ;
16+ const char * name ;
17+ TestFunc func ;
1818} Test ;
1919
2020typedef struct {
21- int C ;
22- int sigma ;
21+ int C ;
22+ int sigma ;
2323} Args ;
2424
2525#ifndef BUILD_MATRIX_FILE_PATH
26- #define BUILD_MATRIX_FILE_PATH (entry , dir , expect , C_str , sigma_str , path ) \
27- { \
28- strcpy((path), "data/"); \
29- strcat((path), (dir)); \
30- strcat((path), (entry)->d_name); \
31- strcat((path), "_C_"); \
32- strcat((path), (C_str)); \
33- strcat((path), "_sigma_"); \
34- strcat((path), (sigma_str)); \
35- strcat((path), (expect)); \
36- }
26+ #define BUILD_MATRIX_FILE_PATH (entry , dir , expect , C_str , sigma_str , path ) \
27+ { \
28+ strcpy((path), "data/"); \
29+ strcat((path), (dir)); \
30+ strcat((path), (entry)->d_name); \
31+ strcat((path), "_C_"); \
32+ strcat((path), (C_str)); \
33+ strcat((path), "_sigma_"); \
34+ strcat((path), (sigma_str)); \
35+ strcat((path), (expect)); \
36+ }
3737#endif
3838
3939#ifndef FORMAT_AND_STRIP_MATRIX_FILE
40- #define FORMAT_AND_STRIP_MATRIX_FILE (A , entry , C_str , sigma_str ) \
41- { \
42- sprintf((C_str), "%d", (A). C); \
43- sprintf((sigma_str), "%d", (A). sigma); \
44- char * dot = strrchr((entry)->d_name, '.'); \
45- if (dot != NULL) { \
46- *dot = '\0'; \
47- } \
48- }
40+ #define FORMAT_AND_STRIP_MATRIX_FILE (A , entry , C_str , sigma_str , arguments ) \
41+ { \
42+ sprintf((C_str), "%d", arguments-> C); \
43+ sprintf((sigma_str), "%d", arguments-> sigma); \
44+ char* dot = strrchr((entry)->d_name, '.'); \
45+ if (dot != NULL) { \
46+ *dot = '\0'; \
47+ } \
48+ }
4949#endif
5050
5151#ifndef BUILD_VECTOR_FILE_PATH
52- #define BUILD_VECTOR_FILE_PATH (entry , dir , expect , path ) \
53- { \
54- strcpy((path), "data/"); \
55- strcat((path), (dir)); \
56- strcat((path), (entry)->d_name); \
57- strcat((path), (expect)); \
58- }
52+ #define BUILD_VECTOR_FILE_PATH (entry , dir , expect , path ) \
53+ { \
54+ strcpy((path), "data/"); \
55+ strcat((path), (dir)); \
56+ strcat((path), (entry)->d_name); \
57+ strcat((path), (expect)); \
58+ }
5959#endif
6060
6161#ifndef FORMAT_AND_STRIP_VECTOR_FILE
62- #define FORMAT_AND_STRIP_VECTOR_FILE (entry ) \
63- { \
64- char * dot = strrchr((entry)->d_name, '.'); \
65- if (dot != NULL) { \
66- *dot = '\0'; \
67- } \
68- }
62+ #define FORMAT_AND_STRIP_VECTOR_FILE (entry ) \
63+ { \
64+ char* dot = strrchr((entry)->d_name, '.'); \
65+ if (dot != NULL) { \
66+ *dot = '\0'; \
67+ } \
68+ }
6969#endif
7070
7171#ifndef STR_LEN
@@ -77,54 +77,57 @@ int sigma;
7777#define ARRAY_ALIGNMENT 64
7878#endif
7979
80- static int diff_files (const char * expectedData , const char * reportedData ) {
81- FILE * f1 = fopen (expectedData , "r" );
82- FILE * f2 = fopen (reportedData , "r" );
83-
84- if (f1 == NULL || f2 == NULL ) {
85- perror ("Error opening file" );
86- return 1 ;
87- }
88-
89- char line1 [2048 ], line2 [2048 ];
90- int line_number = 1 ; // Line number counter
91-
92- // Compare lines until one of the files ends
93- while (fgets (line1 , sizeof (line1 ), f1 ) != NULL && fgets (line2 , sizeof (line2 ), f2 ) != NULL ) {
94- if (strcmp (line1 , line2 ) != 0 ) { // If the lines are different
95- printf ("Files differ at line %d:\n" , line_number );
96- printf ("File 1 (%s): %s\n" , expectedData , line1 );
97- printf ("File 2 (%s): %s\n" , reportedData , line2 );
98- fclose (f1 );
99- fclose (f2 );
100- return 1 ; // Return 1 as soon as a difference is found
101- }
102- line_number ++ ;
103- }
104-
105- // Handle case where one file has more lines
106- if (fgets (line1 , sizeof (line1 ), f1 ) != NULL || fgets (line2 , sizeof (line2 ), f2 ) != NULL ) {
107- printf ("Files differ at line %d:\n" , line_number );
108- if (fgets (line1 , sizeof (line1 ), f1 ) != NULL ) {
109- printf ("File 1 (%s): %s\n" , expectedData , line1 );
110- } else {
111- printf ("File 1 (%s): (no more lines)\n" , expectedData );
112- }
113-
114- if (fgets (line2 , sizeof (line2 ), f2 ) != NULL ) {
115- printf ("File 2 (%s): %s\n" , reportedData , line2 );
116- } else {
117- printf ("File 2 (%s): (no more lines)\n" , reportedData );
118- }
119-
120- fclose (f1 );
121- fclose (f2 );
122- return 1 ; // Files are different if one ends before the other
123- }
124-
125- fclose (f1 );
126- fclose (f2 );
127- return 0 ; // Files are identical
80+ static int diff_files (const char * expectedData , const char * reportedData )
81+ {
82+ FILE * f1 = fopen (expectedData , "r" );
83+ FILE * f2 = fopen (reportedData , "r" );
84+
85+ if (f1 == NULL || f2 == NULL ) {
86+ perror ("Error opening file" );
87+ return 1 ;
88+ }
89+
90+ char line1 [2048 ], line2 [2048 ];
91+ int line_number = 1 ; // Line number counter
92+
93+ // Compare lines until one of the files ends
94+ while (fgets (line1 , sizeof (line1 ), f1 ) != NULL &&
95+ fgets (line2 , sizeof (line2 ), f2 ) != NULL ) {
96+ if (strcmp (line1 , line2 ) != 0 ) { // If the lines are different
97+ printf ("Files differ at line %d:\n" , line_number );
98+ printf ("File 1 (%s): %s\n" , expectedData , line1 );
99+ printf ("File 2 (%s): %s\n" , reportedData , line2 );
100+ fclose (f1 );
101+ fclose (f2 );
102+ return 1 ; // Return 1 as soon as a difference is found
103+ }
104+ line_number ++ ;
105+ }
106+
107+ // Handle case where one file has more lines
108+ if (fgets (line1 , sizeof (line1 ), f1 ) != NULL ||
109+ fgets (line2 , sizeof (line2 ), f2 ) != NULL ) {
110+ printf ("Files differ at line %d:\n" , line_number );
111+ if (fgets (line1 , sizeof (line1 ), f1 ) != NULL ) {
112+ printf ("File 1 (%s): %s\n" , expectedData , line1 );
113+ } else {
114+ printf ("File 1 (%s): (no more lines)\n" , expectedData );
115+ }
116+
117+ if (fgets (line2 , sizeof (line2 ), f2 ) != NULL ) {
118+ printf ("File 2 (%s): %s\n" , reportedData , line2 );
119+ } else {
120+ printf ("File 2 (%s): (no more lines)\n" , reportedData );
121+ }
122+
123+ fclose (f1 );
124+ fclose (f2 );
125+ return 1 ; // Files are different if one ends before the other
126+ }
127+
128+ fclose (f1 );
129+ fclose (f2 );
130+ return 0 ; // Files are identical
128131}
129132
130133#endif //__COMMON_H_
0 commit comments