test_maxout.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. size_t 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 char *test_maxout_less() {
  19. /* Get a compressed buffer */
  20. cbytes = blosc_compress(clevel, doshuffle, typesize, size, src,
  21. dest, size+15);
  22. mu_assert("ERROR: cbytes is not 0", cbytes == 0);
  23. return 0;
  24. }
  25. /* Check maxout with maxout == size */
  26. static char *test_maxout_equal() {
  27. /* Get a compressed buffer */
  28. cbytes = blosc_compress(clevel, doshuffle, typesize, size, src,
  29. dest, size+16);
  30. mu_assert("ERROR: cbytes is not correct", cbytes == size+16);
  31. /* Decompress the buffer */
  32. nbytes = blosc_decompress(dest, dest2, size);
  33. mu_assert("ERROR: nbytes incorrect(1)", nbytes == size);
  34. return 0;
  35. }
  36. /* Check maxout with maxout > size */
  37. static char *test_maxout_great() {
  38. /* Get a compressed buffer */
  39. cbytes = blosc_compress(clevel, doshuffle, typesize, size, src,
  40. dest, size+17);
  41. mu_assert("ERROR: cbytes is not 0", cbytes == size+16);
  42. /* Decompress the buffer */
  43. nbytes = blosc_decompress(dest, dest2, size);
  44. mu_assert("ERROR: nbytes incorrect(1)", nbytes == size);
  45. return 0;
  46. }
  47. static char *all_tests() {
  48. mu_run_test(test_maxout_less);
  49. mu_run_test(test_maxout_equal);
  50. mu_run_test(test_maxout_great);
  51. return 0;
  52. }
  53. #define BUFFER_ALIGN_SIZE 32
  54. int main(int argc, char **argv) {
  55. int32_t *_src;
  56. char *result;
  57. size_t i;
  58. printf("STARTING TESTS for %s", argv[0]);
  59. blosc_init();
  60. blosc_set_nthreads(1);
  61. /* Initialize buffers */
  62. src = blosc_test_malloc(BUFFER_ALIGN_SIZE, size);
  63. srccpy = blosc_test_malloc(BUFFER_ALIGN_SIZE, size);
  64. dest = blosc_test_malloc(BUFFER_ALIGN_SIZE, size + 16);
  65. dest2 = blosc_test_malloc(BUFFER_ALIGN_SIZE, size);
  66. _src = (int32_t *)src;
  67. for (i=0; i < (size/4); i++) {
  68. _src[i] = (int32_t)i;
  69. }
  70. memcpy(srccpy, src, size);
  71. /* Run all the suite */
  72. result = all_tests();
  73. if (result != 0) {
  74. printf(" (%s)\n", result);
  75. }
  76. else {
  77. printf(" ALL TESTS PASSED");
  78. }
  79. printf("\tTests run: %d\n", tests_run);
  80. blosc_test_free(src);
  81. blosc_test_free(srccpy);
  82. blosc_test_free(dest);
  83. blosc_test_free(dest2);
  84. blosc_destroy();
  85. return result != 0;
  86. }