mirror of
https://github.com/NVIDIA/OpenShell.git
synced 2026-10-16 05:20:22 +08:00
104 lines
2.9 KiB
Bash
Executable File
104 lines
2.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
set -euo pipefail
|
|
|
|
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
|
tmpdir="$(mktemp -d)"
|
|
trap 'rm -rf "$tmpdir"' EXIT
|
|
out="${tmpdir}/out"
|
|
err="${tmpdir}/err"
|
|
|
|
export OPENSHELL_INSTALL_SH_TEST=1
|
|
# shellcheck source=../../install.sh
|
|
. "${ROOT}/install.sh"
|
|
|
|
assert_glibc_preflight_passes() {
|
|
local name=$1
|
|
local ldd_output=$2
|
|
|
|
if ! (export OPENSHELL_TEST_GETCONF_UNAVAILABLE=1 OPENSHELL_TEST_LDD_OUTPUT="$ldd_output"; require_linux_package_glibc) >"$out" 2>"$err"; then
|
|
echo "FAIL: ${name}" >&2
|
|
cat "$err" >&2 || true
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
assert_glibc_preflight_fails() {
|
|
local name=$1
|
|
local expected=$2
|
|
local setup=$3
|
|
|
|
if ("$setup"; require_linux_package_glibc) >"$out" 2>"$err"; then
|
|
echo "FAIL: ${name}: expected failure" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if ! grep -Fq "$expected" "$err"; then
|
|
echo "FAIL: ${name}: missing expected message" >&2
|
|
echo "Expected: ${expected}" >&2
|
|
echo "Actual:" >&2
|
|
cat "$err" >&2 || true
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
setup_glibc_227() {
|
|
export OPENSHELL_TEST_GETCONF_UNAVAILABLE=1
|
|
export OPENSHELL_TEST_LDD_OUTPUT="ldd (GNU libc) 2.27"
|
|
}
|
|
|
|
setup_missing_glibc() {
|
|
export OPENSHELL_TEST_GETCONF_UNAVAILABLE=1
|
|
export OPENSHELL_TEST_LDD_UNAVAILABLE=1
|
|
}
|
|
|
|
setup_getconf_musl() {
|
|
export OPENSHELL_TEST_LDD_UNAVAILABLE=1
|
|
export OPENSHELL_TEST_GETCONF_OUTPUT="musl libc"
|
|
}
|
|
|
|
setup_ldd_musl() {
|
|
export OPENSHELL_TEST_GETCONF_UNAVAILABLE=1
|
|
export OPENSHELL_TEST_LDD_OUTPUT="musl libc (x86_64)"
|
|
}
|
|
|
|
assert_glibc_preflight_passes "glibc 2.28 passes" "glibc 2.28"
|
|
assert_glibc_preflight_passes "glibc 2.31 passes" "glibc 2.31"
|
|
assert_glibc_preflight_passes "glibc 2.35 passes" "ldd (GNU libc) 2.35"
|
|
|
|
if ! (export OPENSHELL_TEST_LDD_UNAVAILABLE=1 OPENSHELL_TEST_GETCONF_OUTPUT="glibc 2.35"; require_linux_package_glibc) >"$out" 2>"$err"; then
|
|
echo "FAIL: getconf glibc fallback passes" >&2
|
|
cat "$err" >&2 || true
|
|
exit 1
|
|
fi
|
|
|
|
if ! (export OPENSHELL_TEST_LDD_OUTPUT="not ldd" OPENSHELL_TEST_GETCONF_OUTPUT="glibc 2.35"; require_linux_package_glibc) >"$out" 2>"$err"; then
|
|
echo "FAIL: unparseable ldd output falls back to getconf" >&2
|
|
cat "$err" >&2 || true
|
|
exit 1
|
|
fi
|
|
|
|
assert_glibc_preflight_fails \
|
|
"glibc 2.27 fails" \
|
|
"OpenShell Linux packages require glibc >= 2.28; detected glibc 2.27." \
|
|
setup_glibc_227
|
|
|
|
assert_glibc_preflight_fails \
|
|
"missing glibc detection fails" \
|
|
"OpenShell Linux packages require glibc >= 2.28; could not detect glibc." \
|
|
setup_missing_glibc
|
|
|
|
assert_glibc_preflight_fails \
|
|
"musl detection fails" \
|
|
"OpenShell Linux packages require glibc >= 2.28; detected musl or unsupported libc." \
|
|
setup_getconf_musl
|
|
|
|
assert_glibc_preflight_fails \
|
|
"ldd musl fallback fails" \
|
|
"OpenShell Linux packages require glibc >= 2.28; detected musl or unsupported libc." \
|
|
setup_ldd_musl
|
|
|
|
echo "install.sh libc preflight tests passed"
|