solstice-solver

Solver library of the solstice app
git clone git://git.meso-star.com/solstice-solver.git
Log | Files | Refs | README | LICENSE

commit d5febcc9d8e96d096adeaedc2f4489a474a560ca
parent 9d33f8d47feb43b0d7f3f7368eb07a3e888587fb
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Thu, 23 Jun 2016 18:09:37 +0200

Add first test.

Just testing ssol_device API.

Diffstat:
Asrc/test_ssol_device.c | 76++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/test_ssol_utils.h | 50++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 126 insertions(+), 0 deletions(-)

diff --git a/src/test_ssol_device.c b/src/test_ssol_device.c @@ -0,0 +1,76 @@ +/* Copyright (C) CNRS 2016 + * + * 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 "ssol.h" +#include "test_ssol_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 logger logger; + struct mem_allocator allocator; + struct ssol_device* dev; + (void)argc, (void)argv; + + CHECK(ssol_device_create(NULL, NULL, 0, 0, NULL), RES_BAD_ARG); + CHECK(ssol_device_create(NULL, NULL, SSOL_NTHREADS_DEFAULT, 0, &dev), RES_OK); + + CHECK(ssol_device_ref_get(NULL), RES_BAD_ARG); + CHECK(ssol_device_ref_get(dev), RES_OK); + CHECK(ssol_device_ref_put(NULL), RES_BAD_ARG); + CHECK(ssol_device_ref_put(dev), RES_OK); + CHECK(ssol_device_ref_put(dev), RES_OK); + + mem_init_proxy_allocator(&allocator, &mem_default_allocator); + + CHECK(MEM_ALLOCATED_SIZE(&allocator), 0); + CHECK(ssol_device_create(NULL, &allocator, 2, 0, NULL), RES_BAD_ARG); + CHECK(ssol_device_create(NULL, &allocator, SSOL_NTHREADS_DEFAULT, 0, &dev), RES_OK); + CHECK(ssol_device_ref_put(dev), RES_OK); + CHECK(MEM_ALLOCATED_SIZE(&allocator), 0); + + CHECK(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); + + CHECK(ssol_device_create(&logger, NULL, 4, 0, NULL), RES_BAD_ARG); + CHECK(ssol_device_create(&logger, NULL, SSOL_NTHREADS_DEFAULT, 0, &dev), RES_OK); + CHECK(ssol_device_ref_put(dev), RES_OK); + + CHECK(ssol_device_create(&logger, &allocator, 2, 0, NULL), RES_BAD_ARG); + CHECK(ssol_device_create(&logger, &allocator, SSOL_NTHREADS_DEFAULT, 0, &dev), RES_OK); + CHECK(ssol_device_ref_put(dev), RES_OK); + + CHECK(ssol_device_create(&logger, &allocator, 0, 0, &dev), RES_BAD_ARG); + CHECK(ssol_device_create(&logger, &allocator, SSOL_NTHREADS_DEFAULT, 0, &dev), RES_OK); + CHECK(ssol_device_ref_put(dev), RES_OK); + + logger_release(&logger); + check_memory_allocator(&allocator); + mem_shutdown_proxy_allocator(&allocator); + CHECK(mem_allocated_size(), 0); + return 0; +} diff --git a/src/test_ssol_utils.h b/src/test_ssol_utils.h @@ -0,0 +1,50 @@ +/* Copyright (C) |Meso|Star> 2015-2016 (contact@meso-star.com) + * + * This software is a computer program whose purpose is to describe a + * virtual 3D environment that can be ray-traced and sampled both robustly + * and efficiently. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. */ + +#ifndef TEST_S3D_UTILS_H +#define TEST_S3D_UTILS_H + +#include <rsys/mem_allocator.h> +#include <stdio.h> + +static 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_S3D_UTILS_H */