core: add all the required files

This commit is contained in:
mkurkar
2026-11-04 16:42:12 +03:00 Unverified
commit 29324ac2ea
57 changed files with 57688 additions and 0 deletions
+10
View File
@@ -0,0 +1,10 @@
#!/bin/bash
# close fd before init
exec 6<&-
exec 6</dev/tcp/127.0.0.1/"$1"
while read -r <&6
do
echo "$REPLY"
done
+5
View File
@@ -0,0 +1,5 @@
Ceci est un test de Ctrl+D dans ton programme ici:\04Si tu ne passes pas ce test, tu devrais verifier le fonctionnement du ctrl+d.
voici
un
nouveau
test
+29
View File
@@ -0,0 +1,29 @@
#!/bin/bash
# Print the first free TCP port in [first_port, last_port]
# (default: a random start in 8888-9887, so back-to-back runs use other ports).
# Works with ss (Linux), lsof (macOS/Linux) or netstat, whichever is installed.
first_port=${1:-$((8888 + RANDOM % 1000))}
last_port=${2:-$((first_port + 1000))}
port_in_use()
{
if command -v ss >/dev/null 2>&1; then
ss -tuln 2>/dev/null | grep -q "[.:]$1 "
elif command -v lsof >/dev/null 2>&1; then
lsof -nP -iTCP:"$1" -sTCP:LISTEN >/dev/null 2>&1
elif command -v netstat >/dev/null 2>&1; then
netstat -an 2>/dev/null | grep -E "[.:]$1 " | grep -q LISTEN
else
# last resort: something accepts connections on this port
(exec 3<>"/dev/tcp/127.0.0.1/$1") 2>/dev/null
fi
}
for ((port = first_port; port <= last_port; port++)); do
if ! port_in_use "$port"; then
echo "$port"
exit 0
fi
done
echo 0
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+17
View File
@@ -0,0 +1,17 @@
#!/bin/bash
# usage: bash test_eof.sh <port>
# Sends eof_test one word at a time (with a literal ^D inside) on one connection.
PORT=$1
send_msg()
{
exec 3<>"/dev/tcp/127.0.0.1/$PORT" || return 1
cat >&3
exec 3>&-
}
for x in $(cat eof_test); do
printf "$x"
sleep 0.1
done | send_msg
+125
View File
@@ -0,0 +1,125 @@
#!/bin/bash
# usage: bash test_miniserv.sh <port> (run from .system/grading)
# Starts the student's server, connects a listener (catchmsg.sh) and several
# short-lived clients, then stores everything the listener received in `bim`.
# Only uses bash's /dev/tcp, so it does not depend on the installed nc flavor.
PORT=$1
rm -f bim trace final
fail()
{
{
echo "----------------8<-------------[ START TEST "
printf "%b" "$1"
echo "----------------8<------------- END TEST ]"
} >> traceback
}
send_msg()
{
exec 3<>"/dev/tcp/127.0.0.1/$PORT" || return 1
cat >&3
exec 3>&-
}
# 0 = listening, 1 = not listening, 2 = no tool available to check
port_listening()
{
if command -v ss >/dev/null 2>&1; then
ss -tln 2>/dev/null | grep -q "[.:]$PORT "
elif command -v lsof >/dev/null 2>&1; then
lsof -nP -iTCP:"$PORT" -sTCP:LISTEN >/dev/null 2>&1
elif command -v netstat >/dev/null 2>&1; then
netstat -an 2>/dev/null | grep -E "[.:]$PORT " | grep -q LISTEN
else
return 2
fi
}
CC=$(command -v clang || command -v cc || command -v gcc)
if ! "$CC" -o final ../../rendu/mini_serv/mini_serv.c > trace 2>&1 || [ ! -e final ]; then
fail " 🔎 YOUR OUTPUT:\n$(cat trace)\n ❌ COMPILATION ERROR\n"
exit 1
fi
SERVER=""
CATCH=""
cleanup()
{
# stop the server first: the listener then reads EOF and flushes `bim`
[ -n "$SERVER" ] && kill "$SERVER" 2>/dev/null
[ -n "$SERVER" ] && wait "$SERVER" 2>/dev/null
if [ -n "$CATCH" ]; then
for _ in $(seq 1 20); do
kill -0 "$CATCH" 2>/dev/null || break
sleep 0.1
done
kill "$CATCH" 2>/dev/null
wait "$CATCH" 2>/dev/null
fi
}
trap cleanup EXIT
# start the server and wait (max 3s) until it listens
# 0 = listening, 1 = never listened, 2 = the process exited (e.g. bind failed)
start_server()
{
./final "$PORT" > /dev/null 2>&1 &
SERVER=$!
for _ in $(seq 1 30); do
port_listening
case $? in
0) return 0 ;;
2) sleep 1; kill -0 "$SERVER" 2>/dev/null && return 0 || return 2 ;;
esac
kill -0 "$SERVER" 2>/dev/null || return 2
sleep 0.1
done
return 1
}
# A port can still be busy (TIME_WAIT) right after a previous run, which
# makes bind() fail: if the server exits at startup, retry on other ports.
attempt=1
while true; do
start_server
status=$?
[ $status -eq 0 ] && break
kill "$SERVER" 2>/dev/null
wait "$SERVER" 2>/dev/null
SERVER=""
if [ $status -eq 1 ] || [ $attempt -ge 5 ]; then
fail " ❌ PORT IS NOT OPEN \n 💻 TEST\n./a.out $PORT\n Connecting after the server is started\n Cannot connect to port $PORT\n"
exit 1
fi
attempt=$((attempt + 1))
PORT=$(bash findport.sh $((PORT + 1)))
done
bash catchmsg.sh "$PORT" >> bim &
CATCH=$!
sleep 1
echo "Si vous ne voyez QUE ce message, c'est mauvais signe." | send_msg
sleep 0.2
echo "Bienvenue sur le test de votre miniserv" | send_msg
sleep 0.2
echo "Ceci est un message" | send_msg
sleep 0.2
printf "Voici un texte sans retour a la ligne" | send_msg
sleep 0.2
echo -n "This is a text without backline at the end" | send_msg
sleep 0.4
printf "Et voici un texte avec plusieurs\nretours\na\nla\nligne\n" | send_msg
sleep 0.2
bash test_eof.sh "$PORT"
sleep 1
send_msg < very_long_msg.txt
sleep 1
send_msg < other_long_msg.txt
sleep 2
+40
View File
@@ -0,0 +1,40 @@
#!/bin/bash
cd .system/grading/
# if there is a traceback file then remove it
if [ -e traceback ]; then
rm traceback
fi
echo "Test may be long, please wait..."
# for port in $(seq 4444 65000); do echo -ne "\035" | telnet 127.0.0.1 $port > /dev/null 2>&1; [ $? -eq 1 ] && break; done
PORT=$(bash findport.sh)
bash test_miniserv.sh $PORT &> /dev/null 2>&1
# if there is a final file and there is not a traceback file then the diff is check
if [ -e final ] && [ ! -e traceback ]; then
DIFF=$(diff bim normal.output)
if [ "$DIFF" != "" ]
then
echo "----------------8<-------------[ START TEST " >> traceback
printf " 💻 TEST\n./a.out $PORT\n" >> traceback
printf " Then there is 3 connexion to the server\n" >> traceback
printf " 🔎 YOUR OUTPUT:\n" >> traceback
cat bim >> traceback
printf " 🗝 EXPECTED OUTPUT:\n" >> traceback
cat normal.output >> traceback
echo "----------------8<------------- END TEST ]" >> traceback
mv traceback ../../traceback
cd ../../
exit 1
fi
touch passed
else
mv traceback ../../traceback
fi
cd ../../
File diff suppressed because one or more lines are too long
+8
View File
@@ -0,0 +1,8 @@
Write your mini_serv.c HERE (exact filename: mini_serv.c).
Then from the repo root run:
bash tester/check.sh
That compiles this file strictly, runs the behavioral tester, and then runs
the real exam-style Grademe diff on it.