Commit 74da91ad authored by Jan Kiene's avatar Jan Kiene
Browse files

add first version of ci file

parent a600e619
Loading
Loading
Loading
Loading
Loading

.gitlab-ci.yml

0 → 100644
+234 −0
Original line number Diff line number Diff line
variables:
  REFERENCE_TAG: "main"
  BUILD_OUTPUT: "build_output.txt"
  EXIT_CODE_NON_BE: 123
  EXIT_CODE_FAIL: 1
  TESTS_DIR_CODEC_BE_ON_MR: "tests/codec_be_on_mr_nonselection"
  IVAS_PIPELINE_NAME: ''
  MANUAL_PIPELINE_TYPE:
    description: "Type for the manual pipeline run. Use 'pytest-mld' to run MLD test against reference float codec." # Not implemented yet, but may be good to have a manual pipeline trigger
    value: 'default'
    options:
      - 'default'
      - 'pytest-mld'


default:
  interruptible: true # Make all jobs by default interruptible

stages:
  - build
  - test

# ---------------------------------------------------------------
# Generic script anchors
# ---------------------------------------------------------------

# These can be used later on to do common tasks

# Prints useful information for every job and should be used at the beginning of each job
.print-common-info: &print-common-info
  - |
    echo "Printing common information for build job."
    echo "Current job is run on commit $CI_COMMIT_SHA"
    echo "Commit time was $CI_COMMIT_TIMESTAMP"
    date | xargs echo "System time is"

.get-previous-merge-commit-sha: &get-previous-merge-commit-sha
  - previous_merge_commit=$(git --no-pager log --merges HEAD~1 -n 1 --pretty=format:%H)

.check-for-testvectors: &check-for-testvectors # check if the testvector files specified in scripts/config/ci_linux*.json are present
  - python3 -m pytest ci/test_vectors_available.py

