OpenCores
URL https://opencores.org/ocsvn/c0or1k/c0or1k/trunk

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [conts/] [posix/] [test0/] [src/] [forktest.c] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
/*
2
 * Fork test.
3
 */
4
 
5
#include <stdio.h>
6
#include <unistd.h>
7
#include <sys/types.h>
8
#include <tests.h>
9
#include <l4/macros.h>
10
 
11
int global = 0;
12
 
13
 
14
int forktest(void)
15
{
16
        pid_t myid;
17
 
18
 
19
        /* 16 forks */
20
        for (int i = 0; i < 3; i++) {
21
                test_printf("%d: Forking...\n", getpid());
22
                if (fork() < 0)
23
                        goto out_err;
24
        }
25
 
26
        myid = getpid();
27
 
28
        if (global != 0) {
29
                test_printf("Global not zero.\n");
30
                test_printf("-- FAILED --\n");
31
                goto out_err;
32
        }
33
        global += myid;
34
 
35
        if (global != myid)
36
                goto out_err;
37
 
38
 
39
        if (getpid() != parent_of_all) {
40
                /* Exit here to exit successful children */
41
                //_exit(0);
42
                //BUG();
43
        }
44
 
45
        if (getpid() == parent_of_all)
46
                printf("FORK TEST           -- PASSED --\n");
47
 
48
        return 0;
49
 
50
        /* Any erroneous child or parent comes here */
51
out_err:
52
        printf("FORK TEST           -- FAILED --\n");
53
        return 0;
54
}
55
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.