#!/bin/bash
#
# Copyright (c) 2017-2018, NVIDIA CORPORATION.  All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

test_name=${TEST_SRC##*/}  # Strip path.
test_name=${test_name%.*}  # Strip extension.

temp_dir="$test_name"
rm -rf $temp_dir

MAKE_FILE=$MAKE_FILE_DIR/makefile

mkdir $temp_dir
if [[ ! $KEEP_FILES ]]; then
  # If keep files is not specified, remove these files at the end.
  trap "rm -rf $(pwd)/$temp_dir" EXIT
fi
cd $temp_dir
export PATH=$PATH:$(pwd)

make -f $MAKE_FILE HOMEQA=$MAKE_FILE_DIR TEST=$test_name OPT="$FLAGS" build 2>&1
make -f $MAKE_FILE HOMEQA=$MAKE_FILE_DIR TEST=$test_name OPT="$FLAGS" run 2>&1
make -f $MAKE_FILE HOMEQA=$MAKE_FILE_DIR TEST=$test_name OPT="$FLAGS" verify 2>&1
# CHECK: {{([1-9][0-9]* tests PASSED\. 0 tests failed|^[[:space:]]*PASS[[:space:]]|^[[:space:]]*PASSED[[:space:]]*$)}}
