test_sg2d_device.c (2368B)
1 /* Copyright (C) 2019, 2020, 2023 |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 "sg2d.h" 17 #include "test_sg2d_utils.h" 18 19 #include <rsys/logger.h> 20 21 static INLINE void 22 log_stream(const char* msg, void* ctx) 23 { 24 ASSERT(msg); 25 (void) msg, (void) ctx; 26 printf("%s\n", msg); 27 } 28 29 int 30 main(int argc, char** argv) 31 { 32 struct logger logger; 33 struct mem_allocator allocator; 34 struct sg2d_device* dev; 35 (void)argc, (void)argv; 36 37 BA(sg2d_device_create(NULL, NULL, 0, NULL)); 38 OK(sg2d_device_create(NULL, NULL, 0, &dev)); 39 BA(sg2d_device_ref_get(NULL)); 40 OK(sg2d_device_ref_get(dev)); 41 BA(sg2d_device_ref_put(NULL)); 42 OK(sg2d_device_ref_put(dev)); 43 OK(sg2d_device_ref_put(dev)); 44 45 OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator)); 46 47 CHK(MEM_ALLOCATED_SIZE(&allocator) == 0); 48 BA(sg2d_device_create(NULL, &allocator, 0, NULL)); 49 OK(sg2d_device_create(NULL, &allocator, 0, &dev)); 50 OK(sg2d_device_ref_put(dev)); 51 CHK(MEM_ALLOCATED_SIZE(&allocator) == 0); 52 53 OK(logger_init(&allocator, &logger)); 54 logger_set_stream(&logger, LOG_OUTPUT, log_stream, NULL); 55 logger_set_stream(&logger, LOG_ERROR, log_stream, NULL); 56 logger_set_stream(&logger, LOG_WARNING, log_stream, NULL); 57 58 BA(sg2d_device_create(&logger, NULL, 0, NULL)); 59 OK(sg2d_device_create(&logger, NULL, 1, &dev)); 60 OK(sg2d_device_ref_put(dev)); 61 62 BA(sg2d_device_create(&logger, &allocator, 0, NULL)); 63 OK(sg2d_device_create(&logger, &allocator, 0, &dev)); 64 OK(sg2d_device_ref_put(dev)); 65 66 OK(sg2d_device_create(&logger, &allocator, 0, &dev)); 67 OK(sg2d_device_ref_put(dev)); 68 69 logger_release(&logger); 70 check_memory_allocator(&allocator); 71 mem_shutdown_proxy_allocator(&allocator); 72 CHK(mem_allocated_size() == 0); 73 return 0; 74 } 75