OILS / test / process-table.sh View on Github | oilshell.org

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