diff --git a/asdl/run.sh b/asdl/run.sh index 742391e5ff..b4332e5723 100755 --- a/asdl/run.sh +++ b/asdl/run.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # -# Automation for ASDL. +# Junk drawer for ASDL. # # Usage: # asdl/run.sh @@ -9,12 +9,10 @@ set -o nounset set -o pipefail set -o errexit -REPO_ROOT=$(cd $(dirname $0)/..; pwd) +REPO_ROOT=$(cd "$(dirname $0)/.."; pwd) readonly REPO_ROOT -source build/common.sh # BASE_CXXFLAGS, etc. - -CPPFLAGS="$BASE_CXXFLAGS -g -fsanitize=address" # for debugging tests +source build/common.sh export PYTHONPATH='.:vendor/' @@ -39,28 +37,10 @@ gen-typed-arith-asdl() { gen-mypy-asdl typed_arith 'asdl.typed_arith_abbrev' } -# -# Test specific schemas -# - -arith-both() { py-cpp asdl/arith.asdl; } -osh-both() { py-cpp osh/osh.asdl; } - # # Native Code # -cxx() { - local CXX=$CLANGXX - local opt_flag='-O2' - #local opt_flag='-O0' - - # -Winline - # http://stackoverflow.com/questions/10631283/how-will-i-know-whether-inline-function-is-actually-replaced-at-the-place-where - - $CXX -Winline $opt_flag -std=c++11 "$@" -} - # http://www.commandlinefu.com/commands/view/6004/print-stack-trace-of-a-core-file-without-needing-to-enter-gdb-interactively # http://stackoverflow.com/questions/4521015/how-to-pass-arguments-and-redirect-stdin-from-a-file-to-program-run-in-gdb gdb-trace() { @@ -68,15 +48,6 @@ gdb-trace() { gdb -batch -ex "run" -ex "bt" -args "$@" 2>&1 } -a4() { - local data=_tmp/a4.bin - asdl-arith-encode 'array[99]' $data - gdb-trace _tmp/typed_arith_demo $data - - asdl-arith-encode 'array[5:10] * 5' $data - gdb-trace _tmp/typed_arith_demo $data -} - # http://stackoverflow.com/questions/22769246/disassemble-one-function-using-objdump # It would be nice to disassemble a single function. @@ -163,79 +134,4 @@ EOF ls -l _tmp/asdl_bad* } -# TODO: These two tests should be built with Ninja. - -gen-cpp-test() { - export ASAN_OPTIONS='detect_leaks=0' - - local prefix=_tmp/typed_arith_asdl - asdl/tool.py cpp asdl/typed_arith.asdl $prefix - - local prefix2=_tmp/demo_lib_asdl - asdl/tool.py cpp asdl/demo_lib.asdl $prefix2 - - local prefix3=_tmp/typed_demo_asdl - asdl/tool.py cpp asdl/typed_demo.asdl $prefix3 - - wc -l $prefix* $prefix2* - - local bin=_bin/gen_cpp_test - - # BUG: This doesn't link without the translation of asdl/runtime.py. - - # uses typed_arith_asdl.h, runtime.h, hnode_asdl.h, asdl_runtime.h - # $CLANGXX -ferror-limit=10 \ - $CXX \ - $CPPFLAGS \ - -D USING_OLD_QSN \ - -I . -I _tmp \ - -o $bin \ - asdl/gen_cpp_test.cc \ - asdl/runtime.cc \ - mycpp/mylib.cc \ - mycpp/gc_heap.cc \ - _build/cpp/hnode_asdl.cc \ - _tmp/typed_arith_asdl.cc \ - _tmp/typed_demo_asdl.cc - - #gdb -batch -ex run -ex bt --args $bin "$@" - $bin "$@" -} - -gc-test() { - # TODO: remove this after it works with the garbage collector! - export ASAN_OPTIONS='detect_leaks=0' - - # for hnode_asdl.gc.cc - build/dev.sh oil-asdl-to-cpp-gc - - local dir=_build/gc-test - mkdir -p $dir - - local prefix2=$dir/demo_lib_asdl.gc - GC=1 asdl/tool.py cpp asdl/demo_lib.asdl $prefix2 - - local prefix3=$dir/typed_demo_asdl.gc - GC=1 asdl/tool.py cpp asdl/typed_demo.asdl $prefix3 - - local bin=_bin/asdl_gc_test - - # uses typed_arith_asdl.h, runtime.h, hnode_asdl.h, asdl_runtime.h - $CXX $CPPFLAGS \ - -I . -I $dir \ - -o $bin \ - asdl/gc_test.cc \ - mycpp/gc_heap.cc \ - mycpp/my_runtime.cc \ - mycpp/mylib2.cc \ - asdl/runtime.gc.cc \ - $dir/demo_lib_asdl.gc.cc \ - $dir/typed_demo_asdl.gc.cc \ - _build/cpp/hnode_asdl.gc.cc - - #gdb -batch -ex run -ex bt --args $bin "$@" - - $bin "$@" -} - "$@" diff --git a/asdl/test.sh b/asdl/test.sh new file mode 100755 index 0000000000..b6ba28ef54 --- /dev/null +++ b/asdl/test.sh @@ -0,0 +1,180 @@ +#!/usr/bin/env bash +# +# Tests for ASDL. +# +# Usage: +# asdl/test.sh + +set -o nounset +set -o pipefail +set -o errexit + +REPO_ROOT=$(cd "$(dirname $0)/.."; pwd) + +source build/common.sh # BASE_CXXFLAGS, etc. + +CPPFLAGS="$BASE_CXXFLAGS -g -fsanitize=address" # for debugging tests + +asdl-tool() { + PYTHONPATH='.:vendor/' asdl/tool.py "$@" +} + +gen-cpp-test() { + export ASAN_OPTIONS='detect_leaks=0' + + local prefix=_tmp/typed_arith_asdl + asdl-tool cpp asdl/typed_arith.asdl $prefix + + local prefix2=_tmp/demo_lib_asdl + asdl-tool cpp asdl/demo_lib.asdl $prefix2 + + local prefix3=_tmp/typed_demo_asdl + asdl-tool cpp asdl/typed_demo.asdl $prefix3 + + wc -l $prefix* $prefix2* + + local bin=_bin/gen_cpp_test + + # BUG: This doesn't link without the translation of asdl/runtime.py. + + # uses typed_arith_asdl.h, runtime.h, hnode_asdl.h, asdl_runtime.h + # $CLANGXX -ferror-limit=10 \ + $CXX \ + $CPPFLAGS \ + -D USING_OLD_QSN \ + -I . -I _tmp \ + -o $bin \ + asdl/gen_cpp_test.cc \ + asdl/runtime.cc \ + mycpp/mylib.cc \ + mycpp/gc_heap.cc \ + _build/cpp/hnode_asdl.cc \ + _tmp/typed_arith_asdl.cc \ + _tmp/typed_demo_asdl.cc + + #gdb -batch -ex run -ex bt --args $bin "$@" + $bin "$@" +} + +gc-test() { + # TODO: remove this after it works with the garbage collector! + export ASAN_OPTIONS='detect_leaks=0' + + # for hnode_asdl.gc.cc + build/dev.sh oil-asdl-to-cpp-gc + + local dir=_build/gc-test + mkdir -p $dir + + local prefix2=$dir/demo_lib_asdl.gc + GC=1 asdl-tool cpp asdl/demo_lib.asdl $prefix2 + + local prefix3=$dir/typed_demo_asdl.gc + GC=1 asdl-tool cpp asdl/typed_demo.asdl $prefix3 + + local bin=_bin/asdl_gc_test + + # uses typed_arith_asdl.h, runtime.h, hnode_asdl.h, asdl_runtime.h + $CXX $CPPFLAGS \ + -I . -I $dir \ + -o $bin \ + asdl/gc_test.cc \ + mycpp/gc_heap.cc \ + mycpp/my_runtime.cc \ + mycpp/mylib2.cc \ + asdl/runtime.gc.cc \ + $dir/demo_lib_asdl.gc.cc \ + $dir/typed_demo_asdl.gc.cc \ + _build/cpp/hnode_asdl.gc.cc + + #gdb -batch -ex run -ex bt --args $bin "$@" + + $bin "$@" +} + +hnode-asdl-gc() { + ### Test that hnode can compile by itself + + local dir=_build/asdl-test + mkdir -p $dir _bin + + cat >$dir/hnode_asdl_test.cc <<'EOF' +#include "_build/cpp/hnode_asdl.gc.h" + +int main() { + printf("OK hnode_asdl_test\n"); + return 0; +} +EOF + + local bin=_bin/hnode_asdl_test + $CXX \ + -I $REPO_ROOT \ + -o $bin \ + _build/cpp/hnode_asdl.gc.cc \ + $dir/hnode_asdl_test.cc + + $bin +} + +one-asdl-gc() { + local name=$1 + shift + + if false; then + echo --- + echo "test-one-asdl-gc $name" + echo --- + fi + + local dir=_build/asdl-test + mkdir -p $dir _bin + + cat >$dir/${name}_asdl_test.cc <$dir/hnode_asdl_test.cc <<'EOF' -#include "_build/cpp/hnode_asdl.gc.h" - -int main() { - printf("OK hnode_asdl_test\n"); - return 0; -} -EOF - - local bin=_bin/hnode_asdl_test - $CXX \ - -I $REPO_ROOT \ - -o $bin \ - _build/cpp/hnode_asdl.gc.cc \ - $dir/hnode_asdl_test.cc - - $bin -} - -test-one-asdl-gc() { - local name=$1 - shift - - if false; then - echo --- - echo "test-one-asdl-gc $name" - echo --- - fi - - local dir=_build/asdl-test - mkdir -p $dir _bin - - cat >$dir/${name}_asdl_test.cc <* Str::split(Str* sep) { result = NewList(nullptr, breaks.size() - 1); // reserve enough space place = reinterpret_cast(gHeap.Allocate(num_bytes)); - for (int i = 1; i < breaks.size(); ++i) { + int n = breaks.size(); + for (int i = 1; i < n; ++i) { int prev_pos = breaks[i - 1]; int part_len = breaks[i] - prev_pos - 1; if (part_len > 0) { diff --git a/test/cpp-unit.sh b/test/cpp-unit.sh index 5cd433cd1d..a31cf85231 100755 --- a/test/cpp-unit.sh +++ b/test/cpp-unit.sh @@ -71,15 +71,14 @@ all() { build/codegen.sh flag-gen-cpp # _build/cpp/arg_types.h build/dev.sh oil-asdl-to-cpp # unit tests depend on id_kind_asdl.h, etc. - # test each ASDL file on its own, perhaps with the garbage-collected ASDL runtime - build/dev.sh test-all-asdl-gc - cpp-unit-tests cpp-unit-tests-asan - # TODO: These tests should be built by Ninja. - asdl/run.sh gen-cpp-test - asdl/run.sh gc-test # integration between ASDL and the GC heap + asdl/test.sh gen-cpp-test + asdl/test.sh gc-test # integration between ASDL and the GC heap + + # test each ASDL file on its own, perhaps with the garbage-collected ASDL runtime + asdl/test.sh all-asdl-gc } "$@"