#!/bin/bash

# Import common sanity check definitions
#
if [ -z ${ZEPHYR_BASE} ]; then
	echo "shell variables required to build Zephyr Kernel are not set"
	exit 1
fi
if [ ! -d ${ZEPHYR_BASE} ] ; then
	echo "directory ${ZEPHYR_BASE} not found"
	exit 1
fi

source ${ZEPHYR_BASE}/scripts/sanity_chk/common.defs

# Location of master project directory
#
PRJ_PATH=${ZEPHYR_BASE}/samples

# Identify the file containing the projects to be built (or cleaned)
#
PRJ_LIST=${ZEPHYR_BASE}/scripts/sanity_chk/bt_regression_chk.data

main() {
	# set up default behaviors
	build_only=0
	BSP_NAME=""
	ARCH_NAME=""
	KEEP_LOGS=0

	# set up environment info used to build projects
	build_info_set

	# set up project info used to build projects
	proj_info_set

	# build (and optionally execute) projects
	PRJ_CLASS="regression"
	let cur_proj=0
	let build_proj=0
	let run_proj=0
	while [ ${cur_proj} -lt ${NUM_PROJ} ] ; do
		let cur_proj++
		print_header

		# build project
		build_project ${cur_proj}
		let build_proj++

		# skip non-executable projects (or when doing "build only")
		if [ ${build_only} = 1 -o x${PLATFORM_FLAG[${cur_proj}]} = x ] ; then
			continue
		fi

		# execute project
		qemu_project ${cur_proj}
		let run_proj++
	done

	${ECHO}
        print_header
	${ECHO} "${SCRIPT_NAME} completed successfully "\
	        "(built ${build_proj} projects and ran ${run_proj} of them)"
}

main $*

# success exit
exit 0
