test_s3d_utils.h (1257B)
1 /* Copyright (C) 2015-2023, 2026 |Méso|Star> (contact@meso-star.com) 2 * 3 * This file is part of Star-3D. 4 * 5 * Star-3D is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * Star-3D is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with Star-3D. If not, see <http://www.gnu.org/licenses/>. */ 17 18 #ifndef TEST_S3D_UTILS_H 19 #define TEST_S3D_UTILS_H 20 21 #include <rsys/mem_allocator.h> 22 #include <stdio.h> 23 24 static INLINE float 25 rand_canonic(void) 26 { 27 int r; 28 while((r = rand()) == RAND_MAX); 29 return (float)r / (float)RAND_MAX; 30 } 31 32 static void 33 check_memory_allocator(struct mem_allocator* allocator) 34 { 35 if(MEM_ALLOCATED_SIZE(allocator)) { 36 char dump[512]; 37 MEM_DUMP(allocator, dump, sizeof(dump)/sizeof(char)); 38 fprintf(stderr, "%s\n", dump); 39 FATAL("Memory leaks\n"); 40 } 41 } 42 43 #endif /* TEST_S3D_UTILS_H */