| 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 TOYBOX_DIR=~/src/toybox-0.8.12
|
| 38 |
|
| 39 | readonly SUSH_DIR=../../shells/rusty_bash
|
| 40 | readonly BRUSH_DIR=../../shells/brush
|
| 41 |
|
| 42 | readonly SUSH=$PWD/$SUSH_DIR/target/release/sush
|
| 43 | readonly BRUSH=$PWD/$BRUSH_DIR/target/release/brush
|
| 44 |
|
| 45 | # these are all roughly ksh compatible
|
| 46 | readonly -a SHELLS=(bash mksh ksh $TOYBOX_DIR/sh $SUSH $BRUSH $OSH)
|
| 47 |
|
| 48 | download-toybox() {
|
| 49 | #mkdir -p ~/src
|
| 50 | wget --directory ~/src --no-clobber \
|
| 51 | https://landley.net/toybox/downloads/toybox-0.8.12.tar.gz
|
| 52 | }
|
| 53 |
|
| 54 | build-toybox() {
|
| 55 | pushd $TOYBOX_DIR
|
| 56 |
|
| 57 | make toybox
|
| 58 | # warning: using unfinished code
|
| 59 | make sh
|
| 60 |
|
| 61 | popd
|
| 62 | }
|
| 63 |
|
| 64 | update-rust() {
|
| 65 | . ~/.cargo/env
|
| 66 | time rustup update
|
| 67 | }
|
| 68 |
|
| 69 | build-brush() {
|
| 70 | pushd ../../shells/brush
|
| 71 |
|
| 72 | . ~/.cargo/env
|
| 73 |
|
| 74 | # Test incremental build speed
|
| 75 | # - debug: 3.8 seconds
|
| 76 | # - release: 1:06 minutes !
|
| 77 | # touch brush-core/src/shell.rs
|
| 78 |
|
| 79 | # 41s
|
| 80 | time cargo build
|
| 81 | echo
|
| 82 |
|
| 83 | # 1m 49s
|
| 84 | # It builds a stripped binary by default - disable that for metrics
|
| 85 | RUSTFLAGS='-C strip=none' time cargo build --release
|
| 86 | echo
|
| 87 |
|
| 88 | popd
|
| 89 | }
|
| 90 |
|
| 91 | build-sush() {
|
| 92 | pushd ../../shells/rusty_bash
|
| 93 |
|
| 94 | . ~/.cargo/env
|
| 95 |
|
| 96 | # Test incremental build speed
|
| 97 | # - debug: 1 second
|
| 98 | # - release: 6 seconds
|
| 99 | #touch src/core.rs
|
| 100 |
|
| 101 | # 10 seconds
|
| 102 | time cargo build
|
| 103 | echo
|
| 104 |
|
| 105 | # 15 seconds
|
| 106 | time cargo build --release
|
| 107 | echo
|
| 108 |
|
| 109 | popd
|
| 110 | }
|
| 111 |
|
| 112 | binary-sizes() {
|
| 113 | local oils=_bin/cxx-opt/bin/oils_for_unix.mycpp.stripped
|
| 114 | ninja $oils
|
| 115 | # stripped: 2.4 MB
|
| 116 | ls -l --si $oils
|
| 117 |
|
| 118 | pushd ../../shells/brush
|
| 119 | strip -o target/release/brush.stripped target/release/brush
|
| 120 | # stripped: 7.3 MB
|
| 121 | ls -l --si target/release
|
| 122 | popd
|
| 123 |
|
| 124 | pushd ../../shells/rusty_bash
|
| 125 | strip -o target/release/sush.stripped target/release/sush
|
| 126 | # stripped: 3.4 MB
|
| 127 | ls -l --si target/release
|
| 128 | echo
|
| 129 | popd
|
| 130 | }
|
| 131 |
|
| 132 | symbols() {
|
| 133 | pushd ../../shells/brush
|
| 134 | #file target/release/brush
|
| 135 |
|
| 136 | echo 'BRUSH'
|
| 137 | # 6140
|
| 138 | nm target/release/brush | wc -l
|
| 139 | popd
|
| 140 |
|
| 141 | pushd ../../shells/rusty_bash
|
| 142 | # Not stripped
|
| 143 | #file target/release/sush
|
| 144 |
|
| 145 | echo 'SUSH'
|
| 146 | # 10380
|
| 147 | nm target/release/sush | wc -l
|
| 148 | # More symbols
|
| 149 | # nm target/debug/sush | wc -l
|
| 150 | popd
|
| 151 |
|
| 152 | #local osh=_bin/cxx-opt/bin/oils_for_unix.mycpp.stripped
|
| 153 | local osh=_bin/cxx-opt/bin/oils_for_unix.mycpp
|
| 154 | local dbg=_bin/cxx-dbg/bin/oils_for_unix.mycpp
|
| 155 | ninja $osh
|
| 156 |
|
| 157 | echo 'OSH'
|
| 158 | # 9810 - lots of string literals?
|
| 159 | nm $osh | wc -l
|
| 160 | #nm $osh | less
|
| 161 |
|
| 162 | #ninja $dbg
|
| 163 | # 17570
|
| 164 | #nm $dbg | wc -l
|
| 165 | }
|
| 166 |
|
| 167 | install-geiger() {
|
| 168 | # https://github.com/geiger-rs/cargo-geiger
|
| 169 | . ~/.cargo/env
|
| 170 |
|
| 171 | # 2:34 minutes
|
| 172 | cargo install --locked cargo-geiger
|
| 173 | }
|
| 174 |
|
| 175 | # This is DESTRUCTIVE
|
| 176 | geiger-report() {
|
| 177 | if true; then
|
| 178 | pushd ../../shells/brush
|
| 179 |
|
| 180 | . ~/.cargo/env
|
| 181 |
|
| 182 | # doesn't work
|
| 183 | #time cargo geiger --workspace
|
| 184 | #time cargo geiger --package brush-core --package brush-parser
|
| 185 |
|
| 186 | popd
|
| 187 | fi
|
| 188 |
|
| 189 | if false; then
|
| 190 | pushd ../../shells/rusty_bash
|
| 191 |
|
| 192 | . ~/.cargo/env
|
| 193 |
|
| 194 | # this cleans the build
|
| 195 | #
|
| 196 | # Functions Expressions Impls Traits Methods
|
| 197 | # 181/1056 9377/45040 114/158 30/32 463/2887
|
| 198 | #
|
| 199 | # x/y
|
| 200 | # x = unsafe used by build
|
| 201 | # y = unsafe in crate
|
| 202 |
|
| 203 | # ~7 seconds
|
| 204 | time cargo geiger
|
| 205 |
|
| 206 | popd
|
| 207 | fi
|
| 208 | }
|
| 209 |
|
| 210 | #
|
| 211 | # Spec Tests
|
| 212 | #
|
| 213 |
|
| 214 | run-file() {
|
| 215 | local spec_name=$1
|
| 216 | shift # Pass list of shells
|
| 217 |
|
| 218 | # spec/tilde hangs under toysh - need timeout
|
| 219 | sh-spec spec/$spec_name.test.sh \
|
| 220 | --timeout 1 \
|
| 221 | "$@"
|
| 222 | }
|
| 223 |
|
| 224 | compare() {
|
| 225 | local spec_name=${1:-smoke}
|
| 226 | run-file $spec_name "${SHELLS[@]}"
|
| 227 | }
|
| 228 |
|
| 229 | list() {
|
| 230 | mkdir -p _tmp/spec # _all-parallel also does this
|
| 231 | test/spec-runner.sh write-suite-manifests
|
| 232 | wc -l _tmp/spec/SUITE-*
|
| 233 |
|
| 234 | # TODO:
|
| 235 | # - Remove zsh test files?
|
| 236 | # - What about *-bash test cases? These aren't clearly organized
|
| 237 |
|
| 238 | cat _tmp/spec/SUITE-osh.txt
|
| 239 | }
|
| 240 |
|
| 241 | task-five "$@"
|