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

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [conts/] [test_suite0/] [src/] [api/] [getid.c] - Blame information for rev 5

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
/*
2
 * Test l4_getid system call.
3
 *
4
 * Copyright (C) 2010 B Labs Ltd.
5
 *
6
 * Author: Bahadir Balban
7
 */
8
#include <l4lib/macros.h>
9
#include L4LIB_INC_ARCH(syslib.h)
10
#include L4LIB_INC_ARCH(syscalls.h)
11
#include <l4lib/lib/thread.h>
12
#include <tests.h>
13
 
14
 
15
int thread_getid_nullptr(void *arg)
16
{
17
        return l4_getid(0);
18
}
19
 
20
/*
21
 * Pass nullptr to l4_getid syscall
22
 *
23
 * This exercise proves that the kernel does not crash
24
 * and validly sends a page fault to offending thread's
25
 * pager.
26
 */
27
int test_getid_nullptr(void)
28
{
29
        struct l4_thread *thread;
30
        int err;
31
 
32
        /*
33
         * Create a new thread who will attempt
34
         * passing null ptr argument
35
         */
36
        if ((err = thread_create(thread_getid_nullptr,
37
                                 0, TC_SHARE_SPACE,
38
                                 &thread)) < 0) {
39
                dbg_printf("Thread create failed. "
40
                           "err=%d\n", err);
41
                return err;
42
        }
43
 
44
        dbg_printf("Thread created successfully. "
45
                   "tid=%d\n", thread->ids.tid);
46
 
47
        /*
48
         * Listen on thread for its page fault
49
         * ipc. (Recap: Upon illegal access, the kernel sends
50
         * a page fault ipc message to thread's pager)
51
         */
52
        if ((err = l4_receive(thread->ids.tid)) < 0) {
53
                dbg_printf("%s: listening on page fault for "
54
                           "nullptr thread failed. "
55
                           "err = %d\n", __FUNCTION__, err);
56
                return err;
57
        }
58
 
59
        /*
60
         * Verify ipc was a page fault ipc
61
         */
62
        if (l4_get_tag() != L4_IPC_TAG_PFAULT) {
63
                dbg_printf("%s: Nullptr thread ipc does not "
64
                           "have expected page fault tag.\n"
65
                           "tag=%d, expected=%d\n",
66
                           __FUNCTION__, l4_get_tag(),
67
                           L4_IPC_TAG_PFAULT);
68
                return -1;
69
        }
70
 
71
        /*
72
         * Destroy the thread.
73
         */
74
        if ((err = thread_destroy(thread)) < 0) {
75
                dbg_printf("%s: Failed destroying thread. "
76
                           "err= %d, tid = %d\n",
77
                           __FUNCTION__, err,
78
                           thread->ids.tid);
79
                return err;
80
        }
81
        return 0;
82
}
83
 
84
int test_api_getid(void)
85
{
86
        struct task_ids ids;
87
        int err;
88
 
89
        /*
90
         * Test valid getid request
91
         */
92
        if ((err = l4_getid(&ids)) < 0) {
93
                dbg_printf("Getid request failed. err=%d\n", err);
94
                goto out_err;
95
        }
96
 
97
        /* Check returned results */
98
        if (ids.tid != 1 || ids.spid != 1 || ids.tgid != 1) {
99
                dbg_printf("Getid results not as expected. "
100
                           "tid=%d, spid=%d, tgid=%d\n",
101
                           ids.tid, ids.spid, ids.tgid);
102
                err = -1;
103
                goto out_err;
104
        }
105
 
106
        /*
107
         * Test null pointer argument
108
         */
109
        if ((err = test_getid_nullptr()) < 0) {
110
                dbg_printf("l4_getid() null pointer test failed."
111
                           " err=%d\n", err);
112
                goto out_err;
113
        }
114
 
115
        printf("GETID:                         -- PASSED --\n");
116
        return 0;
117
 
118
out_err:
119
        printf("GETID:                         -- FAILED --\n");
120
        return err;
121
 
122
}
123
 

powered by: WebSVN 2.1.0

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