Skip to content

Commit

Permalink
Added Code Coverage CI (#450)
Browse files Browse the repository at this point in the history
Co-authored-by: Henry LE BERRE <hberre3@gatech.edu>
  • Loading branch information
okBrian and henryleberre authored Jun 7, 2024
1 parent a0a3ef8 commit f347b30
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 35 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: 'Benchmark'

on:
pull_request:
on: pull_request

jobs:
self:
Expand Down
6 changes: 1 addition & 5 deletions .github/workflows/count.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
name: Check Line Counts
on:
push:

pull_request:

workflow_dispatch:
on: [push, pull_request, workflow_dispatch]

jobs:
sz:
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Coverage Check

on: [push, pull_request, workflow_dispatch]

jobs:
run:
name: Coverage Test on CodeCov
runs-on: "ubuntu-latest"
steps:
- name: Setup Ubuntu
run: |
sudo apt update -y
sudo apt install -y tar wget make cmake gcc g++ python3 python3-dev "openmpi-*" libopenmpi-dev
- name: Checkouts
uses: actions/checkout@v4

- name: Build
run: /bin/bash mfc.sh build -j $(nproc) --gcov

- name: Test
run: /bin/bash mfc.sh test -a -j $(nproc)

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4.0.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
7 changes: 1 addition & 6 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
name: Lint

on:
push:

pull_request:

workflow_dispatch:
on: [push, pull_request, workflow_dispatch]

jobs:
docs:
Expand Down
7 changes: 1 addition & 6 deletions .github/workflows/pretty.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
name: Pretty

on:
push:

pull_request:

workflow_dispatch:
on: [push, pull_request, workflow_dispatch]

jobs:
docs:
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/spelling.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: Spell Check
on:
push:
workflow_dispatch:

on: [push, workflow_dispatch]

jobs:
run:
Expand Down
24 changes: 23 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ project(MFC LANGUAGES C CXX Fortran)

option(MFC_MPI "Build with MPI" ON)
option(MFC_OpenACC "Build with OpenACC" OFF)
option(MFC_GCov "Build with GCov" OFF)
option(MFC_PRE_PROCESS "Build pre_process" OFF)
option(MFC_SIMULATION "Build simulation" OFF)
option(MFC_POST_PROCESS "Build post_process" OFF)
Expand Down Expand Up @@ -106,13 +107,34 @@ if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
$<$<COMPILE_LANGUAGE:Fortran>:-ffree-line-length-none>
)

if (MFC_GCov)

# Warning present in gcc versions >= 12 that is treated as an error
# This flag doesn't exist in gcc versions < 12
if (CMAKE_Fortran_COMPILER_VERSION VERSION_GREATER 12)
add_compile_options(
-Wno-error=coverage-invalid-line-number
)
endif()

add_compile_options(
$<$<COMPILE_LANGUAGE:Fortran>:-fprofile-arcs>
$<$<COMPILE_LANGUAGE:Fortran>:-ftest-coverage>
)

add_link_options(
$<$<COMPILE_LANGUAGE:Fortran>:-lgcov>
$<$<COMPILE_LANGUAGE:Fortran>:--coverage>
)
endif()

if (CMAKE_BUILD_TYPE STREQUAL "Debug")
add_compile_options(
-fcheck=all,no-array-temps
-fbacktrace
-fimplicit-none
#-ffpe-trap=invalid,zero,denormal,overflow
)
)
endif()

if (CMAKE_Fortran_COMPILER_VERSION VERSION_GREATER 10)
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
<a href="https://lbesson.mit-license.org/">
<img src="https://img.shields.io/badge/License-MIT-blue.svg" />
</a>
<a href="https://codecov.io/github/MFlowCode/MFC">
<img src="https://codecov.io/github/MFlowCode/MFC/graph/badge.svg?token=8SY043QND4">
</a>
</p>

Welcome to the home of MFC!
Expand Down
1 change: 1 addition & 0 deletions docs/documentation/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ MFC can be built with support for various (compile-time) features:
| **MPI** | `--mpi` | `--no-mpi` | On | Lets MFC run on multiple processors (and nodes) simultaneously. |
| **GPU** | `--gpu` | `--no-gpu` | Off | Enables GPU acceleration via OpenACC. |
| **Debug** | `--debug` | `--no-debug` | Off | Requests the compiler build MFC in debug mode. |
| **GCov** | `--gcov` | `--no-gcov` | Off | Builds MFC with coverage flags on. |

