1 /*
2  * Copyright (C) 2018 Francesc Alted, Aleix Alcacer.
3  * Copyright (C) 2019-present Blosc Development team <blosc@blosc.org>
4  * All rights reserved.
5  *
6  * This source code is licensed under both the BSD-style license (found in the
7  * LICENSE file in the root directory of this source tree) and the GPLv2 (found
8  * in the COPYING file in the root directory of this source tree).
9  * You may select, at your option, one of the above-listed licenses.
10  */
11 
12 #ifndef CATERVA_TEST_COMMON_H
13 #define CATERVA_TEST_COMMON_H
14 
15 #include <caterva.h>
16 #include "cutest.h"
17 
18 
19 #define CATERVA_TEST_ASSERT(rc) CUTEST_ASSERT(print_error(rc), (rc) == CATERVA_SUCCEED);
20 
21 #ifdef __GNUC__
22 #define CATERVA_TEST_UNUSED __attribute__((unused))
23 #else
24 #define CATERVA_TEST_UNUSED
25 #endif
26 
27 static bool fill_buf(void *buf, uint8_t itemsize, size_t buf_size) CATERVA_TEST_UNUSED;
fill_buf(void * buf,uint8_t itemsize,size_t buf_size)28         static bool fill_buf(void *buf, uint8_t itemsize, size_t buf_size) {
29     switch (itemsize) {
30         case 8:
31             for (size_t i = 0; i < buf_size; ++i) {
32                 ((uint64_t *) buf)[i] = (uint64_t) i + 1;
33             }
34             break;
35         case 4:
36             for (size_t i = 0; i < buf_size; ++i) {
37                 ((uint32_t *) buf)[i] = (uint32_t) i + 1;
38             }
39             break;
40         case 2:
41             for (size_t i = 0; i < buf_size; ++i) {
42                 ((uint16_t *) buf)[i] = (uint16_t ) i + 1;
43             }
44             break;
45         case 1:
46             for (size_t i = 0; i < buf_size; ++i) {
47                 ((uint8_t *) buf)[i] = (uint8_t ) i + 1;
48             }
49             break;
50         default:
51             return false;
52     }
53     return true;
54 }
55 
56 
57 /* Tests data */
58 
59 typedef struct {
60     int8_t ndim;
61     int64_t shape[CATERVA_MAX_DIM];
62     int32_t chunkshape[CATERVA_MAX_DIM];
63     int32_t blockshape[CATERVA_MAX_DIM];
64 } _test_shapes;
65 
66 
67 typedef struct {
68     bool sequential;
69     bool persistent;
70 } _test_backend;
71 
72 
caterva_default_parameters()73 void caterva_default_parameters() {
74     CUTEST_PARAMETRIZE(itemsize, uint8_t, CUTEST_DATA(1, 2, 4, 8));
75     CUTEST_PARAMETRIZE(shapes, _test_shapes, CUTEST_DATA(
76         {2, {100, 100}, {20, 20}, {10, 10}},
77         {3, {100, 55, 123}, {31, 5, 22}, {4, 4, 4}},
78         {3, {100, 0, 12}, {31, 0, 12}, {10, 0, 12}},
79         {4, {50, 160, 31, 12}, {25, 20, 20, 10}, {5, 5, 5, 10}},
80         {5, {1, 1, 1024, 1, 1}, {1, 1, 500, 1, 1}, {1, 1, 200, 1, 1}},
81         {6, {5, 1, 200, 3, 1, 2}, {5, 1, 50, 2, 1, 2}, {2, 1, 20, 2, 1, 2}},
82     ));
83     CUTEST_PARAMETRIZE(backend, _test_backend, CUTEST_DATA(
84         {false, false},
85         {true, false},
86         {false, true},
87         {true, true},
88     ));
89 }
90 
91 
92 #define CATERVA_TEST_ASSERT_BUFFER(buffer1, buffer2, buffersize) \
93     for (int i = 0; i < (buffersize); ++i) {                     \
94         CUTEST_ASSERT("elements are not equals!", (buffer1)[i] == (buffer2)[i]); \
95     }
96 
97 
98 #endif //CATERVA_TEST_COMMON_H
99