| 1 | #!/usr/bin/env bash
|
| 2 | #
|
| 3 | # Process table tests for job control.
|
| 4 | #
|
| 5 | # Usage:
|
| 6 | # test/process-table.sh <function name>
|
| 7 |
|
| 8 | set -o nounset
|
| 9 | set -o pipefail
|
| 10 | set -o errexit
|
| 11 | shopt -s strict:all 2>/dev/null || true # dogfood for OSH
|
| 12 |
|
| 13 | REPO_ROOT=$(cd "$(dirname $0)"/..; pwd)
|
| 14 |
|
| 15 | source benchmarks/common.sh # html-head
|
| 16 | source build/dev-shell.sh # python2
|
| 17 | source test/common.sh
|
| 18 | source test/tsv-lib.sh # time-tsv
|
| 19 |
|
| 20 | readonly BASE_DIR=_tmp/process-table
|
| 21 |
|
| 22 | readonly OSH_CPP=_bin/cxx-dbg/osh
|
| 23 | readonly -a JC_SHELLS=(bash dash mksh zsh bin/osh $OSH_CPP)
|
| 24 |
|
| 25 | print-tasks() {
|
| 26 | readonly -a SNIPPETS=(
|
| 27 | fgproc bgproc
|
| 28 | fgpipe fgpipe-lastpipe
|
| 29 | bgpipe bgpipe-lastpipe
|
| 30 | subshell csub psub
|
| 31 | )
|
| 32 |
|
| 33 | for sh in "${JC_SHELLS[@]}"; do
|
| 34 | for snippet in "${SNIPPETS[@]}"; do
|
| 35 | for interactive in - yes; do
|
| 36 | echo "${sh}${TAB}${snippet}${TAB}${interactive}"
|
| 37 | done
|
| 38 | done
|
| 39 | done
|
| 40 | }
|
| 41 |
|
| 42 | run-tasks() {
|
| 43 | local tsv_out=$1
|
| 44 |
|
| 45 | while read sh snippet interactive; do
|
| 46 | # Suppress failure, since exit code is recorded
|
| 47 | time-tsv -o $tsv_out --append \
|
| 48 | --field $sh --field $snippet --field $interactive -- \
|
| 49 | test/process-table-portable.sh run_snippet $sh $snippet $interactive || true
|
| 50 | done
|
| 51 | }
|
| 52 |
|
| 53 | report-html-head() {
|
| 54 | local title=$1
|
| 55 |
|
| 56 | local base_url='../../web'
|
| 57 |
|
| 58 | html-head --title "$title" \
|
| 59 | "$base_url/table/table-sort.js" \
|
| 60 | "$base_url/table/table-sort.css" \
|
| 61 | "$base_url/base.css"
|
| 62 | }
|
| 63 |
|
| 64 | print-report() {
|
| 65 | local tsv_out=$1
|
| 66 |
|
| 67 | local title='Process State for Job Control'
|
| 68 | report-html-head "$title"
|
| 69 |
|
| 70 | # Extra style, doesn't go on any element
|
| 71 | # Pink background same as web/spec-tests.css
|
| 72 | echo '<style> .fail { background-color: #ffe0e0 } </style>'
|
| 73 |
|
| 74 | # Copied from uftrace
|
| 75 | echo '<body style="margin: 0 auto; width: 40em; font-size: large">'
|
| 76 |
|
| 77 | echo "<h1>$title</h1>"
|
| 78 |
|
| 79 | tsv2html $tsv_out
|
| 80 |
|
| 81 | echo '
|
| 82 | </body>
|
| 83 | </html>
|
| 84 | '
|
| 85 | }
|
| 86 |
|
| 87 | add-css-class() {
|
| 88 | python2 -c '
|
| 89 | import sys
|
| 90 | for i, line in enumerate(sys.stdin):
|
| 91 | rest = line.rstrip()
|
| 92 | if i == 0:
|
| 93 | print("ROW_CSS_CLASS\t%s" % rest)
|
| 94 | else:
|
| 95 | row_css_class = "pass" if line.startswith("0") else "fail"
|
| 96 | print("%s\t%s" % (row_css_class, rest))
|
| 97 | '
|
| 98 | }
|
| 99 |
|
| 100 | make-report() {
|
| 101 | local times_tsv=$1
|
| 102 |
|
| 103 | # TODO: Add ROW_CSS_CLASS when status != 0
|
| 104 | add-css-class < $times_tsv > $BASE_DIR/index.tsv
|
| 105 |
|
| 106 | local html=$BASE_DIR/index.html
|
| 107 |
|
| 108 | print-report $BASE_DIR/index.tsv > $html
|
| 109 |
|
| 110 | echo "Wrote $html"
|
| 111 | }
|
| 112 |
|
| 113 | soil-run() {
|
| 114 | test/process-table-portable.sh setup
|
| 115 |
|
| 116 | ninja $OSH_CPP
|
| 117 |
|
| 118 | local times_tsv=$BASE_DIR/times.tsv
|
| 119 | mkdir -p $BASE_DIR
|
| 120 |
|
| 121 | # note: it seems better to align everything right
|
| 122 |
|
| 123 | here-schema-tsv >$BASE_DIR/index.schema.tsv <<EOF
|
| 124 | column_name type
|
| 125 | ROW_CSS_CLASS string
|
| 126 | status integer
|
| 127 | elapsed_secs number
|
| 128 | sh string
|
| 129 | snippet string
|
| 130 | interactive string
|
| 131 | EOF
|
| 132 |
|
| 133 | time-tsv -o $times_tsv --print-header \
|
| 134 | --field sh --field snippet --field interactive
|
| 135 |
|
| 136 | print-tasks | run-tasks $times_tsv
|
| 137 |
|
| 138 | make-report $times_tsv
|
| 139 | }
|
| 140 |
|
| 141 | run-for-release() {
|
| 142 | # Same thing as CI -- put output in _tmp/process-table/index.html
|
| 143 | soil-run
|
| 144 | }
|
| 145 |
|
| 146 | #
|
| 147 | # Reproduce bugs
|
| 148 | #
|
| 149 |
|
| 150 | timeout-issue() {
|
| 151 | ### For some reason bgproc-interactive conflicts with 'timeout' command
|
| 152 |
|
| 153 | set -x
|
| 154 |
|
| 155 | # doesn't hang with OSH
|
| 156 | timeout 900 $0 test-bgproc-interactive
|
| 157 |
|
| 158 | # doesn't hang
|
| 159 | SH=dash timeout --foreground 900 $0 test-bgproc-interactive
|
| 160 | SH=bash timeout --foreground 900 $0 test-bgproc-interactive
|
| 161 |
|
| 162 | # these both hang
|
| 163 | # SH=dash timeout 900 $0 test-bgproc-interactive
|
| 164 | # SH=bash timeout 900 $0 test-bgproc-interactive
|
| 165 | }
|
| 166 |
|
| 167 | time-tsv-issue() {
|
| 168 | #time-tsv -o _tmp/tsv -- $0 test-bgproc-interactive
|
| 169 | time-tsv -o _tmp/tsv -- $0 soil-run
|
| 170 | }
|
| 171 |
|
| 172 | "$@"
|