Files
DucielandClaude Opus 5.5 8d74f1274f Loader thread: Sleep(0) instead of Sleep(1) after each file (0.9.3)
The client's single file-loader thread slept 1 ms after every file
(0x4434D2), so zone-change loading screens spent 55-75% of their time
asleep at ~2 ms per texture. loadsleep (default on, live) patches the
immediate of `mov ecx,1` to 0, only when the 10 bytes are the client's
(logged and left alone otherwise); switching it off restores the byte.
test_loadsleep checks the byte logic on a fake buffer. Not yet tested in
game.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CmDrvE1QTJT4No3PkwJwv4
2026-11-18 01:23:53 +01:00

88 lines
4.5 KiB
Bash

#!/usr/bin/env bash
# Builds and runs the host-side tests (no game needed).
#
# tests/run_tests.sh [fuzz_iterations] [patterns.txt subjects.txt]
#
# test_prefilter checks the Lua pattern prefilter against the real Lua 5.0.3
# string library (tests/lua50, unmodified upstream sources, MIT license).
set -euo pipefail
cd "$(dirname "$0")/.."
ZIG=tools/zig/zig.exe
[ -x "$ZIG" ] || ZIG=$(command -v zig || true)
[ -n "$ZIG" ] || { echo "Zig not found (tools/zig/zig.exe or PATH)"; exit 1; }
OUT=build/tests
mkdir -p "$OUT/obj"
LUA_C=(tests/lua50/src/*.c tests/lua50/lib/lauxlib.c tests/lua50/lib/lbaselib.c tests/lua50/lib/lstrlib.c)
objs=()
for src in "${LUA_C[@]}"; do
obj=$OUT/obj/$(basename "${src%.c}").o
[ "$obj" -nt "$src" ] || "$ZIG" cc -O2 -w -Itests/lua50/include -Itests/lua50/src -c "$src" -o "$obj"
objs+=("$obj")
done
"$ZIG" c++ -O2 -std=c++17 -Wall -Wno-nullability-completeness -Itests/lua50/include tests/test_prefilter.cpp "${objs[@]}" -o "$OUT/test_prefilter.exe"
# bench_alloctrack: 32-bit (it lays out the client's 32-bit Lua structures), with MinHook.
mh_objs=()
for src in third_party/minhook/src/buffer.c third_party/minhook/src/hook.c third_party/minhook/src/trampoline.c \
third_party/minhook/src/hde/hde32.c; do
obj=$OUT/obj/x86_$(basename "${src%.c}").o
[ "$obj" -nt "$src" ] || "$ZIG" cc -target x86-windows-gnu -O2 -w -Ithird_party/minhook/include -c "$src" -o "$obj"
mh_objs+=("$obj")
done
"$ZIG" c++ -target x86-windows-gnu -O2 -std=c++17 -Wall -Wno-nullability-completeness -Ithird_party/minhook/include \
tests/bench_alloctrack.cpp "${mh_objs[@]}" -o "$OUT/bench_alloctrack.exe"
# test_watchdog: 32-bit, per-frame counters and freeze watchdog with stubbed core services.
"$ZIG" c++ -target x86-windows-gnu -O2 -std=c++17 -fno-exceptions -fno-rtti -Wall -Wno-nullability-completeness \
-Wno-unused-function -DDP_TEST tests/test_watchdog.cpp src/modules/framestats.cpp src/modules/watchdog.cpp \
-o "$OUT/test_watchdog.exe"
# test_strbuf: 32-bit Lua 5.0.3 (512-byte luaL_Buffer like the client) with an
# allocation counter; lauxlib without inlining so its functions can be detoured.
lua32=()
for src in "${LUA_C[@]}" tests/lua50/lib/ltablib.c tests/lua50/lib/lmathlib.c; do
obj=$OUT/obj/x86_lua_$(basename "${src%.c}").o
flags="-O2"
case "$src" in *lauxlib.c) flags="-O1 -fno-inline" ;; esac
[ "$obj" -nt "$src" ] && [ "$obj" -nt tests/strbuf_alloc.h ] || "$ZIG" cc -target x86-windows-gnu $flags -w \
-Itests/lua50/include -Itests/lua50/src -include tests/strbuf_alloc.h \
"-Dl_realloc(b,os,s)=dp_test_realloc(b,os,s)" -c "$src" -o "$obj"
lua32+=("$obj")
done
"$ZIG" c++ -target x86-windows-gnu -O2 -std=c++17 -Wall -Wno-nullability-completeness -Itests/lua50/include \
-Ithird_party/minhook/include tests/test_strbuf.cpp "${lua32[@]}" "${mh_objs[@]}" -o "$OUT/test_strbuf.exe"
# test_svwrite: buffered SavedVariables writes (byte-identical output, fewer OS writes).
"$ZIG" c++ -target x86-windows-gnu -O2 -std=c++17 -Wall -Wno-nullability-completeness tests/test_svwrite.cpp \
-o "$OUT/test_svwrite.exe"
# test_framelevel: one-pass frame-level compaction against a port of the client's algorithm.
"$ZIG" c++ -target x86-windows-gnu -O2 -std=c++17 -Wall -Wno-nullability-completeness tests/test_framelevel.cpp \
-o "$OUT/test_framelevel.exe"
# test_loadsleep: loader Sleep patch, byte checks and restore on a fake buffer.
"$ZIG" c++ -target x86-windows-gnu -O2 -std=c++17 -Wall -Wno-nullability-completeness tests/test_loadsleep.cpp \
-o "$OUT/test_loadsleep.exe"
# test_config: ducielperf.cfg writing (comments and other keys kept).
"$ZIG" c++ -target x86-windows-gnu -O2 -std=c++17 -fno-exceptions -fno-rtti -Wall -Wno-nullability-completeness \
-Ithird_party/minhook/include tests/test_config.cpp src/core/core.cpp "${mh_objs[@]}" -o "$OUT/test_config.exe"
# test_addon: the embedded settings addon on a mock WoW API, in real Lua 5.0.
LUA_LIB=(tests/lua50/lib/lauxlib.c tests/lua50/lib/lbaselib.c tests/lua50/lib/lstrlib.c tests/lua50/lib/ltablib.c
tests/lua50/lib/lmathlib.c)
"$ZIG" cc -O1 -w -Itests/lua50/include -Itests/lua50/src tests/addon/luarun.c $(ls tests/lua50/src/*.c | grep -v ltests) \
"${LUA_LIB[@]}" -o "$OUT/luarun.exe"
"$OUT/test_prefilter.exe" "$@"
"$OUT/bench_alloctrack.exe"
"$OUT/test_watchdog.exe"
"$OUT/test_strbuf.exe"
"$OUT/test_svwrite.exe"
"$OUT/test_framelevel.exe"
"$OUT/test_loadsleep.exe"
"$OUT/test_config.exe"
"$OUT/luarun.exe" tests/addon/wow_mock.lua assets/addons/DucielPerf/DucielPerf.lua tests/addon/drive_ui.lua