Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add code coverage for simgrid compilation
[simgrid.git] / buildtools / CPACK / prog_test / prog_GRAS_CHECK_STRUCT_COMPACTION.c
diff --git a/buildtools/CPACK/prog_test/prog_GRAS_CHECK_STRUCT_COMPACTION.c b/buildtools/CPACK/prog_test/prog_GRAS_CHECK_STRUCT_COMPACTION.c
new file mode 100644 (file)
index 0000000..5364c38
--- /dev/null
@@ -0,0 +1,58 @@
+#include <sys/types.h>
+#include <stddef.h> /* offsetof() */
+#include <stdio.h>
+
+void main (void)
+{
+
+struct s0 {char c0; double d0;};
+struct s1 {double d1; int i1; char c1;};
+struct s2 {double d2; int i2; char c2[6];};
+struct s3 {double d3; int a3; int b3;}; 
+
+int gras_struct_packed;
+int gras_struct_compact;
+int gras_array_straddle_struct;
+int gras_compact_struct;
+
+       if (sizeof(struct s0) == sizeof(double)+sizeof(char))
+       {
+               gras_struct_packed=1;
+       }
+       else
+       {
+               gras_struct_packed=0;
+       }
+       if (offsetof(struct s1,c1) == sizeof(double)+sizeof(int))
+       {
+               gras_struct_compact=1;
+       }
+       else
+       {
+               gras_struct_compact=0;
+       }
+       if (offsetof(struct s2,c2) == sizeof(double)+sizeof(int))
+       {
+               gras_array_straddle_struct=1;
+       }
+       else
+       {
+               gras_array_straddle_struct=0;
+       }
+       if (offsetof(struct s3,b3) == sizeof(double)+sizeof(int))
+       {
+               gras_compact_struct=1;
+       }
+       else
+       {
+               gras_compact_struct=0;
+       }
+
+
+       if(gras_struct_packed == 0 && gras_struct_compact == 1) printf("GRAS_STRUCT_COMPACT ");
+
+       if(gras_array_straddle_struct == 1) printf("GRAS_ARRAY_STRADDLE_STRUCT ");
+
+       if(gras_compact_struct == 1) printf("GRAS_COMPACT_STRUCT ");
+
+}