ajout tests valgrind, option -o
This commit is contained in:
4
.valgrindrc
Normal file
4
.valgrindrc
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
--suppressions=./valgrind_readline.supp
|
||||||
|
--leak-check=full
|
||||||
|
--show-reachable=yes
|
||||||
|
--track-fds=yes
|
||||||
103
unitests.sh
103
unitests.sh
@@ -21,9 +21,9 @@ cd $(dirname $0)
|
|||||||
ENDCO="\e[0m"
|
ENDCO="\e[0m"
|
||||||
|
|
||||||
# copy the executable to current directory
|
# copy the executable to current directory
|
||||||
MINISHELL="../minishell"
|
MINISHELL_DIR="../"
|
||||||
make -C ../ &>/dev/null
|
make -C $MINISHELL_DIR &>/dev/null
|
||||||
cp $MINISHELL .
|
cp $MINISHELL_DIR/minishell .
|
||||||
|
|
||||||
# globale variables
|
# globale variables
|
||||||
CURRENT_D="$(pwd)"
|
CURRENT_D="$(pwd)"
|
||||||
@@ -38,15 +38,20 @@ cd $(dirname $0)
|
|||||||
TOTAL_TEST=0
|
TOTAL_TEST=0
|
||||||
TOTAL_SUCCESS=0
|
TOTAL_SUCCESS=0
|
||||||
LINE_NUMBER=0
|
LINE_NUMBER=0
|
||||||
PRINT=0
|
CMD_NBR=0
|
||||||
SCRIPT=0
|
# options
|
||||||
|
ERROR=0
|
||||||
|
VALGR=0
|
||||||
|
OMMIT=0
|
||||||
LIST_FILES=""
|
LIST_FILES=""
|
||||||
DEFAULT_FILES=""
|
DEFAULT_FILES=""
|
||||||
DEFAULT_FILES_USAGE=""
|
DEFAULT_FILES_USAGE=""
|
||||||
|
VALGRIND_OUTPUT_REF=""
|
||||||
ARGS_MAIN=$@
|
ARGS_MAIN=$@
|
||||||
mkdir -p ./logs
|
mkdir -p ./logs
|
||||||
echo "" > ./logs/bash_log.txt
|
echo "" > ./logs/bash_log.txt
|
||||||
echo "" > ./logs/minishell_log.txt
|
echo "" > ./logs/minishell_log.txt
|
||||||
|
echo "" > ./logs/valgrind.log
|
||||||
BASH_LOG="$CURRENT_D/logs/bash_log.txt"
|
BASH_LOG="$CURRENT_D/logs/bash_log.txt"
|
||||||
MINISHELL_LOG="$CURRENT_D/logs/minishell_log.txt"
|
MINISHELL_LOG="$CURRENT_D/logs/minishell_log.txt"
|
||||||
|
|
||||||
@@ -86,8 +91,9 @@ cd $(dirname $0)
|
|||||||
echo -en $CYAN"sudo bash unitest.sh [option] [files list ...]\n"
|
echo -en $CYAN"sudo bash unitest.sh [option] [files list ...]\n"
|
||||||
echo -en $GREEN"\n[options]\n"
|
echo -en $GREEN"\n[options]\n"
|
||||||
echo -en $CYAN"-help : print usage\n"
|
echo -en $CYAN"-help : print usage\n"
|
||||||
echo -en $CYAN" -p : print tests commands\n"
|
echo -en $CYAN" -e : print tests commands\n"
|
||||||
echo -en $CYAN" -s : (only in non-sudo) test in script, not interactif\n"
|
echo -en $CYAN" -v : test valgrin, don't compare with bash\n"
|
||||||
|
echo -en $CYAN" -o : ommit following files\n"
|
||||||
echo -en $GREEN"\n[files list ...] if empty, defaults files will be used :\n"
|
echo -en $GREEN"\n[files list ...] if empty, defaults files will be used :\n"
|
||||||
echo -en $CYAN"$DEFAULT_FILES_USAGE"
|
echo -en $CYAN"$DEFAULT_FILES_USAGE"
|
||||||
echo -en $ENDCO"\n"
|
echo -en $ENDCO"\n"
|
||||||
@@ -131,31 +137,40 @@ cd $(dirname $0)
|
|||||||
# $i expand in integers 1,2,3...
|
# $i expand in integers 1,2,3...
|
||||||
# $1,$2,$3... expand in arguments of process call
|
# $1,$2,$3... expand in arguments of process call
|
||||||
file="${!i}"
|
file="${!i}"
|
||||||
if [ "$file" = "-p" ]
|
if [ "$file" = "-e" ]
|
||||||
then
|
then
|
||||||
PRINT=1
|
ERROR=1
|
||||||
if [ $# -eq 1 ]
|
if [ $# -eq 1 ]
|
||||||
then
|
then
|
||||||
LIST_FILES="$DEFAULT_FILES"
|
LIST_FILES="$DEFAULT_FILES"
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
elif [ "$file" = "-s" ]
|
elif [ "$file" = "-v" ]
|
||||||
then
|
then
|
||||||
SCRIPT=1
|
VALGR=1
|
||||||
if [ $# -eq 1 ]
|
if [ $# -eq 1 ]
|
||||||
then
|
then
|
||||||
LIST_FILES="$DEFAULT_FILES"
|
LIST_FILES="$DEFAULT_FILES"
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
|
elif [ "$file" = "-o" ]
|
||||||
|
then
|
||||||
|
OMMIT=1
|
||||||
|
LIST_FILES="$DEFAULT_FILES"
|
||||||
else
|
else
|
||||||
find_path
|
find_path
|
||||||
if [ -e "$file" ]
|
if [ -e "$file" ]
|
||||||
then
|
then
|
||||||
if [ -n "$LIST_FILES" ]
|
if [ $OMMIT -eq 1 ]
|
||||||
then
|
then
|
||||||
LIST_FILES+=$'\n'
|
LIST_FILES="$( echo "$LIST_FILES" | grep -v "$file")"
|
||||||
|
else
|
||||||
|
if [ -n "$LIST_FILES" ]
|
||||||
|
then
|
||||||
|
LIST_FILES+=$'\n'
|
||||||
|
fi
|
||||||
|
LIST_FILES+="$file"
|
||||||
fi
|
fi
|
||||||
LIST_FILES+="$file"
|
|
||||||
else
|
else
|
||||||
print_usage
|
print_usage
|
||||||
echo " <$file> is not a valid file or option, see usage above"
|
echo " <$file> is not a valid file or option, see usage above"
|
||||||
@@ -192,8 +207,8 @@ cd $(dirname $0)
|
|||||||
(( SUCCESS_TEST++ ))
|
(( SUCCESS_TEST++ ))
|
||||||
(( TOTAL_SUCCESS++ ))
|
(( TOTAL_SUCCESS++ ))
|
||||||
else
|
else
|
||||||
# print failed commands in case of option -p
|
# print failed commands in case of option -e
|
||||||
if [ $PRINT -eq 1 ]
|
if [ $ERROR -eq 1 ] && [ $VALGR -eq 0 ]
|
||||||
then
|
then
|
||||||
failure_cmd="FAILURE line $(( $LINE_NUMBER - 1 )), command : "
|
failure_cmd="FAILURE line $(( $LINE_NUMBER - 1 )), command : "
|
||||||
print_command "$failure_cmd" "$3" "$MAGENTA"
|
print_command "$failure_cmd" "$3" "$MAGENTA"
|
||||||
@@ -234,7 +249,7 @@ cd $(dirname $0)
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
# function test minishell in interactive mode and handle signals and ctrl-d
|
# function test minishell in classic script mode and handle signals and ctrl-d
|
||||||
function test_minishell_signals
|
function test_minishell_signals
|
||||||
{
|
{
|
||||||
# in this order, so that it's not the minishell or bash that goes in background
|
# in this order, so that it's not the minishell or bash that goes in background
|
||||||
@@ -244,17 +259,8 @@ cd $(dirname $0)
|
|||||||
rm -rf $CURRENT_D/tmp/*
|
rm -rf $CURRENT_D/tmp/*
|
||||||
}
|
}
|
||||||
|
|
||||||
# function test minishell in script mode
|
# function test minishell in classic script mode, but cannot handle signals and ctrl-d
|
||||||
function test_minishell_script
|
function test_minishell_script
|
||||||
{
|
|
||||||
bash_execution=$( echo "$commands" | bash 2>/dev/null )
|
|
||||||
rm -rf $CURRENT_D/tmp/*
|
|
||||||
minishell_execution=$( echo "$commands" | $CURRENT_D/minishell 2>/dev/null )
|
|
||||||
rm -rf $CURRENT_D/tmp/*
|
|
||||||
}
|
|
||||||
|
|
||||||
# function test minishell in interactiv mode, but cannot handle signals and ctrl-d
|
|
||||||
function test_minishell_normal
|
|
||||||
{
|
{
|
||||||
bash_execution=$( bash <<<"$commands" 2>/dev/null )
|
bash_execution=$( bash <<<"$commands" 2>/dev/null )
|
||||||
rm -rf $CURRENT_D/tmp/*
|
rm -rf $CURRENT_D/tmp/*
|
||||||
@@ -262,6 +268,24 @@ cd $(dirname $0)
|
|||||||
rm -rf $CURRENT_D/tmp/*
|
rm -rf $CURRENT_D/tmp/*
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# function test minishell in classic script mode, but cannot handle signals and ctrl-d
|
||||||
|
function test_minishell_valgrind
|
||||||
|
{
|
||||||
|
valgrind="valgrind --suppressions=../valgrind_readline.supp --leak-check=full --show-reachable=yes --track-fds=yes"
|
||||||
|
minishell_execution=$( $valgrind $CURRENT_D/minishell <<<"$commands" 2>../logs/valgrind.log )
|
||||||
|
valgrind_output="$( cat ../logs/valgrind.log | grep -e "ERROR SUMMARY: " -e "definitely lost: " -e "indirectly lost: " -e "possibly lost: " -e "still reachable: " -e "FILE DESCRIPTORS: " )"
|
||||||
|
valgrind_output="$( cut -c 13- <<< "$valgrind_output" )"
|
||||||
|
|
||||||
|
valgrind_error="$( echo "$valgrind_output" | grep [1-9] )"
|
||||||
|
if [ -n "$valgrind_error" ]
|
||||||
|
then
|
||||||
|
echo -e $B_RED"line: $LINE_NUMBER, command: "$YELLOW$commands$ENDCO
|
||||||
|
echo "$valgrind_output"
|
||||||
|
fi
|
||||||
|
|
||||||
|
rm -rf $CURRENT_D/tmp/*
|
||||||
|
}
|
||||||
|
|
||||||
# function that will launch the command in bash and minishell and compare them
|
# function that will launch the command in bash and minishell and compare them
|
||||||
# receive parameters : $1 commands to execute, $2 name of the file
|
# receive parameters : $1 commands to execute, $2 name of the file
|
||||||
function test_minishell
|
function test_minishell
|
||||||
@@ -272,14 +296,14 @@ cd $(dirname $0)
|
|||||||
minishell_execution=""
|
minishell_execution=""
|
||||||
|
|
||||||
# execute commands, and logs results
|
# execute commands, and logs results
|
||||||
if [ "$ROOT" -eq 1 ]
|
if [ $ROOT -eq 1 ]
|
||||||
then
|
then
|
||||||
test_minishell_signals
|
test_minishell_signals
|
||||||
elif [ "$SCRIPT" -eq 1 ]
|
elif [ $VALGR -eq 1 ]
|
||||||
then
|
then
|
||||||
test_minishell_script
|
test_minishell_valgrind
|
||||||
else
|
else
|
||||||
test_minishell_normal
|
test_minishell_script
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# for env, special treatment
|
# for env, special treatment
|
||||||
@@ -289,7 +313,10 @@ cd $(dirname $0)
|
|||||||
minishell_execution="$( echo "$minishell_execution" | sort | grep -v -e "LINES=" -e "COLUMNS=" -e "_=" -e"LESSCLOSE=" -e "LESSOPEN=" -e "SHLVL=" )"
|
minishell_execution="$( echo "$minishell_execution" | sort | grep -v -e "LINES=" -e "COLUMNS=" -e "_=" -e"LESSCLOSE=" -e "LESSOPEN=" -e "SHLVL=" )"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
compare_output "$bash_execution" "$minishell_execution" "$commands"
|
if [ "$VALGR" -eq 0 ]
|
||||||
|
then
|
||||||
|
compare_output "$bash_execution" "$minishell_execution" "$commands"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# function to print the results
|
# function to print the results
|
||||||
@@ -377,7 +404,10 @@ cd $(dirname $0)
|
|||||||
echo -en $B_YELLOW "\n\n\nfile: ${filename##*/}\n" $ENDCO >>$MINISHELL_LOG
|
echo -en $B_YELLOW "\n\n\nfile: ${filename##*/}\n" $ENDCO >>$MINISHELL_LOG
|
||||||
read_commands "$filename" "$last_line_number"
|
read_commands "$filename" "$last_line_number"
|
||||||
# '##' print from the right untill... '*/' s slash
|
# '##' print from the right untill... '*/' s slash
|
||||||
print_results ${filename##*/} $SUCCESS_TEST $UNIT_TEST
|
if [ "$VALGR" -eq 0 ]
|
||||||
|
then
|
||||||
|
print_results ${filename##*/} $SUCCESS_TEST $UNIT_TEST
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -408,7 +438,10 @@ cd $(dirname $0)
|
|||||||
# execute script :
|
# execute script :
|
||||||
parse_arguments $ARGS_MAIN
|
parse_arguments $ARGS_MAIN
|
||||||
read_files
|
read_files
|
||||||
print_total_result
|
if [ "$VALGR" -eq 0 ]
|
||||||
show_diff
|
then
|
||||||
|
print_total_result
|
||||||
|
show_diff
|
||||||
|
fi
|
||||||
cd $CURRENT_D
|
cd $CURRENT_D
|
||||||
rm -r $CURRENT_D/tmp/
|
rm -r $CURRENT_D/tmp/
|
||||||
|
|||||||
13
valgrind_readline.supp
Normal file
13
valgrind_readline.supp
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
<readline>
|
||||||
|
Memcheck:Leak
|
||||||
|
...
|
||||||
|
fun:readline
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
<readline history>
|
||||||
|
Memcheck:Leak
|
||||||
|
...
|
||||||
|
fun:add_history
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user