star-uvm

Spatial structuring of unstructured volumetric meshes
git clone git://git.meso-star.fr/star-uvm.git
Log | Files | Refs | README | LICENSE

commit f04d37f62f0ab35a2f0092bc94263155171db313
parent d7f79fc9c490a9c871c215f06399020c0a85c7c4
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Sun, 20 Sep 2020 16:40:36 +0200

Test the device API

Diffstat:
Mcmake/CMakeLists.txt | 26+++++++++++++-------------
Asrc/test_suvm_device.c | 65+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/test_suvm_utils.h | 33+++++++++++++++++++++++++++++++++
3 files changed, 111 insertions(+), 13 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -74,19 +74,19 @@ rcmake_setup_devel(suvm StarUVM ${VERSION} star/suvm_version.h) # Add tests ################################################################################ if(NOT NO_TEST) - # function(build_test _name) - # add_executable(${_name} - # ${SUVM_SOURCE_DIR}/${_name}.c - # ${SUVM_SOURCE_DIR}/test_svx_utils.h) - # target_link_libraries(${_name} svx RSys ${ARGN}) - # endfunction() - # - # function(new_test _name) - # build_test(${_name} ${ARGN}) - # add_test(${_name} ${_name}) - # endfunction() - - # new_test(test_svx_bintree) + function(build_test _name) + add_executable(${_name} + ${SUVM_SOURCE_DIR}/${_name}.c + ${SUVM_SOURCE_DIR}/test_suvm_utils.h) + target_link_libraries(${_name} suvm RSys ${ARGN}) + endfunction() + + function(new_test _name) + build_test(${_name} ${ARGN}) + add_test(${_name} ${_name}) + endfunction() + + new_test(test_suvm_device) endif() ################################################################################ diff --git a/src/test_suvm_device.c b/src/test_suvm_device.c @@ -0,0 +1,65 @@ +/* Copyright (C) 2020 |Meso|Star> (contact@meso-star.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include "suvm.h" +#include "test_suvm_utils.h" + +#include <rsys/logger.h> + +static void +log_stream(const char* msg, void* ctx) +{ + ASSERT(msg); + (void)msg, (void)ctx; + printf("%s\n", msg); +} + +int +main(int argc, char** argv) +{ + struct mem_allocator allocator; + struct logger logger; + struct suvm_device* suvm; + (void)argc, (void)argv; + + CHK(suvm_device_create(NULL, NULL, 0, NULL) == RES_BAD_ARG); + CHK(suvm_device_create(NULL, NULL, 0, &suvm) == RES_OK); + + CHK(suvm_device_ref_get(NULL) == RES_BAD_ARG); + CHK(suvm_device_ref_get(suvm) == RES_OK); + CHK(suvm_device_ref_put(NULL) == RES_BAD_ARG); + CHK(suvm_device_ref_put(suvm) == RES_OK); + CHK(suvm_device_ref_put(suvm) == RES_OK); + + CHK(mem_init_proxy_allocator(&allocator, &mem_default_allocator) == RES_OK); + CHK(suvm_device_create(NULL, &allocator, 1, &suvm) == RES_OK); + CHK(suvm_device_ref_put(suvm) == RES_OK); + + CHK(logger_init(&allocator, &logger) == RES_OK); + logger_set_stream(&logger, LOG_OUTPUT, log_stream, NULL); + logger_set_stream(&logger, LOG_ERROR, log_stream, NULL); + logger_set_stream(&logger, LOG_WARNING, log_stream, NULL); + + CHK(suvm_device_create(&logger, &allocator, 0, &suvm) == RES_OK); + CHK(suvm_device_ref_put(suvm) == RES_OK); + CHK(suvm_device_create(&logger, NULL, 0, &suvm) == RES_OK); + CHK(suvm_device_ref_put(suvm) == RES_OK); + + logger_release(&logger); + check_memory_allocator(&allocator); + mem_shutdown_proxy_allocator(&allocator); + CHK(mem_allocated_size() == 0); + return 0; +} diff --git a/src/test_suvm_utils.h b/src/test_suvm_utils.h @@ -0,0 +1,33 @@ +/* Copyright (C) 2020 |Meso|Star> (contact@meso-star.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#ifndef TEST_SUVM_UTILS_H +#define TEST_SUVM_UTILS_H + +#include <rsys/mem_allocator.h> + +static INLINE void +check_memory_allocator(struct mem_allocator* allocator) +{ + if(MEM_ALLOCATED_SIZE(allocator)) { + char dump[512]; + MEM_DUMP(allocator, dump, sizeof(dump)/sizeof(char)); + fprintf(stderr, "%s\n", dump); + FATAL("Memory leaks\n"); + } +} + +#endif /* TEST_SUVM_UTILS_H */ +