language: cpp
dist: focal
os: linux
compiler: gcc

addons:  
  apt:
    packages:
      - build-essential
      - valgrind
      - libstdc++6

env:
  global:
    - TOOLDIR=$HOME/tools

cache:
  directories:
    - $TOOLDIR
    - $HOME/build32
    - $HOME/build64

before_install:
  - if [ ! -d "$TOOLDIR" ] || [ -z "$(ls -A $TOOLDIR)" ]; then  
      mkdir -p $TOOLDIR;
      OSDIR=ubuntu/focal ./ci/toolchain_install.sh --all;
    fi
  - source ./ci/toolchain_env.sh

stages:
  - setup
  - test

jobs:     
  include:
    - stage: setup
      script:
        - rm -rf $HOME/build32 && cp -r $PWD $HOME/build32
        - rm -rf $HOME/build64 && cp -r $PWD $HOME/build64
        - make -C $HOME/build32
        - XLEN=64 RISCV_TOOLCHAIN_PATH=$TOOLDIR/riscv64-gnu-toolchain make -C $HOME/build64
    - stage: test 
      name: unittest
      script: cp -r $HOME/build32 build && cd build && ./ci/travis_run.py ./ci/regression.sh --unittest
    - stage: test 
      name: isa
      script: cp -r $HOME/build32 build && cd build && ./ci/travis_run.py ./ci/regression.sh --isa
    - stage: test 
      name: isa64
      script: cp -r $HOME/build64 build && cd build && XLEN=64 RISCV_TOOLCHAIN_PATH=$TOOLDIR/riscv64-gnu-toolchain ./ci/travis_run.py ./ci/regression.sh --isa
    - stage: test 
      name: regression
      script: cp -r $HOME/build32 build && cd build && ./ci/travis_run.py ./ci/regression.sh --regression
    - stage: test 
      name: regression64
      script: cp -r $HOME/build64 build && cd build && XLEN=64 RISCV_TOOLCHAIN_PATH=$TOOLDIR/riscv64-gnu-toolchain ./ci/travis_run.py ./ci/regression.sh --regression
    - stage: test 
      name: opencl
      script: cp -r $HOME/build32 build && cd build && ./ci/travis_run.py ./ci/regression.sh --opencl    
    - stage: test 
      name: cluster
      script: cp -r $HOME/build32 build && cd build && ./ci/travis_run.py ./ci/regression.sh --cluster    
    - stage: test 
      name: config
      script: cp -r $HOME/build32 build && cd build && ./ci/travis_run.py ./ci/regression.sh --config
    - stage: test
      name: debug
      script: cp -r $HOME/build32 build && cd build && ./ci/travis_run.py ./ci/regression.sh --debug
    - stage: test 
      name: stress0
      script: cp -r $HOME/build32 build && cd build && ./ci/travis_run.py ./ci/regression.sh --stress0
    - stage: test 
      name: stress1
      script: cp -r $HOME/build32 build && cd build && ./ci/travis_run.py ./ci/regression.sh --stress1
    - stage: test 
      name: synthesis
      script: cp -r $HOME/build32 build && cd build && ./ci/travis_run.py ./ci/regression.sh --synthesis
    - stage: test 
      name: synthesis64
      script: cp -r $HOME/build64 build && cd build && XLEN=64 ./ci/travis_run.py ./ci/regression.sh --synthesis
            
after_success:
  # Gather code coverage
  - lcov --directory runtime --capture --output-file runtime.cov # capture trace  
  - lcov --directory sim --capture --output-file sim.cov # capture trace    
  - lcov --list runtime.cov # output coverage data for debugging
  - lcov --list sim.cov # output coverage data for debugging
  # Upload coverage report
  - bash <(curl -s https://codecov.io/bash) -f runtime.cov
  - bash <(curl -s https://codecov.io/bash) -f sim.cov
