diff --git a/Assignment-06/starter/dsh b/Assignment-06/starter/dsh new file mode 100755 index 0000000000000000000000000000000000000000..b3a2814877cc42b4174b34f709611e542d28b8ae Binary files /dev/null and b/Assignment-06/starter/dsh differ diff --git a/Assignment-06/starter/student_tests.sh b/Assignment-06/starter/student_tests.sh index 638bc341446f7580a80c2aff52971b8023407ea8..673110a4ad94ccf5e56a141c5d3a21a10f371082 100644 --- a/Assignment-06/starter/student_tests.sh +++ b/Assignment-06/starter/student_tests.sh @@ -4,6 +4,18 @@ # # Create your unit tests suit in this file +start_server() { + ./dsh -s -i 127.0.0.1 -p 5678 > /dev/null 2>&1 & + SERVER_PID=$! + sleep 1 # Give the server time to start +} + +# Helper function to stop the server +stop_server() { + kill $SERVER_PID 2>/dev/null || true + wait $SERVER_PID 2>/dev/null || true +} + @test "Example: check ls runs without errors" { run ./dsh <<EOF ls @@ -12,3 +24,66 @@ EOF # Assertions [ "$status" -eq 0 ] } + + +@test "Start server and client without errors" { + # Start the server + start_server + + # Check if the server is running + run ps -p $SERVER_PID + [ "$status" -eq 0 ] + + # Start the client and send a simple command + run ./dsh -c -i 127.0.0.1 -p 5678 <<EOF +echo Hello, World! +exit +EOF + + # Assertions + [ "$status" -eq 0 ] + [[ "$output" == *"Hello, World!"* ]] + + stop_server +} + +@test "Server handles pipes" { + start_server + + echo "testfile1" > testfile1.txt + echo "testfile2" >> testfile1.txt + + run ./dsh -c -i 127.0.0.1 -p 5678 <<EOF +ls -1 | wc -l +exit +EOF + + [ "$status" -eq 0 ] + [[ "$output" == *"2"* ]] + + rm -f testfile1.txt + + stop_server +} + + +@test "Stop server with stop-server command" { + start_server + + run ps -p $SERVER_PID + [ "$status" -eq 0 ] + + run ./dsh -c -i 127.0.0.1 -p 5678 <<EOF +stop-server +EOF + + [ "$status" -eq 0 ] + + sleep 1 + run ps -p $SERVER_PID + [ "$status" -ne 0 ] +} + + + +