|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -u |
| 3 | + |
| 4 | +REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)" |
| 5 | +TOOLCHAIN_DIR="${REPO_ROOT}/toolchain" |
| 6 | +FAILURES=0 |
| 7 | + |
| 8 | +fail() { |
| 9 | + printf 'FAIL: %s\n' "$*" >&2 |
| 10 | + FAILURES=$((FAILURES + 1)) |
| 11 | +} |
| 12 | + |
| 13 | +write_fake_openmpi_commands() { |
| 14 | + local bindir="$1" |
| 15 | + local version="$2" |
| 16 | + |
| 17 | + mkdir -p "$bindir" |
| 18 | + cat >"${bindir}/mpiexec" <<EOF |
| 19 | +#!/usr/bin/env bash |
| 20 | +if [[ "\$1" == "--version" ]]; then |
| 21 | + printf 'mpiexec (Open MPI) ${version}\n' |
| 22 | + exit 0 |
| 23 | +fi |
| 24 | +exit 0 |
| 25 | +EOF |
| 26 | + cat >"${bindir}/mpicxx" <<'EOF' |
| 27 | +#!/usr/bin/env bash |
| 28 | +if [[ "$1" == "--showme:libs" ]]; then |
| 29 | + printf 'mpi\n' |
| 30 | + exit 0 |
| 31 | +fi |
| 32 | +exit 0 |
| 33 | +EOF |
| 34 | + cp "${bindir}/mpicxx" "${bindir}/mpicc" |
| 35 | + cp "${bindir}/mpicxx" "${bindir}/mpifort" |
| 36 | + chmod +x "${bindir}/mpiexec" "${bindir}/mpicc" "${bindir}/mpicxx" "${bindir}/mpifort" |
| 37 | +} |
| 38 | + |
| 39 | +run_openmpi_system_setup() { |
| 40 | + local tmpdir="$1" |
| 41 | + local version="$2" |
| 42 | + |
| 43 | + mkdir -p "${tmpdir}/install" "${tmpdir}/build" |
| 44 | + : >"${tmpdir}/install/setup" |
| 45 | + : >"${tmpdir}/install/toolchain.env" |
| 46 | + cat >"${tmpdir}/install/toolchain.conf" <<'EOF' |
| 47 | +MPI_MODE="openmpi" |
| 48 | +with_openmpi="__SYSTEM__" |
| 49 | +PACK_RUN="__FALSE__" |
| 50 | +EOF |
| 51 | + |
| 52 | + write_fake_openmpi_commands "${tmpdir}/fake-bin" "$version" |
| 53 | + PATH="${tmpdir}/fake-bin:${PATH}" \ |
| 54 | + ROOTDIR="$tmpdir" \ |
| 55 | + SCRIPTDIR="${TOOLCHAIN_DIR}/scripts" \ |
| 56 | + INSTALLDIR="${tmpdir}/install" \ |
| 57 | + BUILDDIR="${tmpdir}/build" \ |
| 58 | + SETUPFILE="${tmpdir}/install/setup" \ |
| 59 | + bash "${TOOLCHAIN_DIR}/scripts/stage1/install_openmpi.sh" \ |
| 60 | + >"${tmpdir}/openmpi.log" 2>&1 |
| 61 | +} |
| 62 | + |
| 63 | +assert_setup_contains() { |
| 64 | + local file="$1" |
| 65 | + local expected="$2" |
| 66 | + |
| 67 | + if ! grep -Fq "$expected" "$file"; then |
| 68 | + cat "$file" >&2 |
| 69 | + fail "${file} does not contain expected text: ${expected}" |
| 70 | + fi |
| 71 | +} |
| 72 | + |
| 73 | +assert_setup_not_contains() { |
| 74 | + local file="$1" |
| 75 | + local unexpected="$2" |
| 76 | + |
| 77 | + if grep -Fq "$unexpected" "$file"; then |
| 78 | + cat "$file" >&2 |
| 79 | + fail "${file} contains unexpected text: ${unexpected}" |
| 80 | + fi |
| 81 | +} |
| 82 | + |
| 83 | +test_openmpi5_setup_disables_prte_binding() { |
| 84 | + local tmpdir status |
| 85 | + tmpdir="$(mktemp -d)" |
| 86 | + |
| 87 | + run_openmpi_system_setup "$tmpdir" "5.0.10" |
| 88 | + status=$? |
| 89 | + |
| 90 | + if [[ "$status" -ne 0 ]]; then |
| 91 | + cat "${tmpdir}/openmpi.log" >&2 |
| 92 | + fail "OpenMPI 5 setup generation failed with status ${status}" |
| 93 | + else |
| 94 | + assert_setup_contains "${tmpdir}/install/setup" "export PRTE_MCA_hwloc_default_binding_policy=none" |
| 95 | + assert_setup_not_contains "${tmpdir}/install/setup" "export OMPI_MCA_hwloc_base_binding_policy=none" |
| 96 | + fi |
| 97 | + |
| 98 | + rm -rf "$tmpdir" |
| 99 | +} |
| 100 | + |
| 101 | +test_openmpi4_setup_disables_ompi_binding() { |
| 102 | + local tmpdir status |
| 103 | + tmpdir="$(mktemp -d)" |
| 104 | + |
| 105 | + run_openmpi_system_setup "$tmpdir" "4.1.8" |
| 106 | + status=$? |
| 107 | + |
| 108 | + if [[ "$status" -ne 0 ]]; then |
| 109 | + cat "${tmpdir}/openmpi.log" >&2 |
| 110 | + fail "OpenMPI 4 setup generation failed with status ${status}" |
| 111 | + else |
| 112 | + assert_setup_contains "${tmpdir}/install/setup" "export OMPI_MCA_hwloc_base_binding_policy=none" |
| 113 | + assert_setup_not_contains "${tmpdir}/install/setup" "export PRTE_MCA_hwloc_default_binding_policy=none" |
| 114 | + fi |
| 115 | + |
| 116 | + rm -rf "$tmpdir" |
| 117 | +} |
| 118 | + |
| 119 | +test_openmpi5_setup_disables_prte_binding |
| 120 | +test_openmpi4_setup_disables_ompi_binding |
| 121 | + |
| 122 | +if [[ "$FAILURES" -ne 0 ]]; then |
| 123 | + printf '%s OpenMPI binding policy setup test(s) failed\n' "$FAILURES" >&2 |
| 124 | + exit 1 |
| 125 | +fi |
| 126 | + |
| 127 | +printf 'OpenMPI binding policy setup tests passed\n' |
0 commit comments