| 1 | #!/usr/bin/env bash
|
| 2 | #
|
| 3 | # Test OSH against any shell
|
| 4 | #
|
| 5 | # Usage:
|
| 6 | # test/spec-any.sh <function name>
|
| 7 |
|
| 8 | : ${LIB_OSH=stdlib/osh}
|
| 9 | source $LIB_OSH/bash-strict.sh
|
| 10 | source $LIB_OSH/task-five.sh
|
| 11 |
|
| 12 | REPO_ROOT=$(cd "$(dirname $0)/.."; pwd)
|
| 13 |
|
| 14 | source test/common.sh
|
| 15 | source test/spec-common.sh
|
| 16 |
|
| 17 | OSH=_bin/cxx-asan/osh
|
| 18 | ninja $OSH
|
| 19 | OSH=$PWD/$OSH
|
| 20 |
|
| 21 | # To compare against:
|
| 22 | # - toysh
|
| 23 | # - brush
|
| 24 | # - rusty_bash
|
| 25 | # - ksh93 - Debian package
|
| 26 |
|
| 27 | # Metrics
|
| 28 | # - binary size - stripped
|
| 29 | # - lines of source code - I think we get this from DWARF debug info
|
| 30 | # - https://claude.ai/chat/40597e2e-4d1e-42b4-a756-7a265f01cc5a shows options
|
| 31 | # - llvm-dwarfdump
|
| 32 | # - Python lib https://github.com/eliben/pyelftools/
|
| 33 | # - right now this isn't worth it - spec tests are more important
|
| 34 | # - unsafe functions / methods?
|
| 35 | # - cargo geiger is also hard to parse
|
| 36 |
|
| 37 | readonly BRUSH_DIR=~/install/brush
|
| 38 |
|
| 39 | # Note: we have the repo too
|
| 40 | download-brush-binary() {
|
| 41 | # The musl libc build works on my old Ubuntu VM, because it's statically linked
|
| 42 | # The GNU one doesn't work
|
| 43 | wget --directory $BRUSH_DIR --no-clobber \
|
| 44 | https://github.com/reubeno/brush/releases/download/brush-shell-v0.2.18/brush-x86_64-unknown-linux-musl.tar.gz
|
| 45 | #https://github.com/reubeno/brush/releases/download/brush-shell-v0.2.18/brush-x86_64-unknown-linux-gnu.tar.gz
|
| 46 | }
|
| 47 |
|
| 48 | #BRUSH=$BRUSH_DIR/brush
|
| 49 |
|
| 50 | readonly TOYBOX_DIR=~/src/toybox-0.8.12
|
| 51 |
|
| 52 | readonly SUSH_DIR=../../shells/rusty_bash
|
| 53 |
|
| 54 | # these are all roughly ksh compatible
|
| 55 | readonly -a SHELLS=(bash mksh ksh $TOYBOX_DIR/sh $PWD/$SUSH_DIR/target/release/sush $OSH)
|
| 56 |
|
| 57 | download-toybox() {
|
| 58 | #mkdir -p ~/src
|
| 59 | wget --directory ~/src --no-clobber \
|
| 60 | https://landley.net/toybox/downloads/toybox-0.8.12.tar.gz
|
| 61 | }
|
| 62 |
|
| 63 | build-toybox() {
|
| 64 | pushd $TOYBOX_DIR
|
| 65 |
|
| 66 | make toybox
|
| 67 | # warning: using unfinished code
|
| 68 | make sh
|
| 69 |
|
| 70 | popd
|
| 71 | }
|
| 72 |
|
| 73 | update-rust() {
|
| 74 | . ~/.cargo/env
|
| 75 | time rustup update
|
| 76 | }
|
| 77 |
|
| 78 | build-brush() {
|
| 79 | pushd ../../shells/brush
|
| 80 |
|
| 81 | . ~/.cargo/env
|
| 82 |
|
| 83 | # Test incremental build speed
|
| 84 | # - debug: 3.8 seconds
|
| 85 | # - release: 1:06 minutes !
|
| 86 | # touch brush-core/src/shell.rs
|
| 87 |
|
| 88 | # 41s
|
| 89 | time cargo build
|
| 90 | echo
|
| 91 |
|
| 92 | # 1m 49s
|
| 93 | # It builds a stripped binary by default - disable that for metrics
|
| 94 | RUSTFLAGS='-C strip=none' time cargo build --release
|
| 95 | echo
|
| 96 |
|
| 97 | popd
|
| 98 | }
|
| 99 |
|
| 100 | build-sush() {
|
| 101 | pushd ../../shells/rusty_bash
|
| 102 |
|
| 103 | . ~/.cargo/env
|
| 104 |
|
| 105 | # Test incremental build speed
|
| 106 | # - debug: 1 second
|
| 107 | # - release: 6 seconds
|
| 108 | #touch src/core.rs
|
| 109 |
|
| 110 | # 10 seconds
|
| 111 | time cargo build
|
| 112 | echo
|
| 113 |
|
| 114 | # 15 seconds
|
| 115 | time cargo build --release
|
| 116 | echo
|
| 117 |
|
| 118 | popd
|
| 119 | }
|
| 120 |
|
| 121 | binary-sizes() {
|
| 122 | local oils=_bin/cxx-opt/bin/oils_for_unix.mycpp.stripped
|
| 123 | ninja $oils
|
| 124 | # stripped: 2.4 MB
|
| 125 | ls -l --si $oils
|
| 126 |
|
| 127 | pushd ../../shells/brush
|
| 128 | strip -o target/release/brush.stripped target/release/brush
|
| 129 | # stripped: 7.1 MB
|
| 130 | ls -l --si target/release
|
| 131 | popd
|
| 132 |
|
| 133 | pushd ../../shells/rusty_bash
|
| 134 | strip -o target/release/sush.stripped target/release/sush
|
| 135 | # stripped: 3.9 MB
|
| 136 | ls -l --si target/release
|
| 137 | echo
|
| 138 | popd
|
| 139 | }
|
| 140 |
|
| 141 | symbols() {
|
| 142 | pushd ../../shells/brush
|
| 143 | #file target/release/brush
|
| 144 |
|
| 145 | echo 'BRUSH'
|
| 146 | # 6140
|
| 147 | nm target/release/brush | wc -l
|
| 148 | popd
|
| 149 |
|
| 150 | pushd ../../shells/rusty_bash
|
| 151 | # Not stripped
|
| 152 | #file target/release/sush
|
| 153 |
|
| 154 | echo 'SUSH'
|
| 155 | # 10380
|
| 156 | nm target/release/sush | wc -l
|
| 157 | # More symbols
|
| 158 | # nm target/debug/sush | wc -l
|
| 159 | popd
|
| 160 |
|
| 161 | #local osh=_bin/cxx-opt/bin/oils_for_unix.mycpp.stripped
|
| 162 | local osh=_bin/cxx-opt/bin/oils_for_unix.mycpp
|
| 163 | local dbg=_bin/cxx-dbg/bin/oils_for_unix.mycpp
|
| 164 | ninja $osh
|
| 165 |
|
| 166 | echo 'OSH'
|
| 167 | # 9810 - lots of string literals?
|
| 168 | nm $osh | wc -l
|
| 169 | #nm $osh | less
|
| 170 |
|
| 171 | #ninja $dbg
|
| 172 | # 17570
|
| 173 | #nm $dbg | wc -l
|
| 174 | }
|
| 175 |
|
| 176 | install-geiger() {
|
| 177 | # https://github.com/geiger-rs/cargo-geiger
|
| 178 | . ~/.cargo/env
|
| 179 |
|
| 180 | # 2:34 minutes
|
| 181 | cargo install --locked cargo-geiger
|
| 182 | }
|
| 183 |
|
| 184 | # This is DESTRUCTIVE
|
| 185 | geiger-report() {
|
| 186 | if true; then
|
| 187 | pushd ../../shells/brush
|
| 188 |
|
| 189 | . ~/.cargo/env
|
| 190 |
|
| 191 | # doesn't work
|
| 192 | #time cargo geiger --workspace
|
| 193 | #time cargo geiger --package brush-core --package brush-parser
|
| 194 |
|
| 195 | popd
|
| 196 | fi
|
| 197 |
|
| 198 | if false; then
|
| 199 | pushd ../../shells/rusty_bash
|
| 200 |
|
| 201 | . ~/.cargo/env
|
| 202 |
|
| 203 | # this cleans the build
|
| 204 | #
|
| 205 | # Functions Expressions Impls Traits Methods
|
| 206 | # 181/1056 9377/45040 114/158 30/32 463/2887
|
| 207 | #
|
| 208 | # x/y
|
| 209 | # x = unsafe used by build
|
| 210 | # y = unsafe in crate
|
| 211 |
|
| 212 | # ~7 seconds
|
| 213 | time cargo geiger
|
| 214 |
|
| 215 | popd
|
| 216 | fi
|
| 217 | }
|
| 218 |
|
| 219 | #
|
| 220 | # Spec Tests
|
| 221 | #
|
| 222 |
|
| 223 | run-file() {
|
| 224 | local spec_name=$1
|
| 225 | shift # Pass list of shells
|
| 226 |
|
| 227 | # spec/tilde hangs under toysh - need timeout
|
| 228 | sh-spec spec/$spec_name.test.sh \
|
| 229 | --timeout 1 \
|
| 230 | "$@"
|
| 231 | }
|
| 232 |
|
| 233 | compare() {
|
| 234 | local spec_name=${1:-smoke}
|
| 235 | run-file $spec_name "${SHELLS[@]}"
|
| 236 | }
|
| 237 |
|
| 238 | list() {
|
| 239 | mkdir -p _tmp/spec # _all-parallel also does this
|
| 240 | test/spec-runner.sh write-suite-manifests
|
| 241 | wc -l _tmp/spec/SUITE-*
|
| 242 |
|
| 243 | # TODO:
|
| 244 | # - Remove zsh test files?
|
| 245 | # - What about *-bash test cases? These aren't clearly organized
|
| 246 |
|
| 247 | cat _tmp/spec/SUITE-osh.txt
|
| 248 | }
|
| 249 |
|
| 250 | task-five "$@"
|