Verified Commit ecdc3d96 authored by GOUVILLE Tom's avatar GOUVILLE Tom 🤞
Browse files

Updated tests

parent f123834b
#!/bin/bash
#ls -l /proc/`ps -x | grep tesh | cut -d " " -f 3 | head -n 1`/fd | tail -n +2 | awk '{ print $9, $10, $11 }'
ls -l /proc/$PPID/fd | tail -n +2 | awk '{ print $9, $10, $11 }'
exec $@
\ No newline at end of file
from os import remove
from ptyprocess import PtyProcessUnicode
import sys
import re
import time
p = PtyProcessUnicode.spawn([sys.argv[1]])
time.sleep(0.2)
command = ""
for x in sys.argv[2:]:
command += x + "\n";
p.write(command)
res = ""
x = p.read(1)
while x != None:
res += x
try:
x = p.read(1)
p.sendeof()
except:
res += x
break
ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[-/]*[@-~])')
res = ansi_escape.sub('', res)
res = ''.join([x for x in res if x != "\r"])
print(res[:-1])
\ No newline at end of file
......@@ -13,8 +13,9 @@ if [ ! -f rapport.pdf ]; then
fi
echo '######### Installing dependencies'
[[ -z $NODEP ]] && apt-get update
[[ -z $NODEP ]] && apt-get -y install --no-install-recommends build-essential libreadline-dev electric-fence
[[ -z $INDOCKER ]] || apt-get update
[[ -z $INDOCKER ]] || apt-get -y install --no-install-recommends build-essential libreadline-dev electric-fence python3 python3-pip
pip install ptyprocess
echo '######### Trying to build'
......@@ -56,6 +57,22 @@ if ! [ "$mo" = "$me" ]; then
fi
}
displayNotTest() {
echo Input:
echo ------------------------------------------------
cat $ti
echo ------------------------------------------------
echo Output:
echo ------------------------------------------------
cat $to
echo ------------------------------------------------
echo Expected output:
echo ------------------------------------------------
cat $te
echo ------------------------------------------------
echo -e "\n\n"
}
# enable Electric Fence
export LD_PRELOAD=libefence.so.0.0
export EF_DISABLE_BANNER=1
......@@ -261,11 +278,21 @@ EOF
timeout 2s bash -c "./tesh < $ti" > $to 2>&1
display $ti $to $te
echo '######### Compiling mockup isatty'
echo "int isatty(int fd) { return 1; }" | gcc -O2 -fpic -shared -ldl -o ./isatty.so -xc -
echo -e "Done\n\n\n"
# echo '######### Trying to test -e'
# cat <<-EOF > $ti 2>&1
# echo a
# echo b
# false
# echo c
# EOF
# cat <<-EOF > $te 2>&1
# a
# b
# EOF
# timeout 2s bash -c "./tesh -e < $ti" > $to 2>&1
# display $ti $to $te
echo '######### Trying to test prompt'
cat <<-EOF > $ti 2>&1
echo foo
......@@ -275,7 +302,7 @@ cat <<-EOF > $te 2>&1
foo
`whoami`@`hostname`:`pwd`$
EOF
timeout 2s bash -c "LD_PRELOAD=./isatty.so ./tesh < $ti" > $to 2>&1
timeout 2s bash -c "python3 tests/ptytester.py ./tesh 'echo foo'" > $to 2>&1
display $ti $to $te
......@@ -287,13 +314,94 @@ cat <<-EOF > $te 2>&1
`whoami`@`hostname`:`pwd`$ cd /
`whoami`@`hostname`:/$
EOF
timeout 2s bash -c "LD_PRELOAD=./isatty.so ./tesh < $ti" > $to 2>&1
timeout 2s bash -c "python3 tests/ptytester.py ./tesh 'cd /'" > $to 2>&1
display $ti $to $te
if [[ -z $INDOCKER ]]; then
echo '######### Trying to test fd leaks'
cat <<-EOF > $ti 2>&1
./tests/fdtester.sh cat ./tests/lorem-ipsum > /tmp/TMPFILE
echo sortie de echo
cat /tmp/TMPFILE
EOF
cat <<-EOF > $te 2>&1
sortie de echo
0 -> ***
1 -> ***
2 -> ***
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
EOF
timeout 2s bash -c "./tesh < $ti" > $to 2>&1
displayNotTest $ti $to $te
if ! grep -Pzo "sortie de echo\n0 ->.*\n1 ->.*\n2 ->.*\nLorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." $to > /dev/null; then
echo "ERROR outputs do not match."
echo "(Ne pas tester dans VSCode)"
exit 1
fi
echo '######### Trying to test fd leaks 2'
cat <<-EOF > $ti 2>&1
./tests/fdtester.sh cat < ./tests/lorem-ipsum
EOF
cat <<-EOF > $te 2>&1
0 -> ***
1 -> ***
2 -> ***
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
EOF
timeout 2s bash -c "./tesh < $ti" > $to 2>&1
displayNotTest $ti $to $te
if ! grep -Pzo "0 ->.*\n1 ->.*\n2 ->.*\nLorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." $to > /dev/null; then
echo "ERROR outputs do not match."
exit 1
fi
echo '######### Trying to test fd leaks 3'
cat <<-EOF > $ti 2>&1
./tests/fdtester.sh cat ./tests/lorem-ipsum > /tmp/TMPFILE
./tests/fdtester.sh cat ./tests/lorem-ipsum > /tmp/TMPFILE
./tests/fdtester.sh cat ./tests/lorem-ipsum >> /tmp/TMPFILE
echo sortie de echo
cat /tmp/TMPFILE
EOF
cat <<-EOF > $te 2>&1
sortie de echo
0 -> ***
1 -> ***
2 -> ***
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
0 -> ***
1 -> ***
2 -> ***
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
EOF
timeout 2s bash -c "./tesh < $ti" > $to 2>&1
displayNotTest $ti $to $te
if ! grep -Pzo "0 ->.*\n1 ->.*\n2 ->.*\nLorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n0 ->.*\n1 ->.*\n2 ->.*\nLorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." $to > /dev/null; then
echo "ERROR outputs do not match."
exit 1
fi
echo '######### Trying to test fd leaks 4'
cat <<-EOF > $ti 2>&1
cat ./tests/lorem-ipsum-long | ./tests/fdtester.sh grep Duis
EOF
cat <<-EOF > $te 2>&1
0 -> ***
1 -> ***
2 -> ***
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
EOF
timeout 2s bash -c "./tesh < $ti" > $to 2>&1
displayNotTest $ti $to $te
if ! grep -Pzo "0 ->.*\n1 ->.*\n2 ->.*\nDuis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur." $to > /dev/null; then
echo "ERROR outputs do not match."
exit 1
fi
echo '######### Cleaning'
rm ./isatty.so
echo -e "Done\n\n\n"
fi
if ldd tesh | grep -q libreadline; then
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment