Skip to content

Test gfortran

Test gfortran #377

Workflow file for this run

name: Test gfortran
on:
# Trigger the workflow on push or pull request
#push:
pull_request: # DANGEROUS! MUST be disabled for self-hosted runners!
# Trigger the workflow by cron. The default time zone of GitHub Actions is UTC.
schedule:
- cron: '0 16 * * *'
# Trigger the workflow manually
workflow_dispatch:
inputs:
git-ref:
description: Git Ref (Optional)
required: false
# Show the git ref in the workflow name if it is invoked manually.
run-name: ${{ github.event_name == 'workflow_dispatch' && format('Manual run {0}', inputs.git-ref) || '' }}
jobs:
test:
name: Run gfortran tests
runs-on: ${{ matrix.os }}
continue-on-error: true
strategy:
fail-fast: false
matrix:
#os: [ubuntu-latest, windows-latest, macos-15-intel, macos-latest]
os: [macos-15-intel, macos-latest]
compiler: [gcc]
version: [12, latest] # Too expensive to test all versions
solver: [uobyqa]
testdim: [big]
#solver: [newuoa, cobyla, lincoa, bobyqa, uobyqa]
#testdim: [small, big]
exclude:
- os: windows-latest
version: 14 # As of 20250816, gfortran 14 is not available on Windows runners.
steps:
- name: Set http.postBuffer and core.compression
# This is a workaround for random "early EOF" of checkout.
# See https://github.com/actions/checkout/issues/748, https://github.com/actions/checkout/issues/1379
if: startsWith(matrix.os, 'windows')
run: git config --global http.postBuffer 1048576000 && git config --global core.compression 0
- name: Run `sudo apt update -y`
if: startsWith(matrix.os, 'ubuntu')
run: sudo apt update -y # Otherwise, free-disk-space or other actions relying on `apt` may fail
- name: Free disk space
if: startsWith(matrix.os, 'ubuntu')
uses: jlumbroso/free-disk-space@main
with:
# all of these default to true, but feel free to set to "false" if necessary for your workflow
android: true
dotnet: true
haskell: true
large-packages: true
docker-images: true
swap-storage: false # Important, or the runner may be shut down due to memory starvation.
- name: Clone Repository (Latest)
uses: actions/checkout@v5.0.0
if: github.event.inputs.git-ref == ''
with:
submodules: recursive
# ssh-key: ${{ secrets.SSH_PRIVATE_KEY_ACT }} # This forces checkout to use SSH, not HTTPS
# As of 231227, checkout with ssh fails frequently on Windows runners.
- name: Clone Repository (Custom Ref)
uses: actions/checkout@v5.0.0
if: github.event.inputs.git-ref != ''
with:
ref: ${{ github.event.inputs.git-ref }}
submodules: recursive
# ssh-key: ${{ secrets.SSH_PRIVATE_KEY_ACT }} # This forces checkout to use SSH, not HTTPS
# As of 231227, checkout with ssh fails frequently on Windows runners.
- name: Miscellaneous setup
shell: bash # Important; otherwise, the following statements do not work on Windows.
run: bash .github/scripts/misc_setup
- name: Make tools such as grep and git available on Windows
if: runner.os == 'Windows'
run: $env:Path += ";C:\Program Files\Git\usr\bin;C:\Program Files\Git\bin;C:\ProgramData\Chocolatey\bin"
- name: Decide the gfortran version to use
shell: bash
run: |
if [[ "${{ matrix.version }}" == "latest" ]]; then
export GFORTRAN_VERSION=${{ env.GFORTRAN_VERSION }}
else
export GFORTRAN_VERSION=${{ matrix.version }}
echo "GFORTRAN_VERSION=${GFORTRAN_VERSION}" >> $GITHUB_ENV
fi
echo "To use gfortran version ${GFORTRAN_VERSION}"
- name: Set up Fortran
#if: ${{ matrix.os != 'macos-latest' }}
uses: fortran-lang/setup-fortran@main
with:
compiler: ${{ matrix.compiler }}
version: ${{ env.GFORTRAN_VERSION }}
# - name: Set up Fortran for macOS latest # As of 20250816, fortran-lang/setup-fortran does not support macos-15
# if: ${{ matrix.os == 'macos-latest' }}
# run: |
# sudo ln -sf $(which gfortran-${{ env.GFORTRAN_VERSION }}) $(dirname $(which gfortran-${{ env.GFORTRAN_VERSION }}))/gfortran
- name: Check gfortran version
shell: bash
run: |
which gcc && gcc --version && which gfortran && gfortran --version
- name: Revise Makefile.common to exclude r16 tests when the dimension is big
if: ${{ matrix.testdim == 'big' }}
shell: bash
run: |
cd fortran/tests/makefiles || exit 42
$SEDI 's|\$(TST)_.*r16_d[0,1]_tst||g' Makefile.common && cat Makefile.common
- name: Revise string.f90, so that we know what is happening if assertion fails
shell: bash
run: |
cd fortran/common || exit 42
$SEDI "s|\(call assert(abs(x - str2real(s)) <= abs(x) \* 10.0\*\*(-ndgt_loc), 'STR2REAL(S) == X', srname)\)|if (.not. abs(x - str2real(s)) <= abs(x) * 10.0**(-ndgt_loc)) then\nwrite(*,*) '====> x = ', x, 's = ', s, 'sx = ', str2real(s)\nerror stop\nelse\n\1\nend if|" string.f90
cat string.f90
- name: Revise linalg.f90 regarding a postcondition of p_norm, so that we know what is happening if it fails
shell: bash
run: |
cd fortran/common || exit 42
$SEDI "s|'Y >= 0 unless X contains NaN'|'Y >= 0 unless X contains NaN'\&\n\&\/\/num2str(y)\/\/num2str(sum(abs(x)))\/\/num2str(int(is_nan(sum(abs(x)))))\/\/num2str(x)|" linalg.f90
$SEDI "s|function p_norm(x, p) result(y)|function p_norm(x, p) result(y)\nuse, non_intrinsic :: string_mod, only : num2str|" linalg.f90
cat linalg.f90
- name: Conduct the test
shell: bash # Important; otherwise, `<` will not work on Windows.
# Not sure whether the Makefile has bugs, but on Windows the making of gtest always invokes
# the making of gtest_c twice even if the former is up to date after the first making. It
# may lead to errors due to parallel making. To avoid this, we make gtest_c first.
run: |
# 20221212: We skip the linting and extensive test on Windows due to the following
# reasons. The example will still be tested on Windows.
# 1. Windows does not support the symlink of linux, and hence mlint and flint do not work.
# 2. Makefile.common does not work on Windows for the moment due to quotation marks.
IK=i$(( 2**(1 + $(date +%-d) % 3) ))
echo "IK=${IK}"
echo "IK=${IK}" >> "$GITHUB_ENV"
if [[ "$RUNNER_OS" != "Windows" ]] ; then
# Use $(( )) rather than $(expr ). See https://unix.stackexchange.com/questions/63166/bash-e-exits-when-let-or-expr-evaluates-to-0
export TESTDIM=${{ matrix.testdim }}
echo "TESTDIM=$TESTDIM" >> "$GITHUB_ENV"
FFLAGS=-O$(($(date +%-d) % 5))
FFLAGS=${FFLAGS/O0/g}
FFLAGS=${FFLAGS/O4/fast}
export FFLAGS
echo "FFLAGS=$FFLAGS"
echo "FFLAGS=$FFLAGS" >> "$GITHUB_ENV"
cd "$ROOT_DIR"/fortran/tests && make gtest_${IK}_c.${{ matrix.solver }} && make gtest_${IK}.${{ matrix.solver }}
fi
cd "$ROOT_DIR"/fortran/examples/${{ matrix.solver }}
export EXAMPLE_NUM=1 && make clean && make gtest
export EXAMPLE_NUM=2 && make clean && make gtest
- name: Store artifacts
uses: actions/upload-artifact@v4.3.1
if: always() # Always run even if the workflow is canceled manually or due to overtime.
# Note that `$TEST_DIR` does not work on Windows, where its equivalent is `$env:TEST_DIR`.
# In the following, we enquire `$TEST_DIR` by using the `env` context, which is platform independent.
with:
name: ${{ matrix.os }}-${{ matrix.solver }}-${{ env.IK }}-${{ matrix.version }}-${{ env.TESTDIM }}-${{ env.FFLAGS }}
path: ${{ env.TEST_DIR }}/prima/fortran/tests/test.${{ matrix.solver }}/log/*.log
- name: Remove the test data
if: always() # Always run even if the workflow is canceled manually or due to overtime.
shell: bash # Important; otherwise, `rm -rf` will not work on Windows.
run: rm -rf ${{ env.TEST_DIR }}
# The following job check whether the tests were successful or cancelled due to timeout.
# N.B.: Remember to specify `continue-on-error: true` for the job of the tests.
check_success_timeout:
runs-on: ubuntu-latest
if: ${{ !cancelled() }}
needs: test
steps:
- name: Clone the GitHub actions scripts
uses: actions/checkout@v5.0.0
with:
repository: equipez/github_actions_scripts
ssh-key: ${{ secrets.SSH_PRIVATE_KEY_ACT }} # This forces checkout to use SSH, not HTTPS
path: scripts
- name: Check whether the tests were successful or cancelled due to timeout
run: bash scripts/check_success_timeout ${{ secrets.GITHUB_TOKEN }} ${{ github.repository }} ${{ github.run_id }}