Sun, 14 Feb 2021 11:30:47 +0100
add test config and let the test binary return nonzero on test failures
test/test_allocator.c | file | annotate | diff | comparison | revisions | |
test/test_config.h | file | annotate | diff | comparison | revisions |
1.1 --- a/test/test_allocator.c Sun Feb 14 11:30:19 2021 +0100 1.2 +++ b/test/test_allocator.c Sun Feb 14 11:30:47 2021 +0100 1.3 @@ -27,8 +27,7 @@ 1.4 */ 1.5 1.6 #include "cx/allocator.h" 1.7 - 1.8 -#include <CUnit/Basic.h> 1.9 +#include "test_config.h" 1.10 1.11 void test_default_allocator_available(void) { 1.12 cx_allocator_class *clazz = cxDefaultAllocator->cl; 1.13 @@ -69,26 +68,31 @@ 1.14 return CU_get_error(); 1.15 } 1.16 1.17 - suite = CU_add_suite("stdlib allocator", NULL, NULL); 1.18 + suite = CU_add_suite("default allocator", NULL, NULL); 1.19 if (NULL == suite) { 1.20 CU_cleanup_registry(); 1.21 return CU_get_error(); 1.22 } 1.23 1.24 if ( 1.25 - (NULL == CU_add_test(suite, "default allocator available", test_default_allocator_available)) || 1.26 - (NULL == CU_add_test(suite, "test of malloc()", test_default_malloc)) || 1.27 - (NULL == CU_add_test(suite, "test of realloc()", test_default_realloc)) || 1.28 - (NULL == CU_add_test(suite, "test of realloc()", test_default_calloc)) || 1.29 - (NULL == CU_add_test(suite, "test of free()", test_default_free)) 1.30 + !CU_add_test(suite, "default allocator available", test_default_allocator_available) || 1.31 + !CU_add_test(suite, "test of malloc()", test_default_malloc)|| 1.32 + !CU_add_test(suite, "test of realloc()", test_default_realloc) || 1.33 + !CU_add_test(suite, "test of realloc()", test_default_calloc) || 1.34 + !CU_add_test(suite, "test of free()", test_default_free) 1.35 ) { 1.36 CU_cleanup_registry(); 1.37 return CU_get_error(); 1.38 } 1.39 1.40 - CU_basic_set_mode(CU_BRM_NORMAL); 1.41 - CU_basic_run_tests(); 1.42 + CU_basic_set_mode(UCX_CU_BRM); 1.43 + 1.44 + int exitcode; 1.45 + if (CU_basic_run_tests()) { 1.46 + exitcode = CU_get_error(); 1.47 + } else { 1.48 + exitcode = CU_get_number_of_failures() == 0 ? 0 : 1; 1.49 + } 1.50 CU_cleanup_registry(); 1.51 - 1.52 - return CU_get_error(); 1.53 + return exitcode; 1.54 }
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/test_config.h Sun Feb 14 11:30:47 2021 +0100 2.3 @@ -0,0 +1,36 @@ 2.4 +/* 2.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 2.6 + * 2.7 + * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved. 2.8 + * 2.9 + * Redistribution and use in source and binary forms, with or without 2.10 + * modification, are permitted provided that the following conditions are met: 2.11 + * 2.12 + * 1. Redistributions of source code must retain the above copyright 2.13 + * notice, this list of conditions and the following disclaimer. 2.14 + * 2.15 + * 2. Redistributions in binary form must reproduce the above copyright 2.16 + * notice, this list of conditions and the following disclaimer in the 2.17 + * documentation and/or other materials provided with the distribution. 2.18 + * 2.19 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 2.20 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2.21 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2.22 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 2.23 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2.24 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2.25 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2.26 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2.27 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2.28 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2.29 + * POSSIBILITY OF SUCH DAMAGE. 2.30 + */ 2.31 + 2.32 +#ifndef UCX_TEST_CONFIG_H 2.33 +#define UCX_TEST_CONFIG_H 2.34 + 2.35 +#include <CUnit/Basic.h> 2.36 + 2.37 +#define UCX_CU_BRM CU_BRM_NORMAL 2.38 + 2.39 +#endif /* UCX_TEST_CONFIG_H */