Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Erm. Really revalidate this dataset (old one must be removed before regeneration...
[simgrid.git] / teshsuite / gras / datadesc / mk_datadesc_structs.pl
1 #! /usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 my @types;
7 my @abrev;
8 my @val;
9
10 push @types,"char";          push @abrev, "c"; push @val, "'w'";
11 push @types,"short int";     push @abrev, "s"; push @val, '134';
12 push @types,"int";           push @abrev, "i"; push @val, '-11249';
13 push @types,"long int";      push @abrev, "l"; push @val, '31319919';
14 push @types,"long long int"; push @abrev, "L"; push @val, '-232130010';
15 push @types,"float";         push @abrev, "f"; push @val, '-11313.1135';
16 push @types,"double";        push @abrev, "d"; push @val, '1424420.11331';
17
18 die 'scalar @types != scalar @abrev' unless (scalar @types == scalar @abrev);
19
20 print "/* This file is perl-generated, of course */\n\n";
21
22 print "#include \"gras.h\"\n\n";
23
24 print "XBT_LOG_NEW_DEFAULT_SUBCATEGORY(structs,test,\"Logs about the gigantic struct test\");\n\n";
25
26 print "#define READ  0\n#define WRITE 1\n#define RW    2\n\n";
27   
28 print "void write_read(const char *type,void *src, void *dst, gras_socket_t *sock, int direction);\n\n";
29
30 my ($i,$j,$k,$l);
31 my $max=scalar @types;
32 # Those max variables can be used to tune how much test you are ready to do.
33 # But WARNING! changing them naturally invalidate any existing data file.
34 my $max_i=$max-1;
35 my $max_j=0;     
36 my $max_k=$max-1;
37 my $max_l=0;     
38 for $i (0..$max_i) { for $j (0..$max_j) { for $k (0..$max_k) { for $l (0..$max_l) {
39     print "GRAS_DEFINE_TYPE(".$abrev[$i].$abrev[$j].$abrev[$k].$abrev[$l].",".
40       "struct ".$abrev[$i].$abrev[$j].$abrev[$k].$abrev[$l]." { ".
41         $types[$i]." a; ".
42         $types[$j]." b; ".
43         $types[$k]." c;".
44         $types[$l]." d;".
45       "};)\n";
46 }}}}
47
48 # print "\n#define test(a) do {if (!(a)) { failed = 1; ERROR1(\"%s failed\",#a);}} while (0)\n";
49  print "\n#define test(a) xbt_assert(a)\n";
50
51 print "void register_structures(void);\n";
52 print "void register_structures(void) {\n";
53 for $i (0..$max_i) { for $j (0..$max_j) { for $k (0..$max_k) { for $l (0..$max_l) {
54     my $struct=$abrev[$i].$abrev[$j].$abrev[$k].$abrev[$l];
55     print "  gras_msgtype_declare(\"$struct\", gras_datadesc_by_symbol($struct));\n";
56 }}}}
57 print "}\n";
58
59 print "void test_structures(gras_socket_t *sock, int direction);\n";
60 print "void test_structures(gras_socket_t *sock, int direction) {\n";
61 for $i (0..$max_i) { for $j (0..$max_j) { for $k (0..$max_k) { for $l (0..$max_l) {
62     my $struct=$abrev[$i].$abrev[$j].$abrev[$k].$abrev[$l];
63     print "  struct $struct my_$struct = {".$val[$i]."+(".$types[$i].")1,"
64                                            .$val[$j]."+(".$types[$j].")2,"
65                                            .$val[$k]."+(".$types[$k].")3,"
66                                            .$val[$l]."+(".$types[$l].")4}, my_${struct}2;\n";
67 }}}}
68
69 print "  INFO0(\"---- Test on all possible struct having 3 fields (".(($max_i+1)*($max_j+1)*($max_k+1)*($max_l+1))." structs) ----\");\n";
70 for $i (0..$max_i) { for $j (0..$max_j) { for $k (0..$max_k) { for $l (0..$max_l) {
71     my $struct=$abrev[$i].$abrev[$j].$abrev[$k].$abrev[$l];
72     print "  write_read(\"$struct\", &my_$struct, &my_${struct}2, sock,direction);\n";
73     print "  if (direction == READ || direction == RW) {\n";
74     print "     int failed = 0;\n";
75     print "     test(my_$struct.a == my_${struct}2.a);\n";
76     print "     test(my_$struct.b == my_${struct}2.b);\n";
77     print "     test(my_$struct.c == my_${struct}2.c);\n";
78     print "     test(my_$struct.d == my_${struct}2.d);\n";
79     print "     if (!failed) VERB0(\"Passed $struct\");\n";
80     print "  }\n";
81 }}}}
82     print "}\n";
83     ;