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: 2024-07-29 18:25:04 Functions: 5 5 100.0 %

          Line data    Source code
       1             : /**
       2             :  *    file  checktools.inc
       3             :  *   brief 
       4             :  *
       5             :  *  test
       6             :  *  bug        A remark about a known bug in the code.
       7             :  *  version
       8             :  *  since
       9             :  *  note       A brief remark about the implementation to help clarify.
      10             :  *  attention  An important remark that may cause code to break
      11             :  *  warning    An import remark that may depend on random conditions etc.
      12             :  *  see        A reference to a class or a link to documentation (e.g. http://document.1a.com)
      13             :  *
      14             :  *  author  François Cerbelle (Fanfan), francois@cerbelle.net
      15             :  *
      16             :  *  internal
      17             :  *       Created:  19/07/2024
      18             :  *      Revision:  none
      19             :  * Last modified:  2024-07-19 15:28
      20             :  *      Compiler:  gcc
      21             :  *  Organization:  Cerbelle.net
      22             :  *     Copyright:  Copyright (c) 2024, François Cerbelle
      23             :  *
      24             :  *  This source code is released for free distribution under the terms of the
      25             :  *  GNU General Public License as published by the Free Software Foundation.
      26             :  */
      27             : 
      28             : 
      29             : #ifdef HAVE_CONFIG_H
      30             : #include "config.h"
      31             : #endif
      32             : 
      33             : #include <unistd.h>                             /* pid_t getpid() */
      34             : #include <sys/stat.h>                           /* mkdir(), chdir(), mode_t */
      35             : 
      36             : #ifdef GCOV
      37             : #include <signal.h>                             /* signal(), SIGABRT, SIG_DFL */
      38             : void __gcov_dump();
      39         173 : static void signals_handler(int sig)
      40             : {
      41             :     (void)sig;
      42         173 :     signal(SIGABRT,SIG_DFL);
      43         173 :     signal(SIGSEGV,SIG_DFL);
      44         173 :     __gcov_dump();
      45           0 : }
      46             : #endif /* GCOV */
      47             : 
      48        9323 : static void signals_catch() {
      49             : #ifdef GCOV
      50        9323 :     signal(SIGABRT,signals_handler);
      51        9323 :     signal(SIGSEGV,signals_handler);
      52             : #endif
      53        9323 : }
      54             : 
      55        8169 : static void signals_release() {
      56             : #ifdef GCOV
      57        8169 :     signal(SIGABRT,SIG_DFL);
      58        8169 :     signal(SIGSEGV,SIG_DFL);
      59             : #endif
      60        8169 : }
      61             : 
      62             : static pid_t _forktest_pid;
      63             : 
      64       58408 : static void forktest_init() {
      65       58408 :     _forktest_pid = getpid();
      66       58408 : }
      67             : 
      68             : #define forktest_only if (_forktest_pid==getpid()) return
      69             : 
      70        9323 : static void forktest_gprofdir() {
      71             : #ifdef GPROF
      72             :     if (_forktest_pid!=getpid()) {
      73             :         /* Forked : mkdir/chdir to a subdir for gmon.out */
      74             :         char dirname[20];
      75             :         int result = snprintf(dirname, 20, "%d", getpid());
      76             :         if ((0<result)&&(20>result)) {
      77             :             mkdir("gprof", S_IRWXU);
      78             :             chdir("gprof");
      79             :             mkdir(dirname, S_IRWXU);
      80             :             chdir(dirname);
      81             :         } else {
      82             :             fprintf(stderr,"Unable to create GPROF/gmon.out subdir\n");
      83             :             abort();
      84             :         }
      85             :     }
      86             : #endif /* GPROF */
      87        9323 : }
      88             : 
      89             : /* vim:se filetype=c : */

Generated by: LCOV version 1.16