Пример #1
0
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; show number of 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]);
        return 1;
      }
   }

   if (! RUNNING_ON_VALGRIND) {
     fprintf(stderr, "*** This program needs to run under memcheck.\n");
     return 1;
   }

   setbuf(stdout, NULL);  // make stdout unbuffered

   fixup_irops();         // determine need for special handling

   // Iterate over all primops
   IROp first = Iop_INVALID + 1;
   IROp last  = Iop_LAST;
   IROp opkind;

   if (0) {   // overwrite for debugging
      first = Iop_CasCmpEQ8; last = first + 1;
   }

   // Iterate over all IROps in the enum type. That is the only way to
   // make sure the operator is tested on at least one platform.

   // Loop assumes no holes in the enumerator values
   for (opkind = first; opkind < last; ++opkind) {

      const irop_t *op = get_irop(opkind);
      if (op == NULL) continue;

      if (op->undef_kind == UNDEF_UNKNOWN) {
         fprintf(stderr, "...skipping %s; unknown undef propagation\n",
                 op->name);
         continue;
      }

      test_data_t *data = new_test_data(op);

      if (verbose > 1) printf("Testing operator %s\n", op->name);

      IRICB iricb = new_iricb(op, data);

      valgrind_vex_init_for_iri(&iricb);

      switch (iricb.num_operands) {
      case 1:
         num_unary_tests += test_unary_op(op, data);
         break;

      case 2:
         num_binary_tests += test_binary_op(op, data);
         break;

      case 3:
         num_ternary_tests += test_ternary_op(op, data);
         break;

      case 4:
         num_qernary_tests += test_qernary_op(op, data);
         break;

      default:
         panic("operator not handled");
      }

      free(data);
   }

   if (verbose) 
      printf("\nvbit-test ran  %d unary, %d binary, %d ternary and"
             " %d qernary tests.\n\n",
             num_unary_tests, num_binary_tests, num_ternary_tests,
             num_qernary_tests);
   return 0;
}
Пример #2
0
static void TestFlate(skiatest::Reporter* reporter, SkMemoryStream* testStream,
                      size_t dataSize) {
    SkASSERT(testStream != NULL);

    SkAutoDataUnref testData(new_test_data(dataSize));
    SkASSERT(testData->size() == dataSize);

    testStream->setMemory(testData->data(), dataSize, /*copyData=*/ true);
    SkDynamicMemoryWStream compressed;
    bool deflateSuccess = SkFlate::Deflate(testStream, &compressed);
    REPORTER_ASSERT(reporter, deflateSuccess);

    // Check that the input data wasn't changed.
    size_t inputSize = testStream->getLength();
    if (inputSize == 0) {
        inputSize = testStream->read(NULL, SkZeroSizeMemStream::kGetSizeKey);
    }
    REPORTER_ASSERT(reporter, dataSize == inputSize);
    if (dataSize == inputSize) {
        REPORTER_ASSERT(reporter, memcmp(testData->data(),
                                         testStream->getMemoryBase(),
                                         dataSize) == 0);
    }

    size_t compressedSize = compressed.getOffset();

    SkAutoDataUnref compressedData(compressed.copyToData());
    testStream->setData(compressedData.get());

    SkDynamicMemoryWStream uncompressed;
    bool inflateSuccess = SkFlate::Inflate(testStream, &uncompressed);
    REPORTER_ASSERT(reporter, inflateSuccess);

    // Check that the input data wasn't changed.
    inputSize = testStream->getLength();
    if (inputSize == 0) {
        inputSize = testStream->read(NULL, SkZeroSizeMemStream::kGetSizeKey);
    }
    REPORTER_ASSERT(reporter,  compressedSize == inputSize);
    if (compressedData->size() == inputSize) {
        REPORTER_ASSERT(reporter, memcmp(testStream->getMemoryBase(),
                                         compressedData->data(),
                                         compressedData->size()) == 0);
    }

    // Check that the uncompressed data matches the source data.
    SkAutoDataUnref uncompressedData(uncompressed.copyToData());
    REPORTER_ASSERT(reporter, dataSize == uncompressedData->size());
    if (dataSize == uncompressedData->size()) {
        REPORTER_ASSERT(reporter, memcmp(testData->data(),
                                         uncompressedData->data(),
                                         dataSize) == 0);
    }

    if (compressedSize < 1) { return; }

    double compressionRatio = static_cast<double>(dataSize) / compressedSize;
    // Assert that some compression took place.
    REPORTER_ASSERT(reporter, compressionRatio > 1.2);

    if (reporter->verbose()) {
        SkDebugf("Flate Test: \t input size: " SK_SIZE_T_SPECIFIER
                 "\tcompressed size: " SK_SIZE_T_SPECIFIER
                 "\tratio: %.4g\n",
                 dataSize, compressedSize, compressionRatio);
    }
}