#!/usr/bin/env bash

# This script fetches, builds, and runs the BoringSSL
# TLS test tool ('BoGo') against rustls.

set -xe

case ${BOGO_SHIM_PROVIDER:-ring} in
  ring)
      cargo build -p rustls --example bogo_shim
      cpp -P -DRING config.json.in -oconfig.json
      ;;
  aws-lc-rs)
      cargo build -p rustls --example bogo_shim --no-default-features --features aws_lc_rs,tls12,logging
      cpp -P -DAWS_LC_RS config.json.in -oconfig.json
      ;;
  existing)
      ;;
  *)
      echo "unsupported BOGO_SHIM_PROVIDER: supported are (ring|aws-lc-rs|existing)"
      exit 1
      ;;
esac

if [ ! -e bogo/ssl/test/runner/runner.test ] ; then
  ./fetch-and-build
  cp -v keys/* bogo/
fi

# Best effort on OS-X
case $OSTYPE in darwin*) set +e ;; esac

( cd bogo/ssl/test/runner && ./runner.test -shim-path ../../../../../target/debug/examples/bogo_shim \
     -shim-config ../../../../config.json \
     -pipe \
     -allow-unimplemented \
     -test.timeout 60s \
     "$@") # you can pass in `-test "Foo;Bar"` to run specific tests
true
