star-schiff

Library for estimating radiative properties
git clone git://git.meso-star.com/star-schiff.git
Log | Files | Refs | README | LICENSE

test_sschiff_device.c (3836B)


      1 /* Copyright (C) 2015, 2016, 2026 Centre National de la Recherche Scientifique
      2  * Copyright (C) 2026 Clermont Auvergne INP
      3  * Copyright (C) 2026 Institut Mines Télécom Albi-Carmaux
      4  * Copyright (C) 2020, 2021, 2023, 2026 |Méso|Star> (contact@meso-star.com)
      5  * Copyright (C) 2026 Université de Lorraine
      6  * Copyright (C) 2026 Université de Toulouse
      7  *
      8  * This program is free software: you can redistribute it and/or modify
      9  * it under the terms of the GNU General Public License as published by
     10  * the Free Software Foundation, either version 3 of the License, or
     11  * (at your option) any later version.
     12  *
     13  * This program is distributed in the hope that it will be useful,
     14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     16  * GNU General Public License for more details.
     17  *
     18  * You should have received a copy of the GNU General Public License
     19  * along with this program. If not, see <http://www.gnu.org/licenses/>. */
     20 
     21 #include "sschiff.h"
     22 #include "test_sschiff_utils.h"
     23 
     24 #include <rsys/logger.h>
     25 #include <rsys/mem_allocator.h>
     26 #include <rsys/rsys.h>
     27 
     28 #include <star/s3d.h>
     29 #define N SSCHIFF_NTHREADS_DEFAULT
     30 
     31 static void
     32 log_stream(const char* msg, void* ctx)
     33 {
     34   ASSERT(msg);
     35   (void)msg, (void)ctx;
     36   printf("%s\n", msg);
     37 }
     38 
     39 int
     40 main(int argc, char** argv)
     41 {
     42   struct logger logger;
     43   struct mem_allocator allocator;
     44   struct sschiff_device* dev;
     45   struct s3d_device* s3d;
     46   unsigned nthreads;
     47 
     48   (void)argc, (void)argv;
     49 
     50   CHK(sschiff_device_create(NULL, NULL, N, 0, NULL, NULL) == RES_BAD_ARG);
     51   CHK(sschiff_device_create(NULL, NULL, N, 0, NULL, &dev) == RES_OK);
     52 
     53   CHK(sschiff_device_ref_get(NULL) == RES_BAD_ARG);
     54   CHK(sschiff_device_ref_get(dev) == RES_OK);
     55   CHK(sschiff_device_ref_put(NULL) == RES_BAD_ARG);
     56   CHK(sschiff_device_ref_put(dev) == RES_OK);
     57   CHK(sschiff_device_ref_put(dev) == RES_OK);
     58 
     59   mem_init_proxy_allocator(&allocator, &mem_default_allocator);
     60 
     61   CHK(MEM_ALLOCATED_SIZE(&allocator) == 0);
     62   CHK(sschiff_device_create(NULL, &allocator, N, 1, NULL, NULL) == RES_BAD_ARG);
     63   CHK(sschiff_device_create(NULL, &allocator, N, 1, NULL, &dev) == RES_OK);
     64   CHK(sschiff_device_ref_put(dev) == RES_OK);
     65   CHK(MEM_ALLOCATED_SIZE(&allocator) == 0);
     66 
     67   CHK(logger_init(&allocator, &logger) == RES_OK);
     68   logger_set_stream(&logger, LOG_OUTPUT, log_stream, NULL);
     69   logger_set_stream(&logger, LOG_ERROR, log_stream, NULL);
     70   logger_set_stream(&logger, LOG_WARNING, log_stream, NULL);
     71 
     72   CHK(sschiff_device_create(&logger, NULL, N, 0, NULL, NULL) == RES_BAD_ARG);
     73   CHK(sschiff_device_create(&logger, NULL, N, 0, NULL, &dev) == RES_OK);
     74   CHK(sschiff_device_ref_put(dev) == RES_OK);
     75 
     76   CHK(sschiff_device_create(&logger, &allocator, N, 1, NULL, NULL) == RES_BAD_ARG);
     77   CHK(sschiff_device_create(&logger, &allocator, N, 1, NULL, &dev) == RES_OK);
     78   CHK(sschiff_device_ref_put(dev) == RES_OK);
     79 
     80   CHK(s3d_device_create(NULL, NULL, 0, &s3d) == RES_OK);
     81   CHK(sschiff_device_create(NULL, NULL, N, 0, s3d, NULL) == RES_BAD_ARG);
     82   CHK(sschiff_device_create(NULL, NULL, N, 0, s3d, &dev) == RES_OK);
     83 
     84   CHK(s3d_device_ref_put(s3d) == RES_OK);
     85   CHK(sschiff_device_ref_put(dev) == RES_OK);
     86 
     87   CHK(sschiff_device_create(NULL, NULL, 0, 0, NULL, &dev) == RES_BAD_ARG);
     88   CHK(sschiff_device_create(NULL, NULL, 1, 0, NULL, &dev) == RES_OK);
     89 
     90   CHK(sschiff_device_get_threads_count(NULL, NULL) == RES_BAD_ARG);
     91   CHK(sschiff_device_get_threads_count(dev, NULL) == RES_BAD_ARG);
     92   CHK(sschiff_device_get_threads_count(NULL, &nthreads) == RES_BAD_ARG);
     93   CHK(sschiff_device_get_threads_count(dev, &nthreads) == RES_OK);
     94   CHK(nthreads == 1);
     95 
     96   CHK(sschiff_device_ref_put(dev) == RES_OK);
     97 
     98   logger_release(&logger);
     99   check_memory_allocator(&allocator);
    100   mem_shutdown_proxy_allocator(&allocator);
    101   CHK(mem_allocated_size() == 0);
    102   return 0;
    103 }
    104