test_maxout.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*********************************************************************
  2. Blosc - Blocked Shuffling and Compression Library
  3. Unit tests for basic features in Blosc.
  4. Creation date: 2010-06-07
  5. Author: Francesc Alted <francesc@blosc.org>
  6. See LICENSES/BLOSC.txt for details about copyright and rights to use.
  7. **********************************************************************/
  8. #include "test_common.h"
  9. int tests_run = 0;
  10. /* Global vars */
  11. void *src, *srccpy, *dest, *dest2;
  12. int nbytes, cbytes;
  13. int clevel = 1;
  14. int doshuffle = 0;
  15. size_t typesize = 4;
  16. size_t size = 1000; /* must be divisible by 4 */
  17. /* Check maxout with maxout < size */
  18. static const char *test_maxout_less(void) {
  19. /* Get a compressed buffer */
  20. cbytes = blosc_compress(clevel, doshuffle, typesize, size, src, dest, size+15);
  21. mu_assert("ERROR: cbytes is not 0", cbytes == 0);
  22. return 0;
  23. }
  24. /* Check maxout with maxout < size (memcpy version) */
  25. static const char *test_maxout_less_memcpy(void) {
  26. /* Get a compressed buffer */
  27. cbytes = blosc_compress(0, doshuffle, typesize, size, src, dest, size+15);
  28. mu_assert("ERROR: cbytes is not 0", cbytes == 0);
  29. return 0;
  30. }
  31. /* Check maxout with maxout == size */
  32. static const char *test_maxout_equal(void) {
  33. /* Get a compressed buffer */
  34. cbytes = blosc_compress(clevel, doshuffle, typesize, size, src, dest, size+16);
  35. mu_assert("ERROR: cbytes is not correct", cbytes == size+16);
  36. /* Decompress the buffer */
  37. nbytes = blosc_decompress(dest, dest2, size);
  38. mu_assert("ERROR: nbytes incorrect(1)", nbytes == size);
  39. return 0;
  40. }
  41. /* Check maxout with maxout == size (memcpy version) */
  42. static const char *test_maxout_equal_memcpy(void) {
  43. /* Get a compressed buffer */
  44. cbytes = blosc_compress(0, doshuffle, typesize, size, src, dest, size+16);
  45. mu_assert("ERROR: cbytes is not correct", cbytes == size+16);
  46. /* Decompress the buffer */
  47. nbytes = blosc_decompress(dest, dest2, size);
  48. mu_assert("ERROR: nbytes incorrect(1)", nbytes == size);
  49. return 0;
  50. }
  51. /* Check maxout with maxout > size */
  52. static const char *test_maxout_great(void) {
  53. /* Get a compressed buffer */
  54. cbytes = blosc_compress(clevel, doshuffle, typesize, size, src, dest, size+17);
  55. mu_assert("ERROR: cbytes is not correct", cbytes == size+16);
  56. /* Decompress the buffer */
  57. nbytes = blosc_decompress(dest, dest2, size);
  58. mu_assert("ERROR: nbytes incorrect(1)", nbytes == size);
  59. return 0;
  60. }
  61. /* Check maxout with maxout > size (memcpy version) */
  62. static const char *test_maxout_great_memcpy(void) {
  63. /* Get a compressed buffer */
  64. cbytes = blosc_compress(0, doshuffle, typesize, size, src, dest, size+17);
  65. mu_assert("ERROR: cbytes is not correct", cbytes == size+16);
  66. /* Decompress the buffer */
  67. nbytes = blosc_decompress(dest, dest2, size);
  68. mu_assert("ERROR: nbytes incorrect(1)", nbytes == size);
  69. return 0;
  70. }
  71. static const char *all_tests(void) {
  72. mu_run_test(test_maxout_less);
  73. mu_run_test(test_maxout_less_memcpy);
  74. mu_run_test(test_maxout_equal);
  75. mu_run_test(test_maxout_equal_memcpy);
  76. mu_run_test(test_maxout_great);
  77. mu_run_test(test_maxout_great_memcpy);
  78. return 0;
  79. }
  80. #define BUFFER_ALIGN_SIZE 32
  81. int main(int argc, char **argv) {
  82. int32_t *_src;
  83. const char *result;
  84. size_t i;
  85. printf("STARTING TESTS for %s", argv[0]);
  86. blosc_init();
  87. blosc_set_nthreads(1);
  88. /* Initialize buffers */
  89. src = blosc_test_malloc(BUFFER_ALIGN_SIZE, size);
  90. srccpy = blosc_test_malloc(BUFFER_ALIGN_SIZE, size);
  91. dest = blosc_test_malloc(BUFFER_ALIGN_SIZE, size + 16);
  92. dest2 = blosc_test_malloc(BUFFER_ALIGN_SIZE, size);
  93. _src = (int32_t *)src;
  94. for (i=0; i < (size/4); i++) {
  95. _src[i] = (int32_t)i;
  96. }
  97. memcpy(srccpy, src, size);
  98. /* Run all the suite */
  99. result = all_tests();
  100. if (result != 0) {
  101. printf(" (%s)\n", result);
  102. }
  103. else {
  104. printf(" ALL TESTS PASSED");
  105. }
  106. printf("\tTests run: %d\n", tests_run);
  107. blosc_test_free(src);
  108. blosc_test_free(srccpy);
  109. blosc_test_free(dest);
  110. blosc_test_free(dest2);
  111. blosc_destroy();
  112. return result != 0;
  113. }