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

# Entry point for EMUv4 Feature Tests

# 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

# Build Docker containers
cd $origin

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

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

# DBC files are generated by the make_dbcs fixture defined in the dbc_builder.py plugin.

# Update dentist protos before the tests have started. This is necessary due
# to dentist being imported before pytest processes it's plug-ins
dentist_proto_updater

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

# Run Tests for Idle State transition and message gatewaying (MON)
# TODO: FWVAL-1326 update marks and conftest.py to pull tests using that instead of specifying
#       specific files here
python -m pytest firmware/validation/emuv4_feature/ \
                 -k "idle or message_gateway" \
                 -W ignore::DeprecationWarning \
                 --verbose

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