X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/49e85177c669d793e84242983a1b1f430e47184e..dc9d4601416c48fbfed05be80d69cb7fd0d56794:/testsuite/mc/dwarf_expression.c diff --git a/testsuite/mc/dwarf_expression.c b/testsuite/mc/dwarf_expression.c new file mode 100644 index 0000000000..1ff04d5efb --- /dev/null +++ b/testsuite/mc/dwarf_expression.c @@ -0,0 +1,122 @@ +#ifdef NDEBUG +#undef NDEBUG +#endif + +#include +#include +#include + +#include "../src/mc/mc_private.h" + +uintptr_t eval_binary_operation(mc_expression_state_t state, int op, uintptr_t a, uintptr_t b) { + state->stack_size = 0; + + Dwarf_Op ops[15]; + ops[0].atom = DW_OP_addr; + ops[0].number = a; + ops[1].atom = DW_OP_addr; + ops[1].number = b; + ops[2].atom = op; + + assert(mc_dwarf_execute_expression(3, ops, state) == MC_EXPRESSION_OK); + assert(state->stack_size==1); + return state->stack[state->stack_size - 1]; +} + +void basic_test(mc_expression_state_t state) { + Dwarf_Op ops[60]; + + uintptr_t a = rand(); + uintptr_t b = rand(); + + ops[0].atom = DW_OP_drop; + assert(mc_dwarf_execute_expression(1, ops, state) == MC_EXPRESSION_E_STACK_UNDERFLOW); + + ops[0].atom = DW_OP_lit21; + assert(mc_dwarf_execute_expression(1, ops, state) == MC_EXPRESSION_OK); + assert(state->stack_size==1); + assert(state->stack[state->stack_size-1]==21); + + ops[0].atom = DW_OP_addr; + ops[0].number = a; + assert(mc_dwarf_execute_expression(1, ops, state) == MC_EXPRESSION_OK); + assert(state->stack_size==2); + assert(state->stack[state->stack_size-1] == a); + + ops[0].atom = DW_OP_drop; + ops[1].atom = DW_OP_drop; + assert(mc_dwarf_execute_expression(2, ops, state) == MC_EXPRESSION_OK); + assert(state->stack_size==0); + + ops[0].atom = DW_OP_lit21; + ops[1].atom = DW_OP_plus_uconst; + ops[1].number = a; + assert(mc_dwarf_execute_expression(2, ops, state) == MC_EXPRESSION_OK); + assert(state->stack_size==1); + assert(state->stack[state->stack_size-1]== a + 21); + + state->stack_size = 0; + ops[0].atom = DW_OP_addr; + ops[0].number = a; + ops[1].atom = DW_OP_dup; + ops[2].atom = DW_OP_plus; + assert(mc_dwarf_execute_expression(3, ops, state) == MC_EXPRESSION_OK); + assert(state->stack_size==1); + assert(state->stack[state->stack_size-1]== a + a); + + state->stack_size = 0; + ops[0].atom = DW_OP_addr; + ops[0].number = a; + ops[1].atom = DW_OP_addr; + ops[1].number = b; + ops[2].atom = DW_OP_over; + assert(mc_dwarf_execute_expression(3, ops, state) == MC_EXPRESSION_OK); + assert(state->stack_size==3); + assert(state->stack[state->stack_size-1]== a); + assert(state->stack[state->stack_size-2]== b); + assert(state->stack[state->stack_size-3]== a); + + state->stack_size = 0; + ops[0].atom = DW_OP_addr; + ops[0].number = a; + ops[1].atom = DW_OP_addr; + ops[1].number = b; + ops[2].atom = DW_OP_swap; + assert(mc_dwarf_execute_expression(3, ops, state) == MC_EXPRESSION_OK); + assert(state->stack_size=2); + assert(state->stack[state->stack_size-1]== a); + assert(state->stack[state->stack_size-2]== b); +} + +int main(int argc, char** argv) { + s_mc_expression_state_t state; + memset(&state, 0, sizeof(s_mc_expression_state_t)); + + basic_test(&state); + + for(int i=0; i!=100; ++i) { + uintptr_t a = rand(); + uintptr_t b = rand(); + assert(eval_binary_operation(&state, DW_OP_plus, a, b) == (a + b)); + } + + for(int i=0; i!=100; ++i) { + uintptr_t a = rand(); + uintptr_t b = rand(); + assert(eval_binary_operation(&state, DW_OP_or, a, b) == (a | b)); + } + + for(int i=0; i!=100; ++i) { + uintptr_t a = rand(); + uintptr_t b = rand(); + assert(eval_binary_operation(&state, DW_OP_and, a, b) == (a & b)); + } + + for(int i=0; i!=100; ++i) { + uintptr_t a = rand(); + uintptr_t b = rand(); + assert(eval_binary_operation(&state, DW_OP_xor, a, b) == (a ^ b)); + } + + return 0; +}