allow test number arg & specify build output flag
This commit is contained in:
parent
8342de6478
commit
595e15f35b
1 changed files with 46 additions and 30 deletions
|
@ -1,35 +1,44 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
build_dir="build-ci-debug"
|
||||||
|
test_suite=${1:-}
|
||||||
|
test_number=${2:-}
|
||||||
|
|
||||||
# Function to select and debug a test
|
# Function to select and debug a test
|
||||||
function select_test() {
|
function select_test() {
|
||||||
test_suite="$1"
|
test_suite=${1:-test}
|
||||||
|
test_number=${2:-}
|
||||||
|
|
||||||
# Sanity Check If Tests Is Detected
|
# Sanity Check If Tests Is Detected
|
||||||
printf "\n\nGathering tests that fit REGEX: ${test_suite} ...\n"
|
printf "\n\nGathering tests that fit REGEX: ${test_suite} ...\n"
|
||||||
tests=($(ctest -R ${test_suite} -V -N | grep -E " +Test +#[0-9]+*" | cut -d':' -f2 | awk '{$1=$1};1'))
|
tests=($(ctest -R ${test_suite} -V -N | grep -E " +Test +#[0-9]+*" | cut -d':' -f2 | awk '{$1=$1};1'))
|
||||||
if [ ${#tests[@]} -eq 0 ]
|
if [ ${#tests[@]} -eq 0 ]
|
||||||
then
|
then
|
||||||
echo "No tests avaliable ..."
|
echo "No tests avaliable... check your compliation process..."
|
||||||
echo "Exiting."
|
echo "Exiting."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# List out avaliable tests
|
if [ -z $test_number ]
|
||||||
printf "Which test would you like to debug?\n"
|
then
|
||||||
id=0
|
# List out avaliable tests
|
||||||
for s in "${tests[@]}"
|
printf "Which test would you like to debug?\n"
|
||||||
do
|
id=0
|
||||||
echo "Test# ${id}"
|
for s in "${tests[@]}"
|
||||||
echo " $s"
|
do
|
||||||
((id++))
|
echo "Test# ${id}"
|
||||||
done
|
echo " $s"
|
||||||
|
((id++))
|
||||||
|
done
|
||||||
|
|
||||||
# Prompt user which test they wanted to run
|
# Prompt user which test they wanted to run
|
||||||
printf "\nRun test#? "
|
printf "\nRun test#? "
|
||||||
read n
|
read test_number
|
||||||
|
else
|
||||||
|
printf "\nUser Already Requested #${test_number}"
|
||||||
|
fi
|
||||||
|
|
||||||
# Start GDB with the requested test binary and arguments
|
# Start GDB with the requested test binary and arguments
|
||||||
printf "Debugging(GDB) test: ${tests[n]}\n"
|
printf "Debugging(GDB) test: ${tests[test_number]}\n"
|
||||||
# Change IFS (Internal Field Separator)
|
# Change IFS (Internal Field Separator)
|
||||||
sIFS=$IFS
|
sIFS=$IFS
|
||||||
IFS=$'\n'
|
IFS=$'\n'
|
||||||
|
@ -37,29 +46,32 @@ function select_test() {
|
||||||
# Get test args
|
# Get test args
|
||||||
gdb_args=($(ctest -R ${test_suite} -V -N | grep "Test command" | cut -d':' -f3 | awk '{$1=$1};1' ))
|
gdb_args=($(ctest -R ${test_suite} -V -N | grep "Test command" | cut -d':' -f3 | awk '{$1=$1};1' ))
|
||||||
IFS=$sIFS
|
IFS=$sIFS
|
||||||
printf "Debug arguments: ${gdb_args[n]}\n\n"
|
printf "Debug arguments: ${gdb_args[test_number]}\n\n"
|
||||||
|
|
||||||
# Expand paths if needed
|
# Expand paths if needed
|
||||||
args=()
|
args=()
|
||||||
for x in $(echo ${gdb_args[n]} | sed -e 's/"\/\<//' -e 's/\>"//')
|
for x in $(echo ${gdb_args[test_number]} | sed -e 's/"\/\<//' -e 's/\>"//')
|
||||||
do
|
do
|
||||||
args+=($(echo $x | sed -e 's/.*\/..\//..\//'))
|
args+=($(echo $x | sed -e 's/.*\/..\//..\//'))
|
||||||
done
|
done
|
||||||
|
|
||||||
# Execute debugger
|
# Execute debugger
|
||||||
|
echo "gdb args: ${args[@]}"
|
||||||
gdb --args ${args[@]}
|
gdb --args ${args[@]}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Step 0: Check the args
|
# Step 0: Check the args
|
||||||
if [ $# -ne 1 ] || [ "$1" = "help" ]
|
if [ -z "$test_suite" ] || [ "$1" = "help" ]
|
||||||
then
|
then
|
||||||
echo "Supply one regex to the script, e.g. test-tokenizer would\n"
|
echo "Usage: $0 [test_regex] [test_number]"
|
||||||
echo "return all the tests in files that match with test-tokenizer."
|
echo "e.g., $0 test-tokenizer"
|
||||||
|
echo " $0 test-tokenizer 3"
|
||||||
|
echo "Supply one regex to the script to filter tests,"
|
||||||
|
echo "and optionally a test number to run a specific test."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Step 1: Prepare the Build Environment
|
# Step 1: Reset and Setup folder context
|
||||||
|
|
||||||
## Sanity check that we are actually in a git repo
|
## Sanity check that we are actually in a git repo
|
||||||
repo_root=$(git rev-parse --show-toplevel)
|
repo_root=$(git rev-parse --show-toplevel)
|
||||||
if [ ! -d "$repo_root" ]; then
|
if [ ! -d "$repo_root" ]; then
|
||||||
|
@ -67,16 +79,20 @@ if [ ! -d "$repo_root" ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
## Build test binaries
|
## Reset folder to root context of git repo
|
||||||
pushd "$repo_root" || exit 1
|
pushd "$repo_root" || exit 1
|
||||||
rm -rf build-ci-debug && mkdir build-ci-debug && pushd build-ci-debug || exit 1
|
|
||||||
cmake -DCMAKE_BUILD_TYPE=Debug -DLLAMA_CUDA=1 -DLLAMA_FATAL_WARNINGS=ON .. && popd || exit 1
|
|
||||||
make -j || exit 1
|
|
||||||
pushd tests || exit 1
|
|
||||||
|
|
||||||
# Step 2: Debug the Test
|
## Create and enter build directory
|
||||||
select_test "$1"
|
rm -rf "$build_dir" && mkdir "$build_dir" || exit 1
|
||||||
|
|
||||||
# Step 3: Return to the directory from which the user ran the command.
|
# Step 2: Setup Build Environment and Compile Test Binaries
|
||||||
|
cmake -B ./build-ci-debug -DCMAKE_BUILD_TYPE=Debug -DLLAMA_CUDA=1 -DLLAMA_FATAL_WARNINGS=ON || exit 1
|
||||||
|
pushd "$build_dir" && make -j || exit 1
|
||||||
|
|
||||||
|
# Step 3: Debug the Test
|
||||||
|
select_test "$test_suite" "$test_number"
|
||||||
|
|
||||||
|
# Step 4: Return to the directory from which the user ran the command.
|
||||||
|
popd || exit 1
|
||||||
popd || exit 1
|
popd || exit 1
|
||||||
popd || exit 1
|
popd || exit 1
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue