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

.test:
  stage: test
  image: jedbrown/mpich-ccache
  only:
    - branches
    - tags
    - merge_requests
  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}"
  after_script:
    - ccache --show-stats
  artifacts:
    reports:
      junit: arch-*/tests/testresults.xml
  cache:
    paths:
      - /ccache/
    key: "${CI_JOB_NAME}"

mpich-cxx-py3:
  extends: .test
  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
  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
  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%


.mcs_test:
  stage: test-long
  only:
    - tags
    - merge_requests
  script:
    - ./config/examples/${TEST_ARCH}.py
    - make
    - make check
    - make cleantest allgtests-tap TIMEOUT=300
  artifacts:
    reports:
      junit: ${TEST_ARCH}/tests/testresults.xml

.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:
    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
