CoolFace
Datasetpublic

echodict/llama.cpp

version https://git-lfs.github.com/spec/v1 oid sha256:cfc44b7ba25614df70e6b65e3341cae0310163bd32fd31a6b928a542df433faf size 30786

sourceHugging Faceupdated 5mo agoView on Hugging Face
0likes762downloads
debug-test.sh203 linesDownload Raw Back to scripts
1#!/usr/bin/env bash2 3PROG=${0##*/}4build_dir="build-ci-debug"5 6# Print Color Commands7red=$(tput setaf 1)8green=$(tput setaf 2)9yellow=$(tput setaf 3)10blue=$(tput setaf 4)11magenta=$(tput setaf 5)12cyan=$(tput setaf 6)13normal=$(tput sgr0)14 15 16# Print Help Message17####################18 19print_full_help() {20  cat << EOF21Usage: $PROG [OPTION]... <test_regex> (test_number)22Debug specific ctest program.23 24Options:25  -h, --help            display this help and exit26  -g                    run in gdb mode27 28Arguments:29  <test_regex>     (Mandatory) Supply one regex to the script to filter tests30  (test_number)    (Optional) Test number to run a specific test31 32Example:33  $PROG test-tokenizer34  $PROG test-tokenizer 335EOF36}37 38abort() {39  echo "Error: $1" >&240  cat << EOF >&241Usage: $PROG [OPTION]... <test_regex> (test_number)42Debug specific ctest program.43Refer to --help for full instructions.44EOF45  exit 146}47 48 49# Dependency Sanity Check50#########################51 52check_dependency() {53  command -v "$1" >/dev/null 2>&1 || {54    abort "$1 is required but not found. Please install it and try again."55  }56}57 58check_dependency ctest59check_dependency cmake60 61 62# Step 0: Check the args63########################64 65if [ x"$1" = x"-h" ] || [ x"$1" = x"--help" ]; then66  print_full_help >&267  exit 068fi69 70# Parse command-line options71gdb_mode=false72while getopts "g" opt; do73    case $opt in74        g)75            gdb_mode=true76            echo "gdb_mode Mode Enabled"77            ;;78    esac79done80 81# Shift the option parameters82shift $((OPTIND - 1))83 84# Positionial Argument Processing : <test_regex>85if [ -z "${1}" ]; then86    abort "Test regex is required"87else88    test_suite=${1:-}89fi90 91# Positionial Argument Processing : (test_number)92test_number=${2:-}93 94 95# Step 1: Reset and Setup folder context96########################################97 98## Sanity check that we are actually in a git repo99repo_root=$(git rev-parse --show-toplevel)100if [ ! -d "$repo_root" ]; then101    abort "Not in a Git repository."102fi103 104## Reset folder to root context of git repo and Create and enter build directory105pushd "$repo_root"106rm -rf "$build_dir" && mkdir "$build_dir" || abort "Failed to make $build_dir"107 108 109# Step 2: Setup Build Environment and Compile Test Binaries110###########################################################111 112cmake -B "./$build_dir" -DCMAKE_BUILD_TYPE=Debug -DGGML_CUDA=1 || abort "Failed to build environment"113pushd "$build_dir"114make -j || abort "Failed to compile"115popd > /dev/null || exit 1116 117 118# Step 3: Find all tests available that matches REGEX119####################################################120 121# Ctest Gather Tests122# `-R test-tokenizer` : looks for all the test files named `test-tokenizer*` (R=Regex)123# `-N` : "show-only" disables test execution & shows test commands that you can feed to GDB.124# `-V` : Verbose Mode125printf "\n\nGathering tests that fit REGEX: ${test_suite} ...\n"126pushd "$build_dir"127tests=($(ctest -R ${test_suite} -V -N | grep -E " +Test +#[0-9]+*" | cut -d':' -f2 | awk '{$1=$1};1'))128if [ ${#tests[@]} -eq 0 ]; then129    abort "No tests available... check your compilation process..."130fi131popd > /dev/null || exit 1132 133 134# Step 4: Identify Test Command for Debugging135#############################################136 137# Select test number138if [ -z $test_number ]; then139    # List out available tests140    printf "Which test would you like to debug?\n"141    id=0142    for s in "${tests[@]}"143    do144        echo "Test# ${id}"145        echo "  $s"146        ((id++))147    done148 149    # Prompt user which test they wanted to run150    printf "\nRun test#? "151    read test_number152 153else154    printf "\nUser Already Requested #${test_number}\n"155 156fi157 158# Grab all tests commands159pushd "$build_dir"160sIFS=$IFS # Save Initial IFS (Internal Field Separator)161IFS=$'\n' # Change IFS (Internal Field Separator) (So we split ctest output by newline rather than by spaces)162test_args=($(ctest -R ${test_suite} -V -N | grep "Test command" | cut -d':' -f3 | awk '{$1=$1};1' )) # Get test args163IFS=$sIFS # Reset IFS (Internal Field Separator)164popd > /dev/null || exit 1165 166# Grab specific test command167single_test_name="${tests[test_number]}"168single_test_command="${test_args[test_number]}"169 170 171# Step 5: Execute or GDB Debug172##############################173 174printf "${magenta}Running Test #${test_number}: ${single_test_name}${normal}\n"175printf "${cyan}single_test_command: ${single_test_command}${normal}\n"176 177if [ "$gdb_mode" = "true" ]; then178    # Execute debugger179    pushd "$repo_root" || exit 1180    eval "gdb --args ${single_test_command}"181    popd > /dev/null || exit 1182 183else184    # Execute Test185    pushd "$repo_root" || exit 1186    eval "${single_test_command}"187    exit_code=$?188    popd > /dev/null || exit 1189 190    # Print Result191    printf "${blue}Ran Test #${test_number}: ${single_test_name}${normal}\n"192    printf "${yellow}Command: ${single_test_command}${normal}\n"193    if [ $exit_code -eq 0 ]; then194        printf "${green}TEST PASS${normal}\n"195    else196        printf "${red}TEST FAIL${normal}\n"197    fi198 199fi200 201# Return to the directory from which the user ran the command.202popd > /dev/null || exit 1203