summaryrefslogtreecommitdiffstats
path: root/src/usr/testcore/kernel/slbtest.H
blob: fef88b5d514f76fc2272e792750ec00ca5c3e225 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
//  IBM_PROLOG_BEGIN_TAG
//  This is an automatically generated prolog.
//
//  $Source: src/usr/testcore/kernel/slbtest.H $
//
//  IBM CONFIDENTIAL
//
//  COPYRIGHT International Business Machines Corp. 2011
//
//  p1
//
//  Object Code Only (OCO) source materials
//  Licensed Internal Code Source Materials
//  IBM HostBoot Licensed Internal Code
//
//  The source code for this program is not published or other-
//  wise divested of its trade secrets, irrespective of what has
//  been deposited with the U.S. Copyright Office.
//
//  Origin: 30
//
//  IBM_PROLOG_END
#ifndef __SLBTEST_H
#define __SLBTEST_H
/**
 *  @file slbtest.H
 *
 *  @brief Test cases for the segment lookaside buffers
*/
#include <cxxtest/TestSuite.H>
#include <arch/ppc.H>
#include <sys/time.h>
#include <sys/task.h>
#include <sys/mmio.h>
#include <sys/mm.h>

class slbtest: public CxxTest::TestSuite
{
    public:

        static volatile int rc;

        void testDevSeg()
        {
            int rc = 0;
            uint64_t ra = 2*1024*1024;
            printkd("Map Device @ ra = 0x%lX using mmio_map\n",ra);
            uint64_t* virtAddrMMIO = static_cast<uint64_t*>
                                (mmio_map(reinterpret_cast<void*>(ra), 1));
            if (virtAddrMMIO == NULL)
            {
                TS_FAIL("Failed to map using mmio_map\n");
            }
            printkd("Unmap Device @ va = %p using mmio_unmap\n",virtAddrMMIO);
            rc = mmio_unmap(reinterpret_cast<void*>(virtAddrMMIO), 1);
            if (rc != 0)
            {
                TS_FAIL("Failed to unmap using mmio_unmap\n");
            }

            printkd("Map Device @ ra = 0x%lX using dev_map\n",ra);
            uint64_t* virtAddrDEV = static_cast<uint64_t*>
                     (mmio_dev_map(reinterpret_cast<void*>(ra), THIRTYTWO_GB));
            if (virtAddrDEV == NULL)
            {
                TS_FAIL("Failed to map using mmio_dev_map\n");
            }
            printkd("Unmap Device @ va = %p using dev_unmap\n",virtAddrDEV);
            rc = mmio_dev_unmap(reinterpret_cast<void*>(virtAddrDEV));
            if (rc != 0)
            {
                TS_FAIL("Failed to unmap using mmio_dev_unmap\n");
            }
        }

        void testSegBlock()
        {
            int rc = -1;
            msg_q_t mq = msg_q_create(); //Create empty message queue
            uint64_t va = 0xC800000000; //800GB
            uint64_t size = 0x100000; //1MB
            printkd("Allocate 1MB block with empty msgq @ vaddr = 800GB within base segment\n");
            rc = mm_alloc_block(mq,reinterpret_cast<void*>(va),size);
            if (rc != 0)
            {
                TS_FAIL("Failed to create BaseSegment block\n");
            }
            msg_q_t mq2 = msg_q_create(); //Create empty message queue
            uint64_t va2 = 0xE100000000; //900GB
            uint64_t size2 = 0x100000; //1MB
            printkd("Allocate 1MB block with empty msgq @ vaddr = 900GB within base segment\n");
            rc = mm_alloc_block(mq2,reinterpret_cast<void*>(va2),size2);
            if (rc != 0)
            {
                TS_FAIL("Failed to create BaseSegment block\n");
            }
        }

        void testPageRemoval()
        {
            int rc = -1;
            uint64_t va = 0xC800000000; //800GB
            uint64_t size = 0x100000; //1MB
            rc = mm_remove_pages(FLUSH,reinterpret_cast<void*>(va),size);
            if (rc != 0)
            {
                TS_FAIL("Failed to remove pages\n");
	    }
	}

        void testSetPerm()
        {
            int rc = 1;
            uint64_t va = 0xC800000000; //800GB
            uint64_t size = 0x0;
            uint64_t access = (uint64_t)(WRITABLE | ALLOCATE_FROM_ZERO); //Access value
            printkd("Update Page Permissions. Writable/Allocate from zero to addr 800Gb and size = 0 \n");
            rc = mm_set_permission(reinterpret_cast<void*>(va), size, access);
            if (rc != 0)
            {
                TS_FAIL(" 1   Failed to Update permissions.\n");
            }

            rc = 1;
            size = PAGESIZE * 3;
            access = (uint64_t)(WRITE_TRACKED); //Access value
            printkd("Update Page Permissions. write_tracked to addr 800Gb and size = 3 pages\n");
            rc = mm_set_permission(reinterpret_cast<void*>(va), size, access);
            if (rc != 0)
            {
                TS_FAIL("2    Failed to Update permissions.\n");
            }
            rc = 1;
            va = 0xC800000000 + (PAGESIZE * 10);
            size = PAGESIZE * 2;
            access = (uint64_t)(EXECUTABLE); //Access value
            printkd("Update Page Permissions. executable to addr C800A000 and size = 2 pages\n");
            rc = mm_set_permission(reinterpret_cast<void*>(va), size, access);
            if (rc != 0)
            {
                TS_FAIL("3   Failed to Update permissions.\n");
            }
            rc = 0;
            va = 0xC800000000; //800GB
            size = 0x0;
            access = (uint64_t)(WRITABLE | EXECUTABLE); //Access value
            printkd("Update Page Permissions. Writable/executable to addr 800Gb and size = 0 \n");
            rc = mm_set_permission(reinterpret_cast<void*>(va), size, access);
            if (rc == 0)
            {
                printk("Error .. invalid combination that did not get detected\n");
                TS_FAIL(" 4   Failed to detect a bad parm condition.\n");
            }

	}

    private:

};
volatile int slbtest::rc = 0;

#endif
OpenPOWER on IntegriCloud