#!/bin/bash

# BSD 3-Clause License
#
# Copyright (c) 2019, Steven F. Hoover
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
#   list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
#   this list of conditions and the following disclaimer in the documentation
#   and/or other materials provided with the distribution.
#
# * Neither the name of the copyright holder nor the names of its
#   contributors may be used to endorse or promote products derived from
#   this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


# For usage, see <repo>/bin/regress

set -e  # Fail on any failure.


# Args:
AWS_REGRESS="$1"
export CONFIG_FILE="$2"


cd "$( dirname "${BASH_SOURCE[0]}")/../build"
mkdir -p ../out/regress ../log

echo "Running mandelbrot regression."


# Run locally.

# Go live
make live TARGET=sw PORT=8887 # && sleep 2
# Access image
wget -O ../out/regress/img.jpg 'http://localhost:8887/img?json={"x":0,"y":0,"pix_x":0.2,"pix_y":0.2,"width":10,"height":10,"max_depth":25,"renderer":"cpp"}'
# Go dead
make dead TARGET=sw



if [[ "$AWS_REGRESS" ]]
then

  echo "Running AWS tests for Mandelbrot."

  # Create and destroy static F1 instance.
  make static_accelerated_instance AUTO_APPROVE=true INSTANCE_NAME=1st-CLaaS_static_accelerated_regress
  make destroy SETUP=1st-CLaaS_static_accelerated_regress AUTO_APPROVE=true

fi
