| 1 | #!/usr/bin/env bash
|
| 2 | #
|
| 3 | # Run tests in this directory.
|
| 4 | #
|
| 5 | # Usage:
|
| 6 | # cpp/TEST.sh <function name>
|
| 7 |
|
| 8 | set -o nounset
|
| 9 | set -o pipefail
|
| 10 | set -o errexit
|
| 11 |
|
| 12 | REPO_ROOT=$(cd "$(dirname $0)/.."; pwd)
|
| 13 | source build/common.sh
|
| 14 | source test/common.sh # run-test
|
| 15 |
|
| 16 | run-test-in-dir() {
|
| 17 | ### Test hand-written code
|
| 18 |
|
| 19 | local rel_path=$1
|
| 20 | local compiler=${2:-cxx}
|
| 21 | local variant=${3:-dbg}
|
| 22 |
|
| 23 | local bin=_bin/$compiler-$variant/$rel_path
|
| 24 | ninja $bin
|
| 25 |
|
| 26 | local working_dir=_tmp/$rel_path
|
| 27 | rm -r -f -v $working_dir
|
| 28 | mkdir -p $working_dir
|
| 29 |
|
| 30 | # to test glob()
|
| 31 | touch $working_dir/{foo,bar,baz}.testdata
|
| 32 |
|
| 33 | # TODO: we need a way to pass -t here
|
| 34 | run-test-bin $bin $working_dir
|
| 35 | }
|
| 36 |
|
| 37 | pre-build() {
|
| 38 | # TODO: fold this into Ninja so it doesn't invalidate build
|
| 39 | build/py.sh fastmatch
|
| 40 | }
|
| 41 |
|
| 42 | unit() {
|
| 43 | ### Run unit tests in this dir; used by test/cpp-unit.sh
|
| 44 |
|
| 45 | local variants=(ubsan asan+gcalways)
|
| 46 | if can-compile-32-bit; then
|
| 47 | variants+=(asan32+gcalways)
|
| 48 | else
|
| 49 | # TODO: CI images need gcc-multilib
|
| 50 | log "Can't compile 32-bit binaries (gcc-multilib g++-multilib needed on Debian)"
|
| 51 | fi
|
| 52 |
|
| 53 | for variant in "${variants[@]}"; do
|
| 54 | run-one-test cpp/obj_layout_test '' $variant
|
| 55 |
|
| 56 | run-test-in-dir cpp/core_test '' $variant # has testdata
|
| 57 |
|
| 58 | run-one-test cpp/data_lang_test '' $variant
|
| 59 |
|
| 60 | run-one-test cpp/frontend_flag_spec_test '' $variant
|
| 61 |
|
| 62 | run-one-test cpp/frontend_match_test '' $variant
|
| 63 |
|
| 64 | run-test-in-dir cpp/libc_test '' $variant # has testdata
|
| 65 |
|
| 66 | run-one-test cpp/osh_test '' $variant
|
| 67 |
|
| 68 | run-one-test cpp/pylib_test '' $variant
|
| 69 |
|
| 70 | run-one-test cpp/stdlib_test '' $variant
|
| 71 | done
|
| 72 | }
|
| 73 |
|
| 74 | data-race-test() {
|
| 75 | ### TODO: Expand this to signal state, and make sure it passes!
|
| 76 |
|
| 77 | run-one-test cpp/data_race_test '' tsan
|
| 78 | }
|
| 79 |
|
| 80 | coverage() {
|
| 81 | ### Run coverage for this dir
|
| 82 |
|
| 83 | pre-build
|
| 84 |
|
| 85 | local compiler=clang
|
| 86 | local variant=coverage
|
| 87 |
|
| 88 | run-one-test cpp/obj_layout_test $compiler $variant
|
| 89 |
|
| 90 | run-test-in-dir cpp/core_test $compiler $variant # has testdata
|
| 91 |
|
| 92 | run-one-test cpp/data_lang_test $compiler $variant
|
| 93 |
|
| 94 | run-one-test cpp/frontend_flag_spec_test $compiler $variant
|
| 95 |
|
| 96 | run-one-test cpp/frontend_match_test $compiler $variant
|
| 97 |
|
| 98 | run-test-in-dir cpp/libc_test $compiler $variant # has testdata
|
| 99 |
|
| 100 | run-one-test cpp/osh_test $compiler $variant
|
| 101 |
|
| 102 | run-one-test cpp/pylib_test $compiler $variant
|
| 103 |
|
| 104 | run-one-test cpp/stdlib_test $compiler $variant
|
| 105 |
|
| 106 | local out_dir=_test/clang-coverage/cpp
|
| 107 | test/coverage.sh html-report $out_dir clang-coverage/cpp
|
| 108 | }
|
| 109 |
|
| 110 | "$@"
|