#!/bin/bash # # Known issues: # - Information on which tests access a particular line is not displayed. # # 2025-Dec-09/Kishore: coded set -e help=''' Generate code coverage reports. Before running this script, pc_auto-test should have been run with the --coverage flag. It is recommended to also use the -C flag in case this is the first time you are generating code coverage reports. Example usage: pc_codecov --output-dir ~/public_html/pc_test/ -j 4 Options: -h,--help Show this help -H,--pencil-home Location of the Pencil code (where pc_auto-test has been run). Default: $PENCIL_HOME -o,--output-dir location in which to write the HTML output. Note that all pre-existing files in this location will be deleted. Default: ./lcov_html -j,--jobs Number of parallel workers to use. Default: 1 -c,--clean After generating the report, remove the *.gcda and *.gcno files generated by gfortran. This is recommended, since these files can cause problems for pc_codecov in the future if they correspond to older versions of the source files. ''' # BEGIN option parsing #https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash/29754866#29754866 set -o errexit -o pipefail -o noclobber -o nounset LONGOPTS=output-dir:,jobs:,pencil-home:,help,clean OPTIONS=o:j:H:hc PARSED=$(getopt --options=$OPTIONS --longoptions=$LONGOPTS --name "$0" -- "$@") || exit 2 eval set -- "$PARSED" jobs=1 pencil_home="${PENCIL_HOME-}" output_dir="./lcov_html" clean="" #false while true; do case "$1" in -o|--output-dir) output_dir=$2 shift 2 ;; -j|--jobs) jobs=$2 shift 2 ;; -H|--pencil-home) pencil_home=$2 shift 2 ;; -h|--help) echo "$help" exit 0 ;; -c|--clean) clean="true" shift 1 ;; --) shift break ;; *) echo "Error in parsing options" exit 3 ;; esac done # END option parsing if test -z "$pencil_home"; then echo "Error: you need to either specify --pencil-home, or define the environment variable PENCIL_HOME" exit 1 fi if ! test -e "$output_dir"; then mkdir -p "$output_dir" fi #clean up old files find "$pencil_home"/samples -type f -name coverage.info -exec rm {} \; find "$output_dir" -type f -exec rm {} \; # The flags needed to cleanly ignore errors in lcov seem to vary from version to version ## lcov 2.4 # geninfo "$pencil_home"/samples -b "$pencil_home"/src -o "$output_dir"/pencil-codecov.info --ignore-errors inconsistent,inconsistent --filter missing,blank --parallel "$jobs" # genhtml --show-proportion --hierarchical --show-navigation --parallel "$jobs" --output-directory "$output_dir" "$output_dir"/pencil-codecov.info ## lcov 2.1 # geninfo "$pencil_home"/samples -b "$pencil_home"/src -o "$output_dir"/pencil-codecov.info --ignore-errors inconsistent,source,range --filter blank --parallel "$jobs" # genhtml --show-proportion --hierarchical --show-navigation --synthesize-missing --ignore-errors missing,empty,source,range --parallel "$jobs" --output-directory "$output_dir" "$output_dir"/pencil-codecov.info ## lcov 2.0 # geninfo "$pencil_home"/samples -b "$pencil_home"/src -o "$output_dir"/pencil-codecov.info --ignore-errors inconsistent,source --filter blank --parallel "$jobs" # genhtml --show-proportion --hierarchical --show-navigation --synthesize-missing --ignore-errors empty,source,unmapped --parallel "$jobs" --output-directory "$output_dir" "$output_dir"/pencil-codecov.info set +e #ignore failures in commands that follow. echo "------------------------------geninfo------------------------------" geninfo "$pencil_home"/samples -b "$pencil_home"/src -o "$output_dir"/pencil-codecov.info --keep-going --filter blank --parallel "$jobs" echo "------------------------------genhtml------------------------------" genhtml --keep-going --show-proportion --hierarchical --show-navigation --synthesize-missing --parallel "$jobs" --output-directory "$output_dir" "$output_dir"/pencil-codecov.info echo "-------------------------------------------------------------------" set -e #resume being careful if test -n "$clean"; then echo "Removing *.gcda and *.gcno files from samples" find "$pencil_home"/samples -type f -name '*.gcno' -or -name '*.gcda' -exec rm {} \; fi