| 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 |
|
| 26 | set -o nounset
|
| 27 | set -o pipefail
|
| 28 | set -o errexit
|
| 29 |
|
| 30 | source test/common.sh # die
|
| 31 |
|
| 32 | OILS_VERSION=$(head -n 1 oil-version.txt)
|
| 33 |
|
| 34 | REPO_ROOT=$(cd "$(dirname $0)/.."; pwd)
|
| 35 |
|
| 36 | FLAG_num_iters=1 # iterations
|
| 37 | FLAG_num_shells=1
|
| 38 | FLAG_num_workloads=1
|
| 39 |
|
| 40 | parse-flags-osh-runtime() {
|
| 41 | ### Sets global vars FLAG_*
|
| 42 |
|
| 43 | while test $# -ne 0; do
|
| 44 | case "$1" in
|
| 45 | -n|--num-iters)
|
| 46 | if test $# -eq 1; then
|
| 47 | die "-n / --num-iters requires an argument"
|
| 48 | fi
|
| 49 | shift
|
| 50 | FLAG_num_iters=$1
|
| 51 | ;;
|
| 52 |
|
| 53 | -s|--num-shells)
|
| 54 | if test $# -eq 1; then
|
| 55 | die "-s / --num-shells requires an argument"
|
| 56 | fi
|
| 57 | shift
|
| 58 | FLAG_num_shells=$1
|
| 59 | ;;
|
| 60 |
|
| 61 | -w|--num-workloads)
|
| 62 | if test $# -eq 1; then
|
| 63 | die "-w / --num-workloads requires an argument"
|
| 64 | fi
|
| 65 | shift
|
| 66 | FLAG_num_shells=$1
|
| 67 | ;;
|
| 68 |
|
| 69 | *)
|
| 70 | die "Invalid flag '$1'"
|
| 71 | ;;
|
| 72 | esac
|
| 73 | shift
|
| 74 | done
|
| 75 | }
|
| 76 |
|
| 77 | osh-runtime() {
|
| 78 | # $XSHAR_DIR looks like like $REPO_ROOT
|
| 79 |
|
| 80 | parse-flags-osh-runtime "$@"
|
| 81 | echo num_iters=$FLAG_num_iters
|
| 82 | echo num_shells=$FLAG_num_shells
|
| 83 | echo num_workloads=$FLAG_num_workloads
|
| 84 |
|
| 85 | local time_py="${XSHAR_DIR:-$REPO_ROOT}/benchmarks/time_.py"
|
| 86 | build/py.sh time-helper
|
| 87 |
|
| 88 | # Extract and compile the tarball
|
| 89 | # Similar to devtools/release-native.sh test-tar
|
| 90 | local tmp=_tmp/oils-tar
|
| 91 | mkdir -p $tmp
|
| 92 |
|
| 93 | pushd $tmp
|
| 94 | tar -x < ../../_release/oils-for-unix.tar
|
| 95 |
|
| 96 | pushd oils-for-unix-$OILS_VERSION
|
| 97 | build/native.sh tarball-demo
|
| 98 |
|
| 99 | local osh=$PWD/_bin/cxx-opt-sh/osh
|
| 100 |
|
| 101 | # Smoke test
|
| 102 | $time_py --tsv --rusage -- \
|
| 103 | $osh -c 'echo "smoke test: osh and time_.py"'
|
| 104 |
|
| 105 | popd
|
| 106 | popd
|
| 107 |
|
| 108 | benchmarks/osh-runtime.sh test-oils-run $osh \
|
| 109 | $FLAG_num_shells $FLAG_num_workloads $FLAG_num_iters
|
| 110 | }
|
| 111 |
|
| 112 | demo() {
|
| 113 | local time_py="$PWD/benchmarks/time_.py"
|
| 114 |
|
| 115 | build/py.sh time-helper
|
| 116 |
|
| 117 | # Extract and compile the tarball
|
| 118 | # Similar to devtools/release-native.sh test-tar
|
| 119 |
|
| 120 | local tmp=_tmp/xshar-demo
|
| 121 | mkdir -p $tmp
|
| 122 |
|
| 123 | pushd $tmp
|
| 124 | tar -x < ../../_release/oils-for-unix.tar
|
| 125 |
|
| 126 | pushd oils-for-unix-$OILS_VERSION
|
| 127 | build/native.sh tarball-demo
|
| 128 |
|
| 129 | local osh=$PWD/_bin/cxx-opt-sh/osh
|
| 130 |
|
| 131 | $time_py --tsv --rusage -o demo.tsv -- \
|
| 132 | $osh -c 'sleep 0.1; echo "hi from osh"'
|
| 133 | cat demo.tsv
|
| 134 |
|
| 135 | popd
|
| 136 |
|
| 137 | popd
|
| 138 |
|
| 139 | #time OILS_GC_STATS=1 $osh Python-2.7.13/configure
|
| 140 | }
|
| 141 |
|
| 142 | main() {
|
| 143 | # TODO
|
| 144 | #
|
| 145 | # - Extract oils tarball, compile it
|
| 146 | # - Run "$@"
|
| 147 | #
|
| 148 | # test-oils.xshar benchmarks/osh-runtime.sh xshar-main
|
| 149 | #
|
| 150 | # - benchmarks/osh-runtime.sh will create TSV files
|
| 151 | # - then it can upload them to a server
|
| 152 |
|
| 153 | echo 'Hello from test-oils.sh'
|
| 154 | }
|
| 155 |
|
| 156 | "$@"
|