# Standard DDR3 Test:
example_ddr3:
    stage: DDR3
    script:
        - export GCOV_PREFIX=$(pwd)
        - export GCOV_PREFIX_STRIP=$(pwd | awk -F"/" '{print NF-1}')
        - cd build/simulator
        - ./DRAMSys ../../DRAMSys/tests/DDR3/simulations/ddr3-example.xml ../../DRAMSys/tests/DDR3/
        - ls -lah
        - ls -lah ../../DRAMSys/tests/DDR3/expected/
        - sqldiff ../../DRAMSys/tests/DDR3/expected/ddr3-example_ddr3_ch0.tdb ddr3-example_ddr3_ch0.tdb
        - perl -e 'if(`sqldiff ../../DRAMSys/tests/DDR3/expected/ddr3-example_ddr3_ch0.tdb ddr3-example_ddr3_ch0.tdb` eq "") {exit(0)} else {exit(-1)}'
        - cd ../traceAnalyzer
        - python3 ../../DRAMSys/traceAnalyzer/scripts/tests.py ../simulator/ddr3-example_ddr3_ch0.tdb | if ! grep "failed"; then exit 0; else exit 1; fi
        # Run Code Coverage
        - lcov -q -c --rc geninfo_adjust_src_path=$GCOV_PREFIX -d ${CI_PROJECT_DIR}/build/ -o ${CI_PROJECT_DIR}/coverage/${CI_JOB_NAME}.out
 
    cache:
        key: build
        paths:
            - build/
        policy: pull

    artifacts:
        paths:
          - build/simulator/ddr3-example_ddr3_ch0.tdb
          - coverage/${CI_JOB_NAME}.out
        expire_in: 2 days

# Testing Reordering with FR_FCFS Scheduling Algorithm:
fr_fcfs:
    stage: DDR3
    script:
        - export GCOV_PREFIX=$(pwd)
        - export GCOV_PREFIX_STRIP=$(pwd | awk -F"/" '{print NF-1}')
        - cd build/simulator
        - ./DRAMSys ../../DRAMSys/tests/DDR3/simulations/ddr3-fr_fcfs.xml ../../DRAMSys/tests/DDR3/
        - ls -lah
        - ls -lah ../../DRAMSys/tests/DDR3/expected/
        - sqldiff ../../DRAMSys/tests/DDR3/expected/ddr3-fr_fcfs_ddr3_ch0.tdb ddr3-fr_fcfs_ddr3_ch0.tdb
        - perl -e 'if(`sqldiff ../../DRAMSys/tests/DDR3/expected/ddr3-fr_fcfs_ddr3_ch0.tdb ddr3-fr_fcfs_ddr3_ch0.tdb` eq "") {exit(0)} else {exit(-1)}'
        - cd ../traceAnalyzer
        - python3 ../../DRAMSys/traceAnalyzer/scripts/tests.py ../simulator/ddr3-fr_fcfs_ddr3_ch0.tdb | if ! grep "failed"; then exit 0; else exit 1; fi
        # Run Code Coverage
        - lcov -q -c --rc geninfo_adjust_src_path=$GCOV_PREFIX -d ${CI_PROJECT_DIR}/build/ -o ${CI_PROJECT_DIR}/coverage/${CI_JOB_NAME}.out

    cache:
        key: build
        paths:
            - build/
        policy: pull

    allow_failure: true # TODO should be removed after first tests

    artifacts:
        paths:
          - build/simulator/ddr3-fr_fcfs_ddr3_ch0.tdb
          - coverage/${CI_JOB_NAME}.out
        expire_in: 2 days

# Testing with TLM Protocol Checker
protocol_checker:
    stage: DDR3
    script:
        - export GCOV_PREFIX=$(pwd)
        - export GCOV_PREFIX_STRIP=$(pwd | awk -F"/" '{print NF-1}')
        - cd build/simulator
        - ./DRAMSys ../../DRAMSys/tests/DDR3/simulations/ddr3-protocol_checker.xml ../../DRAMSys/tests/DDR3/ > output.txt
        - echo "TODO"
        - ls -lah
        # Run Code Coverage
        - lcov -q -c --rc geninfo_adjust_src_path=$GCOV_PREFIX -d ${CI_PROJECT_DIR}/build/ -o ${CI_PROJECT_DIR}/coverage/${CI_JOB_NAME}.out

    cache:
        key: build
        paths:
            - build/
        policy: pull

    artifacts:
        paths:
            - coverage/${CI_JOB_NAME}.out
        expire_in: 2 days
