Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cs503zchen
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ziheng Chen
cs503zchen
Commits
371f701c
Commit
371f701c
authored
2 months ago
by
Ziheng Chen
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
1b012a77
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
w8/student_tests.sh
+100
-0
100 additions, 0 deletions
w8/student_tests.sh
with
100 additions
and
0 deletions
w8/student_tests.sh
0 → 100644
+
100
−
0
View file @
371f701c
#!/usr/bin/env bats
# File: student_tests.sh
#
# Create your unit tests suit in this file
@test
"Example: check ls runs without errors"
{
run ./dsh
<<
EOF
ls
EOF
# Assertions
[
"
$status
"
-eq
0
]
}
# Location of the compiled dsh executable
DSH_EXEC
=
"./dsh"
# Server settings
SERVER_IP
=
"127.0.0.1"
SERVER_PORT
=
"5678"
# Start the server in the background
setup
()
{
# Kill any existing dsh server instances
pkill
-f
"
$DSH_EXEC
-s"
||
true
# Start the server in the background
$DSH_EXEC
-s
-i
0.0.0.0
-p
$SERVER_PORT
>
server_output.log 2>&1 &
sleep
1
# Give the server some time to start
}
# Stop the server after tests
teardown
()
{
pkill
-f
"
$DSH_EXEC
-s"
||
true
}
@test
"Basic command execution"
{
run
$DSH_EXEC
-c
-i
$SERVER_IP
-p
$SERVER_PORT
<<
EOF
ls
exit
EOF
echo
"
$output
"
[[
"
$output
"
=
~
"dsh4> exit"
||
"
$output
"
=
~
"client exited: getting next connection..."
]]
}
@test
"Pipeline command execution"
{
run
$DSH_EXEC
-c
-i
$SERVER_IP
-p
$SERVER_PORT
<<
EOF
echo "hello world" | tr a-z A-Z
exit
EOF
echo
"
$output
"
[[
"
$output
"
=
~
"HELLO WORLD"
]]
}
@test
"Invalid command handling"
{
run
$DSH_EXEC
-c
-i
$SERVER_IP
-p
$SERVER_PORT
<<
EOF
invalidcmd
exit
EOF
echo
"
$output
"
[[
"
$output
"
=
~
"execvp failed"
]]
# Expected failure message
}
@test
"Multi-threaded support test"
{
# Start multi-threaded server
pkill
-f
"
$DSH_EXEC
-s"
||
true
$DSH_EXEC
-s
-i
0.0.0.0
-p
$SERVER_PORT
-x
>
server_output.log 2>&1 &
sleep
1
# Run two clients simultaneously
$DSH_EXEC
-c
-i
$SERVER_IP
-p
$SERVER_PORT
<<
EOF
> client1_output.log 2>&1 &
ls
exit
EOF
$DSH_EXEC
-c
-i
$SERVER_IP
-p
$SERVER_PORT
<<
EOF
> client2_output.log 2>&1 &
whoami
exit
EOF
sleep
2
# Give clients time to execute
# Validate both clients received expected output
run
cat
client1_output.log
echo
"
$output
"
[[
"
$output
"
=
~
"dsh4>"
]]
run
cat
client2_output.log
echo
"
$output
"
[[
"
$output
"
=
~
"dsh4>"
]]
rm
client1_output.log
rm
client2_output.log
rm
server_output.log
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment