/** 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) */ }