find-suites.sh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/env bash
  2. ## If EMQX_CT_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 is useful in ad-hoc runs
  11. if [ -n "${EMQX_CT_SUITES:-}" ]; then
  12. echo "${EMQX_CT_SUITES}"
  13. exit 0
  14. fi
  15. TESTDIR="$1/test"
  16. INTEGRATION_TESTDIR="$1/integration_test"
  17. # Get the output of the find command
  18. IFS=$'\n' read -r -d '' -a FILES < <(find "${TESTDIR}" -name "*_SUITE.erl" 2>/dev/null | sort && printf '\0')
  19. if [[ -d "${INTEGRATION_TESTDIR}" ]]; then
  20. IFS=$'\n' read -r -d '' -a FILES_INTEGRATION < <(find "${INTEGRATION_TESTDIR}" -name "*_SUITE.erl" 2>/dev/null | sort && printf '\0')
  21. fi
  22. # shellcheck disable=SC2206
  23. FILES+=(${FILES_INTEGRATION:-})
  24. SUITEGROUP_RAW="${SUITEGROUP:-1_1}"
  25. SUITEGROUP="$(echo "$SUITEGROUP_RAW" | cut -d '_' -f1)"
  26. SUITEGROUP_COUNT="$(echo "$SUITEGROUP_RAW" | cut -d '_' -f2)"
  27. # Calculate the total number of files
  28. FILE_COUNT=${#FILES[@]}
  29. if (( SUITEGROUP > SUITEGROUP_COUNT )); then
  30. echo "Error: SUITEGROUP in the format of M_N, M must be not greater than M"
  31. exit 1
  32. fi
  33. # Calculate the number of files per group
  34. FILES_PER_GROUP=$(( (FILE_COUNT + SUITEGROUP_COUNT - 1) / SUITEGROUP_COUNT ))
  35. START_INDEX=$(( (SUITEGROUP - 1) * FILES_PER_GROUP ))
  36. END_INDEX=$(( START_INDEX + FILES_PER_GROUP ))
  37. # Print the desired suite group
  38. sep=''
  39. for (( i=START_INDEX; i<END_INDEX; i++ )); do
  40. if (( i < FILE_COUNT )); then
  41. echo -n "${sep}${FILES[$i]}"
  42. sep=','
  43. fi
  44. done
  45. echo