#! /bin/sh
set -xe
origin="$PWD"

# CI Entry point for EMUv4 Feature Tests

# Export vehicle architecture variable
export VEHICLE_ARCHITECTURE=vh6b

# Export QNX enable variable
export ZOOX_ENABLE_QNX70=1
export ZOOX_ENABLE_HIGHTEC_TRICORE=1

# Clean out anything that might be lurking around...
git clean -fdx

# Run the bazel precheck steps (shutdown, remove cache)
firmware/validation/common/ci/bazel_precheck.sh

# Set up virtualenv
if [ -d emuv4_mon_smoke_env ]; then
    rm -rf emuv4_mon_smoke_env
fi

virtualenv -p python3.6 emuv4_mon_smoke_env
. emuv4_mon_smoke_env/bin/activate
python -m pip install -r firmware/validation/emuv4_mon/requirements.txt

# Generate DBCs first. If this fails there is no point in continuing to test
# Note that this does not upload DBCs to Artifactory. To enable upload use the
# upload_dbc.sh script instead
firmware/validation/common/ci/generate_dbc.sh

# Run Smoke Test
python -m pytest firmware/validation/emuv4_feature/test_deploy.py \
                 --verbose

cd $origin

python -m pytest firmware/validation/emuv4_mon/test_emu_mon_gateway.py \
                 --verbose
python -m pytest firmware/validation/emuv4_mon/test_can_load.py \
                 --verbose

# Cleanup bazel job
cd $(bazel info workspace)
firmware/validation/common/ci/bazel_postcheck.sh
