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

# Entry point for L3 TBC Nightly Feature Tests

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

# But first, re-install the bazel for this branch (builds are extremely version-specific)
# Run the setup script for dev with --no-ask-pass to bypass sudo prompt
# and tags for bazel upgrade / downgrade
scripts/setup/setup.sh dev --no-ask-pass --tags bazel

# Do a bazel clean --expunge before clearing out bazel cache
bazel clean --expunge

# Clear out bazel cache
rm -rf ~/.cache/bazel/

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

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

# Run Firmware Deployment tests
python -m pytest firmware/validation/tbc_l3_feature/test_deploy.py \
                 --verbose

# Run nightly tests
python -m pytest firmware/validation/tbc_l3_feature/test_tbc_boot_info.py \
                --verbose --log-level=ERROR
python -m pytest firmware/validation/tbc_l3_feature/test_pump_target.py \
                --verbose --log-level=ERROR
python -m pytest firmware/validation/tbc_l3_feature/test_relay_control.py \
                --verbose --log-level=ERROR
python -m pytest firmware/validation/tbc_l3_feature/test_can_gateway.py \
                --verbose --log-level=ERROR
python -m pytest firmware/validation/tbc_l3_feature/test_coolant_overtemperature_alert.py \
                --verbose --log-level=ERROR
python -m pytest firmware/validation/tbc_l3_feature/test_compressor_control.py \
                --verbose --log-level=ERROR

# Cleanup bazel job
bazel clean --expunge
