Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Partial implementation of DWARF expression evaluator
[simgrid.git] / testsuite / mc / dwarf.c
1 #ifdef NDEBUG
2 #undef NDEBUG
3 #endif
4
5 #include <string.h>
6 #include <assert.h>
7
8 #include <xbt.h>
9 #include <mc/mc.h>
10
11 #include "../../src/include/mc/datatypes.h"
12 #include "../../src/mc/mc_private.h"
13
14 int test_some_array[4][5][6];
15 struct some_struct { int first; int second[4][5]; } test_some_struct;
16
17 static dw_type_t find_type_by_name(mc_object_info_t info, const char* name) {
18   xbt_dict_cursor_t cursor = NULL;
19   char *key;
20   dw_type_t type;
21   xbt_dict_foreach(info->types, cursor, key, type) {
22     if(!strcmp(name, type->name))
23       return type;
24   }
25
26   return NULL;
27 }
28
29 static dw_variable_t find_global_variable_by_name(mc_object_info_t info, const char* name) {
30   unsigned int cursor = 0;
31   dw_variable_t variable;
32   xbt_dynar_foreach(info->global_variables, cursor, variable){
33     if(!strcmp(name, variable->name))
34       return variable;
35   }
36
37   return NULL;
38 }
39
40 static dw_variable_t test_global_variable(mc_object_info_t info, const char* name, void* address, long byte_size) {
41   dw_variable_t variable = find_global_variable_by_name(info, name);
42   xbt_assert(variable, "Global variable %s was not found", name);
43   xbt_assert(!strcmp(variable->name, name), "Name mismatch for %s", name);
44   xbt_assert(variable->global, "Variable %s is not global", name);
45   xbt_assert(variable->address == address,
46       "Address mismatch for %s : %p expected but %p found", name, address, variable->address);
47
48   dw_type_t type = xbt_dict_get_or_null(mc_binary_info->types, variable->type_origin);
49   xbt_assert(type!=NULL, "Missing type for %s", name);
50   xbt_assert(type->byte_size = byte_size, "Byte size mismatch for %s", name);
51   return variable;
52 }
53
54 static dw_type_t find_type(mc_object_info_t info, const char* name, dw_type_t type) {
55   unsigned int cursor = 0;
56   dw_type_t member;
57   xbt_dynar_foreach(type->members, cursor, member){
58     if(!strcmp(name,member->name))
59       return member;
60   }
61   return NULL;
62 }
63
64 int some_local_variable = 0;
65
66 int main(int argc, char** argv) {
67
68   // xbt_init(&argc, argv);
69   SIMIX_global_init(&argc, argv);
70   MC_memory_init();
71   MC_init();
72
73   dw_variable_t var;
74   dw_type_t type;
75
76   var = test_global_variable(mc_binary_info, "some_local_variable", &some_local_variable, sizeof(int));
77
78   var = test_global_variable(mc_binary_info, "test_some_array", &test_some_array, sizeof(test_some_array));
79   type = xbt_dict_get_or_null(mc_binary_info->types, var->type_origin);
80   xbt_assert(type->element_count == 6*5*4, "element_count mismatch in test_some_array : %i / %i", type->element_count, 6*5*4);
81
82   var = test_global_variable(mc_binary_info, "test_some_struct", &test_some_struct, sizeof(test_some_struct));
83   type = xbt_dict_get_or_null(mc_binary_info->types, var->type_origin);
84   assert(find_type(mc_binary_info, "first", type)->offset == 0);
85   assert(find_type(mc_binary_info, "second", type)->offset
86       == ((const char*)&test_some_struct.second) - (const char*)&test_some_struct);
87
88   _exit(0);
89 }