test_suvm_device.c (2205B)
1 /* Copyright (C) 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 "suvm.h" 17 #include "test_suvm_utils.h" 18 19 #include <rsys/logger.h> 20 21 static 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 mem_allocator allocator; 33 struct logger logger; 34 struct suvm_device* suvm; 35 (void)argc, (void)argv; 36 37 CHK(suvm_device_create(NULL, NULL, 0, NULL) == RES_BAD_ARG); 38 CHK(suvm_device_create(NULL, NULL, 0, &suvm) == RES_OK); 39 40 CHK(suvm_device_ref_get(NULL) == RES_BAD_ARG); 41 CHK(suvm_device_ref_get(suvm) == RES_OK); 42 CHK(suvm_device_ref_put(NULL) == RES_BAD_ARG); 43 CHK(suvm_device_ref_put(suvm) == RES_OK); 44 CHK(suvm_device_ref_put(suvm) == RES_OK); 45 46 CHK(mem_init_proxy_allocator(&allocator, &mem_default_allocator) == RES_OK); 47 CHK(suvm_device_create(NULL, &allocator, 1, &suvm) == RES_OK); 48 CHK(suvm_device_ref_put(suvm) == RES_OK); 49 50 CHK(logger_init(&allocator, &logger) == RES_OK); 51 logger_set_stream(&logger, LOG_OUTPUT, log_stream, NULL); 52 logger_set_stream(&logger, LOG_ERROR, log_stream, NULL); 53 logger_set_stream(&logger, LOG_WARNING, log_stream, NULL); 54 55 CHK(suvm_device_create(&logger, &allocator, 0, &suvm) == RES_OK); 56 CHK(suvm_device_ref_put(suvm) == RES_OK); 57 CHK(suvm_device_create(&logger, NULL, 0, &suvm) == RES_OK); 58 CHK(suvm_device_ref_put(suvm) == RES_OK); 59 60 logger_release(&logger); 61 check_memory_allocator(&allocator); 62 mem_shutdown_proxy_allocator(&allocator); 63 CHK(mem_allocated_size() == 0); 64 return 0; 65 }