예제 #1
0
/** Test the blosc_getitem function. */
static int test_getitem(size_t type_size, size_t num_elements,
                        size_t buffer_alignment, int compression_level, int do_shuffle) {
  size_t buffer_size = type_size * num_elements;

  /* Allocate memory for the test. */
  void* original = blosc_test_malloc(buffer_alignment, buffer_size);
  void* intermediate = blosc_test_malloc(buffer_alignment, buffer_size + BLOSC_MAX_OVERHEAD);
  void* result = blosc_test_malloc(buffer_alignment, buffer_size);

  /* Fill the input data buffer with random values. */
  blosc_test_fill_random(original, buffer_size);

  /* Compress the input data, then use blosc_getitem to extract (decompress)
     a range of elements into a new buffer. */
  blosc_compress(compression_level, do_shuffle, type_size, buffer_size,
                 original, intermediate, buffer_size + BLOSC_MAX_OVERHEAD);
  blosc_getitem(intermediate, 0, num_elements, result);

  /* The round-tripped data matches the original data when the
     result of memcmp is 0. */
  int exit_code = memcmp(original, result, buffer_size) ?
                  EXIT_FAILURE : EXIT_SUCCESS;

  /* Free allocated memory. */
  blosc_test_free(original);
  blosc_test_free(intermediate);
  blosc_test_free(result);

  return exit_code;
}
/** Roundtrip tests for the SSE2-accelerated shuffle/unshuffle. */
static int test_shuffle_roundtrip_sse2(size_t type_size, size_t num_elements,
  size_t buffer_alignment, int test_type)
{
#if defined(SHUFFLE_SSE2_ENABLED)
  size_t buffer_size = type_size * num_elements;

  /* Allocate memory for the test. */
  void* original = blosc_test_malloc(buffer_alignment, buffer_size);
  void* shuffled = blosc_test_malloc(buffer_alignment, buffer_size);
  void* unshuffled = blosc_test_malloc(buffer_alignment, buffer_size);

  /* Fill the input data buffer with random values. */
  blosc_test_fill_random(original, buffer_size);

  /* Shuffle/unshuffle, selecting the implementations based on the test type. */
  switch(test_type)
  {
    case 0:
      /* sse2/sse2 */
      shuffle_sse2(type_size, buffer_size, original, shuffled);
      unshuffle_sse2(type_size, buffer_size, shuffled, unshuffled);
      break;
    case 1:
      /* generic/sse2 */
      shuffle_generic(type_size, buffer_size, original, shuffled);
      unshuffle_sse2(type_size, buffer_size, shuffled, unshuffled);
      break;
    case 2:
      /* sse2/generic */
      shuffle_sse2(type_size, buffer_size, original, shuffled);
      unshuffle_generic(type_size, buffer_size, shuffled, unshuffled);
      break;
    default:
      fprintf(stderr, "Invalid test type specified (%d).", test_type);
      return EXIT_FAILURE;
  }

  /* The round-tripped data matches the original data when the
     result of memcmp is 0. */
  int exit_code = memcmp(original, unshuffled, buffer_size) ?
    EXIT_FAILURE : EXIT_SUCCESS;

  /* Free allocated memory. */
  blosc_test_free(original);
  blosc_test_free(shuffled);
  blosc_test_free(unshuffled);

  return exit_code;
#else
  return EXIT_SUCCESS;
#endif /* defined(SHUFFLE_SSE2_ENABLED) */
}
예제 #3
0
int main(int argc, char **argv) {
  int32_t *_src;
  const char *result;
  size_t i;
  int nchildren = 4;

  printf("STARTING TESTS for %s\n", argv[0]);

  /* Launch several subprocesses */
  for (i = 1; i <= nchildren; i++) {
    fork();
  }

  blosc_set_nthreads(4);

  /* Initialize buffers */
  src = blosc_test_malloc(BUFFER_ALIGN_SIZE, size);
  srccpy = blosc_test_malloc(BUFFER_ALIGN_SIZE, size);
  dest = blosc_test_malloc(BUFFER_ALIGN_SIZE, size + BLOSC_MAX_OVERHEAD);
  dest2 = blosc_test_malloc(BUFFER_ALIGN_SIZE, size);
  _src = (int32_t *)src;
  for (i=0; i < (size/4); i++) {
    _src[i] = (int32_t)i;
  }
  memcpy(srccpy, src, size);

  /* Run all the suite */
  result = all_tests();
  if (result != 0) {
    printf(" (%s)\n", result);
  }
  else {
    printf(" ALL TESTS PASSED\n");
  }
  printf("\tTests run: %d\n", tests_run);

  blosc_test_free(src);
  blosc_test_free(srccpy);
  blosc_test_free(dest);
  blosc_test_free(dest2);


  return result != 0;
}
예제 #4
0
int main(int argc, char **argv) {
  int64_t *_src;
  const char *result;
  size_t i;

  printf("STARTING TESTS for %s", argv[0]);

  blosc_init();
  blosc_set_compressor("blosclz");

  /* Initialize buffers */
  src = blosc_test_malloc(BUFFER_ALIGN_SIZE, size);
  srccpy = blosc_test_malloc(BUFFER_ALIGN_SIZE, size);
  dest = blosc_test_malloc(BUFFER_ALIGN_SIZE, size + BLOSC_MAX_OVERHEAD);
  dest2 = blosc_test_malloc(BUFFER_ALIGN_SIZE, size);
  _src = (int64_t *)src;
  for (i=0; i < (size / sizeof(int64_t)); i++) {
    _src[i] = (int64_t)i;
  }
  memcpy(srccpy, src, size);

  /* Run all the suite */
  result = all_tests();
  if (result != 0) {
    printf(" (%s)\n", result);
  }
  else {
    printf(" ALL TESTS PASSED");
  }
  printf("\tTests run: %d\n", tests_run);

  blosc_test_free(src);
  blosc_test_free(srccpy);
  blosc_test_free(dest);
  blosc_test_free(dest2);

  blosc_destroy();

  return result != 0;
}