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

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

Generated by: LCOV version 1.16