Line data Source code
1 : /** \file check_oom.c 2 : * \brief Check unit testing framework main function for oom helpers 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* oomtest_suite(); 30 : 31 355 : int main(int argc, char* argv[], char* env[]) 32 : { 33 : SRunner *sr; 34 : int number_failed; 35 : enum print_output ck_verbosity; 36 : 37 : (void) env; /* Avoids "unused" warning */ 38 : 39 : /* 40 : * CK_SILENT 41 : * CK_MINIMAL 42 : * CK_NORMAL 43 : * CK_VERBOSE 44 : * CK_ENV 45 : */ 46 355 : ck_verbosity = CK_ENV; 47 355 : printf("Verbosity: "); 48 355 : if ((argc==2)&&(0==strcmp(argv[1],"-v"))) { 49 2 : printf("yes-CK_VERBOSE\n"); 50 2 : ck_verbosity = CK_VERBOSE; 51 : } else 52 353 : printf("default-CK_ENV (look for CK_VERBOSITY env)\n"); 53 : 54 : /* No OOM configuration for this unit test, I want to test oomtest_config in 55 : * several configuration, thus I need to fork childs for that. 56 : * oomtest_config will be invoked from test forks in test suites/testcases. 57 : * */ 58 : 59 : /* Empty suite, to initialize the framework with the specific 60 : * function and to display a CRLF in the output */ 61 355 : sr = srunner_create(suite_create("")); 62 : 63 : /* CK_FORK 64 : * CK_NOFORK 65 : * CK_FORK_GETENV (default) 66 : */ 67 355 : printf ("Fork mode (with signal catch): "); 68 355 : if ((getenv("CK_FORK")) && (strlen(getenv("CK_FORK"))>0)) { 69 3 : printf("%s if possible (CK_FORK defined)",getenv("CK_FORK")); 70 : } else { 71 352 : printf("yes if possible (default)"); 72 : } 73 355 : printf("\n"); 74 355 : srunner_set_fork_status (sr, CK_FORK_GETENV); 75 : 76 : /* Print what will be run, in case of environment variable override */ 77 355 : printf("CK_RUN_SUITE="); 78 355 : if ((getenv("CK_RUN_SUITE")) && (strlen(getenv("CK_RUN_SUITE"))>0)) 79 2 : printf("%s\n",getenv("CK_RUN_SUITE")); 80 : else 81 353 : printf("all\n"); 82 355 : printf("CK_RUN_CASE="); 83 355 : if ((getenv("CK_RUN_CASE")) && (strlen(getenv("CK_RUN_CASE"))>0)) 84 2 : printf("%s\n",getenv("CK_RUN_CASE")); 85 : else 86 353 : printf("all\n"); 87 355 : printf("CK_INCLUDE_TAGS="); 88 355 : if ((getenv("CK_INCLUDE_TAGS")) && (strlen(getenv("CK_INCLUDE_TAGS"))>0)) 89 2 : printf("%s\n",getenv("CK_INCLUDE_TAGS")); 90 : else 91 353 : printf("all\n"); 92 355 : printf("CK_EXCLUDE_TAGS="); 93 355 : if ((getenv("CK_EXCLUDE_TAGS")) && (strlen(getenv("CK_EXCLUDE_TAGS"))>0)) 94 2 : printf("%s\n",getenv("CK_EXCLUDE_TAGS")); 95 : else 96 353 : printf("all\n"); 97 : 98 355 : srunner_add_suite (sr, sample_suite()); 99 355 : srunner_add_suite (sr, oomtest_suite()); 100 : 101 355 : srunner_run_all(sr, ck_verbosity); 102 : 103 4 : number_failed = srunner_ntests_failed(sr); 104 4 : srunner_free(sr); 105 : 106 : /* Output memory usage and leaks report */ 107 4 : memreport(); 108 : 109 4 : printf("\n"); 110 : 111 : /* 112 : * Return error code 1 if the one of test failed. 113 : * Return 77 if test skipped 114 : */ 115 4 : return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 116 : }