LCOV - code coverage report
Current view: top level - test - check_test.c (source / functions) Hit Total Coverage
Test: mkernel.info Lines: 38 38 100.0 %
Date: 2024-08-25 14:31:25 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /**   \file  check_test.c
       2             :  *   \brief  Check unit testing framework main function
       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 "debug/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             : 
      30           7 : int main(int argc, char* argv[], char* env[])
      31             : {
      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           7 :     ck_verbosity = CK_ENV;
      46           7 :     printf("Verbosity: ");
      47           7 :     if ((argc==2)&&(0==strcmp(argv[1],"-v"))) {
      48           2 :         printf("yes-CK_VERBOSE\n");
      49           2 :         ck_verbosity = CK_VERBOSE;
      50             :     } else
      51           5 :         printf("default-CK_ENV (look for CK_VERBOSITY env)\n");
      52             : 
      53             :     /* Limit available RAM to really available RAM for all
      54             :      * suites/testcase/process/fork to test OOM without exhausting the system's
      55             :      * resources, hitting the swap or consumming too much time to fill the RAM
      56             :      * */
      57           7 :     oomtest_config(RAMLIMIT_HARD);
      58             : 
      59             :     /* Empty suite, to initialize the framework with the specific
      60             :      * function and to display a CRLF in the output */
      61           7 :     sr = srunner_create(suite_create(""));
      62             : 
      63             :     /*  CK_FORK
      64             :      *  CK_NOFORK
      65             :      *  CK_FORK_GETENV (default)
      66             :      */
      67           7 :     printf ("Fork mode (with signal catch): ");
      68           7 :     if ((getenv("CK_FORK")) && (strlen(getenv("CK_FORK"))>0)) {
      69           3 :         printf("%s if possible (CK_FORK defined)",getenv("CK_FORK"));
      70             :     } else {
      71           4 :         printf("yes if possible (default)");
      72             :     }
      73           7 :     printf("\n");
      74           7 :     srunner_set_fork_status (sr, CK_FORK_GETENV);
      75             : 
      76             :     /* Print what will be run, in case of environment variable override */
      77           7 :     printf("CK_RUN_SUITE=");
      78           7 :     if ((getenv("CK_RUN_SUITE")) && (strlen(getenv("CK_RUN_SUITE"))>0))
      79           2 :         printf("%s\n",getenv("CK_RUN_SUITE"));
      80             :     else
      81           5 :         printf("all\n");
      82           7 :     printf("CK_RUN_CASE=");
      83           7 :     if ((getenv("CK_RUN_CASE")) && (strlen(getenv("CK_RUN_CASE"))>0))
      84           2 :         printf("%s\n",getenv("CK_RUN_CASE"));
      85             :     else
      86           5 :         printf("all\n");
      87           7 :     printf("CK_INCLUDE_TAGS=");
      88           7 :     if ((getenv("CK_INCLUDE_TAGS")) && (strlen(getenv("CK_INCLUDE_TAGS"))>0))
      89           2 :         printf("%s\n",getenv("CK_INCLUDE_TAGS"));
      90             :     else
      91           5 :         printf("all\n");
      92           7 :     printf("CK_EXCLUDE_TAGS=");
      93           7 :     if ((getenv("CK_EXCLUDE_TAGS")) && (strlen(getenv("CK_EXCLUDE_TAGS"))>0))
      94           2 :         printf("%s\n",getenv("CK_EXCLUDE_TAGS"));
      95             :     else
      96           5 :         printf("all\n");
      97             : 
      98           7 :     srunner_add_suite (sr, sample_suite());
      99             : 
     100           7 :     srunner_run_all(sr, ck_verbosity);
     101             : 
     102           4 :     number_failed = srunner_ntests_failed(sr);
     103           4 :     srunner_free(sr);
     104             : 
     105             :     /* Output memory usage and leaks report */
     106           4 :     memreport();
     107             : 
     108           4 :     printf("\n");
     109             : 
     110             :     /*
     111             :      * Return error code 1 if the one of test failed.
     112             :      * Return 77 if test skipped
     113             :      */
     114           4 :     return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
     115             : }

Generated by: LCOV version 1.16