Index: /trunk/src/VBox/Installer/linux/testcase/tstHeadlessXOrg.sh
===================================================================
--- /trunk/src/VBox/Installer/linux/testcase/tstHeadlessXOrg.sh	(revision 43794)
+++ /trunk/src/VBox/Installer/linux/testcase/tstHeadlessXOrg.sh	(revision 43795)
@@ -74,7 +74,8 @@
 }
 
-# Get the directory where the script is located and change to the parent.
-VBOX_FOLDER="$(dirname "$0")/.."
-VBOX_FOLDER=$(cd "${VBOX_FOLDER}" && pwd)
+# Get the directory where the script is located and the parent.
+OUR_FOLDER="$(dirname "$0")"
+OUR_FOLDER=$(cd "${OUR_FOLDER}" && pwd)
+VBOX_FOLDER=$(cd "${OUR_FOLDER}/.." && pwd)
 [ -d "${VBOX_FOLDER}" ] ||
   abort "Failed to change to directory ${VBOX_FOLDER}.\n"
@@ -83,4 +84,11 @@
 # Get our name for output.
 TEST_NAME="$(basename "$0" .sh)"
+
+# And remember the full path.
+TEST_NAME_FULL="${OUR_FOLDER}/$(basename "$0")"
+
+# We use this to test a long-running process
+[ x"$1" = "x--test-sleep" ] &&
+  while true; do true; done
 
 # Create a temporary directory for configuration and logging.
@@ -158,26 +166,39 @@
 create_basic_configuration_file "${TEST_FOLDER}/conf" "${TEST_FOLDER}"
 cat >> "${TEST_FOLDER}/conf" << EOF
-HEADLESS_X_ORG_SERVER_COMMAND="echo $$ > ${TEST_FOLDER}/pid.\\\${screen}; cat"
+HEADLESS_X_ORG_SERVER_COMMAND="\"${TEST_NAME_FULL}\" --test-sleep \\\${screen}"
 EOF
 
 # Long running server command.
-print_line "long running server command"
+print_line "long running server command (sleeps)"
 touch "${XORG_FOLDER}/xorg.conf.1"
 touch "${XORG_FOLDER}/xorg.conf.5"
 FAILURE=""
-./VBoxHeadlessXOrg.sh -c "${TEST_FOLDER}/conf"
+./VBoxHeadlessXOrg.sh -c "${TEST_FOLDER}/conf" &
 PID="$!"
-[ -r "${TEST_FOLDER}/pid.1" ] &&
-  [ -r "${TEST_FOLDER}/pid.5" ] &&
-  ps -p "$(cat "${TEST_FOLDER}/pid.1")" >/dev/null 2>&1 &&
-  ps -p "$(cat "${TEST_FOLDER}/pid.5")" >/dev/null 2>&1 ||
-  FAILURE="\nFAILED to start servers.\n"
-[ -n "${PID}" ] && kill "${PID}"
-{ [ -r "${TEST_FOLDER}/pid.1" ] &&
-    ps -p "$(cat "${TEST_FOLDER}/pid.1")" >/dev/null 2>&1; } ||
-{ [ -r "${TEST_FOLDER}/pid.5" ] &&
-    ps -p "$(cat "${TEST_FOLDER}/pid.5")" >/dev/null 2>&1; } &&
-  FAILURE="\nFAILED to stop servers.\n"  # To terminate or not to terminate?
+STARTED=""
+for i in 1 2 3 4 5; do
+  sleep 1  # Make sure it runs for at least one second.
+  if ps -a -f | grep "${TEST_NAME}.*1" | grep -q -v grep &&
+    ps -a -f | grep "${TEST_NAME}.*5" | grep -q -v grep; then
+    STARTED="true"
+    break
+  fi
+done
+[ -n "${STARTED}" ] || FAILURE="\nFAILED to start servers.\n"
+[ -n "${PID}" ] && kill "${PID}" 2>/dev/null
+STOPPED=""
 if [ -z "${FAILURE}" ]; then
+  for i in 1 2 3 4 5; do
+    if ! ps -a -f | grep "${TEST_NAME}.*1" | grep -q -v grep &&
+      ! ps -a -f | grep "${TEST_NAME}.*5" | grep -q -v grep; then
+      STOPPED="true"
+      break;
+    fi
+    sleep 1
+  done
+  [ -n "${STOPPED}" ] ||
+    FAILURE="\nFAILED to stop servers.\n"  # To terminate or not to terminate?
+fi
+if [ -n "${FAILURE}" ]; then
   printf "${FAILURE}"
 else
@@ -185,5 +206,4 @@
 fi
 rm "${XORG_FOLDER}/"xorg.conf.*
-rm -f "${TEST_FOLDER}/pid.1" "${TEST_FOLDER}/pid.5"
 
 # Set up a configuration file with a pre-requisite.
@@ -214,4 +234,5 @@
 cat >> "${TEST_FOLDER}/conf" << EOF
 HEADLESS_X_ORG_SERVER_PRE_COMMAND="touch \"${TEST_FOLDER}/run/pre\""
+HEADLESS_X_ORG_SERVER_COMMAND="cp \"${TEST_FOLDER}/run/pre\" \"${TEST_FOLDER}/run/pre2\""
 EOF
 
@@ -219,5 +240,4 @@
 print_line "pre-command test"
 touch "${XORG_FOLDER}/xorg.conf.2"
-touch "${XORG_FOLDER}/xorg.conf.4"
 
 test_pre_command()
@@ -228,5 +248,5 @@
     LOG_FOLDER="${TEST_FOLDER}/log"
     LOG="${LOG_FOLDER}/log"
-    if [ -e "${TEST_FOLDER}/run/pre" ]; then
+    if [ -e "${TEST_FOLDER}/run/pre" ] && [ -e "${TEST_FOLDER}/run/pre2" ]; then
       printf "SUCCESS.\n"
     else
@@ -243,3 +263,3 @@
 PID=$!
 expect_exit "${PID}" 5 test_pre_command
-rm -f "${XORG_FOLDER}"/xorg.conf.* "${TEST_FOLDER}/run/pre"
+rm -f "${XORG_FOLDER}"/xorg.conf.* "${TEST_FOLDER}"/run/pre*
