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

Subversion Repositories c0or1k

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
/*
2
 * Test exchange registers system call.
3
 *
4
 * Copyright (C) 2010 B Labs Ltd.
5
 *
6
 * Author: Bahadir Balban
7
 */
8
 
9
#include <l4lib/exregs.h>
10
#include <l4lib/lib/thread.h>
11
#include <stdio.h>
12
#include <string.h>
13
#include <tests.h>
14
 
15
int test_exregs_read_write(void)
16
{
17
        struct task_ids ids;
18
        struct exregs_data exregs[2];
19
        int err;
20
 
21
        /* Get own space id */
22
        l4_getid(&ids);
23
 
24
        /*
25
         * Create a thread in the same space.
26
         * Thread is not runnable.
27
         */
28
        if ((err = l4_thread_control(THREAD_CREATE | TC_SHARE_SPACE,
29
                                     &ids)) < 0) {
30
                dbg_printf("Thread create failed. "
31
                           "err=%d\n", err);
32
                return err;
33
        }
34
 
35
        dbg_printf("Thread created successfully. "
36
                   "tid=%d\n", ids.tid);
37
 
38
        /*
39
         * Prepare a context part full of 0xFF
40
         */
41
        memset(&exregs[0].context, 0xFF, sizeof(exregs[1].context));
42
        exregs[0].valid_vect = 0xFFFFFFFF;
43
 
44
        /* Write to context */
45
        if ((err = l4_exchange_registers(&exregs[0], ids.tid)) < 0)
46
                goto out;
47
 
48
        /* Set the other as read-all */
49
        exregs_set_read(&exregs[1]);
50
        exregs[1].valid_vect = 0xFFFFFFFF;
51
        if ((err = l4_exchange_registers(&exregs[1],
52
                                         ids.tid)) < 0)
53
                goto out;
54
 
55
        /*
56
         * Read back all context and compare results
57
         */
58
        if (memcmp(&exregs[0].context, &exregs[1].context,
59
                   sizeof(exregs[0].context))) {
60
                err = -1;
61
                goto out;
62
        }
63
 
64
out:
65
        /*
66
         * Destroy the thread
67
         */
68
        if ((err = l4_thread_control(THREAD_DESTROY, &ids)) < 0) {
69
                dbg_printf("Thread destroy failed. err=%d\n",
70
                           err);
71
        }
72
        return 0;
73
}
74
 
75
 
76
int test_api_exregs(void)
77
{
78
        int err;
79
 
80
        if ((err = test_exregs_read_write()) < 0)
81
                goto out_err;
82
 
83
        /*
84
         * TODO: Should add more tests here, e.g. setting
85
         * values of a thread we're not a pager of.
86
         */
87
 
88
        printf("EXCHANGE REGISTERS:            -- PASSED --\n");
89
        return 0;
90
 
91
out_err:
92
        printf("EXCHANGE REGISTERS:            -- FAILED --\n");
93
        return err;
94
 
95
}
96
 

powered by: WebSVN 2.1.0

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