summaryrefslogtreecommitdiffstats
path: root/src/test/testcases/testUnsecureMemRegions.py
blob: 7087e32ef35d2d0bedd3abb0aa3268ed44a293a7 (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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# IBM_PROLOG_BEGIN_TAG
# This is an automatically generated prolog.
#
# $Source: src/test/testcases/testUnsecureMemRegions.py $
#
# OpenPOWER sbe Project
#
# Contributors Listed Below - COPYRIGHT 2017
# [+] International Business Machines Corp.
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied. See the License for the specific language governing
# permissions and limitations under the License.
#
# IBM_PROLOG_END_TAG
import sys
import os
import struct
sys.path.append("targets/p9_nimbus/sbeTest" )
import testUtil
import testMemUtil as testMemProcUtil
err = False

# MAIN Test Run Starts Here...
#-------------------------------------------------
def main():
    testUtil.runCycles( 10000000 )

    try:
        # Close the HB dump region
        testMemProcUtil.setUnsecureMemRegion(0x08000000, 32*1024*1024, 0x0120, 0)

        # Test case 1: open RO mem region - success
        testcase = 1
        testMemProcUtil.setUnsecureMemRegion(0x07000000, 1024, 0x0111, 0)
        # Test case 2: open RW mem region - success
        # This region is kept open for mem testcases - will be closed by
        # testUnsecureMemRegionsClose.py
        testcase = 2
        testMemProcUtil.setUnsecureMemRegion(0x08000000, 0x2000, 0x0112, 0)
        # Test case 3: close RO mem region - success
        testcase = 3
        testMemProcUtil.setUnsecureMemRegion(0x07000000, 1024, 0x0120, 0)

        # Test case 4: open 9th window - failure
        testcase = 4
        # 2
        testMemProcUtil.setUnsecureMemRegion(0x07000000, 0x10, 0x0111, 0)
        # 3
        testMemProcUtil.setUnsecureMemRegion(0x07000010, 0x10, 0x0111, 0)
        # 4
        testMemProcUtil.setUnsecureMemRegion(0x07000020, 0x10, 0x0111, 0)
        # 5
        testMemProcUtil.setUnsecureMemRegion(0x07000030, 0x10, 0x0111, 0)
        # 6
        testMemProcUtil.setUnsecureMemRegion(0x07000040, 0x10, 0x0111, 0)
        # 7
        testMemProcUtil.setUnsecureMemRegion(0x07000050, 0x10, 0x0111, 0)
        # 8
        testMemProcUtil.setUnsecureMemRegion(0x07000060, 0x10, 0x0111, 0)
        # 9 - failed - response expected -
        # SBE_PRI_USER_ERROR = 0x03
        # SBE_SEC_MAXIMUM_MEM_REGION_EXCEEDED = 0x16
        testMemProcUtil.setUnsecureMemRegion(0x07000070, 0x10, 0x0111, 0x00030016)
        # Test case 5: open existing window - failure
        testcase = 5
        # response expected
        # SBE_PRI_USER_ERROR = 0x03
        # SBE_SEC_MEM_REGION_AMEND_ATTEMPTED = 0x17
        testMemProcUtil.setUnsecureMemRegion(0x07000060, 0x10, 0x0111, 0x00030017)
        # Test case 6: close non-existing window - failure
        testcase = 6
        # response expected
        # SBE_PRI_USER_ERROR = 0x03
        # SBE_SEC_MEM_REGION_NOT_FOUND = 0x15
        testMemProcUtil.setUnsecureMemRegion(0x07000070, 0x10, 0x0120, 0x00030015)
        # Test case 7: remove a window in between - adding it again should pass
        testcase = 7
        testMemProcUtil.setUnsecureMemRegion(0x07000020, 0x10, 0x0120, 0)
        testMemProcUtil.setUnsecureMemRegion(0x07000020, 0x10, 0x0111, 0)
        # Test case 8: remove all and open again to validate removal
        testcase = 8
        # 1
        testMemProcUtil.setUnsecureMemRegion(0x08000000, 0x2000, 0x0120, 0)
        # Open Window with start address not exsting, but size spanning across
        # existing window
        # failed - response expected -
        # SBE_PRI_USER_ERROR = 0x03
        # SBE_SEC_MEM_REGION_AMEND_ATTEMPTED = 0x17
        testMemProcUtil.setUnsecureMemRegion(0x06FFFFF0, 0x20, 0x0111, 0x00030017)
        # 2
        testMemProcUtil.setUnsecureMemRegion(0x07000000, 0x10, 0x0120, 0)
        # 3
        testMemProcUtil.setUnsecureMemRegion(0x07000010, 0x10, 0x0120, 0)
        # 4
        testMemProcUtil.setUnsecureMemRegion(0x07000020, 0x10, 0x0120, 0)
        # 5
        testMemProcUtil.setUnsecureMemRegion(0x07000030, 0x10, 0x0120, 0)
        # 6
        testMemProcUtil.setUnsecureMemRegion(0x07000040, 0x10, 0x0120, 0)
        # 7
        testMemProcUtil.setUnsecureMemRegion(0x07000050, 0x10, 0x0120, 0)
        # 8
        testMemProcUtil.setUnsecureMemRegion(0x07000060, 0x10, 0x0120, 0)
        # 1
        testMemProcUtil.setUnsecureMemRegion(0x08000000, 0x2000, 0x0112, 0)
        # 2
        testMemProcUtil.setUnsecureMemRegion(0x07000000, 0x10, 0x0111, 0)
        testcase = "8: new window subsuming exsiting windows"
        # failed - response expected -
        # SBE_PRI_USER_ERROR = 0x03
        # SBE_SEC_MEM_REGION_AMEND_ATTEMPTED = 0x17
        testMemProcUtil.setUnsecureMemRegion(0x06FFFFF0, 0x30, 0x0111, 0x00030017)
        testcase = "8"
        # 3
        testMemProcUtil.setUnsecureMemRegion(0x07000010, 0x10, 0x0111, 0)
        # 4
        testMemProcUtil.setUnsecureMemRegion(0x07000020, 0x10, 0x0111, 0)
        # 5
        testMemProcUtil.setUnsecureMemRegion(0x07000030, 0x10, 0x0111, 0)
        # 6
        testMemProcUtil.setUnsecureMemRegion(0x07000040, 0x10, 0x0111, 0)
        # 7
        testMemProcUtil.setUnsecureMemRegion(0x07000050, 0x10, 0x0111, 0)
        # 8
        testMemProcUtil.setUnsecureMemRegion(0x07000060, 0x10, 0x0111, 0)
        # 9 - failed - response expected -
        # SBE_PRI_USER_ERROR = 0x03
        # SBE_SEC_MAXIMUM_MEM_REGION_EXCEEDED = 0x16
        testMemProcUtil.setUnsecureMemRegion(0x07000070, 0x10, 0x0111, 0x00030016)

        # Cleanup - close all the windows open except the one for mem testcases
        # 2
        testMemProcUtil.setUnsecureMemRegion(0x07000000, 0x10, 0x0120, 0)
        # 3
        testMemProcUtil.setUnsecureMemRegion(0x07000010, 0x10, 0x0120, 0)
        # 4
        testMemProcUtil.setUnsecureMemRegion(0x07000020, 0x10, 0x0120, 0)
        # 5
        testMemProcUtil.setUnsecureMemRegion(0x07000030, 0x10, 0x0120, 0)
        # 6
        testMemProcUtil.setUnsecureMemRegion(0x07000040, 0x10, 0x0120, 0)
        # 7
        testMemProcUtil.setUnsecureMemRegion(0x07000050, 0x10, 0x0120, 0)
        # 8
        testMemProcUtil.setUnsecureMemRegion(0x07000060, 0x10, 0x0120, 0)

        # Test case 9: access memory in unopened window - ADU
        testcase = 9
        testMemProcUtil.getmem_failure(0x07000060, 0x40, 0xA5, 0x00050014)
        # Test case 10: access memory in unopened window - PBA
        testcase = 10
        testMemProcUtil.getmem_failure(0x07000080, 0x80, 0x02, 0x00050014)

        # Test case 11: access memory spanning across two windows
        testcase = 11
        testMemProcUtil.setUnsecureMemRegion(0x07000040, 0x40, 0x0111, 0)
        testUtil.runCycles(100000)
        testMemProcUtil.setUnsecureMemRegion(0x07000080, 0x40, 0x0111, 0)
        testUtil.runCycles(100000)
        testMemProcUtil.setUnsecureMemRegion(0x070000C0, 0x40, 0x0111, 0)
        testUtil.runCycles(1000000)
        # start and end on edges
        testMemProcUtil.getmem(0x07000040, 0x80, 0xA5)
        testUtil.runCycles(100000)
        # start in between and end on edge
        testMemProcUtil.getmem(0x07000060, 0x60, 0xA5)
        testUtil.runCycles(100000)
        # start on edge and end in between
        testMemProcUtil.getmem(0x07000040, 0x60, 0xA5)
        testUtil.runCycles(100000)
        # start on edge and end in between - 3rd window
        testMemProcUtil.getmem(0x07000040, 0xA0, 0xA5)
        testUtil.runCycles(100000)

        testMemProcUtil.setUnsecureMemRegion(0x07000040, 0x40, 0x0120, 0)
        testUtil.runCycles(100000)
        testMemProcUtil.setUnsecureMemRegion(0x07000080, 0x40, 0x0120, 0)
        testUtil.runCycles(100000)
        testMemProcUtil.setUnsecureMemRegion(0x070000C0, 0x40, 0x0120, 0)
        testUtil.runCycles(100000)

        # Test case 12: read access in read-write window - ADU
        testcase = 12
        testMemProcUtil.setUnsecureMemRegion(0x07000080, 128, 0x0112, 0)
        testMemProcUtil.getmem(0x07000080, 128, 0xA5)
        testMemProcUtil.setUnsecureMemRegion(0x07000080, 128, 0x0120, 0)
        # Test case 13: read access in read-write window - PBA
        testcase = 13
        testMemProcUtil.getmem(0x08000080, 128, 0x02)

        # Test case 14: write access in read-only window - ADU
        testcase = 14
        testMemProcUtil.setUnsecureMemRegion(0x07000080, 128, 0x0111, 0)
        data = os.urandom(8)
        data = [ord(c) for c in data]
        testMemProcUtil.putmem_failure(0x07000080, data, 0xA5, 0x00050014)
        # Test case 15: write access in read-only window - PBA
        testcase = 15
        data = os.urandom(128)
        data = [ord(c) for c in data]
        testMemProcUtil.putmem_failure(0x07000080, data, 0x02, 0x00050014)
        testMemProcUtil.setUnsecureMemRegion(0x07000080, 128, 0x0120, 0)
        # Test case 16: access memory for which a partial window is open
        testcase = 16
        testUtil.runCycles(1000000)
        testMemProcUtil.setUnsecureMemRegion(0x07000040, 0x30, 0x0111, 0)
        # start in between and end outside
        testUtil.runCycles(1000000)
        testMemProcUtil.getmem_failure(0x07000060, 0x40, 0xA5, 0x00050014)
        # start on edge and end outside
        testUtil.runCycles(1000000)
        testMemProcUtil.getmem_failure(0x07000040, 0x40, 0xA5, 0x00050014)
        # start and end within
        testUtil.runCycles(1000000)
        testMemProcUtil.getmem(0x07000050, 0x10, 0xA5)
        testMemProcUtil.setUnsecureMemRegion(0x07000040, 0x30, 0x0120, 0)
    except:
        print "FAILED Test Case:"+str(testcase)
        raise Exception('Failure')
#-------------------------------------------------
# Calling all test code
#-------------------------------------------------
main()

if err:
    print ("\nTest Suite completed with error(s)")
    #sys.exit(1)
else:
    print ("\nTest Suite completed with no errors")
    #sys.exit(0);
OpenPOWER on IntegriCloud