Changeset 43704 in vbox for trunk/src/VBox/Installer/linux/testcase/tstHeadlessXOrg.sh
- Timestamp:
- Oct 22, 2012 4:18:03 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Installer/linux/testcase/tstHeadlessXOrg.sh
r43688 r43704 14 14 # 15 15 16 [ x"$1" = x"--keep-temp" ] && KEEP_TEMP=true17 18 16 ## The function definition at the start of every non-trivial shell script! 19 17 abort() … … 34 32 } 35 33 36 ## Run a test in which VBoxHeadlessXOrg.sh is expected to complete within a 37 # certain time and call a function if it does which should check whether the 38 # test was successful and print status information. The function takes the 39 # exit status as its single parameter. 40 run_expect_exit() 41 { 42 CONF_FILE="$1" ## The configuration file. 34 ## Expected a process to complete within a certain time and call a function if 35 # it does which should check whether the test was successful and print status 36 # information. The function takes the exit status as its single parameter. 37 expect_exit() 38 { 39 PID="$1" ## The PID we are waiting for. 43 40 TIME_OUT="$2" ## The time-out before we terminate the process. 44 41 TEST_FUNCTION="$3" ## The function to call on exit to check the test result. 45 ./VBoxHeadlessXOrg.sh -c "${CONF_FILE}" & 46 PID=$! 42 47 43 # Give it time to complete. 48 44 { sleep "${TIME_OUT}"; kill "${PID}" 2>/dev/null; } & … … 57 53 ${TEST_FUNCTION} "${STATUS}" 58 54 esac 55 } 56 57 ## Create a simple configuration file. Add items onto the end to override them 58 # on an item-by-item basis. 59 create_basic_configuration_file() 60 { 61 FILE_NAME="$1" ## The name of the configuration file to create. 62 BASE_FOLDER="$2" ## The basic folder for creating things under. 63 cat > "${FILE_NAME}" << EOF 64 HEADLESS_X_ORG_CONFIGURATION_FOLDER="${BASE_FOLDER}/xorg" 65 HEADLESS_X_ORG_LOG_FOLDER="${BASE_FOLDER}/log" 66 HEADLESS_X_ORG_LOG_FILE="log" 67 HEADLESS_X_ORG_RUN_FOLDER="${BASE_FOLDER}/run" 68 HEADLESS_X_ORG_CHECK_PREREQUISITES= 69 HEADLESS_X_ORG_SERVER_PRE_COMMAND= 70 HEADLESS_X_ORG_SERVER_COMMAND="echo \\\${screen} \\\${conf_file} \\\${log_file}" 71 HEADLESS_X_ORG_SERVER_LOG_FILE_TEMPLATE="log.\\\${screen}" 72 EOF 73 59 74 } 60 75 … … 76 91 [ -d "${TEST_FOLDER}" ] || abort "Failed to create a temporary folder\n" 77 92 # Clean up. Small race here, but probably not important. 78 [ -z "${KEEP_TEMP}" ] && 79 trap "rm -r \"${TEST_FOLDER}\" 2>/dev/null" EXIT HUP INT QUIT ABRT TERM 93 trap "rm -r \"${TEST_FOLDER}\" 2>/dev/null" EXIT HUP INT QUIT ABRT TERM 80 94 # Server configuration folder. 81 95 XORG_FOLDER="${TEST_FOLDER}/xorg" 82 mkdir "${XORG_FOLDER}" 83 84 # Set up our basic configuration file. 85 cat > "${TEST_FOLDER}/conf" << EOF 86 HEADLESS_X_ORG_CONFIGURATION_FOLDER="${XORG_FOLDER}" 87 HEADLESS_X_ORG_LOG_FOLDER="${TEST_FOLDER}/log" 88 HEADLESS_X_ORG_LOG_FILE="log" 89 HEADLESS_X_ORG_SERVER_COMMAND="echo \\\${screen} \\\${conf_file} \\\${log_file}" 90 HEADLESS_X_ORG_SERVER_LOG_FILE_TEMPLATE="log.\\\${screen}" 91 EOF 96 mkdir -p "${XORG_FOLDER}" 92 97 93 98 # Simple start-up test. 94 99 print_line "simple start-up test" 95 touch "${XORG_FOLDER}/xorg.conf.2" 96 touch "${XORG_FOLDER}/xorg.conf.4" 100 create_basic_configuration_file "${TEST_FOLDER}/conf" "${TEST_FOLDER}" 101 touch "${XORG_FOLDER}/xorg.conf.2" 102 touch "${XORG_FOLDER}/xorg.conf.4" 103 97 104 test_simple_start_up() 98 105 { … … 113 120 esac 114 121 } 115 run_expect_exit "${TEST_FOLDER}/conf" 5 test_simple_start_up 122 123 ./VBoxHeadlessXOrg.sh -c "${TEST_FOLDER}/conf" & 124 PID=$! 125 expect_exit "${PID}" 5 test_simple_start_up 116 126 rm "${XORG_FOLDER}"/xorg.conf.* 117 127 118 128 # No configuration files. 119 129 print_line "no configuration files" 130 120 131 test_should_fail() 121 132 { … … 129 140 esac 130 141 } 131 run_expect_exit "${TEST_FOLDER}/conf" 5 test_should_fail 142 143 ./VBoxHeadlessXOrg.sh -c "${TEST_FOLDER}/conf" & 144 PID=$! 145 expect_exit "${PID}" 5 test_should_fail 132 146 133 147 # Bad configuration files. … … 136 150 touch "${XORG_FOLDER}/xorg.conf.4" 137 151 touch "${XORG_FOLDER}/xorg.conf.other" 138 run_expect_exit "${TEST_FOLDER}/conf" 5 test_should_fail 152 ./VBoxHeadlessXOrg.sh -c "${TEST_FOLDER}/conf" & 153 PID=$! 154 expect_exit "${PID}" 5 test_should_fail 139 155 rm "${XORG_FOLDER}/"xorg.conf.* 140 156 141 157 # Set up a configuration file for a long-running command. 142 cat > "${TEST_FOLDER}/conf" << EOF 143 HEADLESS_X_ORG_CONFIGURATION_FOLDER="${XORG_FOLDER}" 144 HEADLESS_X_ORG_LOG_FOLDER="${TEST_FOLDER}/log" 145 HEADLESS_X_ORG_LOG_FILE="log" 158 create_basic_configuration_file "${TEST_FOLDER}/conf" "${TEST_FOLDER}" 159 cat >> "${TEST_FOLDER}/conf" << EOF 146 160 HEADLESS_X_ORG_SERVER_COMMAND="echo $$ > ${TEST_FOLDER}/pid.\\\${screen}; cat" 147 HEADLESS_X_ORG_SERVER_LOG_FILE_TEMPLATE="log.\\\${screen}"148 161 EOF 149 162 … … 173 186 rm "${XORG_FOLDER}/"xorg.conf.* 174 187 rm -f "${TEST_FOLDER}/pid.1" "${TEST_FOLDER}/pid.5" 188 189 # Set up a configuration file with a pre-requisite. 190 create_basic_configuration_file "${TEST_FOLDER}/conf" "${TEST_FOLDER}" 191 cat >> "${TEST_FOLDER}/conf" << EOF 192 HEADLESS_X_ORG_CHECK_PREREQUISITES="[ -e \\"${TEST_FOLDER}/run/prereq\\" ]" 193 EOF 194 195 # Pre-requisite test. 196 print_line "configuration file with pre-requisite (sleeps)" 197 touch "${XORG_FOLDER}/xorg.conf.2" 198 touch "${XORG_FOLDER}/xorg.conf.4" 199 FAILURE="" 200 ./VBoxHeadlessXOrg.sh -c "${TEST_FOLDER}/conf" & 201 PID="$!" 202 sleep 1 203 ps -p "${PID}" > /dev/null 2>&1 || FAILURE="\nFAILED to wait for pre-requisite.\n" 204 touch "${TEST_FOLDER}/run/prereq" 205 if [ -z "${FAILURE}" ]; then 206 expect_exit "${PID}" 10 test_simple_start_up 207 else 208 printf "${FAILURE}" 209 fi 210 rm -r "${XORG_FOLDER}"/xorg.conf.* "${TEST_FOLDER}/run" 211 212 # Set up our pre-command test configuration file. 213 create_basic_configuration_file "${TEST_FOLDER}/conf" "${TEST_FOLDER}" 214 cat >> "${TEST_FOLDER}/conf" << EOF 215 HEADLESS_X_ORG_SERVER_PRE_COMMAND="touch \"${TEST_FOLDER}/run/pre\"" 216 EOF 217 218 # Pre-command test. 219 print_line "pre-command test" 220 touch "${XORG_FOLDER}/xorg.conf.2" 221 touch "${XORG_FOLDER}/xorg.conf.4" 222 223 test_pre_command() 224 { 225 STATUS="$1" 226 case "${STATUS}" in 227 0) 228 LOG_FOLDER="${TEST_FOLDER}/log" 229 LOG="${LOG_FOLDER}/log" 230 if [ -e "${TEST_FOLDER}/run/pre" ]; then 231 printf "SUCCESS.\n" 232 else 233 printf "\nFAILED: pre-command not executed.\n" 234 fi 235 ;; 236 *) 237 printf "\nFAILED: exit status ${STATUS}.\n" 238 esac 239 } 240 241 rm -f "${TEST_FOLDER}/run/pre" 242 ./VBoxHeadlessXOrg.sh -c "${TEST_FOLDER}/conf" & 243 PID=$! 244 expect_exit "${PID}" 5 test_pre_command 245 rm -f "${XORG_FOLDER}"/xorg.conf.* "${TEST_FOLDER}/run/pre"
Note:
See TracChangeset
for help on using the changeset viewer.