1 /* Copyright (c) 2014-2020. 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/RemoteSimulation.hpp"
22 static std::default_random_engine rnd_engine;
24 static simgrid::mc::RemoteSimulation* process;
26 static uintptr_t eval_binary_operation(simgrid::dwarf::ExpressionContext const& state, uint8_t op, uintptr_t a,
30 ops[0].atom = DW_OP_const8u;
32 ops[1].atom = DW_OP_const8u;
36 simgrid::dwarf::ExpressionStack stack;
38 simgrid::dwarf::execute(ops, 3, state, stack);
39 } catch (const simgrid::dwarf::evaluation_error&) {
40 fprintf(stderr,"Expression evaluation error");
43 assert(stack.size() == 1);
47 static void basic_test(simgrid::dwarf::ExpressionContext const& state)
52 uintptr_t a = rnd_engine();
53 uintptr_t b = rnd_engine();
55 simgrid::dwarf::ExpressionStack stack;
57 bool caught_ex = false;
59 ops[0].atom = DW_OP_drop;
60 simgrid::dwarf::execute(ops, 1, state, stack);
61 } catch (const simgrid::dwarf::evaluation_error&) {
65 fprintf(stderr, "Exception expected");
67 ops[0].atom = DW_OP_lit21;
68 simgrid::dwarf::execute(ops, 1, state, stack);
69 assert(stack.size() == 1);
70 assert(stack.top() == 21);
72 ops[0].atom = DW_OP_const8u;
74 simgrid::dwarf::execute(ops, 1, state, stack);
75 assert(stack.size() == 2);
76 assert(stack.top() == a);
78 ops[0].atom = DW_OP_drop;
79 ops[1].atom = DW_OP_drop;
80 simgrid::dwarf::execute(ops, 2, state, stack);
81 assert(stack.empty());
84 ops[0].atom = DW_OP_lit21;
85 ops[1].atom = DW_OP_plus_uconst;
87 simgrid::dwarf::execute(ops, 2, state, stack);
88 assert(stack.size() == 1);
89 assert(stack.top() == a + 21);
92 ops[0].atom = DW_OP_const8u;
94 ops[1].atom = DW_OP_dup;
95 ops[2].atom = DW_OP_plus;
96 simgrid::dwarf::execute(ops, 3, state, stack);
97 assert(stack.size() == 1);
98 assert(stack.top() == a + a);
101 ops[0].atom = DW_OP_const8u;
103 ops[1].atom = DW_OP_const8u;
105 ops[2].atom = DW_OP_over;
106 simgrid::dwarf::execute(ops, 3, state, stack);
107 assert(stack.size() == 3);
108 assert(stack.top() == a);
109 assert(stack.top(1) == b);
110 assert(stack.top(2) == a);
113 ops[0].atom = DW_OP_const8u;
115 ops[1].atom = DW_OP_const8u;
117 ops[2].atom = DW_OP_swap;
118 simgrid::dwarf::execute(ops, 3, state, stack);
119 assert(stack.size() == 2);
120 assert(stack.top() == a);
121 assert(stack.top(1) == b);
122 } catch (const simgrid::dwarf::evaluation_error&) {
123 fprintf(stderr,"Expression evaluation error");
127 static void test_deref(simgrid::dwarf::ExpressionContext const& state)
133 ops[0].atom = DW_OP_const8u;
134 ops[0].number = (uintptr_t)&foo;
135 ops[1].atom = DW_OP_deref;
137 simgrid::dwarf::ExpressionStack stack;
139 simgrid::dwarf::execute(ops, 2, state, stack);
140 assert(stack.size() == 1);
141 assert(stack.top() == foo);
142 } catch (const simgrid::dwarf::evaluation_error&) {
143 fprintf(stderr,"Expression evaluation error");
149 process = new simgrid::mc::RemoteSimulation(getpid());
152 simgrid::dwarf::ExpressionContext state;
153 state.address_space = (simgrid::mc::AddressSpace*) process;
157 for(int i=0; i!=100; ++i) {
158 uintptr_t a = rnd_engine();
159 uintptr_t b = rnd_engine();
160 assert(eval_binary_operation(state, DW_OP_plus, a, b) == (a + b));
163 for(int i=0; i!=100; ++i) {
164 uintptr_t a = rnd_engine();
165 uintptr_t b = rnd_engine();
166 assert(eval_binary_operation(state, DW_OP_or, a, b) == (a | b));
169 for(int i=0; i!=100; ++i) {
170 uintptr_t a = rnd_engine();
171 uintptr_t b = rnd_engine();
172 assert(eval_binary_operation(state, DW_OP_and, a, b) == (a & b));
175 for(int i=0; i!=100; ++i) {
176 uintptr_t a = rnd_engine();
177 uintptr_t b = rnd_engine();
178 assert(eval_binary_operation(state, DW_OP_xor, a, b) == (a ^ b));