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

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [conts/] [test_suite0/] [src/] [captest.c] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
#include <thread.h>
2
#include <container.h>
3
#include <capability.h>
4
#include <tests.h>
5
#include <l4/api/errno.h>
6
#include <l4lib/macros.h>
7
#include L4LIB_INC_ARCH(syslib.h)
8
#include <l4/api/capability.h>
9
 
10
int simple_pager_thread(void *arg)
11
{
12
        int err;
13
        int res = *(int *)arg;
14
        struct task_ids ids;
15
        int testres = 0;
16
 
17
        l4_getid(&ids);
18
 
19
        printf("Thread spawned from pager, \
20
               trying to create new thread.\n");
21
        err = l4_thread_control(THREAD_CREATE |
22
                                TC_SHARE_SPACE, &ids);
23
 
24
        if (res == 0)
25
                if (err == -ENOCAP ||
26
                    err == -ENOMEM) {
27
                        printf("Creation failed with %d "
28
                               "as expected.\n", err);
29
                        testres = 0;
30
                } else {
31
                        printf("Creation was supposed to fail "
32
                               "with %d or %d, but err = %d\n",
33
                               -ENOMEM, -ENOCAP, err);
34
                        testres = 1;
35
                }
36
        else
37
                if (err == 0) {
38
                        // printf("Creation succeeded as expected.\n");
39
                        testres = 0;
40
                } else {
41
                        printf("Creation was supposed to succeed, "
42
                               "but err = %d\n", err);
43
                        testres = 1;
44
                }
45
 
46
        /* Destroy thread we created */
47
        if (err == 0 &&
48
            res == 0)
49
                l4_thread_control(THREAD_DESTROY, &ids);
50
 
51
        /* Destroy self */
52
        l4_exit(testres);
53
 
54
        return 0;
55
}
56
 
57
int wait_check_test(struct task_ids *ids)
58
{
59
        int result;
60
 
61
        /* Wait for thread to finish */
62
        result = l4_thread_control(THREAD_WAIT, ids);
63
        if (result < 0) {
64
                printf("Waiting on (%d)'s exit failed.\n", ids->tid);
65
                return -1;
66
        } else if (result > 0) {
67
                printf("Top-level test has failed\n");
68
        }
69
        /* Else it is a success */
70
 
71
        return 0;
72
}
73
 
74
int capability_test(void)
75
{
76
        int err;
77
        struct task_ids ids;
78
        int TEST_MUST_FAIL = 0;
79
        //int TEST_MUST_SUCCEED = 1;
80
 
81
        /* Read pager capabilities */
82
        caps_read_all();
83
 
84
        /*
85
         * Create new thread that will attempt
86
         * a pager privileged operation
87
         */
88
        if ((err = thread_create(simple_pager_thread,
89
                                 &TEST_MUST_FAIL,
90
                                 TC_SHARE_SPACE, &ids)) < 0) {
91
                printf("Top-level simple_pager creation failed.\n");
92
                goto out_err;
93
        }
94
 
95
        printf("waititng for result\n");
96
        /* Wait for test to finish and check result */
97
        if (wait_check_test(&ids) < 0)
98
                goto out_err;
99
#if 0
100
 
101
        /* Destroy test thread */
102
        if ((err = l4_thread_control(THREAD_DESTROY, &ids)) < 0) {
103
                printf("Destruction of top-level simple_pager failed.\n");
104
                BUG();
105
        }
106
 
107
        /*
108
         * Share operations with the same thread
109
         * group
110
         */
111
        if ((err = l4_capability_control(CAP_CONTROL_SHARE,
112
                                         CAP_SHARE_CONTAINER, 0)) < 0) {
113
                printf("Sharing capability with thread group failed.\n");
114
                goto out_err;
115
        }
116
 
117
        /*
118
         * Create new thread that will attempt a pager privileged
119
         * operation. This should succeed as we shared caps with
120
         * the thread group.
121
         */
122
        if ((err = thread_create(simple_pager_thread,
123
                                 &TEST_MUST_SUCCEED,
124
                                 TC_SHARE_SPACE |
125
                                 TC_SHARE_GROUP, &ids)) < 0) {
126
                printf("Top-level simple_pager creation failed.\n");
127
                goto out_err;
128
        }
129
 
130
        /* Wait for test to finish and check result */
131
        if (wait_check_test(&ids) < 0)
132
                goto out_err;
133
 
134
        /* Destroy test thread */
135
        if ((err = l4_thread_control(THREAD_DESTROY, &ids)) < 0) {
136
                printf("Destruction of top-level simple_pager failed.\n");
137
                BUG();
138
        }
139
#endif
140
 
141
        printf("Capability Sharing Test         -- PASSED --\n");
142
 
143
        return 0;
144
 
145
out_err:
146
        printf("Capability Sharing Test         -- FAILED --\n");
147
        return 0;
148
}

powered by: WebSVN 2.1.0

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