test_sdis_accum_buffer.c (2609B)
1 /* Copyright (C) 2016-2025 |Méso|Star> (contact@meso-star.com) 2 * 3 * This program is free software: you can redistribute it and/or modify 4 * it under the terms of the GNU General Public License as published by 5 * the Free Software Foundation, either version 3 of the License, or 6 * (at your option) any later version. 7 * 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * GNU General Public License for more details. 12 * 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. */ 15 16 #include "test_sdis_utils.h" 17 #include <string.h> 18 19 int 20 main(int argc, char** argv) 21 { 22 struct mem_allocator allocator; 23 struct sdis_accum_buffer* buf = NULL; 24 struct sdis_device* dev = NULL; 25 struct sdis_accum_buffer_layout layout; 26 const struct sdis_accum* accums = NULL; 27 struct sdis_accum* accums_tmp = NULL; 28 (void)argc, (void)argv; 29 30 OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator)); 31 OK(sdis_device_create(NULL, &allocator, SDIS_NTHREADS_DEFAULT, 0, &dev)); 32 33 BA(sdis_accum_buffer_create(NULL, 4 ,4, &buf)); 34 BA(sdis_accum_buffer_create(dev, 0 ,4, &buf)); 35 BA(sdis_accum_buffer_create(dev, 4 ,0, &buf)); 36 BA(sdis_accum_buffer_create(dev, 4 ,0, NULL)); 37 OK(sdis_accum_buffer_create(dev, 4 ,4, &buf)); 38 39 BA(sdis_accum_buffer_ref_get(NULL)); 40 OK(sdis_accum_buffer_ref_get(buf)); 41 BA(sdis_accum_buffer_ref_put(NULL)); 42 OK(sdis_accum_buffer_ref_put(buf)); 43 OK(sdis_accum_buffer_ref_put(buf)); 44 45 OK(sdis_accum_buffer_create(dev, 16, 8, &buf)); 46 47 BA(sdis_accum_buffer_get_layout(NULL, &layout)); 48 BA(sdis_accum_buffer_get_layout(buf, NULL)); 49 OK(sdis_accum_buffer_get_layout(buf, &layout)); 50 51 CHK(layout.width == 16); 52 CHK(layout.height == 8); 53 54 BA(sdis_accum_buffer_map(NULL, &accums)); 55 BA(sdis_accum_buffer_map(buf, NULL)); 56 OK(sdis_accum_buffer_map(buf, &accums)); 57 58 /* Check the accessibility to the mapped data */ 59 accums_tmp = MEM_CALLOC 60 (&allocator, layout.width*layout.height, sizeof(struct sdis_accum)); 61 CHK(accums_tmp != NULL); 62 memmove(accums_tmp, accums_tmp, 63 layout.width*layout.height*sizeof(struct sdis_accum)); 64 MEM_RM(&allocator, accums_tmp); 65 66 BA(sdis_accum_buffer_unmap(NULL)); 67 OK(sdis_accum_buffer_unmap(buf)); 68 69 OK(sdis_accum_buffer_ref_put(buf)); 70 OK(sdis_device_ref_put(dev)); 71 72 check_memory_allocator(&allocator); 73 mem_shutdown_proxy_allocator(&allocator); 74 CHK(mem_allocated_size() == 0); 75 return 0; 76 }