
# test-short take only a few minutes and generally run on the cloud; they do not run the full test suite or external packages.
#
# test-long often runs on MCS systems and may take an hour or more. They run the full test suite and may test external packages.
#
# The test-long tests are only started if all of the test-short tests run without error and if the merge request has
# been labeled with "fulltest".
#

stages:
  - test-short
  - test-long
variables:
  GIT_STRATEGY: fetch
  GIT_CLEAN_FLAGS: -ffdxq
  PETSC_OPTIONS: -check_pointer_intensity 0 -error_output_stdout -nox -nox_warning -malloc_dump

#
# The most basic template that most tests will expand upon. It ensures that the tests are run only for merge requests.
#

.test:
  only:
    refs:
      - merge_requests

#
#  This provides the basic order of operations and options template for cloud based test-short tests.
#  Not all test-short need to follow this template but most will.
#

.test-short:
  extends: .test
  stage: test-short
  image: jedbrown/mpich-ccache
  before_script:
    - echo nproc=$(nproc)
    - cat /proc/cpuinfo
    - ccache --zero-stats
    - echo "${CI_JOB_NAME}"
    - export CCACHE_COMPILERCHECK=content
  script:
    - ${PYTHON} ./configure --with-debugging=0 COPTFLAGS='-O -march=native' CXXOPTFLAGS='-O -march=native' FOPTFLAGS='-O -march=native' ${CONFIG_OPTS}
    - make -j$(nproc) -l$(nproc) CFLAGS=-Werror
    - make allgtests-tap search="${TEST_SEARCH}" TIMEOUT=300
  after_script:
    - ls -l /ccache/
    - du -hs /ccache
    - ccache --show-stats
  artifacts:
    reports:
      junit: arch-*/tests/testresults.xml
  cache:
    paths:
      - /ccache/
    key: "${CI_JOB_NAME}"

#
# The following tests run on the cloud as part of test-short.
#

mpich-cxx-py3:
  extends: .test-short
  variables:
    PYTHON: python3
    CONFIG_OPTS: --with-mpi-dir=/usr/local --with-clanguage=cxx --with-fc=0
    TEST_SEARCH: snes_tutorials-ex48%

uni-complex-float-int64:
  extends: .test-short
  variables:
    PYTHON: python3
    CONFIG_OPTS: <
      --with-mpi=0
      --with-scalar-type=complex --with-precision=single --with-64-bit-indices
    TEST_SEARCH: ts_tutorials-ex11_adv_2d_quad_%

c89-mlib-static-py2:
  extends: .test-short
  image: jedbrown/mpich-ccache:python2
  variables:
    PYTHON: python2
    CONFIG_OPTS: <
      --with-mpi-dir=/usr/local
      --with-single-library=0 --with-shared-libraries=0 'CFLAGS=-std=c89 -pedantic -Wno-long-long -Wno-overlength-strings'
    TEST_SEARCH: snes_tutorials-ex48%

#
# This provides the basic order of operations and options template for test-long tests.
# Not all test-long need to follow this template, but most will.
#
.test-long:
  extends: .test
  stage: test-long
  only:
    variables:
      - $CI_MERGE_REQUEST_LABELS =~ /fulltest/
  script:
    - ./config/examples/${TEST_ARCH}.py
    - make
    - make check
    - make cleantest allgtests-tap TIMEOUT=300
  artifacts:
    reports:
      junit: ${TEST_ARCH}/tests/testresults.xml

#
# The following tests run on MCS systems as part of test-long.
#
# The tags variable used in the tests below connects the particular test with the runners
# listed on the left hand side of https://gitlab.com/petsc/petsc/-/settings/ci_cd.
# For example the test linux-gcc-complex-opt which extends .linux_mcs_test will run on
# any runner that has the tag (in a blue box beneath it) of mcs-linux.
#

.mcs_test:
  extends: .test-long

.linux_mcs_test:
  extends: .mcs_test
  tags:
    - mcs-linux
  before_script:
    - hostname
    - grep PRETTY_NAME /etc/os-release
    - echo $(nproc)
    - ccache --zero-stats
  after_script:
    - ccache --show-stats

.freebsd_mcs_test:
  extends: .mcs_test
  tags:
    - mcs-freebsd
  before_script:
    - hostname
    - freebsd-version
    - echo $(sysctl -n hw.ncpu)
    - ccache --zero-stats
  after_script:
    - ccache --show-stats

.osx_mcs_test:
  extends: .mcs_test
  tags:
    - mcs-osx
  variables:
#  the stages definition defines the first line of PETSC_OPTIONS below. Do they have to be repeated here or can one use
#  $PETSC_OPTIONS or another option so that they do not need to be repeated?
    PETSC_OPTIONS: <
      -check_pointer_intensity 0 -error_output_stdout -nox -nox_warning -malloc_dump
      -saws_port_auto_select -saws_port_auto_select_silent -vecscatter_mpi1 false -options_left false
  before_script:
    - hostname
    - sw_vers -productVersion
    - echo $(sysctl -n hw.ncpu)
    - ccache --zero-stats
  after_script:
    - ccache --show-stats

.opensolaris_mcs_test:
  extends: .mcs_test
  tags:
    - mcs-opensolaris
  before_script:
    - hostname
    - uname -a
    - echo $(nproc)

linux-gcc-complex-opt:
  extends: .linux_mcs_test
  variables:
    TEST_ARCH: arch-ci-linux-gcc-complex-opt

linux-gcc-pkgs-opt:
  extends: .linux_mcs_test
  variables:
    TEST_ARCH: arch-ci-linux-gcc-pkgs-opt

linux-gcc-quad-64idx-dbg:
  extends: .linux_mcs_test
  variables:
    TEST_ARCH: arch-ci-linux-gcc-quad-64idx-dbg

freebsd-c-single-opt:
  extends: .freebsd_mcs_test
  variables:
    TEST_ARCH: arch-ci-freebsd-c-single-opt

freebsd-cxx-cmplx-64idx-dbg:
  extends: .freebsd_mcs_test
  variables:
    TEST_ARCH: arch-ci-freebsd-cxx-cmplx-64idx-dbg

osx-cxx-pkgs-opt:
  extends: .osx_mcs_test
  variables:
    TEST_ARCH: arch-ci-osx-cxx-pkgs-opt

opensolaris-cmplx-pkgs-dbg:
  extends: .opensolaris_mcs_test
  variables:
    TEST_ARCH: arch-ci-opensolaris-cmplx-pkgs-dbg

#
# The following tests are experimental; more tests by users at other sites may be added below this.  Experimental test
# that fail produce a warning, but do not block execution of a pipeline.
#

.test-experimental:
  extends: .test
  allow_failure: true

barry-checksource:
  extends: .test-experimental
  stage: test-short
  variables:
# the blank GIT_CLEAN_FLAGS below indicates that the CI should NOT clean the git directory before running the next test
    GIT_CLEAN_FLAGS: -qn
  tags:
    - barry
  script:
    - PETSC_ARCH=arch-barry PETSC_DIR=`pwd` ./configure --with-mpi=0 --with-fc=0
    - PETSC_ARCH=arch-barry PETSC_DIR=`pwd` make checkbadSource

barry-arch-hash:
  extends: .test-experimental
  stage: test-short
  variables:
# the blank GIT_CLEAN_FLAGS below indicates that the CI should NOT clean the git directory before running the next test
    GIT_CLEAN_FLAGS: -qn
  tags:
    - barry
  script:
    - PETSC_DIR=`pwd` ./configure --with-mpi=0 --with-fc=0 --arch-hash
    - PETSC_DIR=`pwd` make checkbadSource
