Commit b3b26071 authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

Merge branch 'ci/add-basic-ci-and-tests' into 'main'

[CI] add basic ci and tests

See merge request !11
parents a600e619 e521aba5
Loading
Loading
Loading
Loading
Loading

.gitlab-ci.yml

0 → 100644
+188 −0
Original line number Diff line number Diff line
variables:
  REFERENCE_TAG: "20231128_Update_Ittiam"
  BUILD_OUTPUT: "build_output.txt"
  SCRIPTS_DIR: "/usr/local/scripts"
  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"

.mld-test-setup-codec: &mld-test-setup-codec 
  - current_commit_sha=$(git rev-parse HEAD)

  ### build reference binaries
  - git checkout $REFERENCE_TAG
  - make clean
  - make -j
  - mv ./IVAS_cod ./IVAS_cod_ref
  - mv ./IVAS_dec ./IVAS_dec_ref

  ### build test binaries
  - git checkout $current_commit_sha
  - make clean
  - make -j

  ### 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 -n auto
  - python3 -m pytest $TESTS_DIR_CODEC_BE_ON_MR -v --update_ref 1 -m create_ref_part2 -n auto

.update-scripts-repo: &update-scripts-repo
  - cd $SCRIPTS_DIR
  - git pull
  - cd -
  - cp -r $SCRIPTS_DIR/ci .
  - cp -r $SCRIPTS_DIR/scripts .
  - cp -r $SCRIPTS_DIR/tests .

# TODO: this needs to be updated in case the reference is updated
.remove-unsupported-testcases: &remove-unsupported-testcases
  - sed -i '1629,1635d' scripts/config/self_test.prm

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

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

.build-job-linux:
  stage: build
  timeout: "2 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/

# ---------------------------------------------------------------
# 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
    - *update-scripts-repo
    - *remove-unsupported-testcases
    - *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 -n auto || 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
    - *update-scripts-repo
    - *remove-unsupported-testcases
    - *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 -n auto || 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