test_nolock.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. #include <unistd.h>
  9. #include "test_common.h"
  10. int tests_run = 0;
  11. /* Global vars */
  12. void *src, *srccpy, *dest, *dest2;
  13. size_t nbytes, cbytes;
  14. int clevel = 1;
  15. int doshuffle = 1;
  16. size_t typesize = 4;
  17. size_t size = 4 * 1000 * 1000; /* must be divisible by 4 */
  18. /* Check just compressing */
  19. static char *test_compress() {
  20. /* Get a compressed buffer */
  21. cbytes = blosc_compress(clevel, doshuffle, typesize, size, src,
  22. dest, size + 16);
  23. mu_assert("ERROR: cbytes is not correct", cbytes < size);
  24. return 0;
  25. }
  26. /* Check compressing + decompressing */
  27. static char *test_compress_decompress() {
  28. /* Get a compressed buffer */
  29. cbytes = blosc_compress(clevel, doshuffle, typesize, size, src,
  30. dest, size + 16);
  31. mu_assert("ERROR: cbytes is not correct", cbytes < size);
  32. /* Decompress the buffer */
  33. nbytes = blosc_decompress(dest, dest2, size);
  34. mu_assert("ERROR: nbytes incorrect(1)", nbytes == size);
  35. return 0;
  36. }
  37. static char *all_tests() {
  38. mu_run_test(test_compress);
  39. mu_run_test(test_compress_decompress);
  40. return 0;
  41. }
  42. #define BUFFER_ALIGN_SIZE 32
  43. int main(int argc, char **argv) {
  44. int32_t *_src;
  45. char *result;
  46. size_t i;
  47. int pid, nchildren = 4;
  48. printf("STARTING TESTS for %s\n", argv[0]);
  49. /* Activate the BLOSC_NOLOCK variable */
  50. setenv("BLOSC_NOLOCK", "TRUE", 0);
  51. /* Launch several subprocesses */
  52. for (i = 1; i <= nchildren; i++) {
  53. pid = fork();
  54. }
  55. blosc_init();
  56. blosc_set_nthreads(4);
  57. /* Initialize buffers */
  58. src = blosc_test_malloc(BUFFER_ALIGN_SIZE, size);
  59. srccpy = blosc_test_malloc(BUFFER_ALIGN_SIZE, size);
  60. dest = blosc_test_malloc(BUFFER_ALIGN_SIZE, size + 16);
  61. dest2 = blosc_test_malloc(BUFFER_ALIGN_SIZE, size);
  62. _src = (int32_t *)src;
  63. for (i=0; i < (size/4); i++) {
  64. _src[i] = (int32_t)i;
  65. }
  66. memcpy(srccpy, src, size);
  67. /* Run all the suite */
  68. result = all_tests();
  69. if (result != 0) {
  70. printf(" (%s)\n", result);
  71. }
  72. else {
  73. printf(" ALL TESTS PASSED\n");
  74. }
  75. printf("\tTests run: %d\n", tests_run);
  76. blosc_test_free(src);
  77. blosc_test_free(srccpy);
  78. blosc_test_free(dest);
  79. blosc_test_free(dest2);
  80. blosc_destroy();
  81. return result != 0;
  82. }