1 /* Copyright (c) 2014-2015. 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 "mc/mc_process.h"
16 #include "mc/mc_private.h"
17 #include "mc/mc_object_info.h"
19 #include "mc/Type.hpp"
20 #include "mc/ObjectInformation.hpp"
21 #include "mc/Variable.hpp"
23 static simgrid::mc::Process* process;
26 uintptr_t eval_binary_operation(mc_expression_state_t state, int op, uintptr_t a, uintptr_t b) {
27 state->stack_size = 0;
30 ops[0].atom = DW_OP_const8u;
32 ops[1].atom = DW_OP_const8u;
36 assert(mc_dwarf_execute_expression(3, ops, state) == MC_EXPRESSION_OK);
37 assert(state->stack_size==1);
38 return state->stack[state->stack_size - 1];
42 void basic_test(mc_expression_state_t state) {
48 ops[0].atom = DW_OP_drop;
49 assert(mc_dwarf_execute_expression(1, ops, state) == MC_EXPRESSION_E_STACK_UNDERFLOW);
51 ops[0].atom = DW_OP_lit21;
52 assert(mc_dwarf_execute_expression(1, ops, state) == MC_EXPRESSION_OK);
53 assert(state->stack_size==1);
54 assert(state->stack[state->stack_size-1]==21);
56 ops[0].atom = DW_OP_const8u;
58 assert(mc_dwarf_execute_expression(1, ops, state) == MC_EXPRESSION_OK);
59 assert(state->stack_size==2);
60 assert(state->stack[state->stack_size-1] == a);
62 ops[0].atom = DW_OP_drop;
63 ops[1].atom = DW_OP_drop;
64 assert(mc_dwarf_execute_expression(2, ops, state) == MC_EXPRESSION_OK);
65 assert(state->stack_size==0);
67 ops[0].atom = DW_OP_lit21;
68 ops[1].atom = DW_OP_plus_uconst;
70 assert(mc_dwarf_execute_expression(2, ops, state) == MC_EXPRESSION_OK);
71 assert(state->stack_size==1);
72 assert(state->stack[state->stack_size-1]== a + 21);
74 state->stack_size = 0;
75 ops[0].atom = DW_OP_const8u;
77 ops[1].atom = DW_OP_dup;
78 ops[2].atom = DW_OP_plus;
79 assert(mc_dwarf_execute_expression(3, ops, state) == MC_EXPRESSION_OK);
80 assert(state->stack_size==1);
81 assert(state->stack[state->stack_size-1]== a + a);
83 state->stack_size = 0;
84 ops[0].atom = DW_OP_const8u;
86 ops[1].atom = DW_OP_const8u;
88 ops[2].atom = DW_OP_over;
89 assert(mc_dwarf_execute_expression(3, ops, state) == MC_EXPRESSION_OK);
90 assert(state->stack_size==3);
91 assert(state->stack[state->stack_size-1]== a);
92 assert(state->stack[state->stack_size-2]== b);
93 assert(state->stack[state->stack_size-3]== a);
95 state->stack_size = 0;
96 ops[0].atom = DW_OP_const8u;
98 ops[1].atom = DW_OP_const8u;
100 ops[2].atom = DW_OP_swap;
101 assert(mc_dwarf_execute_expression(3, ops, state) == MC_EXPRESSION_OK);
102 assert(state->stack_size=2);
103 assert(state->stack[state->stack_size-1]== a);
104 assert(state->stack[state->stack_size-2]== b);
108 void test_deref(mc_expression_state_t state) {
112 ops[0].atom = DW_OP_const8u;
113 ops[0].number = (uintptr_t) &foo;
114 ops[1].atom = DW_OP_deref;
115 state->stack_size = 0;
117 assert(mc_dwarf_execute_expression(2, ops, state) == MC_EXPRESSION_OK);
118 assert(state->stack_size==1);
119 assert(state->stack[state->stack_size-1] == foo);
122 int main(int argc, char** argv) {
123 process = new simgrid::mc::Process(getpid(), -1);
125 s_mc_expression_state_t state;
126 memset(&state, 0, sizeof(s_mc_expression_state_t));
127 state.address_space = (simgrid::mc::AddressSpace*) process;
131 for(int i=0; i!=100; ++i) {
132 uintptr_t a = rand();
133 uintptr_t b = rand();
134 assert(eval_binary_operation(&state, DW_OP_plus, a, b) == (a + b));
137 for(int i=0; i!=100; ++i) {
138 uintptr_t a = rand();
139 uintptr_t b = rand();
140 assert(eval_binary_operation(&state, DW_OP_or, a, b) == (a | b));
143 for(int i=0; i!=100; ++i) {
144 uintptr_t a = rand();
145 uintptr_t b = rand();
146 assert(eval_binary_operation(&state, DW_OP_and, a, b) == (a & b));
149 for(int i=0; i!=100; ++i) {
150 uintptr_t a = rand();
151 uintptr_t b = rand();
152 assert(eval_binary_operation(&state, DW_OP_xor, a, b) == (a ^ b));