Simple fork test and run script

Currently the test is failing because fork is not yet implemented.
This commit is contained in:
Norman Feske 2012-02-14 16:18:16 +01:00
parent 42c21e4582
commit b6b05a032b
4 changed files with 118 additions and 0 deletions

77
ports/run/noux_fork.run Normal file
View File

@ -0,0 +1,77 @@
if {![have_spec x86_32]} {
puts "\nNoux is supported on the x86_32 architecture only\n"
exit 0
}
if {[have_spec linux]} {
puts "\nLinux not supported because of missing UART driver\n"
exit 0
}
build "core init drivers/timer drivers/uart noux lib/libc_noux test/noux_fork"
# strip coreutils binaries and create tar archive
exec tar cfv bin/noux_fork.tar -h -C bin test-noux_fork
create_boot_directory
install_config {
<config verbose="yes">
<parent-provides>
<service name="ROM"/>
<service name="LOG"/>
<service name="CAP"/>
<service name="RAM"/>
<service name="RM"/>
<service name="CPU"/>
<service name="PD"/>
<service name="IRQ"/>
<service name="IO_MEM"/>
<service name="IO_PORT"/>
<service name="SIGNAL"/>
</parent-provides>
<default-route>
<any-service> <any-child/> <parent/> </any-service>
</default-route>
<start name="timer">
<resource name="RAM" quantum="512K"/>
<provides><service name="Timer"/></provides>
</start>
<start name="uart_drv">
<resource name="RAM" quantum="1M"/>
<provides><service name="Terminal"/></provides>
<config>
<policy label="noux" uart="1"/>
</config>
</start>
<start name="noux">
<resource name="RAM" quantum="1G"/>
<config>
<fstab> <tar name="noux_fork.tar" at="/"/> </fstab>
<start name="test-noux_fork"> </start>
</config>
</start>
</config>
}
build_boot_image {
core init timer uart_drv ld.lib.so noux libc.lib.so libm.lib.so
libc_noux.lib.so noux_fork.tar
}
#
# Redirect the output of Noux via the virtual serial port 1 into a file to be
# dumped after the successful completion of the test.
#
set noux_output_file "noux_output.log"
append qemu_args " -nographic"
append qemu_args " -serial mon:stdio"
append qemu_args " -serial file:$noux_output_file"
#run_genode_until "child exited with exit value 0.*\n" 20
run_genode_until "child.*exited.*\n" 20
puts "[exec cat $noux_output_file]"
exec rm bin/noux_fork.tar
exec rm $noux_output_file

View File

@ -0,0 +1,3 @@
TARGET = test-noux_fork
SRC_CC = test.cc
LIBS = libc libc_noux

BIN
ports/src/test/noux_fork/test Executable file

Binary file not shown.

View File

@ -0,0 +1,38 @@
/*
* \brief Simple fork test
* \author Norman Feske
* \date 2012-02-14
*/
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
int main(int, char **)
{
int i = 0;
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);
if (fork_ret == 0) {
printf("pid %d: child says hello\n", getpid());
for (int j = 0; j < 50; j++) {
printf("pid %d: child i = %d\n", getpid(), i);
}
}
printf("pid %d: parent received child pid %d, starts counting...\n",
getpid(), fork_ret);
for (; i < 50; ) {
printf("pid %d: parent i = %d\n", getpid(), i++);
}
return 0;
}