.mld-test-setup-codec: &mld-test-setup-codec 
  ### build test binaries, initial clean for paranoia reasons
  - make clean
  - mkdir build
  - cd build
  - cmake ..
  - make -j
  - mv IVAS_cod ../IVAS_cod_test
  - mv IVAS_dec ../IVAS_dec_test
  - mv IVAS_rend ../IVAS_rend_test
  - cd ..
  - rm -rf build/*
  - git restore .

  ### store the current commit hash
  - source_branch_commit_sha=$(git rev-parse HEAD)

  ### checkout version to compare against
  - git checkout $REFERENCE_TAG

  ### build reference binaries
  - cd build
  - cmake ..
  - make -j
  - mv IVAS_cod ../IVAS_cod_ref
  - mv IVAS_dec ../IVAS_dec_ref
  - mv IVAS_rend ../IVAS_rend_ref
  - cd ..
  - git restore .

  # rename test binaries back
  - mv IVAS_cod_test IVAS_cod
  - mv IVAS_dec_test IVAS_dec
  - mv IVAS_rend_test IVAS_rend

  # switch back to target branch
  - git checkout $source_branch_commit_sha

  ### prepare pytest
  # create short test vectors
  - python3 tests/create_short_testvectors.py
  # create references
  - python3 -m pytest $TESTS_DIR_CODEC_BE_ON_MR -v --update_ref 1 -m create_ref
  - python3 -m pytest $TESTS_DIR_CODEC_BE_ON_MR -v --update_ref 1 -m create_ref_part2

.update-ltv-repo: &update-ltv-repo
  - cd $LTV_DIR
  - git pull
  - cd -


.copy-ltv-files-to-testv-dir: &copy-ltv-files-to-testv-dir
    - cp "$LTV_DIR"/*.wav scripts/testv/
    - cp "$LTV_DIR"/*.met scripts/testv/
    - cp "$LTV_DIR"/*.csv scripts/testv/


# ---------------------------------------------------------------
# Job templates
# ---------------------------------------------------------------

# templates to define stages and platforms
.test-job-linux:
  tags:
    - ivas-basop-linux

.build-job-linux:
  stage: build
  timeout: "4 minutes"
  needs: []
  tags:
    - ivas-basop-linux

# template for test jobs on linux that need the TESTV_DIR
.test-job-linux-needs-testv-dir:
  extends: .test-job-linux
  before_script:
    - if [ ! -d "$TESTV_DIR" ]; then mkdir -p $TESTV_DIR; fi
    - cp -r scripts/testv/* $TESTV_DIR/

# ---------------------------------------------------------------
# .pre jobs for setting up things
# ---------------------------------------------------------------

# See: https://gitlab.com/gitlab-org/gitlab/-/issues/194023
# Solution to make main branch pipelines uninterruptible while all other
# pipelines can be interrupted by default. This works because all jobs
# after uninterruptible jobs will be uninterruptible. Resource group
# setting avoids rare case where two fast merges could still interrupt
# pipeline. This should be revisited if there are updates to Gitlab.
uninterruptible:
  stage: .pre
  interruptible: false
  resource_group: uninterruptible
  script:
    - echo "$CI_COMMIT_BRANCH is uninterruptible"
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
      when: always
  tags:
    - ivas-linux

# ---------------------------------------------------------------
# Build jobs
# ---------------------------------------------------------------

# ensure that codec builds on linux
build-codec-linux-make:
  extends:
    - .build-job-linux
  script:
    - *print-common-info
    - make -j

# ---------------------------------------------------------------
# Test jobs 
# ---------------------------------------------------------------

.ivas-pytest-mld-enc-dec:
  extends:
    - .test-job-linux
  stage: test
  needs: ["build-codec-linux-make"]
  timeout: "30 minutes"
  script:
    - *print-common-info
    - *mld-test-setup-codec

    ### run pytest
    - exit_code=0
    - python3 -m pytest $TESTS_DIR_CODEC_BE_ON_MR -v --html=report.html --self-contained-html --junit-xml=report-junit.xml --mld || exit_code=$?
    - zero_errors=$(cat report-junit.xml | grep -c 'errors="0"') || true
    
    - python3 scripts/parse_mld.py report.html mld.csv

    - if [ $zero_errors != 1 ]; then echo "Run errors encountered!"; exit $EXIT_CODE_FAIL; fi
    - if [ $exit_code -eq 1 ]; then echo "Differences encountered"; exit $EXIT_CODE_NON_BE; fi
    - exit 0

  allow_failure:
    exit_codes:
      - 123
  artifacts:
    name: "mld--sha-$CI_COMMIT_SHORT_SHA--stage-$CI_JOB_STAGE--results"
    expire_in: 1 week
    when: always
    paths:
      - report-junit.xml
      - report.html
      - mld.csv
    expose_as: "pytest mld results"
    reports:
      junit:
        - report-junit.xml


.ivas-pytest-mld-dec:
  extends:
    - .test-job-linux
  stage: test
  needs: ["build-codec-linux-make"]
  timeout: "30 minutes"
  script:
    - *print-common-info
    - *mld-test-setup-codec

    ### run pytest
    - exit_code=0
    - python3 -m pytest $TESTS_DIR_CODEC_BE_ON_MR -v --html=report.html --self-contained-html --junit-xml=report-junit.xml --mld --dut_encoder_path ./IVAS_cod_ref || exit_code=$?
    - zero_errors=$(cat report-junit.xml | grep -c 'errors="0"') || true

    - python3 scripts/parse_mld.py report.html mld.csv

    - if [ $zero_errors != 1 ]; then echo "Run errors encountered!"; exit $EXIT_CODE_FAIL; fi
    - if [ $exit_code -eq 1 ]; then echo "Differences encountered"; exit $EXIT_CODE_NON_BE; fi
    - exit 0

  allow_failure:
    exit_codes:
      - 123
  artifacts:
    name: "mld--sha-$CI_COMMIT_SHORT_SHA--stage-$CI_JOB_STAGE--results"
    expire_in: 1 week
    when: always
    paths:
      - report-junit.xml
      - report.html
      - mld.csv
    expose_as: "pytest mld results"
    reports:
      junit:
        - report-junit.xml