debug-test: refactor for clarity
This commit is contained in:
parent
d4239194cb
commit
edec5ba3d7
2 changed files with 120 additions and 104 deletions
|
@ -55,7 +55,7 @@ cmake -DCMAKE_BUILD_TYPE=Debug -DLLAMA_CUDA=1 -DLLAMA_FATAL_WARNINGS=ON ..
|
||||||
make -j
|
make -j
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Step 3.1: Identify Test Command for Debugging
|
#### Step 3: Find all tests available that matches REGEX
|
||||||
|
|
||||||
The output of this command will give you the command & arguments needed to run GDB.
|
The output of this command will give you the command & arguments needed to run GDB.
|
||||||
|
|
||||||
|
@ -83,11 +83,13 @@ Labels: main
|
||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|
||||||
So for test #1 we can tell these two pieces of relevant information:
|
#### Step 4: Identify Test Command for Debugging
|
||||||
|
|
||||||
|
So for test #1 above we can tell these two pieces of relevant information:
|
||||||
* Test Binary: `~/llama.cpp/build-ci-debug/bin/test-tokenizer-0`
|
* Test Binary: `~/llama.cpp/build-ci-debug/bin/test-tokenizer-0`
|
||||||
* Test GGUF Model: `~/llama.cpp/tests/../models/ggml-vocab-llama-spm.gguf`
|
* Test GGUF Model: `~/llama.cpp/tests/../models/ggml-vocab-llama-spm.gguf`
|
||||||
|
|
||||||
#### Step 3.2: Run GDB on test command
|
#### Step 5: Run GDB on test command
|
||||||
|
|
||||||
Based on the ctest 'test command' report above we can then run a gdb session via this command below:
|
Based on the ctest 'test command' report above we can then run a gdb session via this command below:
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,8 @@ red=$(tput setaf 1)
|
||||||
green=$(tput setaf 2)
|
green=$(tput setaf 2)
|
||||||
yellow=$(tput setaf 3)
|
yellow=$(tput setaf 3)
|
||||||
blue=$(tput setaf 4)
|
blue=$(tput setaf 4)
|
||||||
|
magenta=$(tput setaf 5)
|
||||||
|
cyan=$(tput setaf 6)
|
||||||
normal=$(tput sgr0)
|
normal=$(tput sgr0)
|
||||||
|
|
||||||
print_full_help() {
|
print_full_help() {
|
||||||
|
@ -39,6 +41,15 @@ EOF
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
check_dependency() {
|
||||||
|
command -v "$1" >/dev/null 2>&1 || {
|
||||||
|
abort "$1 is required but not found. Please install it and try again."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
check_dependency ctest
|
||||||
|
check_dependency cmake
|
||||||
|
|
||||||
if [ x"$1" = x"-h" ] || [ x"$1" = x"--help" ]; then
|
if [ x"$1" = x"-h" ] || [ x"$1" = x"--help" ]; then
|
||||||
print_full_help >&2
|
print_full_help >&2
|
||||||
exit 0
|
exit 0
|
||||||
|
@ -60,35 +71,55 @@ shift $((OPTIND - 1))
|
||||||
|
|
||||||
# Step 0: Check the args
|
# Step 0: Check the args
|
||||||
if [ -z "${1}" ]; then
|
if [ -z "${1}" ]; then
|
||||||
echo "Usage: $PROG [OPTION]... <test_regex> (test_number)"
|
abort "Test regex is required"
|
||||||
echo "Supply one regex to the script to filter tests,"
|
|
||||||
echo "and optionally a test number to run a specific test."
|
|
||||||
echo "Use --help flag for full instructions"
|
|
||||||
exit 1
|
|
||||||
else
|
else
|
||||||
test_suite=${1:-}
|
test_suite=${1:-}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
test_number=${2:-}
|
test_number=${2:-}
|
||||||
|
|
||||||
# Function to select and debug a test
|
# Step 1: Reset and Setup folder context
|
||||||
function select_test() {
|
########################################
|
||||||
test_suite=${1:-test}
|
|
||||||
test_number=${2:-}
|
|
||||||
repo_root=${3:-}
|
|
||||||
|
|
||||||
# Sanity Check If Tests Is Detected
|
## Sanity check that we are actually in a git repo
|
||||||
printf "\n\nGathering tests that fit REGEX: ${test_suite} ...\n"
|
repo_root=$(git rev-parse --show-toplevel)
|
||||||
tests=($(ctest -R ${test_suite} -V -N | grep -E " +Test +#[0-9]+*" | cut -d':' -f2 | awk '{$1=$1};1'))
|
if [ ! -d "$repo_root" ]; then
|
||||||
if [ ${#tests[@]} -eq 0 ]
|
abort "Not in a Git repository."
|
||||||
then
|
fi
|
||||||
echo "No tests avaliable... check your compliation process..."
|
|
||||||
echo "Exiting."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z $test_number ]
|
## Reset folder to root context of git repo and Create and enter build directory
|
||||||
then
|
pushd "$repo_root"
|
||||||
|
rm -rf "$build_dir" && mkdir "$build_dir" || abort "Failed to make $build_dir"
|
||||||
|
|
||||||
|
# Step 2: Setup Build Environment and Compile Test Binaries
|
||||||
|
###########################################################
|
||||||
|
|
||||||
|
# Note: test-eval-callback requires -DLLAMA_CURL
|
||||||
|
cmake -B "./$build_dir" -DCMAKE_BUILD_TYPE=Debug -DLLAMA_CUDA=1 -DLLAMA_FATAL_WARNINGS=ON -DLLAMA_CURL=1 || abort "Failed to build enviroment"
|
||||||
|
pushd "$build_dir"
|
||||||
|
make -j || abort "Failed to compile"
|
||||||
|
popd > /dev/null || exit 1
|
||||||
|
|
||||||
|
# Step 3: Find all tests available that matches REGEX
|
||||||
|
####################################################
|
||||||
|
|
||||||
|
# Ctest Gather Tests
|
||||||
|
# `-R test-tokenizer` : looks for all the test files named `test-tokenizer*` (R=Regex)
|
||||||
|
# `-N` : "show-only" disables test execution & shows test commands that you can feed to GDB.
|
||||||
|
# `-V` : Verbose Mode
|
||||||
|
printf "\n\nGathering tests that fit REGEX: ${test_suite} ...\n"
|
||||||
|
pushd "$build_dir"
|
||||||
|
tests=($(ctest -R ${test_suite} -V -N | grep -E " +Test +#[0-9]+*" | cut -d':' -f2 | awk '{$1=$1};1'))
|
||||||
|
if [ ${#tests[@]} -eq 0 ]; then
|
||||||
|
abort "No tests avaliable... check your compliation process..."
|
||||||
|
fi
|
||||||
|
popd > /dev/null || exit 1
|
||||||
|
|
||||||
|
# Step 4: Identify Test Command for Debugging
|
||||||
|
#############################################
|
||||||
|
|
||||||
|
# Select test number
|
||||||
|
if [ -z $test_number ]; then
|
||||||
# List out avaliable tests
|
# List out avaliable tests
|
||||||
printf "Which test would you like to debug?\n"
|
printf "Which test would you like to debug?\n"
|
||||||
id=0
|
id=0
|
||||||
|
@ -102,79 +133,62 @@ function select_test() {
|
||||||
# Prompt user which test they wanted to run
|
# Prompt user which test they wanted to run
|
||||||
printf "\nRun test#? "
|
printf "\nRun test#? "
|
||||||
read test_number
|
read test_number
|
||||||
else
|
|
||||||
|
else
|
||||||
printf "\nUser Already Requested #${test_number}\n"
|
printf "\nUser Already Requested #${test_number}\n"
|
||||||
fi
|
|
||||||
|
|
||||||
# Start GDB with the requested test binary and arguments
|
fi
|
||||||
printf "Debugging(GDB) test: ${tests[test_number]}\n"
|
|
||||||
# Change IFS (Internal Field Separator)
|
|
||||||
sIFS=$IFS
|
|
||||||
IFS=$'\n'
|
|
||||||
|
|
||||||
# Get test args
|
# Grab all tests commands
|
||||||
test_args=($(ctest -R ${test_suite} -V -N | grep "Test command" | cut -d':' -f3 | awk '{$1=$1};1' ))
|
pushd "$build_dir"
|
||||||
IFS=$sIFS
|
sIFS=$IFS # Save Initial IFS (Internal Field Separator)
|
||||||
|
IFS=$'\n' # Change IFS (Internal Field Separator) (So we split ctest output by newline rather than by spaces)
|
||||||
|
test_args=($(ctest -R ${test_suite} -V -N | grep "Test command" | cut -d':' -f3 | awk '{$1=$1};1' )) # Get test args
|
||||||
|
IFS=$sIFS # Reset IFS (Internal Field Separator)
|
||||||
|
popd > /dev/null || exit 1
|
||||||
|
|
||||||
printf "${blue}Running Test #${test_number}: ${tests[test_number]}${normal}\n"
|
# Grab specific test command
|
||||||
printf "${blue}test_args[test_number]: ${test_args[test_number]}${normal}\n"
|
single_test_name="${tests[test_number]}"
|
||||||
|
single_test_command="${test_args[test_number]}"
|
||||||
|
|
||||||
if [ "$gdb_mode" = "true" ]; then
|
# Step 5: Execute or GDB Debug
|
||||||
# Expand paths if needed
|
##############################
|
||||||
|
printf "${magenta}Running Test #${test_number}: ${single_test_name}${normal}\n"
|
||||||
|
printf "${cyan}single_test_command: ${single_test_command}${normal}\n"
|
||||||
|
|
||||||
|
if [ "$gdb_mode" = "true" ]; then
|
||||||
|
printf "${blue}Replacing single test command string that may have /../ in them with the relative path, i.e. path/../path -> ../path.${normal}\n"
|
||||||
gdb_args=()
|
gdb_args=()
|
||||||
for x in $(echo ${test_args[test_number]} | sed -e 's/"\/\<//' -e 's/\>"//')
|
for piece in $(echo ${single_test_command} | sed -e 's/"\/\<//' -e 's/\>"//')
|
||||||
do
|
do
|
||||||
gdb_args+=($(echo $x | sed -e 's/.*\/..\//..\//'))
|
transformed_piece=($(echo $piece | sed -e 's/.*\/..\//..\//'))
|
||||||
|
printf "${blue} - '${piece}' --> '${transformed_piece}' ${normal}\n"
|
||||||
|
gdb_args+="$transformed_piece"
|
||||||
done
|
done
|
||||||
|
|
||||||
printf "${blue}gdb_args @: ${gdb_args[@]}${normal}\n"
|
printf "${yellow}gdb_args[@]: ${gdb_args[@]}${normal}\n"
|
||||||
|
|
||||||
# Execute debugger
|
# Execute debugger
|
||||||
pushd "$repo_root" || exit 1
|
pushd "$repo_root" || exit 1
|
||||||
gdb --args ${gdb_args[@]}
|
gdb --args ${gdb_args[@]}
|
||||||
popd > /dev/null || exit 1
|
popd > /dev/null || exit 1
|
||||||
else
|
|
||||||
|
|
||||||
|
else
|
||||||
# Execute Test
|
# Execute Test
|
||||||
pushd "$repo_root" || exit 1
|
pushd "$repo_root" || exit 1
|
||||||
eval "${test_args[test_number]}"
|
eval "${single_test_command}"
|
||||||
exit_code=$?
|
exit_code=$?
|
||||||
popd > /dev/null || exit 1
|
popd > /dev/null || exit 1
|
||||||
|
|
||||||
# Print Result
|
# Print Result
|
||||||
printf "${blue}Ran Test #${test_number}: ${tests[test_number]}${normal}\n"
|
printf "${blue}Ran Test #${test_number}: ${single_test_name}${normal}\n"
|
||||||
printf "${yellow}Command: ${test_args[test_number]}${normal}\n"
|
printf "${yellow}Command: ${single_test_command}${normal}\n"
|
||||||
if [ $exit_code -eq 0 ]; then
|
if [ $exit_code -eq 0 ]; then
|
||||||
printf "${green}TEST PASS${normal}\n"
|
printf "${green}TEST PASS${normal}\n"
|
||||||
else
|
else
|
||||||
printf "${red}TEST FAIL${normal}\n"
|
printf "${red}TEST FAIL${normal}\n"
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# Step 1: Reset and Setup folder context
|
|
||||||
## Sanity check that we are actually in a git repo
|
|
||||||
repo_root=$(git rev-parse --show-toplevel)
|
|
||||||
if [ ! -d "$repo_root" ]; then
|
|
||||||
echo "Error: Not in a Git repository."
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
## Reset folder to root context of git repo
|
|
||||||
pushd "$repo_root" || exit 1
|
|
||||||
|
|
||||||
## Create and enter build directory
|
|
||||||
rm -rf "$build_dir" && mkdir "$build_dir" || exit 1
|
|
||||||
|
|
||||||
# Step 2: Setup Build Environment and Compile Test Binaries
|
|
||||||
# Note: test-eval-callback requires -DLLAMA_CURL
|
|
||||||
cmake -B "./$build_dir" -DCMAKE_BUILD_TYPE=Debug -DLLAMA_CUDA=1 -DLLAMA_FATAL_WARNINGS=ON -DLLAMA_CURL=1 || exit 1
|
|
||||||
pushd "$build_dir" && make -j || exit 1
|
|
||||||
|
|
||||||
# Step 3: Debug the Test
|
|
||||||
select_test "$test_suite" "$test_number" "$repo_root"
|
|
||||||
|
|
||||||
# Step 4: Return to the directory from which the user ran the command.
|
|
||||||
popd > /dev/null || exit 1
|
|
||||||
popd > /dev/null || exit 1
|
popd > /dev/null || exit 1
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue