diff --git a/.gitignore b/.gitignore index a34e165..a319eee 100644 --- a/.gitignore +++ b/.gitignore @@ -53,4 +53,6 @@ dkms.conf test test.elf -test.exe \ No newline at end of file +test.exe + +stress.log \ No newline at end of file diff --git a/makefile b/makefile index 6f9c705..4fd43e1 100644 --- a/makefile +++ b/makefile @@ -6,8 +6,4 @@ test: carg-parse.c carg-parse.h test.c stress: @make test @echo "STRESSING - if you see any errors / segfaults / fuckups please revert changes or open an issue" - ./test - ./test -a -a - ./test --a - ./test - - ./test a b c d -a a -b b -c c -d d + @./stress.sh diff --git a/stress.sh b/stress.sh new file mode 100755 index 0000000..c213e73 --- /dev/null +++ b/stress.sh @@ -0,0 +1,63 @@ +#!/bin/bash + +# Number of iterations for the stress test +ITERATIONS=100 + +# Executable name +EXECUTABLE="./test" + +# Log file name +LOG_FILE="stress.log" + +# List of possible arguments +ARGUMENTS=( + "-option1" + "-option2" + "-option3" + "-option4" + "-" +) + +# Function to generate a random number within a range +generate_random_number() { + local min=$1 + local max=$2 + echo $((RANDOM % (max - min + 1) + min)) +} + +# Function to generate a random argument combination +generate_random_arguments() { + local arg_count=$(generate_random_number 1 ${#ARGUMENTS[@]}) + local args=() + local used_indexes=() + for (( i = 0; i < arg_count; i++ )); do + local index + while true; do + index=$(generate_random_number 0 $((${#ARGUMENTS[@]} - 1))) + if [[ ! " ${used_indexes[@]} " =~ " ${index} " ]]; then + used_indexes+=($index) + break + fi + done + args+=("${ARGUMENTS[$index]}") + done + echo "${args[@]}" +} + +# Clear the log file +> "$LOG_FILE" + +# Main stress test loop +for (( i = 0; i < ITERATIONS; i++ )); do + arguments=$(generate_random_arguments) + echo "Running test iteration $((i+1)) with arguments: $arguments" + # Add extra quotes to preserve trailing dashes + $EXECUTABLE $arguments + exit_code=$? + if [[ $exit_code -eq 139 ]]; then + echo "Segfault detected!" + echo "Arguments: $arguments" >> "$LOG_FILE" + break + fi + echo "-----------------------------------------" +done