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

# Entry point for VH6B 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_pt_cooling_venv ]; then
    rm -rf tbc_pt_cooling_venv
fi

virtualenv -p python3.6 tbc_pt_cooling_venv
. tbc_pt_cooling_venv/bin/activate
python -m pip install -r firmware/validation/tbc_pt_cooling/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 Firmware Deployment tests
python -m pytest firmware/validation/tbc_pt_cooling/test_deploy.py \
                 --verbose

# Run nightly tests
python -m pytest firmware/validation/tbc_pt_cooling/test_cpu_resources.py \
                --verbose --log-level=ERROR
python -m pytest firmware/validation/tbc_pt_cooling/test_tbc_application_running.py \
                --verbose --log-level=ERROR
python -m pytest firmware/validation/tbc_pt_cooling/test_tbc_off_state.py \
                --verbose --log-level=ERROR
python -m pytest firmware/validation/tbc_pt_cooling/test_tbc_lv_state.py \
                --verbose --log-level=ERROR
python -m pytest firmware/validation/tbc_pt_cooling/test_thermal_status.py \
                --verbose --log-level=ERROR
python -m pytest firmware/validation/tbc_pt_cooling/test_door_control_gateway.py \
                --verbose --log-level=ERROR

# Cleanup bazel job
bazel clean --expunge
