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

Subversion Repositories c0or1k

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

powered by: WebSVN 2.1.0

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