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;
40 simgrid::dwarf::execute(ops, 3, state, stack);
41 } catch (const simgrid::dwarf::evaluation_error&) {
42 fprintf(stderr,"Expression evaluation error");
45 assert(stack.size() == 1);
50 void basic_test(simgrid::dwarf::ExpressionContext const& state) {
55 uintptr_t a = rnd_engine();
56 uintptr_t b = rnd_engine();
58 simgrid::dwarf::ExpressionStack stack;
60 bool caught_ex = false;
62 ops[0].atom = DW_OP_drop;
63 simgrid::dwarf::execute(ops, 1, state, stack);
64 } catch (const simgrid::dwarf::evaluation_error&) {
68 fprintf(stderr, "Exception expected");
70 ops[0].atom = DW_OP_lit21;
71 simgrid::dwarf::execute(ops, 1, state, stack);
72 assert(stack.size() == 1);
73 assert(stack.top() == 21);
75 ops[0].atom = DW_OP_const8u;
77 simgrid::dwarf::execute(ops, 1, state, stack);
78 assert(stack.size() == 2);
79 assert(stack.top() == a);
81 ops[0].atom = DW_OP_drop;
82 ops[1].atom = DW_OP_drop;
83 simgrid::dwarf::execute(ops, 2, state, stack);
84 assert(stack.empty());
87 ops[0].atom = DW_OP_lit21;
88 ops[1].atom = DW_OP_plus_uconst;
90 simgrid::dwarf::execute(ops, 2, state, stack);
91 assert(stack.size() == 1);
92 assert(stack.top() == a + 21);
95 ops[0].atom = DW_OP_const8u;
97 ops[1].atom = DW_OP_dup;
98 ops[2].atom = DW_OP_plus;
99 simgrid::dwarf::execute(ops, 3, state, stack);
100 assert(stack.size() == 1);
101 assert(stack.top() == a + a);
104 ops[0].atom = DW_OP_const8u;
106 ops[1].atom = DW_OP_const8u;
108 ops[2].atom = DW_OP_over;
109 simgrid::dwarf::execute(ops, 3, state, stack);
110 assert(stack.size() == 3);
111 assert(stack.top() == a);
112 assert(stack.top(1) == b);
113 assert(stack.top(2) == a);
116 ops[0].atom = DW_OP_const8u;
118 ops[1].atom = DW_OP_const8u;
120 ops[2].atom = DW_OP_swap;
121 simgrid::dwarf::execute(ops, 3, state, stack);
122 assert(stack.size() == 2);
123 assert(stack.top() == a);
124 assert(stack.top(1) == b);
126 } catch (const simgrid::dwarf::evaluation_error&) {
127 fprintf(stderr,"Expression evaluation error");
132 void test_deref(simgrid::dwarf::ExpressionContext const& state) {
138 ops[0].atom = DW_OP_const8u;
139 ops[0].number = (uintptr_t) &foo;
140 ops[1].atom = DW_OP_deref;
142 simgrid::dwarf::ExpressionStack stack;
144 simgrid::dwarf::execute(ops, 2, state, stack);
145 assert(stack.size() == 1);
146 assert(stack.top() == foo);
148 } catch (const simgrid::dwarf::evaluation_error&) {
149 fprintf(stderr,"Expression evaluation error");
153 int main(int argc, char** argv) {
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));