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

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

cd $origin
# Set up virtualenv
if [ -d emu_smoke_env ]; then
    rm -rf emu_smoke_env
fi

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

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

# Run Smoke Test
# --exitfirst will exit if at the first test that fails (subsequent tests will not run)
# --capture=no is same as -s and will print stderr/stdout to console instead of capturing it
# --verbose will print detailed test output for the test cases (not just dots/Fs)
# and displaying it after all the tests end
python -m pytest firmware/validation/emuv2_smoke/test_deploy.py \
                 --log-cli-level=INFO \
                 --exitfirst \
                 --capture=no \
                 --verbose

# Run everything else
python -m pytest firmware/validation/emuv2_smoke/ \
                 -m "not deprecated and not needs_rework" \
                 --ignore=firmware/validation/emuv2_smoke/test_deploy.py \
                 --verbose


# Other tests need to be stress tested in before adding them to CI. Only run MVP tests
python -m pytest firmware/validation/emuv2_smoke/test_emu_idle_state.py \
                 -m "not needs_rework" \
                 --verbose

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