OILS / devtools / test-oils.sh View on Github | oilshell.org

251 lines, 108 significant
1#!/usr/bin/env bash
2#
3# Main file for test-oils.xshar
4#
5# Usage:
6# devtools/test-oils.sh <function name>
7#
8# It will contain
9#
10# _release/
11# oils-for-unix.tar
12# benchmarks/
13# time-helper.c
14# osh-runtime.sh
15#
16# It will run benchmarks, and then upload a TSV file to a server.
17#
18# The TSV file will be labeled with
19#
20# - git commit that created the xshar file (in oilshell/oil)
21# - date
22# - label: github actions / sourcehut
23# - and then we'll also have provenance and system info
24# - machine name, OS, CPUs, etc.
25
26set -o nounset
27set -o pipefail
28set -o errexit
29
30source test/common.sh # die
31
32OILS_VERSION=$(head -n 1 oil-version.txt)
33
34REPO_ROOT=$(cd "$(dirname $0)/.."; pwd)
35
36FLAG_num_iters=1 # iterations
37FLAG_num_shells=1
38FLAG_num_workloads=1
39
40readonly XSHAR_NAME=test-oils.xshar # hard-coded for now
41
42print-help() {
43 # Other flags:
44 #
45 # --host host to upload to?
46 # --auth allow writing to host
47 # --no-taskset disable taskset?
48
49 cat <<EOF
50Usage: $XSHAR_NAME ACTION FLAGS*
51
52This is a self-extracting, executable shell archive (xshar) to test Oils. It
53contains:
54
55 1. The oils-for-unix tarball, which can be compiled on any machine
56 2. Test / benchmark scripts and their dependencies
57 3. This harness, which compiles the tarball, accepts flags, runs benchmarks.
58
59Actions:
60
61 osh-runtime (currently the only one)
62
63 Flags:
64 -n --num-iters (default: 1) Run everything this number of times.
65
66 -s --num-shells Run the first N of osh, bash, dash
67
68 -w --num-workloads Run the first N of the workloads
69
70 Workloads:
71EOF
72 benchmarks/osh-runtime.sh print-workloads
73 cat <<EOF
74
75Example:
76
77 $XSHAR_NAME osh-runtime --num-iters 2 --num-shells 2 --num-workloads 3
78
79will run this benchmark matrix 2 times:
80
81 (osh, bash) X (hello-world, bin-true, configure-cpython)
82
83xshar runtime dependencies:
84
85 - base64, tar, gzip - for unpacking the payload
86
87osh-runtime dependencies:
88
89 - C++ compiler, for oils-for-unix and benchmarks/time-helper.c
90 - On OS X, the compiler comes with XCode
91 - python2 for - benchmarks/time_.py, tsv*.py, gc_stats*.py
92 - curl for uploading results via HTTP
93EOF
94}
95
96print-version() {
97 echo "$XSHAR_NAME was built from git commit ${XSHAR_GIT_COMMIT:-?}"
98}
99
100parse-flags-osh-runtime() {
101 ### Sets global vars FLAG_*
102
103 while test $# -ne 0; do
104 case "$1" in
105 -v|--version)
106 print-version
107 exit
108 ;;
109 -h|--help)
110 print-help
111 exit
112 ;;
113
114 -n|--num-iters)
115 if test $# -eq 1; then
116 die "-n / --num-iters requires an argument"
117 fi
118 shift
119 FLAG_num_iters=$1
120 ;;
121
122 -s|--num-shells)
123 if test $# -eq 1; then
124 die "-s / --num-shells requires an argument"
125 fi
126 shift
127 FLAG_num_shells=$1
128 ;;
129
130 -w|--num-workloads)
131 if test $# -eq 1; then
132 die "-w / --num-workloads requires an argument"
133 fi
134 shift
135 FLAG_num_shells=$1
136 ;;
137
138 *)
139 die "Invalid flag '$1'"
140 ;;
141 esac
142 shift
143 done
144}
145
146osh-runtime() {
147 # $XSHAR_DIR looks like like $REPO_ROOT
148
149 parse-flags-osh-runtime "$@"
150 echo num_iters=$FLAG_num_iters
151 echo num_shells=$FLAG_num_shells
152 echo num_workloads=$FLAG_num_workloads
153
154 local time_py="${XSHAR_DIR:-$REPO_ROOT}/benchmarks/time_.py"
155 build/py.sh time-helper
156
157 # Extract and compile the tarball
158 # Similar to devtools/release-native.sh test-tar
159 local tmp=_tmp/oils-tar
160 mkdir -p $tmp
161
162 pushd $tmp
163 tar -x < ../../_release/oils-for-unix.tar
164
165 pushd oils-for-unix-$OILS_VERSION
166 build/native.sh tarball-demo
167
168 local osh=$PWD/_bin/cxx-opt-sh/osh
169
170 # Smoke test
171 $time_py --tsv --rusage -- \
172 $osh -c 'echo "smoke test: osh and time_.py"'
173
174 popd
175 popd
176
177 benchmarks/osh-runtime.sh test-oils-run $osh \
178 $FLAG_num_shells $FLAG_num_workloads $FLAG_num_iters
179
180 # TODO: upload these with curl
181 #
182 # _tmp/
183 # osh-runtime/
184 # shell-id/
185 # host-id/
186 #
187 # Either as individual files:
188 #
189 # curl \
190 # --form client=$XSHAR_NAME \
191 # --form file1=@_tmp/foo \
192 # --form file2=@_tmp/bar \
193 # http://travis-ci.oilshell.org/untrusted/
194 #
195 # Or as a .wwz or .zip file?
196 #
197 # wwup can either write the .wwz literally, or it can unpack it with zipfile
198 # module. (Beware of file system traversal issues!)
199 #
200 # Then enhance devtools/src_tree.py to make a nicer view of the tree,
201 # including TSV files rendered as HTML.
202}
203
204demo() {
205 ### Show how we compile the code
206
207 local time_py="$PWD/benchmarks/time_.py"
208
209 build/py.sh time-helper
210
211 # Extract and compile the tarball
212 # Similar to devtools/release-native.sh test-tar
213
214 local tmp=_tmp/xshar-demo
215 mkdir -p $tmp
216
217 pushd $tmp
218 tar -x < ../../_release/oils-for-unix.tar
219
220 pushd oils-for-unix-$OILS_VERSION
221 build/native.sh tarball-demo
222
223 local osh=$PWD/_bin/cxx-opt-sh/osh
224
225 $time_py --tsv --rusage -o demo.tsv -- \
226 $osh -c 'sleep 0.1; echo "hi from osh"'
227 cat demo.tsv
228
229 popd
230
231 popd
232
233 #time OILS_GC_STATS=1 $osh Python-2.7.13/configure
234}
235
236if test $# -eq 0; then
237 print-help
238else
239 case "$1" in
240 -v|--version)
241 print-version
242 exit
243 ;;
244 -h|--help)
245 print-help
246 exit
247 ;;
248 esac
249
250 "$@"
251fi