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

# CI Entry point for BMUv4 Feature Tests

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

# Environment variable injection is done via pytest fixture. See:
# https://confluence.zooxlabs.com/pages/viewpage.action?pageId=161154284

# Run the bazel environment checks
firmware/validation/common/ci/bazel_precheck.sh

# Build Docker containers
cd firmware/validation/docker/net_man
./build.sh bmuv4_feature
cd $origin

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

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

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

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

# Run everything else
python -m pytest firmware/validation/bmuv4_feature/ \
                 -m "bmu and not parking_brake" \
                 --ignore=firmware/validation/bmuv4_feature/test_deploy.py \
                 --verbose --json-report --json-report-file=/tmp/report.json

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