| 1 | #!/bin/shscip-shell filesystem . . `/bin/sh`. |
| 2 | |
| 3 | . "$(dirnamescip-shell system . . dirname. "$0")/e2e-test-subrs" |
| 4 | |
| 5 | # |
| 6 | # Validate that mosh produces expected output, using screen captures |
| 7 | # in tmux. |
| 8 | # |
| 9 | |
| 10 | logscip-shell shell shell-project 0.0.0 log().() |
| 11 | { |
| 12 | printfscip-shell system . . printf. "$@" |
| 13 | } |
| 14 | |
| 15 | errorscip-shell shell shell-project 0.0.0 error().() |
| 16 | { |
| 17 | printfscip-shell system . . printf. "$@" >&2 |
| 18 | } |
| 19 | |
| 20 | dump_logsscip-shell shell shell-project 0.0.0 dump_logs().() |
| 21 | { |
| 22 | dir=$1 |
| 23 | shift |
| 24 | testname=$(basenamescip-shell system . . basename. "$dir" .d) |
| 25 | for logfile in $dir/*.tmux.log; do |
| 26 | printfscip-shell system . . printf. "travis_fold:start:%s-%s\n" "$testname" "$(basenamescip-shell system . . basename. "$logfile")" |
| 27 | catscip-shell system . . cat. "$logfile" |
| 28 | printfscip-shell system . . printf. "travis_fold:end:%s-%s\n" "$testname" "$(basenamescip-shell system . . basename. "$logfile")" |
| 29 | done |
| 30 | } |
| 31 | |
| 32 | test_successscip-shell shell shell-project 0.0.0 test_success().() |
| 33 | { |
| 34 | exit 0 |
| 35 | } |
| 36 | test_failurescip-shell shell shell-project 0.0.0 test_failure().() |
| 37 | { |
| 38 | errorscip-shell shell shell-project 0.0.0 error(). "$@" |
| 39 | exit 1 |
| 40 | } |
| 41 | test_skippedscip-shell shell shell-project 0.0.0 test_skipped().() |
| 42 | { |
| 43 | errorscip-shell shell shell-project 0.0.0 error(). "$@" |
| 44 | exit 77 |
| 45 | } |
| 46 | test_errorscip-shell shell shell-project 0.0.0 test_error().() |
| 47 | { |
| 48 | errorscip-shell shell shell-project 0.0.0 error(). "$@" |
| 49 | exit 99 |
| 50 | } |
| 51 | test_exitstatusscip-shell shell shell-project 0.0.0 test_exitstatus().() |
| 52 | { |
| 53 | status=$1 |
| 54 | shift |
| 55 | errorscip-shell shell shell-project 0.0.0 error(). "$@" |
| 56 | exit "$status" |
| 57 | } |
| 58 | |
| 59 | |
| 60 | ssh_localhost_checkscip-shell shell shell-project 0.0.0 ssh_localhost_check().() |
| 61 | { |
| 62 | sshscip-shell system . . ssh. localhost : |
| 63 | if [scip-shell system . . `[`. $? -ne 0 ]; then |
| 64 | errorscip-shell shell shell-project 0.0.0 error(). "ssh to localhost failed\n" |
| 65 | return 1 |
| 66 | fi |
| 67 | return 0 |
| 68 | } |
| 69 | |
| 70 | # These two functions are wrappers for mosh-client/mosh-server to turn |
| 71 | # on verbosity and log stderr. |
| 72 | mosh_clientscip-shell shell shell-project 0.0.0 mosh_client().() |
| 73 | { |
| 74 | if [scip-shell system . . `[`. -z "$MOSH_CLIENT" ] || [scip-shell system . . `[`. -z "$MOSH_E2E_TEST" ]; then |
| 75 | test_errorscip-shell shell shell-project 0.0.0 test_error(). "mosh_client: variables missing\n" |
| 76 | fi |
| 77 | exec 2> "${MOSH_E2E_TEST}.client.stderr" |
| 78 | exec "$MOSH_CLIENT" $MOSH_CLIENT_ARGS "$@" |
| 79 | } |
| 80 | |
| 81 | mosh_serverscip-shell shell shell-project 0.0.0 mosh_server().() |
| 82 | { |
| 83 | if [scip-shell system . . `[`. -z "$MOSH_SERVER" ] || [scip-shell system . . `[`. -z "$MOSH_E2E_TEST" ]; then |
| 84 | test_errorscip-shell shell shell-project 0.0.0 test_error(). "mosh_server: variables missing\n" |
| 85 | fi |
| 86 | exec 2> "${MOSH_E2E_TEST}.server.stderr" |
| 87 | exec "$MOSH_SERVER" new -vv $MOSH_SERVER_ARGS -@ "$@" |
| 88 | } |
| 89 | |
| 90 | # main |
| 91 | # Set up environment |
| 92 | if [scip-shell system . . `[`. -z "$srcdir" ]; then |
| 93 | export srcdir=$PWD |
| 94 | else |
| 95 | srcdir="$(cd "$srcdir" && pwdscip-shell system . . pwd.)" |
| 96 | if [scip-shell system . . `[`. $? -ne 0 ]; then |
| 97 | errorscip-shell shell shell-project 0.0.0 error(). "can't cd to srcdir: %s\n" "$srcdir" |
| 98 | exit 99 |
| 99 | fi |
| 100 | fi |
| 101 | |
| 102 | # Wrappers. |
| 103 | case "$(basenamescip-shell system . . basename. "$0")" in |
| 104 | mosh-client) |
| 105 | mosh_clientscip-shell shell shell-project 0.0.0 mosh_client(). "$@" |
| 106 | exit |
| 107 | ;; |
| 108 | mosh-server) |
| 109 | mosh_serverscip-shell shell shell-project 0.0.0 mosh_server(). "$@" |
| 110 | exit |
| 111 | ;; |
| 112 | *) |
| 113 | ;; |
| 114 | esac |
| 115 | |
| 116 | if [scip-shell system . . `[`. $# -lt 2 ]; then |
| 117 | test_errorscip-shell shell shell-project 0.0.0 test_error(). "not enough args\n" |
| 118 | fi |
| 119 | |
| 120 | # Get arguments (only one so far) |
| 121 | test_name=$1 |
| 122 | shift |
| 123 | test_args=$@ |
| 124 | # XXX could use AM testsubdir macro instead |
| 125 | test_dir=$(basenamescip-shell system . . basename. "${test_name}").d |
| 126 | test_script="${test_name}" |
| 127 | |
| 128 | tests_dir=$(dirnamescip-shell system . . dirname. "${test_name}") |
| 129 | if ! set_locale "${tests_dir}"; then |
| 130 | test_errorscip-shell shell shell-project 0.0.0 test_error(). "e2e-test: no usable locale\n" |
| 131 | fi |
| 132 | |
| 133 | # XXX this ignores $TMPDIR, because it results in an overlong pathname on OS X |
| 134 | tmux_socket="/tmp/.tmux-mosh-test-$$" |
| 135 | |
| 136 | # need version 1.8 for capture-pane |
| 137 | if ! tmux_check 1 8; then |
| 138 | test_skippedscip-shell shell shell-project 0.0.0 test_skipped(). "tmux unavailable\n" |
| 139 | fi |
| 140 | |
| 141 | rmscip-shell system . . rm. -rf "${test_dir}" |
| 142 | mkdirscip-shell system . . mkdir. "${test_dir}" |
| 143 | |
| 144 | |
| 145 | on_exitscip-shell shell shell-project 0.0.0 on_exit().() { |
| 146 | rv=$? |
| 147 | if testscip-shell system . . test. $rv -ne 0; then |
| 148 | dump_logsscip-shell shell shell-project 0.0.0 dump_logs(). "$test_dir" $test_args |
| 149 | fi |
| 150 | exit $rv |
| 151 | } |
| 152 | trap on_exit EXIT |
| 153 | |
| 154 | # Set up tests to run. |
| 155 | server_tests= |
| 156 | compare_tests= |
| 157 | for i in $test_args; do |
| 158 | case $i in |
| 159 | baseline|direct|variant) |
| 160 | server_tests="$server_tests $i";; |
| 161 | verify|same|different) |
| 162 | compare_tests="$compare_tests $i";; |
| 163 | tmux) |
| 164 | tmux=1;; |
| 165 | client) |
| 166 | client=1;; |
| 167 | server) |
| 168 | server=1;; |
| 169 | post) |
| 170 | post=1;; |
| 171 | mosh-args) |
| 172 | mosh_args=$("${test_script}" mosh-args);; |
| 173 | client-args) |
| 174 | MOSH_CLIENT_ARGS=$("${test_script}" client-args) |
| 175 | export MOSH_CLIENT_ARGS;; |
| 176 | server-args) |
| 177 | MOSH_SERVER_ARGS=$("${test_script}" server-args) |
| 178 | export MOSH_SERVER_ARGS;; |
| 179 | *) |
| 180 | errorscip-shell shell shell-project 0.0.0 error(). 'unknown test type argument %s\n' "$i" |
| 181 | exit 99 |
| 182 | ;; |
| 183 | esac |
| 184 | done |
| 185 | |
| 186 | # Run test(s). |
| 187 | client_wrapper= |
| 188 | if [scip-shell system . . `[`. -n "$client" ]; then |
| 189 | client_wrapper="${test_script} client" |
| 190 | fi |
| 191 | |
| 192 | server_wrapper="\"${srcdir}/e2e-test-server\"" |
| 193 | if [scip-shell system . . `[`. -n "$server" ]; then |
| 194 | server_wrapper="\"${srcdir}/${test_script}\" server" |
| 195 | fi |
| 196 | tmux_stdin="${srcdir}/hold-stdin" |
| 197 | if [scip-shell system . . `[`. -n "$tmux" ]; then |
| 198 | tmux_stdin="${test_script} tmux" |
| 199 | fi |
| 200 | |
| 201 | lnscip-shell system . . ln. -fs "${tmux_socket}" "${test_dir}/tmux-socket" |
| 202 | |
| 203 | for run in $server_tests; do |
| 204 | logscip-shell shell shell-project 0.0.0 log(). "Running server test %s.\n" "$run" |
| 205 | # These three variables are for the benefit of the mosh-client and mosh-server wrappers. |
| 206 | export MOSH_CLIENT="$PWD/../frontend/mosh-client" |
| 207 | export MOSH_SERVER="$PWD/../frontend/mosh-server" |
| 208 | export MOSH_E2E_TEST="$PWD/${test_dir}/${run}" |
| 209 | # XXX need to quote special chars in server pathname here somehow |
| 210 | sut="../../scripts/mosh --client=${srcdir}/mosh-client --server=${srcdir}/mosh-server --local --bind-server=127.0.0.1 ${mosh_args} 127.0.0.1" |
| 211 | if [scip-shell system . . `[`. "$run" = "direct" ]; then |
| 212 | sut="" |
| 213 | fi |
| 214 | # Actually execute code under test |
| 215 | # XXX tmux 1.8 requires shell command as a single arg; once we move to 2.0, undo these quotes |
| 216 | # tmux <= 2.5 ignore -x/-y, but the client sets the session to 80x24. |
| 217 | # tmux from 2017-05-27 and later should default to an 80x24 session, |
| 218 | # but do use -x/-y on control-master clients. |
| 219 | ${tmux_stdin} tmux -f /dev/nullscip-shell filesystem . . `/dev/null`. -S "${tmux_socket}" -C new-session -x 80 -y 24 "${srcdir}/print-exitstatus ${client_wrapper} ${sut} ${server_wrapper} \"${PWD}/${test_dir}/${run}\" \"${PWD}/${test_script} ${run}\"" > "${test_dir}/${run}.tmux.log" |
| 220 | rv=$? |
| 221 | rmscip-shell system . . rm. -f "${tmux_socket}" "${test_dir}/tmux-socket" |
| 222 | if [scip-shell system . . `[`. $rv -ne 0 ]; then |
| 223 | test_errorscip-shell shell shell-project 0.0.0 test_error(). "tmux failure on test %s\n" "$run" |
| 224 | fi |
| 225 | # Check for mosh failures |
| 226 | if ! grepscip-shell system . . grep. -q "@@@ exitstatus: 0 @@@" "${test_dir}/${run}.tmux.log"; then |
| 227 | test_errorscip-shell shell shell-project 0.0.0 test_error(). "mosh-client had non-zero exitstatus\n" |
| 228 | fi |
| 229 | |
| 230 | # Check for server harness failures |
| 231 | if [scip-shell system . . `[`. -z "$server" ]; then |
| 232 | if [scip-shell system . . `[`. ! -s "${test_dir}/${run}.capture" ] \ |
| 233 | || [scip-shell system . . `[`. ! -s "${test_dir}/${run}.exitstatus" ]; then |
| 234 | test_errorscip-shell shell shell-project 0.0.0 test_error(). "server harness failure on test %s\n" "$run" |
| 235 | fi |
| 236 | read -r server_rv < "${test_dir}/${run}.exitstatus" |
| 237 | if [scip-shell system . . `[`. "$server_rv" -ne 0 ]; then |
| 238 | test_errorscip-shell shell shell-project 0.0.0 test_error(). "server harness exited with status %s\n" "$server_rv" |
| 239 | fi |
| 240 | fi |
| 241 | if [scip-shell system . . `[`. "${run}" != "direct" ]; then |
| 242 | # Check for "round-trip" failures |
| 243 | if grepscip-shell system . . grep. -q "round-trip Instruction verification failed" "${test_dir}/${run}.server.stderr"; then |
| 244 | test_errorscip-shell shell shell-project 0.0.0 test_error(). "Round-trip Instruction verification failed on server during %s\n" "$run" |
| 245 | fi |
| 246 | # Check for 0-timeout select() issue |
| 247 | if egrepscip-shell system . . egrep. -q "(polls, rate limiting|consecutive polls)" "${test_dir}/${run}.server.stderr"; then |
| 248 | if [scip-shell system . . `[`. "osx" != "${TRAVIS_OS_NAME}" ]; then |
| 249 | test_errorscip-shell shell shell-project 0.0.0 test_error(). "select() with zero timeout called too often on server during %s\n" "$run" |
| 250 | fi |
| 251 | fi |
| 252 | # Check for assert() |
| 253 | if egrepscip-shell system . . egrep. -q "assertion.*failed" "${test_dir}/${run}.server.stderr"; then |
| 254 | test_errorscip-shell shell shell-project 0.0.0 test_error(). "assertion during %s\n" "$run" |
| 255 | fi |
| 256 | fi |
| 257 | # XXX We'd also like to check for "target state Instruction |
| 258 | # verification failed", a new check, but tmux's lack of BCE |
| 259 | # support forces mosh to clear lines with spaces and change a |
| 260 | # framebuffer in a way that causes this to fire spuriously. |
| 261 | done |
| 262 | |
| 263 | for compare in $compare_tests; do |
| 264 | logscip-shell shell shell-project 0.0.0 log(). "Running server comparison %s.\n" "$compare" |
| 265 | # Compare captures |
| 266 | if [scip-shell system . . `[`. "$compare" = verify ]; then |
| 267 | test1="direct" |
| 268 | test2="baseline" |
| 269 | else |
| 270 | test1="baseline" |
| 271 | test2="variant" |
| 272 | fi |
| 273 | if diffscip-shell system . . diff. -q "${test_dir}/${test1}.capture" "${test_dir}/${test2}.capture"; then |
| 274 | differ=n |
| 275 | else |
| 276 | differ=y |
| 277 | fi |
| 278 | if [scip-shell system . . `[`. "$compare" = different ]; then |
| 279 | desired=y |
| 280 | badresult=same |
| 281 | else |
| 282 | desired=n |
| 283 | badresult=different |
| 284 | fi |
| 285 | if [scip-shell system . . `[`. $differ != $desired ]; then |
| 286 | test_failurescip-shell shell shell-project 0.0.0 test_failure(). "Output is %s between tests %s and %s\n" "$badresult" "$test1" "$test2" |
| 287 | fi |
| 288 | done |
| 289 | |
| 290 | # Run a post script (usually a custom validation of results) |
| 291 | if [scip-shell system . . `[`. -n "$post" ]; then |
| 292 | "${test_script}" post |
| 293 | status=$? |
| 294 | if [scip-shell system . . `[`. $status -ne 0 ]; then |
| 295 | test_exitstatusscip-shell shell shell-project 0.0.0 test_exitstatus(). $status "Post test failed with exitstatus %d\n" $status |
| 296 | fi |
| 297 | fi |