find-suites.sh 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/env bash
  2. ## If EMQX_CT_SUITES or SUITES is provided, it prints the variable.
  3. ## Otherwise this script tries to find all test/*_SUITE.erl files of then given app,
  4. ## file names are separated by comma for rebar3 ct's `--suite` option
  5. ## If SUITEGROUP is set as M_N, it prints the Nth chunk of all suites.
  6. ## SUITEGROUP default value is 1_1
  7. set -euo pipefail
  8. # ensure dir
  9. cd -P -- "$(dirname -- "$0")/.."
  10. ## EMQX_CT_SUITES or SUITES is useful in ad-hoc runs
  11. EMQX_CT_SUITES="${EMQX_CT_SUITES:-${SUITES:-}}"
  12. if [ -n "${EMQX_CT_SUITES:-}" ]; then
  13. echo "${EMQX_CT_SUITES}"
  14. exit 0
  15. fi
  16. TESTDIR="$1/test"
  17. INTEGRATION_TESTDIR="$1/integration_test"
  18. # Get the output of the find command
  19. IFS=$'\n' read -r -d '' -a FILES < <(find "${TESTDIR}" -name "*_SUITE.erl" 2>/dev/null | sort && printf '\0')
  20. if [[ -d "${INTEGRATION_TESTDIR}" ]]; then
  21. IFS=$'\n' read -r -d '' -a FILES_INTEGRATION < <(find "${INTEGRATION_TESTDIR}" -name "*_SUITE.erl" 2>/dev/null | sort && printf '\0')
  22. fi
  23. # shellcheck disable=SC2206
  24. FILES+=(${FILES_INTEGRATION:-})
  25. SUITEGROUP_RAW="${SUITEGROUP:-1_1}"
  26. SUITEGROUP="$(echo "$SUITEGROUP_RAW" | cut -d '_' -f1)"
  27. SUITEGROUP_COUNT="$(echo "$SUITEGROUP_RAW" | cut -d '_' -f2)"
  28. # Calculate the total number of files
  29. FILE_COUNT=${#FILES[@]}
  30. if (( SUITEGROUP > SUITEGROUP_COUNT )); then
  31. echo "Error: SUITEGROUP in the format of M_N, M must be not greater than M"
  32. exit 1
  33. fi
  34. # Calculate the number of files per group
  35. FILES_PER_GROUP=$(( (FILE_COUNT + SUITEGROUP_COUNT - 1) / SUITEGROUP_COUNT ))
  36. START_INDEX=$(( (SUITEGROUP - 1) * FILES_PER_GROUP ))
  37. END_INDEX=$(( START_INDEX + FILES_PER_GROUP ))
  38. # Print the desired suite group
  39. sep=''
  40. for (( i=START_INDEX; i<END_INDEX; i++ )); do
  41. if (( i < FILE_COUNT )); then
  42. echo -n "${sep}${FILES[$i]}"
  43. sep=','
  44. fi
  45. done
  46. echo