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

# Entry point for TBC Smoke 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

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

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

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

# Temporary fix for socket can no buffer spaace issue
# TODO : FWVAL- 1935 Find permanent solution
sudo ip link set BDY_CAN1 down
sudo ip link set BDY_CAN1 up

# Run Smoke Test
python -m pytest firmware/validation/tbc_smoke/test_deploy.py \
                 --verbose
python -m pytest firmware/validation/tbc_smoke/test_tbc_boot_info.py
python -m pytest firmware/validation/tbc_smoke/test_control_code_communication.py
python -m pytest firmware/validation/tbc_smoke/test_cpu_resources.py
python -m pytest firmware/validation/tbc_smoke/test_tbc_application_running.py
python -m pytest firmware/validation/tbc_smoke/test_bdy_can2_message.py

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