}
-static void
+static int
test_shift(const irop_t *op, test_data_t *data)
{
unsigned num_input_bits, i;
opnd_t *opnds = data->opnds;
+ int tests_done = 0;
/* When testing the 1st operand's undefinedness propagation,
do so with all possible shift amnounts */
valgrind_execute_test(op, data);
check_result_for_binary(op, data);
+ tests_done++;
}
}
// 2nd (right) operand
/* If the operand is an immediate value, there are no v-bits to set. */
- if (op->shift_amount_is_immediate) return;
+ if (op->shift_amount_is_immediate) return tests_done;
num_input_bits = bitsof_irtype(opnds[1].type);
valgrind_execute_test(op, data);
check_result_for_binary(op, data);
+
+ tests_done++;
}
+ return tests_done;
}
}
-static void
+static int
test_and(const irop_t *op, test_data_t *data)
{
unsigned num_input_bits, bitpos;
opnd_t *opnds = data->opnds;
+ int tests_done = 0;
/* Undefinedness does not propagate if the other operand is 0.
Use an all-bits-zero operand and test the other operand in
valgrind_execute_test(op, data);
check_result_for_binary(op, data);
+ tests_done++;
}
// 2nd (right) operand variable, 1st operand all-bits-zero
valgrind_execute_test(op, data);
check_result_for_binary(op, data);
+ tests_done++;
}
/* Undefinedness propagates if the other operand is 1.
valgrind_execute_test(op, data);
check_result_for_binary(op, data);
+ tests_done++;
}
// 2nd (right) operand variable, 1st operand all-bits-one
valgrind_execute_test(op, data);
check_result_for_binary(op, data);
+ tests_done++;
}
+ return tests_done;
}
-static void
+static int
test_or(const irop_t *op, test_data_t *data)
{
unsigned num_input_bits, bitpos;
opnd_t *opnds = data->opnds;
+ int tests_done = 0;
/* Undefinedness does not propagate if the other operand is 1.
Use an all-bits-one operand and test the other operand in
valgrind_execute_test(op, data);
check_result_for_binary(op, data);
+ tests_done++;
}
// 2nd (right) operand variable, 1st operand all-bits-one
valgrind_execute_test(op, data);
check_result_for_binary(op, data);
+ tests_done++;
}
/* Undefinedness propagates if the other operand is 0.
valgrind_execute_test(op, data);
check_result_for_binary(op, data);
+ tests_done++;
}
// 2nd (right) operand variable, 1st operand all-bits-zero
valgrind_execute_test(op, data);
check_result_for_binary(op, data);
+ tests_done++;
}
+ return tests_done;
}
-void
+int
test_binary_op(const irop_t *op, test_data_t *data)
{
unsigned num_input_bits, i, bitpos;
opnd_t *opnds = data->opnds;
+ int tests_done = 0;
/* Handle special cases upfront */
switch (op->undef_kind) {
case UNDEF_SHL:
case UNDEF_SHR:
case UNDEF_SAR:
- test_shift(op, data);
- return;
+ return test_shift(op, data);
case UNDEF_AND:
- test_and(op, data);
- return;
+ return test_and(op, data);
case UNDEF_OR:
- test_or(op, data);
- return;
+ return test_or(op, data);
default:
break;
valgrind_execute_test(op, data);
check_result_for_binary(op, data);
+
+ tests_done++;
}
}
+ return tests_done;
}
main(int argc, char *argv[])
{
assert(sizeof(long long) == 8);
+ int num_unary_tests = 0, num_binary_tests = 0;
+ int num_ternary_tests = 0, num_qernary_tests = 0;
for (int i = 1; i < argc; ++i) {
if (strcmp(argv[i], "-v") == 0) ++verbose;
else if (strcmp(argv[i], "--help") == 0) {
printf("\nvbit-test [ -v | --help ]\n");
- printf("\n\t-v verbose mode; shows IROps being tested\n");
- printf("\n\t-v -v verbose mode, extreme edition\n\n");
+ printf("\n\t-v verbose mode; show number of 1, 2, 3 and 4 operand tests\n");
+ printf("\n\t-v -v verbose mode; shows IROps being tested\n");
+ printf("\n\t-v -v -v verbose mode, extreme edition\n\n");
return 0;
} else {
printf("%s ? Nothing happens.\n", argv[i]);
continue;
}
- if (verbose) printf("Testing operator %s\n", op->name);
+ if (verbose > 1) printf("Testing operator %s\n", op->name);
IRICB iricb = new_iricb(op, data);
switch (iricb.num_operands) {
case 1:
- test_unary_op(op, data);
+ num_unary_tests += test_unary_op(op, data);
break;
case 2:
- test_binary_op(op, data);
+ num_binary_tests += test_binary_op(op, data);
break;
case 3:
- test_ternary_op(op, data);
+ num_ternary_tests += test_ternary_op(op, data);
break;
case 4:
- test_qernary_op(op, data);
+ num_qernary_tests += test_qernary_op(op, data);
break;
default:
free(data);
}
+ if (verbose)
+ printf("\nvbit-test ran %d unary, %d binary, %d ternary and %d qernary tests.\n",
+ num_unary_tests, num_binary_tests, num_ternary_tests,
+ num_qernary_tests);
return 0;
}
}
-void
+int
test_qernary_op(const irop_t *op, test_data_t *data)
{
unsigned num_input_bits, i, bitpos;
opnd_t *opnds = data->opnds;
+ int tests_done = 0;
/* For each operand, set a single bit to undefined and observe how
that propagates to the output. Do this for all bits in each
valgrind_execute_test(op, data);
check_result_for_qernary(op, data);
+
+ tests_done++;
}
}
+ return tests_done;
}
}
-void
+int
test_ternary_op(const irop_t *op, test_data_t *data)
{
unsigned num_input_bits, i, bitpos;
opnd_t *opnds = data->opnds;
+ int tests_done = 0;
/* For each operand, set a single bit to undefined and observe how
that propagates to the output. Do this for all bits in each
valgrind_execute_test(op, data);
check_result_for_ternary(op, data);
+
+ tests_done++;
}
}
}
}
-void
+int
test_unary_op(const irop_t *op, test_data_t *data)
{
unsigned num_input_bits, bitpos;
+ int tests_done = 0;
num_input_bits = bitsof_irtype(data->opnds[0].type);
valgrind_execute_test(op, data);
check_result_for_unary(op, data);
+ tests_done++;
}
+ return tests_done;
}
{
unsigned i, num_operands;
- if (verbose > 1) printf("---------- Running a test\n");
+ if (verbose > 2) printf("---------- Running a test\n");
num_operands = get_num_operands(op->op);
for (i = 0; i < num_operands; ++i) {
valgrind_set_vbits(&data->opnds[i]);
- if (verbose > 1) {
+ if (verbose > 2) {
printf("opnd #%u: ", i);
print_opnd(stdout, &data->opnds[i]);
printf("\n");
}
valgrind_vex_inject_ir();
valgrind_get_vbits(&data->result);
- if (verbose > 1) {
+ if (verbose > 2) {
printf("result: ");
print_opnd(stdout, &data->result);
printf("\n");
void print_opnd(FILE *, const opnd_t *);
-void test_unary_op(const irop_t *, test_data_t *);
-void test_binary_op(const irop_t *, test_data_t *);
-void test_ternary_op(const irop_t *, test_data_t *);
-void test_qernary_op(const irop_t *, test_data_t *);
+int test_unary_op(const irop_t *, test_data_t *);
+int test_binary_op(const irop_t *, test_data_t *);
+int test_ternary_op(const irop_t *, test_data_t *);
+int test_qernary_op(const irop_t *, test_data_t *);
void valgrind_vex_init_for_iri(IRICB *);
void valgrind_execute_test(const irop_t *, test_data_t *);