Line data Source code
1 : /** \file check_libdebug.c 2 : * \brief Check unit testing framework main function for libdebug 3 : * \author François Cerbelle (Fanfan), francois@cerbelle.net 4 : * 5 : * \internal 6 : * Created: 19/03/2022 7 : * Revision: none 8 : * Last modified: 2024-07-21 13:12 9 : * Compiler: gcc 10 : * Organization: Cerbelle.net 11 : * Copyright: Copyright (c) 2024, François Cerbelle 12 : * 13 : * This source code is released for free distribution under the terms of the 14 : * GNU General Public License as published by the Free Software Foundation. 15 : */ 16 : 17 : #ifdef HAVE_CONFIG_H 18 : #include "config.h" 19 : #endif 20 : 21 : #include "oom.h" /* oomtest_setup */ 22 : #include <check.h> 23 : #include <stdlib.h> /* EXIT_SUCCESS */ 24 : #include <stdio.h> /* printf */ 25 : #include <stdlib.h> /* abort() */ 26 : #include "debug/memory.h" /* memreport */ 27 : 28 : Suite* sample_suite(); 29 : Suite* libdebug_memtrack_suite(); 30 : Suite* libdebug_memdbg_suite(); 31 : Suite* libdebug_memory_suite(); 32 : Suite* libdebug_assert_suite(); 33 : 34 3909 : int main(int argc, char* argv[], char* env[]) 35 : { 36 : SRunner *sr; 37 : int number_failed; 38 : enum print_output ck_verbosity; 39 : 40 : (void) env; /* Avoids "unused" warning */ 41 : 42 : /* 43 : * CK_SILENT 44 : * CK_MINIMAL 45 : * CK_NORMAL 46 : * CK_VERBOSE 47 : * CK_ENV 48 : */ 49 3909 : ck_verbosity = CK_ENV; 50 3909 : printf("Verbosity: "); 51 3909 : if ((argc==2)&&(0==strcmp(argv[1],"-v"))) { 52 2 : printf("yes-CK_VERBOSE\n"); 53 2 : ck_verbosity = CK_VERBOSE; 54 : } else 55 3907 : printf("default-CK_ENV (look for CK_VERBOSITY env)\n"); 56 : 57 : /* Limit available RAM to really available RAM for all 58 : * suites/testcase/process/fork to test OOM without exhausting the system's 59 : * resources, hitting the swap or consumming too much time to fill the RAM 60 : * */ 61 3909 : oomtest_config(RAMLIMIT_HARD); 62 : 63 : /* Empty suite, to initialize the framework with the specific 64 : * function and to display a CRLF in the output */ 65 3909 : sr = srunner_create(suite_create("")); 66 : 67 : /* CK_FORK 68 : * CK_NOFORK 69 : * CK_FORK_GETENV (default) 70 : */ 71 3909 : printf ("Fork mode (with signal catch): "); 72 3909 : if ((getenv("CK_FORK")) && (strlen(getenv("CK_FORK"))>0)) { 73 3 : printf("%s if possible (CK_FORK defined)",getenv("CK_FORK")); 74 : } else { 75 3906 : printf("yes if possible (default)"); 76 : } 77 3909 : printf("\n"); 78 3909 : srunner_set_fork_status (sr, CK_FORK_GETENV); 79 : 80 : /* Print what will be run, in case of environment variable override */ 81 3909 : printf("CK_RUN_SUITE="); 82 3909 : if ((getenv("CK_RUN_SUITE")) && (strlen(getenv("CK_RUN_SUITE"))>0)) 83 2 : printf("%s\n",getenv("CK_RUN_SUITE")); 84 : else 85 3907 : printf("all\n"); 86 3909 : printf("CK_RUN_CASE="); 87 3909 : if ((getenv("CK_RUN_CASE")) && (strlen(getenv("CK_RUN_CASE"))>0)) 88 2 : printf("%s\n",getenv("CK_RUN_CASE")); 89 : else 90 3907 : printf("all\n"); 91 3909 : printf("CK_INCLUDE_TAGS="); 92 3909 : if ((getenv("CK_INCLUDE_TAGS")) && (strlen(getenv("CK_INCLUDE_TAGS"))>0)) 93 2 : printf("%s\n",getenv("CK_INCLUDE_TAGS")); 94 : else 95 3907 : printf("all\n"); 96 3909 : printf("CK_EXCLUDE_TAGS="); 97 3909 : if ((getenv("CK_EXCLUDE_TAGS")) && (strlen(getenv("CK_EXCLUDE_TAGS"))>0)) 98 2 : printf("%s\n",getenv("CK_EXCLUDE_TAGS")); 99 : else 100 3907 : printf("all\n"); 101 : 102 3909 : srunner_add_suite (sr, sample_suite()); 103 3909 : srunner_add_suite (sr, libdebug_memtrack_suite()); 104 3909 : srunner_add_suite (sr, libdebug_memdbg_suite()); 105 3909 : srunner_add_suite (sr, libdebug_memory_suite()); 106 3909 : srunner_add_suite (sr, libdebug_assert_suite()); 107 : 108 3909 : srunner_run_all(sr, ck_verbosity); 109 : 110 3 : number_failed = srunner_ntests_failed(sr); 111 3 : srunner_free(sr); 112 : 113 : /* Output memory usage and leaks report */ 114 3 : memreport(); 115 : 116 3 : printf("\n"); 117 : 118 : /* 119 : * Return error code 1 if the one of test failed. 120 : * Return 77 if test skipped 121 : */ 122 3 : return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 123 : }