Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ add_test(NAME serve_hangup COMMAND ${CMAKE_SOURCE_DIR}/tests/serve_hangup_test.s
# engine#1945: scripts/bump-hrx-sync.sh tells AMD's own commit from a line AMD rebased apart from a commit that
# is not AMD's. Local git repositories only: no network, no GPU.
add_test(NAME bump_hrx_sync COMMAND bash ${CMAKE_SOURCE_DIR}/tests/bump_hrx_sync_test.sh ${CMAKE_SOURCE_DIR}/scripts/bump-hrx-sync.sh)
add_test(NAME hrx_test_compile COMMAND bash ${CMAKE_SOURCE_DIR}/tests/hrx_test_compile_test.sh ${CMAKE_SOURCE_DIR}/scripts/hrx-test-compile.sh)
add_test(NAME bump_hrx_report COMMAND bash ${CMAKE_SOURCE_DIR}/tests/bump_hrx_report_test.sh ${CMAKE_SOURCE_DIR}/scripts/bump-hrx-report.sh)
add_test(NAME metrics_serve COMMAND ${CMAKE_SOURCE_DIR}/tests/metrics_serve.sh $<TARGET_FILE:onebit>)
# serve --print-backend: the llama-server Lemonade starts itself, one hop (docs/serve.md): no GPU.
Expand Down
77 changes: 77 additions & 0 deletions scripts/hrx-test-compile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/bin/bash
# Copyright 2026 bong-water-water-bong
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# hrx-test-compile.sh -- compile the fork's HRX test targets, and nothing else.
#
# Why this exists (engine#2068): `tests/hrx-backend-test.cpp` in 1bit-MONSTER/llama.cpp stopped compiling at
# llama.cpp#262 and NOBODY SAW IT, because no automated job builds that file -- it is registered under
# `if (TARGET ggml-hrx)` in the fork's tests/CMakeLists.txt, so a build without the HRX backend skips it, and no
# build asks for tests. Three host rows then failed in a binary nothing ran. A compile break in a 654 KB test
# file is the one thing a *build* catches for free and a *run* never gets the chance to.
#
# This is a compile gate only: it never runs the tests and needs no device.
#
# usage: hrx-test-compile.sh <fork-checkout> [--build-dir DIR]
# exit: 0 all HRX test targets built; 1 a target failed to build; 2 usage; 77 the tree has no HRX backend
set -uo pipefail

if [ $# -lt 1 ]; then
echo "usage: hrx-test-compile.sh <fork-checkout> [--build-dir DIR]" >&2
exit 2
fi
tree=$1
shift || true
build_dir=""
while [ $# -gt 0 ]; do
case "$1" in
--build-dir) build_dir=${2:?--build-dir needs a path}; shift 2 ;;
*) echo "hrx-test-compile: unknown argument: $1" >&2; exit 2 ;;
esac
done
[ -d "$tree" ] || { echo "hrx-test-compile: not a directory: $tree" >&2; exit 2; }
[ -d "$tree/tests" ] || { echo "hrx-test-compile: no tests/ in $tree" >&2; exit 2; }
[ -n "$build_dir" ] || build_dir="$tree/build-hrx-test-compile"

# Configure with the HRX backend and the tests on: those two switches are what make the file part of the build.
# GGM L_HRX's own option name is the fork's; if it is renamed, this configure fails loudly rather than skipping.
if ! cmake -S "$tree" -B "$build_dir" -DLLAMA_BUILD_TESTS=ON -DGGML_HRX=ON -DCMAKE_BUILD_TYPE=Release >"$build_dir.configure.log" 2>&1; then
echo "hrx-test-compile: configure FAILED (see $build_dir.configure.log)" >&2
tail -5 "$build_dir.configure.log" >&2
exit 1
fi

# Which of the HRX test targets this tree actually declares. Asking CMake rather than grepping the CMakeLists keeps
# the gate honest when the target list changes: a target that disappears is reported, not silently dropped.
have=$(cmake --build "$build_dir" --target help 2>/dev/null | sed -n 's/^\.\.\. \([A-Za-z0-9_.-]*\)$/\1/p' | grep -x 'test-hrx-backend\|test-hrx-rope-claim-params' | sort -u)

if [ -z "$have" ]; then
# Not "passed": no HRX target exists in this tree, so this gate proved nothing about the file it exists for.
echo "hrx-test-compile: no HRX test targets in $tree (GGML_HRX=ON did not produce them) -- SKIP, not PASS" >&2
exit 77
fi

rc=0
for t in $have; do
if cmake --build "$build_dir" --target "$t" >>"$build_dir.build.log" 2>&1; then
echo "ok built $t"
else
echo "FAIL build $t (see $build_dir.build.log)" >&2
grep -E "error:" "$build_dir.build.log" | head -3 >&2
rc=1
fi
done
[ "$rc" = 0 ] && echo "ok HRX test targets compile ($(echo $have | wc -w) target(s))"
exit "$rc"
101 changes: 101 additions & 0 deletions tests/hrx_test_compile_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/bin/bash
# Copyright 2026 bong-water-water-bong
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# hrx_test_compile_test.sh -- arms for scripts/hrx-test-compile.sh (engine#2068).
#
# The gate's whole value is that it fails on the source that did not compile (#262) and does not report a pass when
# it never built the file. So the arms are: a tree that builds, a tree whose test source has the #262-shaped error,
# and a tree with no HRX targets at all -- the last one must exit 77, because "not built" and "built fine" are the
# two states this gate exists to keep apart.
#
# usage: hrx_test_compile_test.sh <path-to-hrx-test-compile.sh>
set -uo pipefail

S=${1:?usage: hrx_test_compile_test.sh <path-to-hrx-test-compile.sh>}
[ -x "$S" ] || { echo "not executable: $S"; exit 1; }
command -v cmake >/dev/null 2>&1 || { echo "skip: no cmake (exit 77)"; exit 77; }

# The stub trees need a real C and C++ compiler, and they must be found the way this box names them: CI configures the
# engine build with gcc-16/g++-16 and may have no plain `cc`/`c++` on PATH at all, which is how this test failed its
# first CI run while passing locally. CMake honours CC/CXX on a first configure, so the arms hand it what exists.
pick() { for c in "$@"; do command -v "$c" >/dev/null 2>&1 && { command -v "$c"; return 0; }; done; return 1; }
CC=$(pick "${CC:-}" cc gcc gcc-16 gcc-15 gcc-14) || { echo "skip: no C compiler (exit 77)"; exit 77; }
CXX=$(pick "${CXX:-}" c++ g++ g++-16 g++-15 g++-14) || { echo "skip: no C++ compiler (exit 77)"; exit 77; }
export CC CXX
work=$(mktemp -d "${TMPDIR:-/tmp}/hrxtc.XXXXXX") # scratch, removed below
trap 'rm -rf "$work"' EXIT
fail=0
ok() { echo "ok $1"; }
bad() { echo "FAIL $1"; fail=1; }

# A stub "fork": the smallest tree whose CMakeLists declares the HRX test target the gate looks for, so the gate's
# own logic (configure, ask for the target, build it) is exercised without the real 654 KB source or the HRX toolchain.
mktree() { # mktree <dir> <source-body> [declare-hrx]
local d=$1 body=$2 hrx=${3:-yes}
mkdir -p "$d/tests"
cat > "$d/CMakeLists.txt" <<EOF
cmake_minimum_required(VERSION 3.16)
project(stub C CXX)
option(LLAMA_BUILD_TESTS "tests" ON)
option(GGML_HRX "hrx" ON)
if (LLAMA_BUILD_TESTS AND GGML_HRX AND ${hrx/yes/TRUE})
add_subdirectory(tests)
endif()
EOF
cat > "$d/tests/CMakeLists.txt" <<'EOF'
add_executable(test-hrx-backend hrx-backend-test.cpp)
EOF
printf '%s\n' "$body" > "$d/tests/hrx-backend-test.cpp"
}

# 1. Compiles cleanly -> 0.
mktree "$work/good" 'int main(void) { return 0; }'
# On failure, print what the gate itself said: an arm that reports only "exits 0" fails the first CI run with no cause,
# which is what happened here (the real reason was a missing compiler, and the arm said nothing about it).
run_arm() { # run_arm <label> <expected-rc> <args...>
local label=$1 want=$2; shift 2
local out rc
out=$("$S" "$@" 2>&1); rc=$?
if [ "$rc" = "$want" ]; then ok "$label"; else
bad "$label (got $rc, wanted $want)"
printf '%s\n' "$out" | tail -6 | sed 's/^/ | /'
fi
}
run_arm "a tree whose HRX test compiles exits 0" 0 "$work/good" --build-dir "$work/b-good"

# 2. The #262 shape: an error in the test source -> non-zero, and the error text is surfaced.
mktree "$work/bad" 'int main(void) { const int x = "not an int"; return x; }'
out=$("$S" "$work/bad" --build-dir "$work/b-bad" 2>&1); rc=$?
[ "$rc" = 1 ] && ok "a tree with a broken HRX test exits 1" || bad "a tree with a broken HRX test exits 1 (got $rc)"
[[ $out == *test-hrx-backend* ]] && ok "and names the target that failed" || bad "and names the target that failed"
[[ $out == *error:* ]] && ok "and surfaces the compiler's error line" || bad "and surfaces the compiler's error line"

# 3. No HRX targets at all -> 77, never 0. This is the arm that keeps the gate from being vacuous.
mktree "$work/nohrx" 'int main(void) { return 0; }' no
out=$("$S" "$work/nohrx" --build-dir "$work/b-nohrx" 2>&1); rc=$?
if [ "$rc" = 77 ]; then ok "a tree without HRX targets exits 77 (skip, not pass)"; else
bad "a tree without HRX targets exits 77 (got $rc)"
printf '%s\n' "$out" | tail -6 | sed 's/^/ | /'
fi
[[ $out == *"SKIP, not PASS"* ]] && ok "and says so in those words" || bad "and says so in those words"

# 4. Usage contract.
"$S" >/dev/null 2>&1; [ $? = 2 ] && ok "a missing tree exits 2" || bad "a missing tree exits 2"
"$S" "$work/good" --nope >/dev/null 2>&1; [ $? = 2 ] && ok "an unknown argument exits 2" || bad "an unknown argument exits 2"
"$S" "$work/absent" >/dev/null 2>&1; [ $? = 2 ] && ok "a non-existent tree exits 2" || bad "a non-existent tree exits 2"

[ $fail = 0 ] && echo "all hrx-test-compile arms passed"
exit $fail
Loading