1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
/*********************************************************************
Blosc - Blocked Shuffling and Compression Library
Unit tests for Blosc API.
Copyright (c) 2021 Blosc Development Team <blosc@blosc.org>
https://blosc.org
License: BSD 3-Clause (see LICENSE.txt)
See LICENSE.txt for details about copyright and rights to use.
**********************************************************************/
#include "test_common.h"
int tests_run = 0;
/* Global vars */
void* src, * srccpy, * dest, * dest2;
int nbytes, cbytes;
int clevel = 3;
int doshuffle = 1;
int typesize = 4;
int size = 1 * MB;
static char* test_cbuffer_sizes(void) {
size_t nbytes_, cbytes_, blocksize;
blosc1_cbuffer_sizes(dest, &nbytes_, &cbytes_, &blocksize);
mu_assert("ERROR: nbytes incorrect(1)", nbytes == size);
mu_assert("ERROR: nbytes incorrect(2)", nbytes_ == (size_t)nbytes);
mu_assert("ERROR: cbytes incorrect", cbytes_ == (size_t)cbytes);
mu_assert("ERROR: blocksize incorrect", blocksize >= 128);
return 0;
}
static char* test_cbuffer_metainfo(void) {
size_t typesize_;
int flags;
blosc1_cbuffer_metainfo(dest, &typesize_, &flags);
mu_assert("ERROR: typesize incorrect", typesize_ == (size_t)typesize);
mu_assert("ERROR: shuffle incorrect", (flags & BLOSC_DOSHUFFLE) == doshuffle);
return 0;
}
static char* test_cbuffer_versions(void) {
int version_;
int versionlz_;
blosc2_cbuffer_versions(dest, &version_, &versionlz_);
mu_assert("ERROR: version incorrect", version_ == BLOSC2_VERSION_FORMAT);
mu_assert("ERROR: versionlz incorrect", versionlz_ == BLOSC_BLOSCLZ_VERSION_FORMAT);
return 0;
}
static char* test_cbuffer_complib(void) {
const char* complib;
complib = blosc2_cbuffer_complib(dest);
mu_assert("ERROR: complib incorrect", strcmp(complib, "BloscLZ") == 0);
return 0;
}
static char *test_nthreads(void) {
int16_t nthreads;
nthreads = blosc2_set_nthreads(4);
mu_assert("ERROR: set_nthreads incorrect", nthreads == 1);
nthreads = blosc2_get_nthreads();
mu_assert("ERROR: get_nthreads incorrect", nthreads == 4);
return 0;
}
static char *test_blocksize(void) {
int blocksize;
blocksize = blosc1_get_blocksize();
mu_assert("ERROR: get_blocksize incorrect", blocksize == 0);
blosc1_set_blocksize(4096);
blocksize = blosc1_get_blocksize();
mu_assert("ERROR: get_blocksize incorrect", blocksize == 4096);
return 0;
}
static char* all_tests(void) {
mu_run_test(test_cbuffer_sizes);
mu_run_test(test_cbuffer_metainfo);
mu_run_test(test_cbuffer_versions);
mu_run_test(test_cbuffer_complib);
mu_run_test(test_nthreads);
mu_run_test(test_blocksize);
return 0;
}
#define BUFFER_ALIGN_SIZE 8
int main(void) {
char* result;
install_blosc_callback_test(); /* optionally install callback test */
blosc2_init();
blosc2_set_nthreads(1);
/* Initialize buffers */
src = blosc_test_malloc(BUFFER_ALIGN_SIZE, size);
srccpy = blosc_test_malloc(BUFFER_ALIGN_SIZE, size);
dest = blosc_test_malloc(BUFFER_ALIGN_SIZE, size);
dest2 = blosc_test_malloc(BUFFER_ALIGN_SIZE, size);
memset(src, 0, size);
memcpy(srccpy, src, size);
/* Get a compressed buffer */
cbytes = blosc1_compress(clevel, doshuffle, typesize, size, src, dest, size);
/* Get a decompressed buffer */
nbytes = blosc1_decompress(dest, dest2, size);
/* Run all the suite */
result = all_tests();
if (result != 0) {
printf(" (%s)\n", result);
}
else {
printf(" ALL TESTS PASSED");
}
printf("\tTests run: %d\n", tests_run);
blosc_test_free(src);
blosc_test_free(srccpy);
blosc_test_free(dest);
blosc_test_free(dest2);
blosc2_destroy();
return result != 0;
}
|