test_noinit.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*********************************************************************
  2. Blosc - Blocked Shuffling and Compression Library
  3. Unit tests for BLOSC_NOLOCK environment variable in Blosc.
  4. Creation date: 2016-04-25
  5. Author: Francesc Alted <francesc@blosc.org>
  6. See LICENSES/BLOSC.txt for details about copyright and rights to use.
  7. **********************************************************************/
  8. /* Test for using blosc without blosc_init() and blosc_destroy() */
  9. #include <unistd.h>
  10. #include "test_common.h"
  11. int tests_run = 0;
  12. /* Global vars */
  13. void *src, *srccpy, *dest, *dest2;
  14. size_t nbytes, cbytes;
  15. int clevel = 1;
  16. int doshuffle = 1;
  17. size_t typesize = 4;
  18. size_t size = 4 * 1000 * 1000; /* must be divisible by 4 */
  19. /* Check just compressing */
  20. static char *test_compress() {
  21. /* Get a compressed buffer */
  22. cbytes = blosc_compress(clevel, doshuffle, typesize, size, src,
  23. dest, size + 16);
  24. mu_assert("ERROR: cbytes is not correct", cbytes < size);
  25. return 0;
  26. }
  27. /* Check compressing + decompressing */
  28. static char *test_compress_decompress() {
  29. /* Get a compressed buffer */
  30. cbytes = blosc_compress(clevel, doshuffle, typesize, size, src,
  31. dest, size + 16);
  32. mu_assert("ERROR: cbytes is not correct", cbytes < size);
  33. /* Decompress the buffer */
  34. nbytes = blosc_decompress(dest, dest2, size);
  35. mu_assert("ERROR: nbytes incorrect(1)", nbytes == size);
  36. return 0;
  37. }
  38. static char *all_tests() {
  39. mu_run_test(test_compress);
  40. mu_run_test(test_compress_decompress);
  41. return 0;
  42. }
  43. #define BUFFER_ALIGN_SIZE 32
  44. int main(int argc, char **argv) {
  45. int32_t *_src;
  46. char *result;
  47. size_t i;
  48. int pid, nchildren = 4;
  49. printf("STARTING TESTS for %s\n", argv[0]);
  50. /* Launch several subprocesses */
  51. for (i = 1; i <= nchildren; i++) {
  52. pid = fork();
  53. }
  54. blosc_set_nthreads(4);
  55. /* Initialize buffers */
  56. src = blosc_test_malloc(BUFFER_ALIGN_SIZE, size);
  57. srccpy = blosc_test_malloc(BUFFER_ALIGN_SIZE, size);
  58. dest = blosc_test_malloc(BUFFER_ALIGN_SIZE, size + 16);
  59. dest2 = blosc_test_malloc(BUFFER_ALIGN_SIZE, size);
  60. _src = (int32_t *)src;
  61. for (i=0; i < (size/4); i++) {
  62. _src[i] = (int32_t)i;
  63. }
  64. memcpy(srccpy, src, size);
  65. /* Run all the suite */
  66. result = all_tests();
  67. if (result != 0) {
  68. printf(" (%s)\n", result);
  69. }
  70. else {
  71. printf(" ALL TESTS PASSED\n");
  72. }
  73. printf("\tTests run: %d\n", tests_run);
  74. blosc_test_free(src);
  75. blosc_test_free(srccpy);
  76. blosc_test_free(dest);
  77. blosc_test_free(dest2);
  78. return result != 0;
  79. }