Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TP-shell-student
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
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
gc_courses
sys-exploit
TP-shell-student
Commits
f7ec8f82
Commit
f7ec8f82
authored
2 years ago
by
Guillaume Chanel
Browse files
Options
Downloads
Patches
Plain Diff
Add test for SIGINT
parent
86a53fd3
No related branches found
No related tags found
No related merge requests found
Pipeline
#20590
failed
2 years ago
Stage: build
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/test.py
+26
-15
26 additions, 15 deletions
test/test.py
with
26 additions
and
15 deletions
test/test.py
+
26
−
15
View file @
f7ec8f82
...
...
@@ -7,7 +7,7 @@
# Author: Guillaume Chanel <guillaume.chanel@unige.ch>
# TODO: There are many sleep functions called to wait for the shell. Would there be a way to be sure that:
# - the shell is up and waiting for an input
# - the shell has
process
ed a command
# - the shell has
execut
ed a command
(i.e. the command is running but not finished)
# - the shell as received and treated / ignored a signal (could be done by launching a command and waiting for it to be processed)
# -> check shell state is sleep ?
...
...
@@ -32,7 +32,7 @@ def print_usage():
def
find_last_trace
(
trace
,
f
):
"""
Follow a trace to find the last one
but
still belonging to file f
"""
Follow a trace to find the last one still belonging to file f
trace: a starting trace
f: a file as a full absolute path
"""
...
...
@@ -101,10 +101,6 @@ class Shell:
self
.
stderr
=
None
def
is_alive
(
self
):
return
self
.
shell_process
.
poll
()
==
None
def
get_children
(
self
):
return
self
.
shell_ps
.
children
()
...
...
@@ -216,6 +212,7 @@ class Shell:
def
get_cwd
(
self
):
return
self
.
shell_ps
.
cwd
()
def
is_running
(
self
):
return
self
.
shell_process
.
poll
()
==
None
...
...
@@ -446,10 +443,28 @@ class Test:
shell
.
send_signal
(
signal
.
SIGTERM
)
shell
.
send_signal
(
signal
.
SIGQUIT
)
time
.
sleep
(
0.1
)
# To be sure that signals are treated
assert
shell
.
is_
alive
(),
'
SIGTERM and SIGQUIT sent, the shell should ignore those signals but it died
'
assert
shell
.
is_
running
(),
'
SIGTERM and SIGQUIT sent, the shell should ignore those signals but it died
'
shell
.
exit
()
@test
def
test_SIGINT
(
self
):
# Launch foreground job and send SIGINT
shell
=
Shell
(
self
.
shell_exec
)
shell
.
exec_command
(
Cmd
([
'
sleep
'
,
'
5
'
]),
wait_cmd
=
False
)
time
.
sleep
(
0.1
)
# wait for the process to be spawn
shell
.
send_signal
(
signal
.
SIGINT
)
time
.
sleep
(
0.1
)
# Wait for the signal to be received
# Check that SIGINT did not kill the shell
assert
shell
.
is_running
(),
'
SIGINT seems to have terminated the shell, it should only terminate the child process by redirection
'
# check that the signal killed the foreground command in less than a second
shell
.
wait_children
(
timeout
=
1
)
# TODO: should I test Ctrl+C ? Normally not as it simply sends SIGINT.
@test
def
test_SIGHUP
(
self
):
# Launch two commands and send sighup
...
...
@@ -462,7 +477,7 @@ class Test:
time
.
sleep
(
0.1
)
# To be sure that signal was treated
#Check that shell is dead
if
shell
.
is_
alive
():
if
shell
.
is_
running
():
shell
.
exit
()
raise
AssertionError
(
'
SIGHUP sent but shell was still alive
'
)
...
...
@@ -488,16 +503,12 @@ if __name__ == "__main__":
print
(
'
--- TESTING background jobs and signals ---
'
)
t
.
test_background_jobs
()
t
.
test_SIGTERM_SIGQUIT
()
#TODO:
test
SIGINT
t
.
test
_
SIGINT
()
t
.
test_SIGHUP
()
sys
.
exit
(
test_failed
)
sys
.
exit
(
test_failed
)
# # Pipe
# # Background job where shell exit right after
# execute_commandon_shell(tp_dir, tp_shell_name, b'sleep 2 &', 5)
# # Background job exit code
# execute_commandon_shell(tp_dir, tp_shell_name, b'ls clkscncqp &')
# # Background job SIGHUP
# #execute_commandon_shell(tp_dir, tp_shell_name, b'sleep 10 &\nsleep 1\nkill -SIGHUP {pid}', 6)
# execute_commandon_shell(tp_dir, tp_shell_name, b'ls clkscncqp &')
\ No newline at end of file
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