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
86a53fd3
Commit
86a53fd3
authored
2 years ago
by
Guillaume Chanel
Browse files
Options
Downloads
Patches
Plain Diff
Add SIGHUP test
parent
d34884b6
No related branches found
No related tags found
No related merge requests found
Pipeline
#20573
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
+30
-5
30 additions, 5 deletions
test/test.py
with
30 additions
and
5 deletions
test/test.py
+
30
−
5
View file @
86a53fd3
...
...
@@ -9,6 +9,7 @@
# - the shell is up and waiting for an input
# - the shell has processed a command
# - 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 ?
import
filecmp
import
logging
...
...
@@ -113,7 +114,7 @@ class Shell:
# TODO: move out of Shell ?
def
check_ophan
s
(
self
,
cmd
:
Cmd
):
def
check_o
r
phan
(
self
,
cmd
:
Cmd
):
"""
Check if an orphan process (child of 1) was executed with cmd
cmd: if None the tested command will be the last executed command
"""
...
...
@@ -125,8 +126,9 @@ class Shell:
str_cmd
=
str
(
cmd
)
init_ps
=
psutil
.
Process
(
1
)
for
p
in
init_ps
.
children
():
if
p
.
cmdline
()
==
str_cmd
:
raise
AssertionError
(
'
The command
"
{}
"
seem to be a child of process 1
'
.
format
(
str_cmd
))
init_cmd
=
Cmd
(
p
.
cmdline
())
if
str
(
init_cmd
)
==
str_cmd
:
raise
AssertionError
(
'
The command
"
{}
"
seem to be a child of process 1 -> orphelin process
'
.
format
(
str_cmd
))
def
wait_children
(
self
,
test_zombies
:
bool
=
True
,
timeout
:
int
=
3
):
...
...
@@ -434,6 +436,8 @@ class Test:
# TODO: test return error message or error value ?
# TODO: Test double background jobs? (par souci de simplicité, on interdira d’avoir plus d’un job en tâche de fond à la fois)
@test
def
test_SIGTERM_SIGQUIT
(
self
):
...
...
@@ -442,10 +446,30 @@ 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_alive
(),
'
SIGTERM and SIGQUIT sent, the shell should ignore those signals but it died
'
shell
.
exit
()
@test
def
test_SIGHUP
(
self
):
# Launch two commands and send sighup
shell
=
Shell
(
self
.
shell_exec
)
time
.
sleep
(
0.1
)
# To be sure that handlers are configured
shell
.
exec_command
(
Cmd
([
'
sleep
'
,
'
2
'
,
'
&
'
]),
wait_cmd
=
False
)
shell
.
exec_command
(
Cmd
([
'
sleep
'
,
'
3
'
]),
wait_cmd
=
False
)
time
.
sleep
(
0.1
)
# To be sure that commands are executed
shell
.
send_signal
(
signal
.
SIGHUP
)
time
.
sleep
(
0.1
)
# To be sure that signal was treated
#Check that shell is dead
if
shell
.
is_alive
():
shell
.
exit
()
raise
AssertionError
(
'
SIGHUP sent but shell was still alive
'
)
# Check that the two processes are dead as well
shell
.
check_orphan
(
Cmd
([
'
sleep
'
,
'
2
'
]))
shell
.
check_orphan
(
Cmd
([
'
sleep
'
,
'
3
'
]))
if
__name__
==
"
__main__
"
:
...
...
@@ -464,7 +488,8 @@ if __name__ == "__main__":
print
(
'
--- TESTING background jobs and signals ---
'
)
t
.
test_background_jobs
()
t
.
test_SIGTERM_SIGQUIT
()
#TODO: test SIGINT
t
.
test_SIGHUP
()
sys
.
exit
(
test_failed
)
...
...
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