|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 4 | +# SPDX-License-Identifier: Apache-2.0 |
| 5 | + |
| 6 | +set -euo pipefail |
| 7 | + |
| 8 | +# Simple, dependency-free orchestrator to run tests for all packages. |
| 9 | +# Usage: |
| 10 | +# toolshed/run_all_tests.sh [ -v|--verbose ] [ --install | --no-install ] [ --with-cython | --skip-cython ] |
| 11 | +# toolshed/run_all_tests.sh [ flags ] # pathfinder -> bindings -> core |
| 12 | +# toolshed/run_all_tests.sh [ flags ] core # only core |
| 13 | +# toolshed/run_all_tests.sh [ flags ] bindings # only bindings |
| 14 | +# toolshed/run_all_tests.sh [ flags ] pathfinder # only pathfinder |
| 15 | +# toolshed/run_all_tests.sh [ flags ] smoke # meta-level import smoke tests |
| 16 | + |
| 17 | +repo_root=$(cd "$(dirname "$0")/.." && pwd) |
| 18 | +cd "${repo_root}" |
| 19 | + |
| 20 | +print_help() { |
| 21 | + cat <<'USAGE' |
| 22 | +Usage: toolshed/run_all_tests.sh [options] [target] |
| 23 | +
|
| 24 | +Targets: |
| 25 | + all (default) Run pathfinder → bindings → core |
| 26 | + core Run cuda_core tests |
| 27 | + bindings Run cuda_bindings tests |
| 28 | + pathfinder Run cuda_pathfinder tests |
| 29 | + smoke Run meta-level smoke tests (tests/integration) |
| 30 | +
|
| 31 | +Options: |
| 32 | + -v, --verbose Verbose pytest output (-ra -s -v) |
| 33 | + --install Force editable install with [test] extras |
| 34 | + --no-install Skip install checks (assume environment is ready) |
| 35 | + --with-cython Build and run cython tests (needs CUDA_HOME for core) |
| 36 | + --skip-cython Skip cython tests (default) |
| 37 | + -h, --help Show this help and exit |
| 38 | +
|
| 39 | +Examples: |
| 40 | + toolshed/run_all_tests.sh --install |
| 41 | + toolshed/run_all_tests.sh --no-install core |
| 42 | + toolshed/run_all_tests.sh -v --with-cython bindings |
| 43 | + toolshed/run_all_tests.sh smoke |
| 44 | +USAGE |
| 45 | +} |
| 46 | + |
| 47 | +# Parse optional flags |
| 48 | +VERBOSE=0 |
| 49 | +RUN_CYTHON=0 |
| 50 | +INSTALL_MODE=auto # auto|force|skip |
| 51 | +while [[ $# -gt 0 ]]; do |
| 52 | + case "$1" in |
| 53 | + -h|--help) |
| 54 | + print_help |
| 55 | + exit 0 |
| 56 | + ;; |
| 57 | + -v|--verbose) |
| 58 | + VERBOSE=1 |
| 59 | + shift |
| 60 | + ;; |
| 61 | + --install) |
| 62 | + INSTALL_MODE=force |
| 63 | + shift |
| 64 | + ;; |
| 65 | + --no-install) |
| 66 | + INSTALL_MODE=skip |
| 67 | + shift |
| 68 | + ;; |
| 69 | + --with-cython) |
| 70 | + RUN_CYTHON=1 |
| 71 | + shift |
| 72 | + ;; |
| 73 | + --skip-cython) |
| 74 | + RUN_CYTHON=0 |
| 75 | + shift |
| 76 | + ;; |
| 77 | + *) |
| 78 | + break |
| 79 | + ;; |
| 80 | + esac |
| 81 | +done |
| 82 | + |
| 83 | +target=${1:-all} |
| 84 | + |
| 85 | +if [[ ${VERBOSE} -eq 1 ]]; then |
| 86 | + PYTEST_FLAGS=( -ra -s -v ) |
| 87 | +else |
| 88 | + # Very quiet: show failures/errors summary only |
| 89 | + PYTEST_FLAGS=( -qq ) |
| 90 | +fi |
| 91 | + |
| 92 | +declare -A RESULTS |
| 93 | +ORDERED_RESULTS=() |
| 94 | + |
| 95 | +add_result() { |
| 96 | + local name="$1"; shift |
| 97 | + local rc="$1"; shift |
| 98 | + RESULTS["${name}"]="${rc}" |
| 99 | + ORDERED_RESULTS+=("${name}") |
| 100 | +} |
| 101 | + |
| 102 | +status_from_rc() { |
| 103 | + local rc="$1" |
| 104 | + case "${rc}" in |
| 105 | + 0) echo "PASS" ;; |
| 106 | + 5) echo "SKIP(no-tests)" ;; |
| 107 | + 1) echo "FAIL" ;; |
| 108 | + 2) echo "INTERRUPTED" ;; |
| 109 | + 3) echo "ERROR" ;; |
| 110 | + 4) echo "USAGE" ;; |
| 111 | + *) echo "RC=${rc}" ;; |
| 112 | + esac |
| 113 | +} |
| 114 | + |
| 115 | +run_pytest() { |
| 116 | + # Run pytest safely under set -e and return its exit code |
| 117 | + set +e |
| 118 | + pytest "${PYTEST_FLAGS[@]}" "$@" |
| 119 | + local rc=$? |
| 120 | + set -e |
| 121 | + return ${rc} |
| 122 | +} |
| 123 | + |
| 124 | +ensure_installed() { |
| 125 | + # Args: module.import.name repo_subdir |
| 126 | + local mod_name="$1"; shift |
| 127 | + local subdir_name="$1"; shift |
| 128 | + |
| 129 | + if [[ "${INSTALL_MODE}" == "skip" ]]; then |
| 130 | + return 0 |
| 131 | + fi |
| 132 | + |
| 133 | + if [[ "${INSTALL_MODE}" == "force" ]]; then |
| 134 | + pip install -e .[test] |
| 135 | + return 0 |
| 136 | + fi |
| 137 | + |
| 138 | + # auto-detect: if module imports from this repo, assume installed; otherwise install |
| 139 | + python - <<PY 2>/dev/null |
| 140 | +import importlib, sys, pathlib |
| 141 | +mod = "${mod_name}" |
| 142 | +try: |
| 143 | + m = importlib.import_module(mod) |
| 144 | +except Exception: |
| 145 | + sys.exit(2) |
| 146 | +p = pathlib.Path(getattr(m, "__file__", "")).resolve() |
| 147 | +root = pathlib.Path(r"${repo_root}").resolve() |
| 148 | +sub = pathlib.Path(r"${repo_root}/${subdir_name}").resolve() |
| 149 | +print(p) |
| 150 | +sys.exit(0 if str(p).startswith(str(sub)) else 3) |
| 151 | +PY |
| 152 | + rc=$? |
| 153 | + if [[ $rc -ne 0 ]]; then |
| 154 | + pip install -e .[test] |
| 155 | + fi |
| 156 | +} |
| 157 | + |
| 158 | +run_pathfinder() { |
| 159 | + echo "[tests] cuda_pathfinder" |
| 160 | + cd "${repo_root}/cuda_pathfinder" |
| 161 | + ensure_installed "cuda.pathfinder" "cuda_pathfinder" |
| 162 | + run_pytest tests/ |
| 163 | + local rc=$? |
| 164 | + add_result "pathfinder" "${rc}" |
| 165 | +} |
| 166 | + |
| 167 | +run_bindings() { |
| 168 | + echo "[tests] cuda_bindings" |
| 169 | + cd "${repo_root}/cuda_bindings" |
| 170 | + ensure_installed "cuda.bindings" "cuda_bindings" |
| 171 | + run_pytest tests/ |
| 172 | + local rc=$? |
| 173 | + add_result "bindings" "${rc}" |
| 174 | + if [ ${RUN_CYTHON} -eq 1 ] && [ -d tests/cython ]; then |
| 175 | + if [ -x tests/cython/build_tests.sh ]; then |
| 176 | + echo "[build] cuda_bindings cython tests" |
| 177 | + ( cd tests/cython && ./build_tests.sh ) || true |
| 178 | + fi |
| 179 | + run_pytest tests/cython |
| 180 | + local rc_cy=$? |
| 181 | + add_result "bindings-cython" "${rc_cy}" |
| 182 | + fi |
| 183 | +} |
| 184 | + |
| 185 | +run_core() { |
| 186 | + echo "[tests] cuda_core" |
| 187 | + cd "${repo_root}/cuda_core" |
| 188 | + ensure_installed "cuda.core" "cuda_core" |
| 189 | + run_pytest tests/ |
| 190 | + local rc=$? |
| 191 | + add_result "core" "${rc}" |
| 192 | + if [ ${RUN_CYTHON} -eq 1 ] && [ -d tests/cython ]; then |
| 193 | + if [ -x tests/cython/build_tests.sh ]; then |
| 194 | + echo "[build] cuda_core cython tests" |
| 195 | + if [ -z "${CUDA_HOME-}" ]; then |
| 196 | + echo "[skip] CUDA_HOME not set; skipping cython tests" |
| 197 | + else |
| 198 | + ( cd tests/cython && ./build_tests.sh ) || true |
| 199 | + fi |
| 200 | + fi |
| 201 | + run_pytest tests/cython |
| 202 | + local rc_cy=$? |
| 203 | + add_result "core-cython" "${rc_cy}" |
| 204 | + fi |
| 205 | +} |
| 206 | + |
| 207 | +run_smoke() { |
| 208 | + echo "[tests] meta-level smoke" |
| 209 | + cd "${repo_root}" |
| 210 | + python - <<PY 2>/dev/null || pip install pytest>=6.2.4 |
| 211 | +import pytest |
| 212 | +PY |
| 213 | + run_pytest tests/integration |
| 214 | + local rc=$? |
| 215 | + add_result "smoke" "${rc}" |
| 216 | +} |
| 217 | + |
| 218 | +case "${target}" in |
| 219 | + all) |
| 220 | + run_pathfinder |
| 221 | + run_bindings |
| 222 | + run_core |
| 223 | + ;; |
| 224 | + core) |
| 225 | + run_core ;; |
| 226 | + bindings) |
| 227 | + run_bindings ;; |
| 228 | + pathfinder) |
| 229 | + run_pathfinder ;; |
| 230 | + smoke) |
| 231 | + run_smoke ;; |
| 232 | + *) |
| 233 | + echo "Unknown target: ${target}" >&2 |
| 234 | + exit 1 |
| 235 | + ;; |
| 236 | +esac |
| 237 | + |
| 238 | +# Print summary |
| 239 | +echo |
| 240 | +echo "==================== Test Summary ====================" |
| 241 | +overall_rc=0 |
| 242 | +if [ -t 1 ]; then |
| 243 | + GREEN=$(printf '\033[32m') |
| 244 | + RED=$(printf '\033[31m') |
| 245 | + RESET=$(printf '\033[0m') |
| 246 | +else |
| 247 | + GREEN=""; RED=""; RESET="" |
| 248 | +fi |
| 249 | +for name in "${ORDERED_RESULTS[@]}"; do |
| 250 | + rc="${RESULTS[$name]}" |
| 251 | + status=$(status_from_rc "${rc}") |
| 252 | + color="" |
| 253 | + case "${status}" in |
| 254 | + PASS) color="${GREEN}" ;; |
| 255 | + FAIL|ERROR|INTERRUPTED|USAGE|RC=*) color="${RED}" ;; |
| 256 | + *) color="" ;; |
| 257 | + esac |
| 258 | + printf "%-18s : %s%s%s\n" "${name}" "${color}" "${status}" "${RESET}" |
| 259 | + if [[ "${rc}" -ne 0 && "${rc}" -ne 5 ]]; then |
| 260 | + overall_rc=1 |
| 261 | + fi |
| 262 | +done |
| 263 | +echo "======================================================" |
| 264 | +exit ${overall_rc} |
0 commit comments