mirror of
https://github.com/mudler/LocalAI.git
synced 2026-07-31 10:28:43 -04:00
run-unit-tests.sh pruned */llama.cpp/* but not */audio.cpp/*. It is safe today only by luck: upstream's 44 tests all put "test" at the FRONT of the filename (17 test-*.cpp, 27 test_*.cpp, zero *_test.cpp), so the glob misses every one of them, and nothing enforces that. This gate runs on every PR for every backend and compiles each match as a standalone translation unit with nothing but nlohmann/json on the include path, so the day upstream adds or renames one test the gate goes red repo-wide on an Apache-2.0 file nobody here wrote. audio-cpp-darwin.sh now logs the raw otool -L output and the parsed LC_RPATH list unconditionally, before the walk. Both awk filters in that script assume a column layout nobody working on this can observe, since it runs only on the CI Mac, and a green first Darwin run proves nothing about the assumption: an awk that silently matched nothing yields an empty dependency list, which reads exactly like "no non-system dependencies" and packages happily. Both filters otherwise feed process substitutions, so their input never reached the log. It also lists every symlink in the package and fails on one that cannot resolve inside the image. A dangling link does not fail anything else here, because every assertion tests with -e, which follows links; it fails at dlopen on a user's Mac. Links are NOT banned outright, which the review suggested but which would break the libggml.dylib -> libggml.0.dylib chain the `cp -a` above exists to preserve. What is banned is a link that resolves on the build host and will not resolve in the image: a broken one, or an absolute one pointing outside the package. Assisted-by: Claude:claude-opus-5 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
82 lines
3.0 KiB
Bash
Executable File
82 lines
3.0 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# Discovers and runs every standalone C++ unit test under backend/cpp/.
|
|
#
|
|
# A "standalone" unit test is a *_test.cpp that depends only on the C++ standard
|
|
# library and nlohmann/json (single header) - i.e. it exercises pure helpers and
|
|
# does not need the full llama.cpp + gRPC backend build. Tests that DO need the
|
|
# backend build use the CMake/ctest path (e.g. -DLLAMA_GRPC_BUILD_TESTS=ON)
|
|
# instead and are skipped here.
|
|
#
|
|
# This keeps CI generic: adding a new pure-C++ unit test file named *_test.cpp in
|
|
# an active backend source dir is picked up automatically, with no CI edits.
|
|
#
|
|
# Env:
|
|
# NLOHMANN_INCLUDE include dir that contains nlohmann/json.hpp. If unset, the
|
|
# nlohmann/json single header is fetched to a temp dir.
|
|
# CXX compiler (default: g++).
|
|
# JSON_VERSION nlohmann/json tag to fetch when NLOHMANN_INCLUDE is unset
|
|
# (default: v3.11.3).
|
|
set -uo pipefail
|
|
|
|
ROOT="$(cd "$(dirname "$0")" && pwd)"
|
|
CXX="${CXX:-g++}"
|
|
JSON_VERSION="${JSON_VERSION:-v3.11.3}"
|
|
|
|
JSON_INC="${NLOHMANN_INCLUDE:-}"
|
|
if [ -z "$JSON_INC" ]; then
|
|
JSON_INC="$(mktemp -d)"
|
|
mkdir -p "$JSON_INC/nlohmann"
|
|
echo "Fetching nlohmann/json ${JSON_VERSION} single header..."
|
|
if ! curl -L -sf \
|
|
"https://raw.githubusercontent.com/nlohmann/json/${JSON_VERSION}/single_include/nlohmann/json.hpp" \
|
|
-o "$JSON_INC/nlohmann/json.hpp"; then
|
|
echo "ERROR: failed to fetch nlohmann/json header" >&2
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
# Active source dirs only - exclude per-variant build copies, dev snapshots and
|
|
# the vendored upstream checkouts.
|
|
#
|
|
# Every upstream checkout needs its own -not -path, and audio.cpp is safe TODAY
|
|
# only by luck: its 44 tests all put "test" at the FRONT (17 test-*.cpp, 27
|
|
# test_*.cpp, zero *_test.cpp), so the glob below misses every one of them.
|
|
# Nothing enforces that. This gate runs on every PR for every backend, and it
|
|
# compiles each match as a STANDALONE translation unit with nothing but
|
|
# nlohmann/json on the include path, so the day upstream adds or renames one
|
|
# test to *_test.cpp the whole gate goes red repo-wide, on an Apache-2.0 file
|
|
# nobody here wrote. Exclude it now rather than diagnose that later.
|
|
mapfile -t tests < <(find "$ROOT" -name '*_test.cpp' \
|
|
-not -path '*/llama.cpp/*' \
|
|
-not -path '*/audio.cpp/*' \
|
|
-not -path '*-build/*' \
|
|
-not -path '*-dev/*' \
|
|
-not -path '*fallback*' | sort)
|
|
|
|
if [ "${#tests[@]}" -eq 0 ]; then
|
|
echo "No standalone C++ unit tests found under $ROOT"
|
|
exit 0
|
|
fi
|
|
|
|
fail=0
|
|
for test_src in "${tests[@]}"; do
|
|
name="$(basename "$test_src" .cpp)"
|
|
bin="$(mktemp -d)/$name"
|
|
echo "==> $test_src"
|
|
if ! "$CXX" -std=c++17 -Wall -Wextra -pthread \
|
|
-I"$JSON_INC" -I"$(dirname "$test_src")" \
|
|
"$test_src" -o "$bin"; then
|
|
echo "COMPILE FAILED: $test_src" >&2
|
|
fail=1
|
|
continue
|
|
fi
|
|
if ! "$bin"; then
|
|
echo "TEST FAILED: $test_src" >&2
|
|
fail=1
|
|
fi
|
|
done
|
|
|
|
echo "Ran ${#tests[@]} standalone C++ unit test file(s)"
|
|
exit "$fail"
|