Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
relibc
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
Container Registry
Model registry
Operate
Environments
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
redox-os
relibc
Commits
cf390d6a
Verified
Commit
cf390d6a
authored
8 months ago
by
Jacob Lorentzon
Browse files
Options
Downloads
Patches
Plain Diff
Add SIGCHLD test.
parent
b64b0ebe
No related branches found
No related tags found
1 merge request
!480
Refactor redox runtime and impl signals in userspace
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/Makefile
+1
-0
1 addition, 0 deletions
tests/Makefile
tests/sigchld.c
+105
-0
105 additions, 0 deletions
tests/sigchld.c
with
106 additions
and
0 deletions
tests/Makefile
+
1
−
0
View file @
cf390d6a
...
...
@@ -30,6 +30,7 @@ EXPECT_NAMES=\
select
\
setjmp
\
sigaction
\
sigchld
\
signal
\
stdio/all
\
stdio/buffer
\
...
...
This diff is collapsed.
Click to expand it.
tests/sigchld.c
0 → 100644
+
105
−
0
View file @
cf390d6a
#include
<assert.h>
#include
<errno.h>
#include
<signal.h>
#include
<sched.h>
#include
<stddef.h>
#include
<stdio.h>
#include
<stdlib.h>
#include
<sys/wait.h>
#include
<unistd.h>
#include
"test_helpers.h"
volatile
sig_atomic_t
atomic
=
0
;
volatile
sig_atomic_t
atomic2
=
0
;
void
action
(
int
sig
,
siginfo_t
*
info
,
void
*
context
)
{
(
void
)
context
;
assert
(
sig
==
SIGCHLD
);
assert
(
info
!=
NULL
);
atomic
+=
1
;
}
void
handler
(
int
sig
)
{
assert
(
sig
==
SIGPIPE
);
atomic2
+=
1
;
}
int
main
(
void
)
{
int
child
=
fork
();
ERROR_IF
(
fork
,
child
,
==
-
1
);
int
fds
[
2
];
int
status
=
pipe
(
fds
);
ERROR_IF
(
pipe
,
status
,
==
-
1
);
struct
sigaction
sa
;
sigemptyset
(
&
sa
.
sa_mask
);
sa
.
sa_flags
=
0
;
sa
.
sa_sigaction
=
action
;
status
=
sigaction
(
SIGCHLD
,
&
sa
,
NULL
);
ERROR_IF
(
sigaction
,
status
,
==
-
1
);
sa
.
sa_handler
=
handler
;
status
=
sigaction
(
SIGPIPE
,
&
sa
,
NULL
);
ERROR_IF
(
sigaction
,
status
,
==
-
1
);
if
(
child
==
0
)
{
status
=
close
(
fds
[
1
]);
ERROR_IF
(
close
,
status
,
==
-
1
);
char
buf
[
1
];
status
=
read
(
fds
[
0
],
buf
,
1
);
ERROR_IF
(
read
,
status
,
==
-
1
);
puts
(
"Child exiting."
);
return
EXIT_SUCCESS
;
}
else
{
int
waitpid_stat
;
close
(
fds
[
0
]);
ERROR_IF
(
close
,
status
,
==
-
1
);
puts
(
"Sending SIGSTOP..."
);
status
=
kill
(
child
,
SIGSTOP
);
ERROR_IF
(
kill
,
status
,
==
-
1
);
while
(
atomic
==
0
)
{
status
=
sched_yield
();
ERROR_IF
(
sched_yield
,
status
,
==
-
1
);
}
puts
(
"First handler ran, checking status."
);
status
=
waitpid
(
child
,
&
waitpid_stat
,
WUNTRACED
);
ERROR_IF
(
waitpid
,
status
,
==
-
1
);
assert
(
WIFSTOPPED
(
waitpid_stat
));
assert
(
WSTOPSIG
(
waitpid_stat
)
==
SIGSTOP
);
puts
(
"Correct, sending SIGCONT..."
);
status
=
kill
(
child
,
SIGCONT
);
ERROR_IF
(
kill
,
status
,
==
-
1
);
while
(
atomic
==
1
)
{
status
=
sched_yield
();
ERROR_IF
(
sched_yield
,
status
,
==
-
1
);
}
puts
(
"Second handler ran, checking status."
);
status
=
waitpid
(
child
,
&
waitpid_stat
,
0
);
ERROR_IF
(
waitpid
,
status
,
==
-
1
);
assert
(
WIFEXITED
(
waitpid_stat
));
assert
(
WEXITSTATUS
(
waitpid_stat
)
==
0
);
puts
(
"Child exited."
);
puts
(
"Writing to (broken) pipe."
);
status
=
write
(
fds
[
1
],
"C"
,
1
);
ERROR_IF
(
write
,
status
,
!=
-
1
);
assert
(
errno
==
EPIPE
);
while
(
atomic2
==
0
)
{
status
=
sched_yield
();
ERROR_IF
(
sched_yield
,
status
,
==
-
1
);
}
puts
(
"SIGSTOP handler successfully executed."
);
return
EXIT_SUCCESS
;
}
}
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