find-suites.sh 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. # Get the output of the find command
  17. IFS=$'\n' read -r -d '' -a FILES < <(find "${TESTDIR}" -name "*_SUITE.erl" 2>/dev/null | sort && printf '\0')
  18. SUITEGROUP_RAW="${SUITEGROUP:-1_1}"
  19. SUITEGROUP="$(echo "$SUITEGROUP_RAW" | cut -d '_' -f1)"
  20. SUITEGROUP_COUNT="$(echo "$SUITEGROUP_RAW" | cut -d '_' -f2)"
  21. # Calculate the total number of files
  22. FILE_COUNT=${#FILES[@]}
  23. if (( SUITEGROUP > SUITEGROUP_COUNT )); then
  24. echo "Error: SUITEGROUP in the format of M_N, M must be not greater than M"
  25. exit 1
  26. fi
  27. # Calculate the number of files per group
  28. FILES_PER_GROUP=$(( (FILE_COUNT + SUITEGROUP_COUNT - 1) / SUITEGROUP_COUNT ))
  29. START_INDEX=$(( (SUITEGROUP - 1) * FILES_PER_GROUP ))
  30. END_INDEX=$(( START_INDEX + FILES_PER_GROUP ))
  31. # Print the desired suite group
  32. sep=''
  33. for (( i=START_INDEX; i<END_INDEX; i++ )); do
  34. if (( i < FILE_COUNT )); then
  35. echo -n "${sep}${FILES[$i]}"
  36. sep=','
  37. fi
  38. done
  39. echo