11 #include "../../src/include/mc/datatypes.h"
12 #include "../../src/mc/mc_private.h"
14 int test_some_array[4][5][6];
15 struct some_struct { int first; int second[4][5]; } test_some_struct;
17 static dw_type_t find_type_by_name(mc_object_info_t info, const char* name) {
18 xbt_dict_cursor_t cursor = NULL;
21 xbt_dict_foreach(info->types, cursor, key, type) {
22 if(!strcmp(name, type->name))
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))
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);
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);
54 static dw_type_t find_type(mc_object_info_t info, const char* name, dw_type_t type) {
55 unsigned int cursor = 0;
57 xbt_dynar_foreach(type->members, cursor, member){
58 if(!strcmp(name,member->name))
64 int some_local_variable = 0;
66 int main(int argc, char** argv) {
68 // xbt_init(&argc, argv);
69 SIMIX_global_init(&argc, argv);
76 var = test_global_variable(mc_binary_info, "some_local_variable", &some_local_variable, sizeof(int));
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);
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);