1 /* Copyright (c) 2014-2019. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
10 #include "src/mc/mc_private.hpp"
12 #include "src/mc/inspect/ObjectInformation.hpp"
13 #include "src/mc/inspect/Type.hpp"
14 #include "src/mc/inspect/Variable.hpp"
15 #include "src/mc/remote/RemoteClient.hpp"
22 static std::default_random_engine rnd_engine;
24 static simgrid::mc::RemoteClient* process;
27 uintptr_t eval_binary_operation(
28 simgrid::dwarf::ExpressionContext& state, int op, uintptr_t a, uintptr_t b) {
31 ops[0].atom = DW_OP_const8u;
33 ops[1].atom = DW_OP_const8u;
37 simgrid::dwarf::ExpressionStack stack;
39 simgrid::dwarf::execute(ops, 3, state, stack);
40 } catch (const simgrid::dwarf::evaluation_error&) {
41 fprintf(stderr,"Expression evaluation error");
44 assert(stack.size() == 1);
49 void basic_test(simgrid::dwarf::ExpressionContext const& state) {
54 uintptr_t a = rnd_engine();
55 uintptr_t b = rnd_engine();
57 simgrid::dwarf::ExpressionStack stack;
59 bool caught_ex = false;
61 ops[0].atom = DW_OP_drop;
62 simgrid::dwarf::execute(ops, 1, state, stack);
63 } catch (const simgrid::dwarf::evaluation_error&) {
67 fprintf(stderr, "Exception expected");
69 ops[0].atom = DW_OP_lit21;
70 simgrid::dwarf::execute(ops, 1, state, stack);
71 assert(stack.size() == 1);
72 assert(stack.top() == 21);
74 ops[0].atom = DW_OP_const8u;
76 simgrid::dwarf::execute(ops, 1, state, stack);
77 assert(stack.size() == 2);
78 assert(stack.top() == a);
80 ops[0].atom = DW_OP_drop;
81 ops[1].atom = DW_OP_drop;
82 simgrid::dwarf::execute(ops, 2, state, stack);
83 assert(stack.empty());
86 ops[0].atom = DW_OP_lit21;
87 ops[1].atom = DW_OP_plus_uconst;
89 simgrid::dwarf::execute(ops, 2, state, stack);
90 assert(stack.size() == 1);
91 assert(stack.top() == a + 21);
94 ops[0].atom = DW_OP_const8u;
96 ops[1].atom = DW_OP_dup;
97 ops[2].atom = DW_OP_plus;
98 simgrid::dwarf::execute(ops, 3, state, stack);
99 assert(stack.size() == 1);
100 assert(stack.top() == a + a);
103 ops[0].atom = DW_OP_const8u;
105 ops[1].atom = DW_OP_const8u;
107 ops[2].atom = DW_OP_over;
108 simgrid::dwarf::execute(ops, 3, state, stack);
109 assert(stack.size() == 3);
110 assert(stack.top() == a);
111 assert(stack.top(1) == b);
112 assert(stack.top(2) == a);
115 ops[0].atom = DW_OP_const8u;
117 ops[1].atom = DW_OP_const8u;
119 ops[2].atom = DW_OP_swap;
120 simgrid::dwarf::execute(ops, 3, state, stack);
121 assert(stack.size() == 2);
122 assert(stack.top() == a);
123 assert(stack.top(1) == b);
125 } catch (const simgrid::dwarf::evaluation_error&) {
126 fprintf(stderr,"Expression evaluation error");
131 void test_deref(simgrid::dwarf::ExpressionContext const& state) {
137 ops[0].atom = DW_OP_const8u;
138 ops[0].number = (uintptr_t) &foo;
139 ops[1].atom = DW_OP_deref;
141 simgrid::dwarf::ExpressionStack stack;
143 simgrid::dwarf::execute(ops, 2, state, stack);
144 assert(stack.size() == 1);
145 assert(stack.top() == foo);
147 } catch (const simgrid::dwarf::evaluation_error&) {
148 fprintf(stderr,"Expression evaluation error");
154 process = new simgrid::mc::RemoteClient(getpid(), -1);
157 simgrid::dwarf::ExpressionContext state;
158 state.address_space = (simgrid::mc::AddressSpace*) process;
162 for(int i=0; i!=100; ++i) {
163 uintptr_t a = rnd_engine();
164 uintptr_t b = rnd_engine();
165 assert(eval_binary_operation(state, DW_OP_plus, a, b) == (a + b));
168 for(int i=0; i!=100; ++i) {
169 uintptr_t a = rnd_engine();
170 uintptr_t b = rnd_engine();
171 assert(eval_binary_operation(state, DW_OP_or, a, b) == (a | b));
174 for(int i=0; i!=100; ++i) {
175 uintptr_t a = rnd_engine();
176 uintptr_t b = rnd_engine();
177 assert(eval_binary_operation(state, DW_OP_and, a, b) == (a & b));
180 for(int i=0; i!=100; ++i) {
181 uintptr_t a = rnd_engine();
182 uintptr_t b = rnd_engine();
183 assert(eval_binary_operation(state, DW_OP_xor, a, b) == (a ^ b));