LCOV - code coverage report
Current view: top level - test - checktools.inc (source / functions) Hit Total Coverage
Test: mkernel.info Lines: 17 18 94.4 %
Date: 2025-02-25 19:40:41 Functions: 5 5 100.0 %

          Line data    Source code
       1             : /**
       2             :  *    file  checktools.inc
       3             :  *   brief 
       4             :  *
       5             :  *  author  François Cerbelle (Fanfan), francois@cerbelle.net
       6             :  *
       7             :  *  internal
       8             :  *       Created:  19/07/2024
       9             :  *      Revision:  none
      10             :  * Last modified:  2024-10-31 00:54
      11             :  *      Compiler:  gcc
      12             :  *  Organization:  Cerbelle.net
      13             :  *     Copyright:  Copyright (c) 2024, François Cerbelle
      14             :  *
      15             :  *  This source code is released for free distribution under the terms of the
      16             :  *  GNU General Public License as published by the Free Software Foundation.
      17             :  */
      18             : 
      19             : 
      20             : #ifdef HAVE_CONFIG_H
      21             : #include "config.h"
      22             : #endif
      23             : 
      24             : #include <unistd.h>                             /* pid_t getpid() */
      25             : #include <sys/stat.h>                           /* mkdir(), chdir(), mode_t */
      26             : 
      27             : #ifdef GCOV
      28             : #include <signal.h>                             /* signal(), SIGABRT, SIG_DFL */
      29             : void __gcov_dump();
      30          77 : static void signals_handler(int sig)
      31             : {
      32             :     (void)sig;
      33          77 :     signal(SIGABRT,SIG_DFL);
      34          77 :     signal(SIGSEGV,SIG_DFL);
      35          77 :     __gcov_dump();
      36           0 : }
      37             : #endif /* GCOV */
      38             : 
      39        5950 : static void signals_catch() {
      40             : #ifdef GCOV
      41        5950 :     signal(SIGABRT,signals_handler);
      42        5950 :     signal(SIGSEGV,signals_handler);
      43             : #endif
      44        5950 : }
      45             : 
      46        5793 : static void signals_release() {
      47             : #ifdef GCOV
      48        5793 :     signal(SIGABRT,SIG_DFL);
      49        5793 :     signal(SIGSEGV,SIG_DFL);
      50             : #endif
      51        5793 : }
      52             : 
      53             : static pid_t _forktest_pid;
      54             : 
      55       35410 : static void forktest_init() {
      56       35410 :     _forktest_pid = getpid();
      57       35410 : }
      58             : 
      59             : #define forktest_only if (_forktest_pid==getpid()) return
      60             : 
      61        5950 : static void forktest_gprofdir() {
      62             : #ifdef GPROF
      63             :     if (_forktest_pid!=getpid()) {
      64             :         /* Forked : mkdir/chdir to a subdir for gmon.out */
      65             :         char dirname[20];
      66             :         int result = snprintf(dirname, 20, "%d", getpid());
      67             :         if ((0<result)&&(20>result)) {
      68             :             mkdir("gprof", S_IRWXU);
      69             :             chdir("gprof");
      70             :             mkdir(dirname, S_IRWXU);
      71             :             chdir(dirname);
      72             :         } else {
      73             :             fprintf(stderr,"Unable to create GPROF/gmon.out subdir\n");
      74             :             abort();
      75             :         }
      76             :     }
      77             : #endif /* GPROF */
      78        5950 : }
      79             : 
      80             : /* vim:se filetype=c : */

Generated by: LCOV version 1.16