language: cpp
dist: bionic
os: linux
compiler: gcc
addons:
    apt:
        sources:
        - ubuntu-toolchain-r-test
        packages:
        - build-essential
        - valgrind
        - verilator
        - yosys

install:
  # Set environments
  - export RISCV_TOOLCHAIN_PATH=/opt/riscv-gnu-toolchain
  - export VERILATOR_ROOT=/opt/verilator
  - export PATH=$VERILATOR_ROOT/bin:$PATH
  # Install toolchain
  - ci/toolchain_install.sh -all
  # clone build directory
  - make -s

# stages ordering
stages:
  - test

jobs:     
  include:
    - stage: test
      name: coverage
      script: cp -r $PWD ../build1 && cd ../build1 && ./ci/travis_run.py ./ci/regression.sh -coverage
    - stage: test
      name: cluster
      script: cp -r $PWD ../build2 && cd ../build2 && ./ci/travis_run.py ./ci/regression.sh -cluster
    - stage: test
      name: debug
      script: cp -r $PWD ../build3 && cd ../build3 && ./ci/travis_run.py ./ci/regression.sh -debug
    - stage: test
      name: config
      script: cp -r $PWD ../build4 && cd ../build4 && ./ci/travis_run.py ./ci/regression.sh -config
    - stage: test
      name: stress0
      script: cp -r $PWD ../build5 && cd ../build5 && ./ci/travis_run.py ./ci/regression.sh -stress0
    - stage: test
      name: stress1
      script: cp -r $PWD ../build6 && cd ../build6 && ./ci/travis_run.py ./ci/regression.sh -stress1
    - stage: test
      name: compiler
      script: cp -r $PWD ../build7 && cd ../build7 && ./ci/travis_run.py ./ci/test_compiler.sh
  
after_success:
  # Gather code coverage
  - lcov --directory driver --capture --output-file driver.cov # capture trace  
  - lcov --directory simx --capture --output-file simx.cov # capture trace    
  - lcov --list driver.cov # output coverage data for debugging
  - lcov --list simx.cov # output coverage data for debugging
  # Upload coverage report
  - bash <(curl -s https://codecov.io/bash) -f driver.cov
  - bash <(curl -s https://codecov.io/bash) -f simx.cov
