feat(tfut): add run support for unit testing

This patch adds the necessary changes in order for unit tests to
be run, given a run config.
Unit tests run on te host machine, so there is no FVP or any other
type of platform involved.

Signed-off-by: Juan Pablo Conde <juanpablo.conde@arm.com>
Signed-off-by: Edward Potapov <edward.potapov@arm.com>
Change-Id: Ida431e2355aa19d34289804dfc2461411148be25
diff --git a/script/run_unit_tests.sh b/script/run_unit_tests.sh
new file mode 100644
index 0000000..937bb88
--- /dev/null
+++ b/script/run_unit_tests.sh
@@ -0,0 +1,62 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2024 Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+# Runs the built unit tests
+
+set -e
+
+ci_root="$(readlink -f "$(dirname "$0")/..")"
+source "$ci_root/script/run_common.sh"
+source "$ci_root/utils.sh"
+
+artefacts="${artefacts-$workspace/artefacts}"
+
+run_root="$workspace/unit_tests/run"
+
+mkdir -p "$run_root"
+
+export run_root
+
+export tfut_root="${tfut_root:-$workspace/tfut}"
+
+
+run_test() {
+	test="${1:?}"
+	echo "Running test $test..."
+	"./$@"
+}
+
+export -f run_test
+
+# Accept BIN_MODE from environment, or default to release. If bin_mode is set
+# and non-empty (intended to be set from command line), that takes precedence.
+pkg_bin_mode="${BIN_MODE:-release}"
+bin_mode="${bin_mode:-$pkg_bin_mode}"
+
+# Change directory so that all binaries can be accessed realtive to where they
+# lie
+run_cwd="$artefacts/$bin_mode"
+cd "$run_cwd"
+
+run_sh="$run_root/run.sh"
+
+#Generate run.sh file
+echo "echo \"Running unit tests\"" > "$run_sh"
+echo "pwd" >> "$run_sh"
+cat "tfut_artefacts.txt" | while read test; do
+	if upon "$test_run"; then
+		echo "run_test $test \$@" >> "$run_sh"
+	fi
+done
+chmod +x "$run_sh"
+
+# Run the unit tests directly
+if upon "$test_run"; then
+	echo
+        "$run_sh" "$@" -v -c
+        exit 0
+fi