_⚠️ The `--gpu` option requires that your compiler supports OpenACC for Fortran for your target GPU architecture._

Expand Down
10 changes: 5 additions & 5 deletions toolchain/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3

import signal, getpass, platform, itertools, dataclasses
import signal, getpass, platform, itertools

from mfc import args, lock, build, bench, state, count
from mfc.state import ARG
Expand All @@ -21,11 +21,11 @@ def __print_greeting():
MFC_SIDEBAR_LINES = [
f"[bold]{host_line}[/bold]",
'-' * len(host_line),
f"[bold]--jobs [magenta]{ARG('jobs')}[/magenta][/bold]"
] + [
f"[bold]--{'' if getattr(state.gCFG, field.name) else 'no-'}{field.name}[/bold]" for field in dataclasses.fields(state.gCFG)
] + [
'',
f"[bold]--jobs [magenta]{ARG('jobs')}[/magenta][/bold]",
f"[bold]{' '.join(state.gCFG.make_options())}[/bold]",
targets_line if ARG("command") != "test" else "",
'',
'-' * len(help_line),
f"[yellow]{help_line}[/yellow]",
]
Expand Down
5 changes: 3 additions & 2 deletions toolchain/mfc/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,9 @@ def configure(self, case: input.MFCInputFile):
flags.append('--debug-find')

if not self.isDependency:
flags.append(f"-DMFC_MPI={ 'ON' if ARG('mpi') else 'OFF'}")
flags.append(f"-DMFC_OpenACC={'ON' if ARG('gpu') else 'OFF'}")
flags.append(f"-DMFC_MPI={ 'ON' if ARG('mpi') else 'OFF'}")
flags.append(f"-DMFC_OpenACC={'ON' if ARG('gpu') else 'OFF'}")
flags.append(f"-DMFC_GCov={ 'ON' if ARG('gcov') else 'OFF'}")

command = ["cmake"] + flags + ["-S", cmake_dirpath, "-B", build_dirpath]

Expand Down
2 changes: 1 addition & 1 deletion toolchain/mfc/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
.:++=----------====+*= ==..:%.....
.:-=++++===--==+=-+= +. :=
+#=::::::::=%=. -+: =+ *:
.*=-=*=.. :=+*+: -...--\
.*=-=*=.. :=+*+: -...--
"""


Expand Down
2 changes: 1 addition & 1 deletion toolchain/mfc/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from .printer import cons


MFC_LOCK_CURRENT_VERSION: int = 3
MFC_LOCK_CURRENT_VERSION: int = 4


@dataclasses.dataclass
Expand Down
7 changes: 4 additions & 3 deletions toolchain/mfc/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class MFCConfig:
mpi: bool = True
gpu: bool = False
debug: bool = False
gcov: bool = False

@staticmethod
def from_dict(d: dict):
Expand All @@ -23,12 +24,12 @@ def items(self) -> typing.List[typing.Tuple[str, bool]]:

def make_options(self) -> typing.List[str]:
""" Returns a list of options that could be passed to mfc.sh again.
Example: --no-debug --mpi --no-gpu """
Example: --no-debug --mpi --no-gpu --no-gcov"""
return [ f"--{'no-' if not v else ''}{k}" for k, v in self.items() ]

def make_slug(self) -> str:
""" Sort the items by key, then join them with underscores. This uniquely
identifies the configuration. Example: no-debug_no-gpu_mpi """
identifies the configuration. Example: no-debug_no-gpu_no_mpi_no-gcov """
return '_'.join([ f"{'no-' if not v else ''}{k}" for k, v in sorted(self.items(), key=lambda x: x[0]) ])

def __eq__(self, other) -> bool:
Expand All @@ -40,7 +41,7 @@ def __eq__(self, other) -> bool:
return True

def __str__(self) -> str:
""" Returns a string like "mpi=No & gpu=No & debug=No" """
""" Returns a string like "mpi=No & gpu=No & debug=No & gcov=No" """

return ' & '.join([ f"{k}={'Yes' if v else 'No'}" for k, v in self.items() ])

Expand Down

0 comments on commit f347b30

Please sign in to comment.