fvp-dockerfiles: Add debug version of stdout-flush-wrapper.sh

We still get occasional issues with LAVA failing to read FVP stdout
completely prior to detecting process termination. Have a version with
"set -x" and with longer pause to help debug those.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
Change-Id: Idbe38d9d992320318cf69901221bc3a5cc7da805
diff --git a/dockerfile-template b/dockerfile-template
index 4f5fbbd..505a7b8 100644
--- a/dockerfile-template
+++ b/dockerfile-template
@@ -26,6 +26,7 @@
 
 COPY setup-sshd /usr/sbin/setup-sshd
 COPY stdout-flush-wrapper.sh /usr/bin/stdout-flush-wrapper.sh
+COPY stdout-flush-wrapper-debug.sh /usr/bin/stdout-flush-wrapper-debug.sh
 
 # Add the FVP model tarball
 # NOTE: some tarballs contain an installer script others don't, so it may be the case
diff --git a/stdout-flush-wrapper-debug.sh b/stdout-flush-wrapper-debug.sh
new file mode 100755
index 0000000..2588eca
--- /dev/null
+++ b/stdout-flush-wrapper-debug.sh
@@ -0,0 +1,12 @@
+#!/bin/sh -x
+# This script is to workaround an apparent LAVA race condition, when it
+# detects "EOF" (i.e. app termination) before it reads out all the stdout
+# from the app (FVP in this case). The wrapper explicitly runs a command
+# in line-buffered mode, that helps a little (LAVA reads more output),
+# but not completely, so we just give LAVA more time with some sleep after
+# command termination.
+
+cmd="$1"
+shift
+stdbuf -oL "$cmd" "$@"
+sleep 10