Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
test local version of gras, not the installed one; use gras_init now that it exists...
[simgrid.git] / testsuite / gras / 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
29 print "xbt_error_t write_read(gras_datadesc_type_t type,void *src, void *dst, gras_socket_t *sock, int direction);\n\n";
30
31 my ($i,$j,$k,$l);
32 my $max=scalar @types;
33 my $maxl=0; # set it to "$max-1" to do 2401 tests (takes for ever to compile)
34 for $i (0..$max-1) { for $j (0..$max-1) { for $k (0..$max-1) { for $l (0..$maxl) {
35     print "GRAS_DEFINE_TYPE(".$abrev[$i].$abrev[$j].$abrev[$k].$abrev[$l].",".
36       "struct ".$abrev[$i].$abrev[$j].$abrev[$k].$abrev[$l]." { ".
37         $types[$i]." a; ".
38         $types[$j]." b; ".
39         $types[$k]." c;".
40         $types[$l]." d;".
41       "};)\n";
42 }}}}
43
44 # print "\n#define test(a) do {if (!(a)) { failed = 1; ERROR1(\"%s failed\",#a);}} while (0)\n";
45  print "\n#define test(a) xbt_assert(a)\n";
46
47 print "\nxbt_error_t test_structures(gras_socket_t *sock, int direction);\n";
48 print "\nxbt_error_t test_structures(gras_socket_t *sock, int direction) {\n";
49 print "  xbt_error_t errcode;\n";
50 for $i (0..$max-1) { for $j (0..$max-1) { for $k (0..$max-1) { for $l (0..$maxl) {
51     my $struct=$abrev[$i].$abrev[$j].$abrev[$k].$abrev[$l];
52     print "  struct $struct my_$struct = {".$val[$i]."+(".$types[$i].")1,"
53                                            .$val[$j]."+(".$types[$j].")2,"
54                                            .$val[$k]."+(".$types[$k].")3,"
55                                            .$val[$l]."+(".$types[$l].")4}, my_${struct}2;\n";
56 }}}}
57
58 print "  INFO0(\"---- Test on all possible struct having 3 fields (".($max*$max*$max*($maxl+1))." structs) ----\");\n";
59 for $i (0..$max-1) { for $j (0..$max-1) { for $k (0..$max-1) { for $l (0..$maxl) {
60     my $struct=$abrev[$i].$abrev[$j].$abrev[$k].$abrev[$l];
61     print "  TRY(write_read(gras_datadesc_by_symbol($struct), &my_$struct, &my_${struct}2, sock,direction));\n";
62     print "  if (direction == READ || direction == RW) {\n";
63     print "     int failed = 0;\n";
64     print "     test(my_$struct.a == my_${struct}2.a);\n";
65     print "     test(my_$struct.b == my_${struct}2.b);\n";
66     print "     test(my_$struct.c == my_${struct}2.c);\n";
67     print "     test(my_$struct.d == my_${struct}2.d);\n";
68     print "     if (!failed) VERB0(\"Passed $struct\");\n";
69     print "  }\n";
70 }}}}
71     print "  return no_error;\n";
72     print "}\n";
73     ;