]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
vbit-tester, add counts for the number of 1, 2, 3 and 4 operand tests.
authorCarl Love <cel@us.ibm.com>
Fri, 16 Nov 2012 19:41:21 +0000 (19:41 +0000)
committerCarl Love <cel@us.ibm.com>
Fri, 16 Nov 2012 19:41:21 +0000 (19:41 +0000)
This patch adds code to count the number of each type of test.  The
number of 1, 2, 3 and 4 operand tests that are generated by the vbit-tester
are counted and printed by the vbit-tester.  The user should refer to the
Valgrind output to see if any of the tests failed.

The existing two verbose levels was increased by one level and the the
new output giving the number of tests was inserted as the first verbose
level.  The verbose levels are now:

-v        shows the number of 1, 2, 3 and 4 operand tests that are generated
-v -v     shows IROps being tested
-v -v -v  extreme edition, shows input values

This patch is for bugzilla 309229

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@13124

memcheck/tests/vbit-test/binary.c
memcheck/tests/vbit-test/main.c
memcheck/tests/vbit-test/qernary.c
memcheck/tests/vbit-test/ternary.c
memcheck/tests/vbit-test/unary.c
memcheck/tests/vbit-test/valgrind.c
memcheck/tests/vbit-test/vtest.h

index 98cbe25e4268d1914840345aea12b640601ba050..64b43a3ed0fae668cc2ec05de1544f25394dbb0f 100644 (file)
@@ -172,11 +172,12 @@ check_result_for_binary(const irop_t *op, const test_data_t *data)
 }
 
 
-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 */
@@ -193,13 +194,14 @@ test_shift(const irop_t *op, test_data_t *data)
          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);
 
@@ -210,7 +212,10 @@ test_shift(const irop_t *op, test_data_t *data)
       valgrind_execute_test(op, data);
 
       check_result_for_binary(op, data);
+
+      tests_done++;
    }
+   return tests_done;
 }
 
 
@@ -248,11 +253,12 @@ all_bits_one_value(unsigned num_bits)
 }
 
 
-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
@@ -269,6 +275,7 @@ test_and(const irop_t *op, test_data_t *data)
       valgrind_execute_test(op, data);
          
       check_result_for_binary(op, data);
+      tests_done++;
    }
    
    // 2nd (right) operand variable, 1st operand all-bits-zero
@@ -282,6 +289,7 @@ test_and(const irop_t *op, test_data_t *data)
       valgrind_execute_test(op, data);
          
       check_result_for_binary(op, data);
+      tests_done++;
    }
 
    /* Undefinedness propagates if the other operand is 1.
@@ -299,6 +307,7 @@ test_and(const irop_t *op, test_data_t *data)
       valgrind_execute_test(op, data);
          
       check_result_for_binary(op, data);
+      tests_done++;
    }
    
    // 2nd (right) operand variable, 1st operand all-bits-one
@@ -312,15 +321,18 @@ test_and(const irop_t *op, test_data_t *data)
       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
@@ -339,6 +351,7 @@ test_or(const irop_t *op, test_data_t *data)
       valgrind_execute_test(op, data);
          
       check_result_for_binary(op, data);
+      tests_done++;
    }
    
    // 2nd (right) operand variable, 1st operand all-bits-one
@@ -354,6 +367,7 @@ test_or(const irop_t *op, test_data_t *data)
       valgrind_execute_test(op, data);
          
       check_result_for_binary(op, data);
+      tests_done++;
    }
 
    /* Undefinedness propagates if the other operand is 0.
@@ -373,6 +387,7 @@ test_or(const irop_t *op, test_data_t *data)
       valgrind_execute_test(op, data);
          
       check_result_for_binary(op, data);
+      tests_done++;
    }
    
    // 2nd (right) operand variable, 1st operand all-bits-zero
@@ -388,31 +403,31 @@ test_or(const irop_t *op, test_data_t *data)
       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;
@@ -446,6 +461,9 @@ test_binary_op(const irop_t *op, test_data_t *data)
          valgrind_execute_test(op, data);
 
          check_result_for_binary(op, data);
+
+         tests_done++;
       }
    }
+   return tests_done;
 }
index a6c27010b8bd298788723002e035373e05b70bd1..7b9c4de99ba4b343d0c726fba0d98ced2183ed5c 100644 (file)
@@ -68,13 +68,16 @@ int
 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]);
@@ -117,7 +120,7 @@ main(int argc, char *argv[])
          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);
 
@@ -125,19 +128,19 @@ main(int argc, char *argv[])
 
       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:
@@ -147,5 +150,9 @@ main(int argc, char *argv[])
       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;
 }
index b9adde5e7f6f6c7eeb63d615660669f887ce755e..324bb20568638a0cf90a36fd31f96684da10242c 100644 (file)
@@ -36,11 +36,12 @@ check_result_for_qernary(const irop_t *op, const test_data_t *data)
 }
 
 
-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
@@ -59,6 +60,9 @@ test_qernary_op(const irop_t *op, test_data_t *data)
          valgrind_execute_test(op, data);
 
          check_result_for_qernary(op, data);
+
+         tests_done++;
       }
    }
+   return tests_done;
 }
index 8365b24383cbecdc68777aa7f9327f760adac32b..cef7b70fd09188a8cd4336279fc38c7f9c6acefe 100644 (file)
@@ -35,11 +35,12 @@ check_result_for_ternary(const irop_t *op, const test_data_t *data)
 }
 
 
-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
@@ -57,6 +58,8 @@ test_ternary_op(const irop_t *op, test_data_t *data)
          valgrind_execute_test(op, data);
 
          check_result_for_ternary(op, data);
+
+        tests_done++;
       }
    }
 }
index ca710c2b42e5bb7b99aff2095a3f06bfa8b10970..30ba87f8602a69a59035cd4170374adc0df05025 100644 (file)
@@ -53,10 +53,11 @@ check_result_for_unary(const irop_t *op, const test_data_t *data)
 }
 
 
-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);
 
@@ -66,5 +67,7 @@ test_unary_op(const irop_t *op, test_data_t *data)
       valgrind_execute_test(op, data);
 
       check_result_for_unary(op, data);
+      tests_done++;
    }
+   return tests_done;
 }
index 6073fcb27b095b24e10ba1885abb458824a8b570..cbe246c2cec29331639413986f0ce734e9a0b3a3 100644 (file)
@@ -93,12 +93,12 @@ valgrind_execute_test(const irop_t *op, test_data_t *data)
 {
    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");
@@ -106,7 +106,7 @@ valgrind_execute_test(const irop_t *op, test_data_t *data)
    }
    valgrind_vex_inject_ir();
    valgrind_get_vbits(&data->result);
-   if (verbose > 1) {
+   if (verbose > 2) {
       printf("result:   ");
       print_opnd(stdout, &data->result);
       printf("\n");
index 8f107b44196dc8469d70e52bd36904b684fd742d..b4517ca61c7cd08275b5cc4230381e69394390e8 100644 (file)
@@ -104,10 +104,10 @@ int  get_num_operands(IROp);
 
 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 *);