Improve noux fork test (grand child, waitpid)

The test now forks twice - the parent forks a child and the child itself
forks a grand child. Both, parent and child, wait for termination of
their forked process with waitpid(). Additionally, the run script now
checks for exit of the parent (not any noux process).
This commit is contained in:
Christian Helmuth 2016-12-17 14:05:57 +01:00 committed by Norman Feske
parent aaa079c360
commit a52543acd2
2 changed files with 43 additions and 8 deletions

View File

@ -30,9 +30,12 @@ install_config {
<provides><service name="Terminal"/></provides>
</start>
<start name="noux">
<resource name="RAM" quantum="1G"/>
<config verbose="yes">
<fstab> <rom name="test-noux_fork" /> </fstab>
<resource name="RAM" quantum="64M"/>
<config verbose="yes" stdin="/null" stdout="/log" stderr="/log">
<fstab>
<null/> <log/>
<rom name="test-noux_fork" />
</fstab>
<start name="test-noux_fork"> </start>
</config>
</start>
@ -46,4 +49,5 @@ build_boot_image {
append qemu_args " -nographic "
run_genode_until "child.*exited with exit value 0.*\n" 20
run_genode_until "--- parent done ---.*\n" 20
run_genode_until "child.*exited.*\n" 5 [output_spawn_id]

View File

@ -7,6 +7,7 @@
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <sys/wait.h>
enum { MAX_COUNT = 1000 };
@ -22,11 +23,38 @@ int main(int, char **)
printf("pid %d: fork returned %d\n", getpid(), fork_ret);
/* child */
if (fork_ret == 0) {
printf("pid %d: child says hello\n", getpid());
for (int j = 0; j < MAX_COUNT; j++) {
printf("pid %d: child j = %d\n", getpid(), j);
pid_t fork_ret = fork();
if (fork_ret < 0) {
printf("Error: fork returned %d, errno=%d\n", fork_ret, errno);
return -1;
}
printf("pid %d: fork returned %d\n", getpid(), fork_ret);
/* grand child */
if (fork_ret == 0) {
printf("pid %d: grand child says hello\n", getpid());
for (int k = 0; k < MAX_COUNT; k++) {
printf("pid %d: grand child k = %d\n", getpid(), k);
}
return 0;
};
for (int j = 0; j < MAX_COUNT; j++) {
printf("pid %d: child j = %d\n", getpid(), j);
}
if (fork_ret != 0) {
printf("pid %d: child waits for grand-child exit\n", getpid());
waitpid(fork_ret, nullptr, 0);
}
return 0;
}
@ -34,9 +62,12 @@ int main(int, char **)
getpid(), fork_ret);
for (int i = 0; i < MAX_COUNT; ) {
printf("pid %d: parent i = %d\n", getpid(), i++);
printf("pid %d: parent i = %d\n", getpid(), i++);
}
pause();
printf("pid %d: parent waits for child exit\n", getpid());
waitpid(fork_ret, nullptr, 0);
printf("--- parent done ---\n");
return 0;
}