qa: add setsid test to newlib

This commit is contained in:
Giacomo Tesio 2017-09-08 00:15:12 +02:00
parent 3255a6aa47
commit f3b882ba4a
3 changed files with 69 additions and 0 deletions

View File

@ -0,0 +1,53 @@
#include <unistd.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
int
main(int argc, char **argv)
{
pid_t pid;
int p[2], ppgrp, opgrp, npgrp;
char c = '?';
if (pipe(p) != 0)
perror("pipe() error");
else {
ppgrp = getpgrp();
printf("parent's pid %d; process group id %d\n", getpid(), ppgrp);
if ((pid = fork()) == 0) {
opgrp = getpgrp();
printf("child's pid %d; process group id %d\n", getpid(), opgrp);
write(p[1], &c, 1);
setsid();
npgrp = getpgrp();
if(opgrp == npgrp){
printf("FAIL: setsid did not changed child's process group id\n");
exit(EXIT_FAILURE);
}
printf("child's process group id is now %d\n", npgrp);
sleep(5);
exit(EXIT_SUCCESS);
} else {
read(p[0], &c, 1);
sleep(3);
if(ppgrp != getpgrp()){
printf("FAIL: parent's process group id changed from %d to %d\n", ppgrp, getpgrp());
exit(EXIT_FAILURE);
}
#ifndef WITH_SIGCHLD
npgrp = getsid(pid);
if(npgrp < 0){
printf("FAIL: parent's getsid(%d) failed with errno %d\n", pid, errno);
exit(EXIT_FAILURE);
}
if(npgrp == ppgrp){
printf("FAIL: parent's getsid(%d) returned old process group id that should be changed\n", pid);
exit(EXIT_FAILURE);
}
#endif
}
}
}

15
qa/lib/newlib/050-setsid.runner Executable file
View File

@ -0,0 +1,15 @@
#!/cmd/rc
runner=$0
test = `{echo $runner|sed 's/.runner//'}
test_output = /tmp/output-`{basename $test}
if ( test -e $test_output) rm $test_output
$test $test_output > /dev/null
if ( cat $test_output | grep 'FAIL' > /dev/null ) {
cat $test_output
echo FAIL
exit FAIL
}
echo PASS
exit PASS

View File

@ -37,6 +37,7 @@
"030-pause.c", "030-pause.c",
"031-setjmp.c", "031-setjmp.c",
"040-gettimeofday.c", "040-gettimeofday.c",
"050-setsid.c",
"100-files.c", "100-files.c",
"101-files.c", "101-files.c",
"102-files.c", "102-files.c",