run_tests.sh 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env bash
  2. # Licensed to the Apache Software Foundation (ASF) under one or more
  3. # contributor license agreements. See the NOTICE file distributed with
  4. # this work for additional information regarding copyright ownership.
  5. # The ASF licenses this file to You under the Apache License, Version 2.0
  6. # (the "License"); you may not use this file except in compliance with
  7. # the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. test_num=0
  17. failed_test=""
  18. rc=0
  19. test_bins="test_butil test_bvar bthread*unittest brpc*unittest"
  20. ulimit -c unlimited # turn on coredumps
  21. for test_bin in $test_bins; do
  22. test_num=$((test_num + 1))
  23. >&2 echo "[runtest] $test_bin"
  24. ./$test_bin
  25. rc=$?
  26. if [ $rc -ne 0 ]; then
  27. failed_test="$test_bin"
  28. break;
  29. fi
  30. done
  31. if [ $test_num -eq 0 ]; then
  32. >&2 echo "[runtest] Cannot find any tests"
  33. exit 1
  34. fi
  35. print_bt () {
  36. # find newest core file
  37. COREFILE=$(find . -name "core*" -type f -printf "%T@ %p\n" | sort -k 1 -n | cut -d' ' -f 2- | tail -n 1)
  38. if [ ! -z "$COREFILE" ]; then
  39. >&2 echo "corefile=$COREFILE prog=$1"
  40. gdb -c "$COREFILE" $1 -ex "thread apply all bt" -ex "set pagination 0" -batch;
  41. fi
  42. }
  43. if [ -z "$failed_test" ]; then
  44. >&2 echo "[runtest] $test_num succeeded"
  45. elif [ $test_num -gt 1 ]; then
  46. print_bt $failed_test
  47. >&2 echo "[runtest] '$failed_test' failed, $((test_num-1)) succeeded"
  48. else
  49. print_bt $failed_test
  50. >&2 echo "[runtest] '$failed_test' failed"
  51. fi
  52. exit $rc