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