~andyc/oil

5619ad99549c6f4bef75b828d1e1dfc436998bd9 — Andy C 2 months ago c4ffc5f
[ASDL] Fix tests under podman (on sourcehut)

By making ASAN_OPTIONS global to asdl/test.sh

Improve automation / logging
7 files changed, 69 insertions(+), 43 deletions(-)

M asdl/test.sh
M cpp/test.sh
M mycpp/build.sh
M mycpp/test.sh
M soil/common.sh
M soil/worker.sh
M test/cpp-unit.sh
M asdl/test.sh => asdl/test.sh +41 -21
@@ 16,6 16,9 @@ source cpp/NINJA-steps.sh  # compile_and_link

CPPFLAGS="$BASE_CXXFLAGS -g -fsanitize=address"  # for debugging tests

# Could we turn on the leak detector for the GC tests?
export ASAN_OPTIONS='detect_leaks=0'

asdl-tool() {
  PYTHONPATH='.:vendor/' asdl/tool.py "$@"
}


@@ 23,12 26,13 @@ asdl-tool() {
readonly TMP_DIR='_build/asdl-test'

gen-cpp-test() {
  export ASAN_OPTIONS='detect_leaks=0'
  local compiler=${1:-cxx}
  local variant=${1:-asan}

  local tmp_dir=$TMP_DIR
  local out_dir=_bin/cxx-asan/asdl
  local bin_dir="_bin/$compiler-$variant/asdl"

  mkdir -p $tmp_dir $out_dir
  mkdir -p $tmp_dir $bin_dir

  local prefix=$tmp_dir/typed_arith_asdl
  asdl-tool cpp asdl/typed_arith.asdl $prefix


@@ 41,9 45,9 @@ gen-cpp-test() {

  wc -l $prefix* $prefix2*

  local bin=$out_dir/gen_cpp_test
  local bin=$bin_dir/gen_cpp_test

  compile_and_link cxx asan '-D LEAKY_BINDINGS' $bin \
  compile_and_link $compiler $variant '-D LEAKY_BINDINGS' $bin \
    asdl/gen_cpp_test.cc \
    asdl/runtime.cc \
    mycpp/mylib_leaky.cc \


@@ 52,10 56,17 @@ gen-cpp-test() {
    $tmp_dir/typed_arith_asdl.cc \
    $tmp_dir/typed_demo_asdl.cc 

  $bin "$@"
  local log_dir="test/$compiler-$variant/asdl"
  mkdir -p $log_dir
  local log="$log_dir/gen_cpp_test.log"
  log "RUN $bin > $log"
  $bin "$@" > "$log"
}

gc-test() {
  local compiler=${1:-cxx}
  local variant=${1:-asan}

  # TODO: remove this after it works with the garbage collector!
  export ASAN_OPTIONS='detect_leaks=0'



@@ 63,8 74,8 @@ gc-test() {
  build/dev.sh oil-asdl-to-cpp

  local tmp_dir=$TMP_DIR
  local out_dir=_bin/cxx-asan/asdl
  mkdir -p $tmp_dir $out_dir
  local bin_dir=_bin/$compiler-$variant/asdl
  mkdir -p $tmp_dir $bin_dir

  local prefix2=$tmp_dir/demo_lib_asdl
  asdl-tool cpp asdl/demo_lib.asdl $prefix2


@@ 72,10 83,10 @@ gc-test() {
  local prefix3=$tmp_dir/typed_demo_asdl
  asdl-tool cpp asdl/typed_demo.asdl $prefix3

  local bin=$out_dir/asdl_gc_test
  local bin=$bin_dir/gc_test

  # uses typed_arith_asdl.h, runtime.h, hnode_asdl.h, asdl_runtime.h
  compile_and_link cxx asan '' $bin \
  compile_and_link $compiler $variant '' $bin \
    asdl/gc_test.cc \
    mycpp/gc_heap.cc \
    mycpp/my_runtime.cc \


@@ 85,15 96,19 @@ gc-test() {
    $tmp_dir/demo_lib_asdl.cc \
    $tmp_dir/typed_demo_asdl.cc

  $bin "$@"
  local log_dir="test/$compiler-$variant/asdl"
  mkdir -p $log_dir
  local log="$log_dir/gc_test.log"
  log "RUN $bin > $log"
  $bin "$@" > "$log"
}

hnode-asdl-gc() {
  ### Test that hnode can compile by itself

  local tmp_dir=$TMP_DIR
  local out_dir=_bin/cxx-asan/asdl
  mkdir -p $tmp_dir $out_dir
  local bin_dir=_bin/cxx-asan/asdl
  mkdir -p $tmp_dir $bin_dir

  cat >$tmp_dir/hnode_asdl_test.cc <<'EOF'
#include "_build/cpp/hnode_asdl.h"


@@ 104,12 119,13 @@ int main() {
}
EOF

  local bin=$out_dir/hnode_asdl_test
  local bin=$bin_dir/hnode_asdl_test

  compile_and_link cxx asan '' $bin \
    _build/cpp/hnode_asdl.cc \
    $tmp_dir/hnode_asdl_test.cc

  log "RUN $bin"
  $bin
}



@@ 126,8 142,8 @@ one-asdl-gc() {
  fi

  local tmp_dir=$TMP_DIR
  local out_dir=_bin/cxx-asan/asdl
  mkdir -p $tmp_dir $out_dir
  local bin_dir=_bin/cxx-asan/asdl
  mkdir -p $tmp_dir $bin_dir

  cat >$tmp_dir/${name}_asdl_test.cc <<EOF
#include "_build/cpp/${name}_asdl.h"


@@ 138,7 154,7 @@ int main() {
}
EOF

  local bin=$out_dir/${name}_asdl_test
  local bin=$bin_dir/${name}_asdl_test

  compile_and_link cxx asan '' $bin \
    _build/cpp/${name}_asdl.cc \


@@ 149,6 165,7 @@ EOF
    $tmp_dir/${name}_asdl_test.cc \
    "$@"

  log "RUN $bin"
  $bin
}



@@ 170,13 187,16 @@ all-asdl-gc() {
}

unit() {
  # TODO: Write logs to _test/cxx-dbg/asdl/ like mycpp/test.sh does
  ### Run unit tests

  gen-cpp-test
  echo

  asdl/test.sh gen-cpp-test
  asdl/test.sh gc-test  # integration between ASDL and the GC heap
  gc-test  # integration between ASDL and the GC heap
  echo

  # test each ASDL file on its own, perhaps with the garbage-collected ASDL runtime
  asdl/test.sh all-asdl-gc
  all-asdl-gc
}

"$@"

M cpp/test.sh => cpp/test.sh +3 -1
@@ 9,6 9,8 @@ set -o nounset
set -o pipefail
set -o errexit

REPO_ROOT=$(cd "$(dirname $0)/.."; pwd)
source build/common.sh
source cpp/NINJA-steps.sh  # for compile_and_link function

# https://github.com/google/sanitizers/wiki/AddressSanitizerLeakSanitizer


@@ 115,7 117,7 @@ run-test() {
  export LLVM_PROFILE_FILE=$dir/$name.profraw

  local log=$dir/$name.log
  echo "RUN $bin > $log"
  log "RUN $bin > $log"
  $bin > $log
}


M mycpp/build.sh => mycpp/build.sh +2 -2
@@ 19,13 19,13 @@ soil-run() {

  set +o errexit

  # 'mycpp-all' has other stuff like type checking alone, stripping
  # 'mycpp-all' has other stuff like type checking alone, stripping, clang builds
  ninja mycpp-logs-equal

  local status=$?
  set -o errexit

  find-dir-html _test
  find-dir-html _test mycpp-examples

  # Now we want to zip up
  return $status

M mycpp/test.sh => mycpp/test.sh +17 -14
@@ 9,6 9,9 @@ set -o nounset
set -o pipefail
set -o errexit

REPO_ROOT=$(cd "$(dirname $0)/.."; pwd)
source build/common.sh

# in case binaries weren't built
shopt -s failglob



@@ 49,11 52,11 @@ examples-variant() {

    local log="${prefix}${do_benchmark}.log"

    echo "RUN $b > $log"
    log "RUN $b > $log"

    local test_name=$(basename $b)
    if test -n "$do_benchmark" && [[ $test_name == test_* ]]; then
      echo "Skipping $test_name in benchmark mode"
      log "Skipping $test_name in benchmark mode"
      continue
    fi



@@ 62,9 65,9 @@ examples-variant() {
    status=$?

    if test "$status" -eq 0; then
      echo 'OK'
      log 'OK'
    else
      echo "FAIL with status $?"
      log "FAIL with status $?"
      #return $status
    fi



@@ 74,9 77,9 @@ examples-variant() {
    num_tests=$((num_tests + 1))
  done

  echo
  echo "$num_failed of $num_tests tests failed"
  echo
  log ''
  log "$num_failed of $num_tests tests failed"
  log ''
}

#


@@ 143,9 146,9 @@ unit() {
  local compiler=${1:-cxx}
  local variant=${2:-testgc}

  echo
  echo "mycpp/test.sh unit $compiler $variant"
  echo
  log ''
  log "mycpp/test.sh unit $compiler $variant"
  log ''


  # TODO: Exclude examples here


@@ 159,7 162,7 @@ unit() {
    local prefix=$log_dir/$(basename $b)
    local log=$prefix.log

    echo "RUN $b > $log"
    log "RUN $b > $log"

    case $variant in
      (coverage)


@@ 172,7 175,7 @@ unit() {
    case $variant in
      (asan|ubsan|coverage)
        if test "$(basename $b)" = 'my_runtime_test'; then
          echo "SKIPPING $b because it's not compatible with $variant"
          log "SKIPPING $b because it's not compatible with $variant"
          continue
        fi
        ;;


@@ 184,9 187,9 @@ unit() {
    set -o errexit

    if test "$status" -eq 0; then
      echo 'OK'
      log 'OK'
    else
      echo "FAIL with status $?"
      log "FAIL with status $?"
      return $status
    fi
  done

M soil/common.sh => soil/common.sh +3 -2
@@ 33,9 33,10 @@ soil-html-head() {
# Used by mycpp/build.sh and benchmarks/auto.sh
find-dir-html() {
  local dir=$1
  local out_name=${2:-index}

  local txt=$dir/index.txt
  local html=$dir/index.html
  local txt=$dir/$out_name.txt
  local html=$dir/$out_name.html

  find $dir -type f | sort > $txt
  echo "Wrote $txt"

M soil/worker.sh => soil/worker.sh +2 -2
@@ 180,13 180,13 @@ cpp-small-tasks() {
  cat <<EOF
dump-versions    soil/worker.sh dump-versions          -
build-minimal    build/dev.sh minimal                  -
cpp-unit         test/cpp-unit.sh soil-run             _test/index.html
cpp-unit         test/cpp-unit.sh soil-run             _test/cpp-unit.html
build-osh-eval   build/dev.sh oil-cpp                  -
osh-eval-smoke   build/native.sh osh-eval-smoke        -
line-counts      metrics/source-code.sh write-reports  _tmp/metrics/line-counts/index.html
preprocessed     metrics/source-code.sh oil-native-preprocessed -
shell-benchmarks benchmarks/auto.sh soil-run           _tmp/benchmark-data/index.html
mycpp-examples   mycpp/build.sh soil-run               _test/index.html
mycpp-examples   mycpp/build.sh soil-run               _test/mycpp-examples.html
parse-errors     test/parse-errors.sh soil-run-cpp     -
EOF
}

M test/cpp-unit.sh => test/cpp-unit.sh +1 -1
@@ 31,7 31,7 @@ soil-run() {
  set -o errexit

  # Logs in _test/cxx-asan, etc.
  find-dir-html _test
  find-dir-html _test cpp-unit

  return $status
}