1 /* Copyright (c) 2014-2018. 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. */
15 #include "src/mc/mc_private.hpp"
17 #include "src/mc/ObjectInformation.hpp"
18 #include "src/mc/Type.hpp"
19 #include "src/mc/Variable.hpp"
20 #include "src/mc/remote/RemoteClient.hpp"
22 static simgrid::mc::RemoteClient* process;
25 uintptr_t eval_binary_operation(
26 simgrid::dwarf::ExpressionContext& state, int op, uintptr_t a, uintptr_t b) {
29 ops[0].atom = DW_OP_const8u;
31 ops[1].atom = DW_OP_const8u;
35 simgrid::dwarf::ExpressionStack stack;
38 simgrid::dwarf::execute(ops, 3, state, stack);
40 catch(std::runtime_error& e) {
41 fprintf(stderr,"Expression evaluation error");
44 assert(stack.size() == 1);
49 void basic_test(simgrid::dwarf::ExpressionContext const& state) {
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 (simgrid::dwarf::evaluation_error& e) {
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);
126 catch(std::runtime_error& e) {
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);
149 catch(std::runtime_error& e) {
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 = rand();
165 uintptr_t b = rand();
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 = rand();
171 uintptr_t b = rand();
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 = rand();
177 uintptr_t b = rand();
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 = rand();
183 uintptr_t b = rand();
184 assert(eval_binary_operation(state, DW_OP_xor, a, b) == (a ^ b));