1 /* Copyright (c) 2014-2019. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
16 #include "src/mc/mc_private.hpp"
18 #include "src/mc/ObjectInformation.hpp"
19 #include "src/mc/Type.hpp"
20 #include "src/mc/Variable.hpp"
21 #include "src/mc/remote/RemoteClient.hpp"
23 static std::default_random_engine rnd_engine;
25 static simgrid::mc::RemoteClient* process;
28 uintptr_t eval_binary_operation(
29 simgrid::dwarf::ExpressionContext& state, int op, uintptr_t a, uintptr_t b) {
32 ops[0].atom = DW_OP_const8u;
34 ops[1].atom = DW_OP_const8u;
38 simgrid::dwarf::ExpressionStack stack;
41 simgrid::dwarf::execute(ops, 3, state, stack);
42 } catch (const std::runtime_error&) {
43 fprintf(stderr,"Expression evaluation error");
46 assert(stack.size() == 1);
51 void basic_test(simgrid::dwarf::ExpressionContext const& state) {
56 uintptr_t a = rnd_engine();
57 uintptr_t b = rnd_engine();
59 simgrid::dwarf::ExpressionStack stack;
61 bool caught_ex = false;
63 ops[0].atom = DW_OP_drop;
64 simgrid::dwarf::execute(ops, 1, state, stack);
65 } catch (const simgrid::dwarf::evaluation_error&) {
69 fprintf(stderr, "Exception expected");
71 ops[0].atom = DW_OP_lit21;
72 simgrid::dwarf::execute(ops, 1, state, stack);
73 assert(stack.size() == 1);
74 assert(stack.top() == 21);
76 ops[0].atom = DW_OP_const8u;
78 simgrid::dwarf::execute(ops, 1, state, stack);
79 assert(stack.size() == 2);
80 assert(stack.top() == a);
82 ops[0].atom = DW_OP_drop;
83 ops[1].atom = DW_OP_drop;
84 simgrid::dwarf::execute(ops, 2, state, stack);
85 assert(stack.empty());
88 ops[0].atom = DW_OP_lit21;
89 ops[1].atom = DW_OP_plus_uconst;
91 simgrid::dwarf::execute(ops, 2, state, stack);
92 assert(stack.size() == 1);
93 assert(stack.top() == a + 21);
96 ops[0].atom = DW_OP_const8u;
98 ops[1].atom = DW_OP_dup;
99 ops[2].atom = DW_OP_plus;
100 simgrid::dwarf::execute(ops, 3, state, stack);
101 assert(stack.size() == 1);
102 assert(stack.top() == a + a);
105 ops[0].atom = DW_OP_const8u;
107 ops[1].atom = DW_OP_const8u;
109 ops[2].atom = DW_OP_over;
110 simgrid::dwarf::execute(ops, 3, state, stack);
111 assert(stack.size() == 3);
112 assert(stack.top() == a);
113 assert(stack.top(1) == b);
114 assert(stack.top(2) == a);
117 ops[0].atom = DW_OP_const8u;
119 ops[1].atom = DW_OP_const8u;
121 ops[2].atom = DW_OP_swap;
122 simgrid::dwarf::execute(ops, 3, state, stack);
123 assert(stack.size() == 2);
124 assert(stack.top() == a);
125 assert(stack.top(1) == b);
127 } catch (const std::runtime_error&) {
128 fprintf(stderr,"Expression evaluation error");
133 void test_deref(simgrid::dwarf::ExpressionContext const& state) {
139 ops[0].atom = DW_OP_const8u;
140 ops[0].number = (uintptr_t) &foo;
141 ops[1].atom = DW_OP_deref;
143 simgrid::dwarf::ExpressionStack stack;
145 simgrid::dwarf::execute(ops, 2, state, stack);
146 assert(stack.size() == 1);
147 assert(stack.top() == foo);
149 } catch (const std::runtime_error&) {
150 fprintf(stderr,"Expression evaluation error");
154 int main(int argc, char** argv) {
155 process = new simgrid::mc::RemoteClient(getpid(), -1);
158 simgrid::dwarf::ExpressionContext state;
159 state.address_space = (simgrid::mc::AddressSpace*) process;
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_plus, 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_or, 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_and, a, b) == (a & b));
181 for(int i=0; i!=100; ++i) {
182 uintptr_t a = rnd_engine();
183 uintptr_t b = rnd_engine();
184 assert(eval_binary_operation(state, DW_OP_xor, a, b) == (a ^ b));