2023-03-01 04:36:01 +01:00
# **************************************************************************** #
# #
# .--. _ #
# test.sh |o_o || | #
# |:_/ || |_ _ ___ __ #
# By: houtworm <codam@houtworm.net> // \ \ __| | | \ \/ / #
# (| | )|_| |_| |> < #
# Created: 2023/02/20 12:46:46 by houtworm /'\_ _/`\__|\__,_/_/\_\ #
2023-03-06 09:18:56 +01:00
# Updated: 2023/03/06 09:18:15 by houtworm \___)=(___/ #
2023-03-01 04:36:01 +01:00
# #
# **************************************************************************** #
#!/bin/bash
SLEEP = 1
SERVER = $1
FAULTS = 0
if [ -z " $1 " ]
then
printf "\e[1;31mPlease add the server pid as an argument\e[0;00m\n"
exit 1
fi
if [ $2 ]
then
SLEEP = $2
fi
checkfile( )
{
ls $1 2> /dev/null | grep $1 > /dev/null
if [ $? -ne $2 ]
then
printf " \e[1;31mMakefile does not create $1 \e[0;00m\n "
exit 1
fi
}
searchobj( )
{
FILES = $( find ./ -name '*.o' | wc -l)
if [ $1 -eq 0 ]
then
if [ $FILES -ne 0 ]
then
printf "\e[1;31mObject files found after clean\e[0;00m\n"
FAULTS = $(( $FAULTS + 1 ))
fi
fi
if [ $1 -eq 1 ]
then
if [ $FILES -eq 0 ]
then
printf "\e[1;31mObject files not found after make\e[0;00m\n"
FAULTS = $(( $FAULTS + 1 ))
fi
fi
}
checkrule( )
{
make $1 > /dev/null 2>& 1
if [ $? -eq 2 ]
then
printf " \e[1;31mMissing rule $1 \e[0;00m\n "
FAULTS = $(( $FAULTS + 1 ))
fi
}
# Norminette Check
printf "\e[1;36mChecking all source with Norminette\e[0;00m\n"
norminette > /dev/null 2>& 1
if [ $? -eq 1 ]
then
printf "\e[1;31mYour shit is not norm!\e[0;00m\n"
FAULTS = $(( $FAULTS + 1 ))
else
printf "\e[1;32mNorminette OK\e[0;00m\n"
fi
sleep $SLEEP
# Makefile Rule check
printf "\e[1;36mChecking all mandatory rules Makefile\e[0;00m\n"
checkrule all
checkfile server 0
checkfile client 0
searchobj 1
checkrule clean
searchobj 0
checkrule fclean
checkrule server
checkfile server 0
checkfile client 1
searchobj 1
checkrule fclean
checkrule client
checkfile server 1
checkfile client 0
searchobj 1
checkrule fclean
searchobj 0
checkfile server 1
checkfile client 1
checkrule re
searchobj 1
checkfile server 0
checkfile client 0
if [ $FAULTS -eq 0 ]
then
printf "\e[1;32mMakefile rules OK\e[0;00m\n"
fi
sleep $SLEEP
# Makefile Relink Test
printf "\e[1;36mChecking if Makefile relinks\e[0;00m\n"
make 2>& 1 | grep Nothing
if [ $? -eq 1 ]
then
printf "\e[1;31mMakefile relinks\e[0;00m\n"
FAULTS = $(( $FAULTS + 1 ))
else
printf "\e[1;32mMakefile OK\e[0;00m\n"
fi
sleep $SLEEP
# Wrong input test
printf "\e[1;36mRunning client without arguments\e[0;00m\n"
./client
if [ $? -eq 0 ]
then
printf "\e[1;31mwrong return value without arguments\e[0;00m\n"
FAULTS = $(( $FAULTS + 1 ))
else
printf "\e[1;32mNo Arguments OK\e[0;00m\n"
fi
sleep $SLEEP
printf "\e[1;36mRunning client with one argument\e[0;00m\n"
./client "hallo"
if [ $? -eq 0 ]
then
printf "\e[1;31mwrong return value with single argument\e[0;00m\n"
FAULTS = $(( $FAULTS + 1 ))
else
printf "\e[1;32mSingle Argument OK\e[0;00m\n"
fi
sleep $SLEEP
printf "\e[1;36mRunning client with three arguments\e[0;00m\n"
./client $SERVER "hallo" "hallo"
if [ $? -eq 0 ]
then
printf "\e[1;31mwrong return value with 3 arguments\e[0;00m\n"
FAULTS = $(( $FAULTS + 1 ))
else
printf "\e[1;32m3 Arguments OK\e[0;00m\n"
fi
sleep $SLEEP
printf "\e[1;36mRunning client with invalid PID -1\e[0;00m\n"
./client -1 "hallo"
if [ $? -eq 0 ]
then
printf "\e[1;31mWrong return value with invalid PID -1\e[0;00m\n"
FAULTS = $(( $FAULTS + 1 ))
else
printf "\e[1;32mInvalid PID int OK\e[0;00m\n"
fi
sleep $SLEEP
printf "\e[1;36mRunning client with invalid PID 0\e[0;00m\n"
./client 0 "hallo"
if [ $? -eq 0 ]
then
printf "\e[1;31mWrong return value with invalid PID -1\e[0;00m\n"
FAULTS = $(( $FAULTS + 1 ))
else
printf "\e[1;32mInvalid PID int OK\e[0;00m\n"
fi
sleep $SLEEP
printf "\e[1;36mRunning client with invalid PID a\e[0;00m\n"
./client a "hallo"
if [ $? -eq 0 ]
then
printf "\e[1;31mWrong return value with invalid PID a\e[0;00m\n"
FAULTS = $(( $FAULTS + 1 ))
else
printf "\e[1;32mInvalid PID char OK\e[0;00m\n"
fi
sleep $SLEEP
# Basic test
printf "\e[1;36mRunning client with proper input\e[0;00m\n"
./client $SERVER "The whole test should take no langer than 30 seconds"
if [ $? -eq 0 ]
then
printf "\e[1;32mBasic test OK\e[0;00m\n"
else
printf "\e[1;31mwrong return value with the basic test\e[0;00m\n"
FAULTS = $(( $FAULTS + 1 ))
fi
sleep $SLEEP
# Multiple test
printf "\e[1;36mRunning client 10.000 times\e[0;00m\n"
MULTIPLETEST = 0
for ( ( i = 1; i<= 10000; i++) )
do
./client $SERVER GNU/🐧 > /dev/null 2>& 1
if [ $? -eq 0 ]
then
continue
else
printf "\e[1;31mwrong return value with 10.000 clients test\e[0;00m\n"
FAULTS = $(( $FAULTS + 1 ))
MULTIPLETEST = 1
break
fi
done
if [ $MULTIPLETEST -eq 0 ]
then
printf "\e[1;32m10.000 clients test OK\e[0;00m\n"
fi
sleep $SLEEP
# 100000 char string test
printf "\e[1;36mRunning client with 100.000 char str\e[0;00m\n"
./client $SERVER 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
if [ $? -eq 0 ]
then
printf "\e[1;32m100.000 char string test OK\e[0;00m\n"
else
printf "\e[1;31mwrong return value with 100.000 char string test\e[0;00m\n"
FAULTS = $(( $FAULTS + 1 ))
fi
sleep $SLEEP
# Empty string test
printf "\e[1;36mRunning client with NULL string\e[0;00m\n"
./client $SERVER ""
if [ $? -eq 0 ]
then
printf "\e[1;32mNULL string test OK\e[0;00m\n"
else
printf "\e[1;31mwrong return value NULL string test\e[0;00m\n"
FAULTS = $(( $FAULTS + 1 ))
fi
sleep $SLEEP
# Space test
printf "\e[1;36mRunning client with single space string\e[0;00m\n"
./client $SERVER " "
if [ $? -eq 0 ]
then
printf "\e[1;32mSpace test OK\e[0;00m\n"
else
printf "\e[1;31mwrong return value with Space test\e[0;00m\n"
FAULTS = $(( $FAULTS + 1 ))
fi
sleep $SLEEP
# Multiline test
printf "\e[1;36mRunning client with multiline string\e[0;00m\n"
./client $SERVER " 1
2
3
4
5"
if [ $? -eq 0 ]
then
printf "\e[1;32mMultiline test OK\e[0;00m\n"
else
printf "\e[1;31mwrong return value with multiline test\e[0;00m\n"
FAULTS = $(( $FAULTS + 1 ))
fi
sleep $SLEEP
# All Emoji test
printf "\e[1;36mRunning client with all Emojis\e[0;00m\n"
./client $SERVER 😀😃😄😁😆😅😂🤣🥲🥹☺️ 😊😇🙂🙃😉😌😍🥰😘😗😙😚😋😛😝😜🤪🤨🧐🤓😎🥸🤩🥳😏😒😞😔😟😕🙁☹️ 😣😖😫😩🥺😢😭😮 💨😤😠😡🤬🤯😳🥵🥶😱😨😰😥😓🫣🤗🫡🤔🫢🤭🤫🤥😶😶 🌫️ 😐😑😬🫠🙄😯😦😧😮😲🥱😴🤤😪😵😵 💫🫥🤐🥴🤢🤮🤧😷🤒🤕🤑🤠😈👿👹👺🤡💩👻💀☠️ 👽👾🤖🎃😺😸😹😻😼😽🙀😿😾👋🤚🖐✋🖖👌🤌🤏✌️ 🤞🫰🤟🤘🤙🫵🫱🫲🫳🫴👈👉👆🖕👇☝️ 👍👎✊👊🤛🤜👏🫶🙌👐🤲🤝🙏✍️ 💅🤳💪🦾🦵🦿🦶👣👂🦻👃🫀🫁🧠🦷🦴👀👁👅👄🫦💋🩸👶👧🧒👦👩🧑👨👩 🦱🧑 🦱👨 🦱👩 🦰🧑 🦰👨 🦰👱 ♀️ 👱👱 ♂️ 👩 🦳🧑 🦳👨 🦳👩 🦲🧑 🦲👨 🦲🧔 ♀️ 🧔🧔 ♂️ 👵🧓👴👲👳 ♀️ 👳👳 ♂️ 🧕👮 ♀️ 👮👮 ♂️ 👷 ♀️ 👷👷 ♂️ 💂 ♀️ 💂💂 ♂️ 🕵️ ♀️ 🕵️ 🕵️ ♂️ 👩 ⚕️ 🧑 ⚕️ 👨 ⚕️ 👩 🌾🧑 🌾👨 🌾👩 🍳🧑 🍳👨 🍳👩 🎓🧑 🎓👨 🎓👩 🎤🧑 🎤👨 🎤👩 🏫🧑 🏫👨 🏫👩 🏭🧑 🏭👨 🏭👩 💻🧑 💻👨 💻👩 💼🧑 💼👨 💼👩 🔧🧑 🔧👨 🔧👩 🔬🧑 🔬👨 🔬👩 🎨🧑 🎨👨 🎨👩 🚒🧑 🚒👨 🚒👩 ✈️ 🧑 ✈️ 👨 ✈️ 👩 🚀🧑 🚀👨 🚀👩 ⚖️ 🧑 ⚖️ 👨 ⚖️ 👰 ♀️ 👰👰 ♂️ 🤵 ♀️ 🤵🤵 ♂️ 👸🫅🤴🥷🦸 ♀️ 🦸🦸 ♂️ 🦹 ♀️ 🦹🦹 ♂️ 🤶🧑 🎄🎅🧙 ♀️ 🧙🧙 ♂️ 🧝 ♀️ 🧝🧝 ♂️ 🧛 ♀️ 🧛🧛 ♂️ 🧟 ♀️ 🧟🧟 ♂️ 🧞 ♀️ 🧞🧞 ♂️ 🧜 ♀️ 🧜🧜 ♂️ 🧚 ♀️ 🧚🧚 ♂️ 🧌👼🤰🫄🫃🤱👩 🍼🧑 🍼👨 🍼🙇 ♀️ 🙇🙇 ♂️ 💁 ♀️ 💁💁 ♂️ 🙅 ♀️ 🙅🙅 ♂️ 🙆 ♀️ 🙆🙆 ♂️ 🙋 ♀️ 🙋🙋 ♂️ 🧏 ♀️ 🧏🧏 ♂️ 🤦 ♀️ 🤦🤦 ♂️ 🤷 ♀️ 🤷🤷 ♂️ 🙎 ♀️ 🙎🙎 ♂️ 🙍 ♀️ 🙍🙍 ♂️ 💇 ♀️ 💇💇 ♂️ 💆 ♀️ 💆💆 ♂️ 🧖 ♀️ 🧖🧖 ♂️ 💅🤳💃🕺👯 ♀️ 👯👯 ♂️ 🕴👩 🦽🧑 🦽👨 🦽👩 🦼🧑 🦼👨 🦼🚶 ♀️ 🚶🚶 ♂️ 👩 🦯🧑 🦯👨 🦯🧎 ♀️ 🧎🧎 ♂️ 🏃 ♀️ 🏃🏃 ♂️ 🧍 ♀️ 🧍🧍 ♂️ 👭🧑 🤝 🧑👬👫👩 ❤️ 👩💑👨 ❤️ 👨👩 ❤️ 👨👩 ❤️ 💋 👩💏👨 ❤️ 💋 👨👩 ❤️ 💋 👨👪👨 👩 👦👨 👩 👧👨 👩 👧 👦👨 👩 👦 👦👨 👩 👧 👧👨 👨 👦👨 👨 👧👨 👨 👧 👦👨 👨 👦 👦👨 👨 👧 👧👩 👩 👦👩 👩 👧👩 👩 👧 👦👩 👩 👦 👦👩 👩 👧 👧👨 👦👨 👦 👦👨 👧👨 👧 👦👨 👧 👧👩 👦👩 👦 👦👩 👧👩 👧 👦👩 👧 👧🗣👤👥🫂🧳🌂☂️ 🧵🪡🪢🧶👓🕶🥽🥼🦺👔👕👖🧣🧤🧥🧦👗👘🥻🩴🩱🩲🩳👙👚👛👜👝🎒👞👟🥾🥿👠👡🩰👢👑👒🎩🎓🧢⛑🪖💄💍💼👋🏻🤚🏻🖐🏻✋🏻🖖🏻👌🏻🤌🏻🤏🏻✌🏻🤞🏻🫰🏻🤟🏻🤘🏻🤙🏻🫵🏻🫱🏻🫲🏻🫳🏻🫴🏻👈🏻👉🏻👆🏻🖕🏻👇🏻☝🏻👍🏻👎🏻✊🏻👊🏻🤛🏻🤜🏻👏🏻🫶🏻🙌🏻👐🏻🤲🏻🙏🏻✍🏻💅🏻🤳🏻💪🏻🦵🏻🦶🏻👂🏻🦻🏻👃🏻👶🏻👧🏻🧒🏻👦<F09F8FBB> <F09F91A6>
if [ $? -eq 0 ]
then
printf "\e[1;32mAll Emoticon test OK\e[0;00m\n"
else
printf "\e[1;31mwrong return value with emoticon test\e[0;00m\n"
FAULTS = $(( $FAULTS + 1 ))
fi
sleep $SLEEP
2023-03-06 09:18:56 +01:00
printf "\e[1;36mRunning client 20 times simultaniously\e[0;00m\n"
./client $SERVER "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" | ./client $SERVER "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" | ./client $SERVER "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" | ./client $SERVER "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" | ./client $SERVER "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" | ./client $SERVER "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" | ./client $SERVER "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" | ./client $SERVER "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" | ./client $SERVER "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" | ./client $SERVER "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" | ./client $SERVER "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" | ./client $SERVER "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" | ./client $SERVER "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" | ./client $SERVER "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" | ./client $SERVER "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" | ./client $SERVER "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" | ./client $SERVER "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" | ./client $SERVER "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" | ./client $SERVER "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" | ./client $SERVER "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
if [ $? -eq 0 ]
then
printf "\e[1;32mSimiltanious test OK\e[0;00m\n"
else
printf "\e[1;31mwrong return value with similtanious test\e[0;00m\n"
FAULTS = $(( $FAULTS + 1 ))
fi
sleep $SLEEP
2023-03-01 04:36:01 +01:00
# Congratulations
if [ $FAULTS -eq 0 ]
then
printf "There are no problems with the error codes\nDouble check the output in the server terminal\nFor the bonus check emojis and the following confirmation message\n"
./client $SERVER "Congratulations🎉"
printf "\e[1;32mAlso kudos if the whole test finished within 30 seconds\e[0;00m\n"
else
printf " \e[1;31mwe got $FAULTS faulty error codes\nSo that's a bummer\e[0;00m\n "
exit 1
fi
exit 0