star-vx

Structuring voxels for ray-tracing
git clone git://git.meso-star.fr/star-vx.git
Log | Files | Refs | README | LICENSE

commit 4921220dd28c71da5d3b265005c09e599f6c99ca
parent 6cd5a2d27503eddf4d71969c9af9f903abc33a70
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Thu,  1 Feb 2018 10:42:48 +0100

Change the project prefix from htvx to htvox

Diffstat:
Mcmake/CMakeLists.txt | 48++++++++++++++++++++++++------------------------
Asrc/htvox.h | 118+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/htvox_device.c | 95+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/htvox_device.h | 29+++++++++++++++++++++++++++++
Asrc/htvox_scene.c | 22++++++++++++++++++++++
Dsrc/htvx.h | 118-------------------------------------------------------------------------------
Dsrc/htvx_device.c | 95-------------------------------------------------------------------------------
Dsrc/htvx_device.h | 29-----------------------------
Asrc/test_htvox_device.c | 65+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/test_htvox_utils.h | 34++++++++++++++++++++++++++++++++++
Dsrc/test_htvx_device.c | 65-----------------------------------------------------------------
Dsrc/test_htvx_utils.h | 34----------------------------------
12 files changed, 387 insertions(+), 365 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -14,10 +14,10 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. cmake_minimum_required(VERSION 2.8) -project(htvx C) +project(htvox C) enable_testing() -set(HTVX_SOURCE_DIR ${PROJECT_SOURCE_DIR}/../src) +set(HTVOX_SOURCE_DIR ${PROJECT_SOURCE_DIR}/../src) option(NO_TEST "Do not build tests" OFF) ################################################################################ @@ -40,30 +40,30 @@ set(VERSION_MINOR 0) set(VERSION_PATCH 0) set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}) -set(HTVX_FILES_SRC - htvx_device.c) +set(HTVOX_FILES_SRC + htvox_device.c) set(SSOL_FILES_INC - htvx_device.h) + htvox_device.h) set(SSOL_FILES_INC_API - htvx.h) + htvox.h) -set(HTVX_FILES_DOC COPYING README.md) +set(HTVOX_FILES_DOC COPYING README.md) -# Prepend each file in the `HTVX_FILES_<SRC|INC>' list by `HTVX_SOURCE_DIR' -rcmake_prepend_path(HTVX_FILES_SRC ${HTVX_SOURCE_DIR}) -rcmake_prepend_path(HTVX_FILES_INC ${HTVX_SOURCE_DIR}) -rcmake_prepend_path(HTVX_FILES_INC_API ${HTVX_SOURCE_DIR}) -rcmake_prepend_path(HTVX_FILES_DOC ${PROJECT_SOURCE_DIR}/../) +# Prepend each file in the `HTVOX_FILES_<SRC|INC>' list by `HTVOX_SOURCE_DIR' +rcmake_prepend_path(HTVOX_FILES_SRC ${HTVOX_SOURCE_DIR}) +rcmake_prepend_path(HTVOX_FILES_INC ${HTVOX_SOURCE_DIR}) +rcmake_prepend_path(HTVOX_FILES_INC_API ${HTVOX_SOURCE_DIR}) +rcmake_prepend_path(HTVOX_FILES_DOC ${PROJECT_SOURCE_DIR}/../) -add_library(htvx SHARED ${HTVX_FILES_SRC} ${HTVX_FILES_INC} ${HTVX_FILES_INC_API}) -target_link_libraries(htvx RSys) +add_library(htvox SHARED ${HTVOX_FILES_SRC} ${HTVOX_FILES_INC} ${HTVOX_FILES_INC_API}) +target_link_libraries(htvox RSys) -set_target_properties(htvx PROPERTIES - DEFINE_SYMBOL HTVX_SHARED_BUILD +set_target_properties(htvox PROPERTIES + DEFINE_SYMBOL HTVOX_SHARED_BUILD VERSION ${VERSION} SOVERSION ${VERSION_MAJOR}) -rcmake_setup_devel(htvx HTVX ${VERSION} high_tune/htvx.h) +rcmake_setup_devel(htvox HTVOX ${VERSION} high_tune/htvox.h) ################################################################################ # Add tests @@ -71,9 +71,9 @@ rcmake_setup_devel(htvx HTVX ${VERSION} high_tune/htvx.h) if(NOT NO_TEST) function(build_test _name) add_executable(${_name} - ${HTVX_SOURCE_DIR}/${_name}.c - ${HTVX_SOURCE_DIR}/test_htvx_utils.h) - target_link_libraries(${_name} htvx RSys) + ${HTVOX_SOURCE_DIR}/${_name}.c + ${HTVOX_SOURCE_DIR}/test_htvox_utils.h) + target_link_libraries(${_name} htvox RSys) endfunction() function(new_test _name) @@ -81,16 +81,16 @@ if(NOT NO_TEST) add_test(${_name} ${_name}) endfunction() - new_test(test_htvx_device) + new_test(test_htvox_device) endif() ################################################################################ # Define output & install directories ################################################################################ -install(TARGETS htvx +install(TARGETS htvox ARCHIVE DESTINATION bin LIBRARY DESTINATION lib RUNTIME DESTINATION bin) -install(FILES ${HTVX_FILES_INC_API} DESTINATION include/high_tune) -install(FILES ${HTVX_FILES_DOC} DESTINATION share/doc/htvx) +install(FILES ${HTVOX_FILES_INC_API} DESTINATION include/high_tune) +install(FILES ${HTVOX_FILES_DOC} DESTINATION share/doc/htvox) diff --git a/src/htvox.h b/src/htvox.h @@ -0,0 +1,118 @@ +/* Copyright (C) CNRS 2018 + * + * 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 HTVOX_H +#define HTVOX_H + +#include <rsys/rsys.h> + +/* Library symbol management */ +#if defined(HTVOX_SHARED_BUILD) /* Build shared library */ + #define HTVOX_API extern EXPORT_SYM +#elif defined(HTVOX_STATIC) /* Use/build static library */ + #define HTVOX_API extern LOCAL_SYM +#else /* Use shared library */ + #define HTVOX_API extern IMPORT_SYM +#endif + +/* Helper macro that asserts if the invocation of the htvox function `Func' + * returns an error. One should use this macro on htvox function calls for + * which no explicit error checking is performed */ +#ifndef NDEBUG + #define HTVOX(Func) ASSERT(htvox_ ## Func == RES_OK) +#else + #define HTVOX(Func) htvox_ ## Func +#endif + +enum htvox_type { + HTVOX_DOUBLE +}; + +struct htvox_voxel { + double data; /* Data of the voxel */ + size_t id; /* Indentifier of the voxel */ +}; + +struct htvox_hit { + double distance; /* Distance from the ray origin to the impacted voxel */ + struct htvox_voxel voxel; /* Intersected voxel */ +}; + +/* Forward declaration of external data types */ +struct logger; +struct mem_allocator; + +/* Forward declaration of opaque data types */ +struct htvox_device; +struct htvox_scene; + +BEGIN_DECLS + +/******************************************************************************* + * Device + ******************************************************************************/ +HTVOX_API res_T +htvox_device_create + (struct logger* logger, + struct mem_allocator* allocator, /* NULL <=> use default allocator */ + const int verbose, /* Verbosity level */ + struct htvox_device** htvox); + +HTVOX_API res_T +htvox_device_ref_get + (struct htvox_device* htvox); + +HTVOX_API res_T +htvox_device_ref_put + (struct htvox_device* htvox); + +/******************************************************************************* + * Scene + ******************************************************************************/ +HTVOX_API res_T +htvox_scene_create + (struct htvox_device, + const double lower[3], /* Lower bound of the scene */ + const double upper[3], /* Upper bound of the scene */ + const size_t nvoxels[3], /* # voxels along the 3 axis */ + const enum htvox_type type, /* Per voxel data type */ + void (*get)(const size_t xyz[3], double* value, void* ctx), + void* context, /* Client data send as the last param of the `get' callback */ + struct htvox_scene** scn); + +HTVOX_API res_T +htvox_scene_ref_get + (struct htvox_scene* scn); + +HTVOX_API res_T +htvox_scene_ref_put + (struct htvox_scene* scn); + +HTVOX_API res_T +htvox_scene_trace_ray + (struct htvox_scene* scn, + const double ray_origin[3], + const double ray_direction[3], + struct htvox_hit* hit); + +HTVOX_API res_T +htvox_scene_at + (struct htvox_scene* scn, + const double position[3], + struct htvox_voxel* voxel); + +#endif /* HTVOX_H */ + + diff --git a/src/htvox_device.c b/src/htvox_device.c @@ -0,0 +1,95 @@ +/* Copyright (C) CNRS 2018 + * + * 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 "htvox.h" +#include "htvox_device.h" + +#include <rsys/logger.h> +#include <rsys/mem_allocator.h> + +/******************************************************************************* + * Helper functions + ******************************************************************************/ +static void +device_release(ref_T* ref) +{ + struct htvox_device* dev; + ASSERT(ref); + dev = CONTAINER_OF(ref, struct htvox_device, ref); + MEM_RM(dev->allocator, dev); +} + +/******************************************************************************* + * Exported functions + ******************************************************************************/ +res_T +htvox_device_create + (struct logger* log, + struct mem_allocator* mem_allocator, + const int verbose, + struct htvox_device** out_dev) +{ + struct htvox_device* dev = NULL; + struct mem_allocator* allocator = NULL; + struct logger* logger = NULL; + res_T res = RES_OK; + + if(!out_dev) { + res = RES_BAD_ARG; + goto error; + } + + allocator = mem_allocator ? mem_allocator : &mem_default_allocator; + logger = log ? log : LOGGER_DEFAULT; + + dev = MEM_CALLOC(allocator, 1, sizeof(struct htvox_device)); + if(!dev) { + res = RES_MEM_ERR; + goto error; + } + + + ref_init(&dev->ref); + dev->allocator = allocator; + dev->logger = logger; + dev->verbose = verbose; + +exit: + if(out_dev) *out_dev = dev; + return res; +error: + if(dev) { + HTVOX(device_ref_put(dev)); + dev = NULL; + } + goto exit; +} + +res_T +htvox_device_ref_get(struct htvox_device* dev) +{ + if(!dev) return RES_BAD_ARG; + ref_get(&dev->ref); + return RES_OK; +} + +res_T +htvox_device_ref_put(struct htvox_device* dev) +{ + if(!dev) return RES_BAD_ARG; + ref_put(&dev->ref, device_release); + return RES_OK; +} + diff --git a/src/htvox_device.h b/src/htvox_device.h @@ -0,0 +1,29 @@ +/* Copyright (C) CNRS 2018 + * + * 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 HTVOX_DEVICE_H +#define HTVOX_DEVICE_H + +#include <rsys/ref_count.h> + +struct htvox_device { + int verbose; /* Verbosity level */ + struct logger* logger; + struct mem_allocator* allocator; + ref_T ref; +}; + +#endif /* HTVOX_DEVICE_H */ + diff --git a/src/htvox_scene.c b/src/htvox_scene.c @@ -0,0 +1,22 @@ +/* Copyright (C) CNRS 2018 + * + * 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 "htvx.h" + +/******************************************************************************* + * Exported functions + ******************************************************************************/ +res_T +htvx_scene_c diff --git a/src/htvx.h b/src/htvx.h @@ -1,118 +0,0 @@ -/* Copyright (C) CNRS 2018 - * - * 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 HTVX_H -#define HTVX_H - -#include <rsys/rsys.h> - -/* Library symbol management */ -#if defined(HTVX_SHARED_BUILD) /* Build shared library */ - #define HTVX_API extern EXPORT_SYM -#elif defined(HTVX_STATIC) /* Use/build static library */ - #define HTVX_API extern LOCAL_SYM -#else /* Use shared library */ - #define HTVX_API extern IMPORT_SYM -#endif - -/* Helper macro that asserts if the invocation of the htvx function `Func' - * returns an error. One should use this macro on htvx function calls for - * which no explicit error checking is performed */ -#ifndef NDEBUG - #define HTVX(Func) ASSERT(htvx_ ## Func == RES_OK) -#else - #define HTVX(Func) htvx_ ## Func -#endif - -enum htvx_type { - HTVX_DOUBLE -}; - -struct htvx_voxel { - double data; /* Data of the voxel */ - size_t id; /* Indentifier of the voxel */ -}; - -struct htvx_hit { - double distance; /* Distance from the ray origin to the impacted voxel */ - struct htvx_voxel voxel; /* Intersected voxel */ -}; - -/* Forward declaration of external data types */ -struct logger; -struct mem_allocator; - -/* Forward declaration of opaque data types */ -struct htvx_device; -struct htvx_scene; - -BEGIN_DECLS - -/******************************************************************************* - * Device - ******************************************************************************/ -HTVX_API res_T -htvx_device_create - (struct logger* logger, - struct mem_allocator* allocator, /* NULL <=> use default allocator */ - const int verbose, /* Verbosity level */ - struct htvx_device** htvx); - -HTVX_API res_T -htvx_device_ref_get - (struct htvx_device* htvx); - -HTVX_API res_T -htvx_device_ref_put - (struct htvx_device* htvx); - -/******************************************************************************* - * Scene - ******************************************************************************/ -HTVX_API res_T -htvx_scene_create - (struct htvx_device, - const double lower[3], /* Lower bound of the scene */ - const double upper[3], /* Upper bound of the scene */ - const size_t nvoxels[3], /* # voxels along the 3 axis */ - const enum htvx_type type, /* Per voxel data type */ - void (*get)(const size_t xyz[3], double* value, void* ctx), - void* context, /* Client data send as the last param of the `get' callback */ - struct htvx_scene** scn); - -HTVX_API res_T -htvx_scene_ref_get - (struct htvx_scene* scn); - -HTVX_API res_T -htvx_scene_ref_put - (struct htvx_scene* scn); - -HTVX_API res_T -htvx_scene_trace_ray - (struct htvx_scene* scn, - const double ray_origin[3], - const double ray_direction[3], - struct htvx_hit* hit); - -HTVX_API res_T -htvx_scene_at - (struct htvx_scene* scn, - const double position[3], - struct htvx_voxel* voxel); - -#endif /* HTVX_H */ - - diff --git a/src/htvx_device.c b/src/htvx_device.c @@ -1,95 +0,0 @@ -/* Copyright (C) CNRS 2018 - * - * 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 "htvx.h" -#include "htvx_device.h" - -#include <rsys/logger.h> -#include <rsys/mem_allocator.h> - -/******************************************************************************* - * Helper functions - ******************************************************************************/ -static void -device_release(ref_T* ref) -{ - struct htvx_device* dev; - ASSERT(ref); - dev = CONTAINER_OF(ref, struct htvx_device, ref); - MEM_RM(dev->allocator, dev); -} - -/******************************************************************************* - * Exported functions - ******************************************************************************/ -res_T -htvx_device_create - (struct logger* log, - struct mem_allocator* mem_allocator, - const int verbose, - struct htvx_device** out_dev) -{ - struct htvx_device* dev = NULL; - struct mem_allocator* allocator = NULL; - struct logger* logger = NULL; - res_T res = RES_OK; - - if(!out_dev) { - res = RES_BAD_ARG; - goto error; - } - - allocator = mem_allocator ? mem_allocator : &mem_default_allocator; - logger = log ? log : LOGGER_DEFAULT; - - dev = MEM_CALLOC(allocator, 1, sizeof(struct htvx_device)); - if(!dev) { - res = RES_MEM_ERR; - goto error; - } - - - ref_init(&dev->ref); - dev->allocator = allocator; - dev->logger = logger; - dev->verbose = verbose; - -exit: - if(out_dev) *out_dev = dev; - return res; -error: - if(dev) { - HTVX(device_ref_put(dev)); - dev = NULL; - } - goto exit; -} - -res_T -htvx_device_ref_get(struct htvx_device* dev) -{ - if(!dev) return RES_BAD_ARG; - ref_get(&dev->ref); - return RES_OK; -} - -res_T -htvx_device_ref_put(struct htvx_device* dev) -{ - if(!dev) return RES_BAD_ARG; - ref_put(&dev->ref, device_release); - return RES_OK; -} - diff --git a/src/htvx_device.h b/src/htvx_device.h @@ -1,29 +0,0 @@ -/* Copyright (C) CNRS 2018 - * - * 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 HTVX_DEVICE_H -#define HTVX_DEVICE_H - -#include <rsys/ref_count.h> - -struct htvx_device { - int verbose; /* Verbosity level */ - struct logger* logger; - struct mem_allocator* allocator; - ref_T ref; -}; - -#endif /* HTVX_DEVICE_H */ - diff --git a/src/test_htvox_device.c b/src/test_htvox_device.c @@ -0,0 +1,65 @@ +/* Copyright (C) CNRS 2018 + * + * 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 "htvox.h" +#include "test_htvox_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 htvox_device* htvox; + (void)argc, (void)argv; + + CHK(htvox_device_create(NULL, NULL, 0, NULL) == RES_BAD_ARG); + CHK(htvox_device_create(NULL, NULL, 0, &htvox) == RES_OK); + + CHK(htvox_device_ref_get(NULL) == RES_BAD_ARG); + CHK(htvox_device_ref_get(htvox) == RES_OK); + CHK(htvox_device_ref_put(NULL) == RES_BAD_ARG); + CHK(htvox_device_ref_put(htvox) == RES_OK); + CHK(htvox_device_ref_put(htvox) == RES_OK); + + CHK(mem_init_proxy_allocator(&allocator, &mem_default_allocator) == RES_OK); + CHK(htvox_device_create(NULL, &allocator, 1, &htvox) == RES_OK); + CHK(htvox_device_ref_put(htvox) == 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(htvox_device_create(&logger, &allocator, 0, &htvox) == RES_OK); + CHK(htvox_device_ref_put(htvox) == RES_OK); + CHK(htvox_device_create(&logger, NULL, 0, &htvox) == RES_OK); + CHK(htvox_device_ref_put(htvox) == 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_htvox_utils.h b/src/test_htvox_utils.h @@ -0,0 +1,34 @@ +/* Copyright (C) CNRS 2018 + * + * 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_HTVOX_UTILS_H +#define TEST_HTVOX_UTILS_H + +#include <rsys/mem_allocator.h> +#include <stdio.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_HTVOX_UTILS_H */ + diff --git a/src/test_htvx_device.c b/src/test_htvx_device.c @@ -1,65 +0,0 @@ -/* Copyright (C) CNRS 2018 - * - * 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 "htvx.h" -#include "test_htvx_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 htvx_device* htvx; - (void)argc, (void)argv; - - CHK(htvx_device_create(NULL, NULL, 0, NULL) == RES_BAD_ARG); - CHK(htvx_device_create(NULL, NULL, 0, &htvx) == RES_OK); - - CHK(htvx_device_ref_get(NULL) == RES_BAD_ARG); - CHK(htvx_device_ref_get(htvx) == RES_OK); - CHK(htvx_device_ref_put(NULL) == RES_BAD_ARG); - CHK(htvx_device_ref_put(htvx) == RES_OK); - CHK(htvx_device_ref_put(htvx) == RES_OK); - - CHK(mem_init_proxy_allocator(&allocator, &mem_default_allocator) == RES_OK); - CHK(htvx_device_create(NULL, &allocator, 1, &htvx) == RES_OK); - CHK(htvx_device_ref_put(htvx) == 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(htvx_device_create(&logger, &allocator, 0, &htvx) == RES_OK); - CHK(htvx_device_ref_put(htvx) == RES_OK); - CHK(htvx_device_create(&logger, NULL, 0, &htvx) == RES_OK); - CHK(htvx_device_ref_put(htvx) == 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_htvx_utils.h b/src/test_htvx_utils.h @@ -1,34 +0,0 @@ -/* Copyright (C) CNRS 2018 - * - * 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_HTVX_UTILS_H -#define TEST_HTVX_UTILS_H - -#include <rsys/mem_allocator.h> -#include <stdio.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_HTVX_UTILS_H */ -