author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 25 May 2010 14:09:55 +0300 | |
branch | RCL_3 |
changeset 117 | 5b5d147c7838 |
parent 80 | 597aaf25e343 |
child 256 | c1f20ce4abcf |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
2 |
// All rights reserved. |
|
3 |
// This component and the accompanying materials are made available |
|
4 |
// under the terms of the License "Eclipse Public License v1.0" |
|
5 |
// which accompanies this distribution, and is available |
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 |
// |
|
8 |
// Initial Contributors: |
|
9 |
// Nokia Corporation - initial contribution. |
|
10 |
// |
|
11 |
// Contributors: |
|
12 |
// |
|
13 |
// Description: |
|
14 |
// Overview: |
|
15 |
// Test the video driver kernel extension that provides chunk handle to access video memory. |
|
16 |
// API Information: |
|
17 |
// HAL, UserSvr |
|
18 |
// Details: |
|
19 |
// - Check that the "old" GetMemoryAddress function still works, for legacy compatibility. |
|
20 |
// - Check that we can get a chunk and that we can read/write the memory belonging to that chunk. |
|
21 |
// - Check that asking for a DisplayMemoryHandle twice gives the same piece of memory. |
|
22 |
// - Test that the same memory is available to a second process, by starting second process and |
|
23 |
// the second process can write to memory. Validate by confirming that the value in the second process |
|
24 |
// is changed. |
|
25 |
// Platforms/Drives/Compatibility: |
|
26 |
// All. |
|
27 |
// Assumptions/Requirement/Pre-requisites: |
|
28 |
// Failures and causes: |
|
29 |
// Base Port information: |
|
30 |
// |
|
31 |
// |
|
32 |
||
33 |
#include <e32test.h> |
|
34 |
#include <videodriver.h> |
|
35 |
#include <hal.h> |
|
36 |
#include <e32svr.h> |
|
37 |
#include <dispchannel.h> |
|
38 |
#include "t_videomemory.h" |
|
39 |
||
40 |
LOCAL_D RTest test(_L("T_VIDEOMEMORY")); |
|
41 |
||
42 |
#ifndef __WINS__ |
|
43 |
#define DUMP(x) test.Printf(_L(#x"= %d =0x%08x\n"), x, x) |
|
44 |
#endif |
|
45 |
||
46 |
||
47 |
LOCAL_C void RunTestsForScreen(TInt aScreenID) |
|
48 |
{ |
|
49 |
||
50 |
TInt ret = KErrNone; |
|
51 |
||
52 |
#ifdef __WINS__ |
|
53 |
RDisplayChannel displayChannel; |
|
54 |
||
55 |
test.Next(_L("Open Display Driver")); |
|
56 |
||
57 |
_LIT(KDisplayDriver, "display0"); |
|
58 |
ret = User::LoadLogicalDevice(KDisplayDriver); |
|
59 |
test(KErrNone == ret || KErrAlreadyExists == ret); |
|
60 |
||
61 |
ret = displayChannel.Open(aScreenID); |
|
62 |
test(KErrNone == ret); |
|
63 |
||
64 |
#endif |
|
65 |
||
66 |
test.Next(_L("Checking Display Memory Address")); |
|
67 |
||
68 |
// This is the real basic form of test: |
|
69 |
// Get the display memory address from the HAL. |
|
70 |
// Check that it's not zero - that would be invalid memory. |
|
71 |
// Try to write to the memory - it should not give a page-fault/crash. |
|
72 |
// Try to read the memory - we should get the same value as we wrote. |
|
73 |
||
74 |
TInt memoryAddress=0; |
|
75 |
volatile TUint32 *pMemory = 0; |
|
76 |
ret = HAL::Get(aScreenID, HAL::EDisplayMemoryAddress, memoryAddress); |
|
77 |
test (KErrNone == ret || KErrNotSupported == ret); |
|
78 |
||
79 |
if (KErrNone == ret) |
|
80 |
{ |
|
81 |
test.Printf(_L("Display Memory Address = %08x\n"), memoryAddress); |
|
82 |
// Now check that we can write to memoryAddress: |
|
83 |
test (memoryAddress != 0); |
|
84 |
pMemory = reinterpret_cast<TUint32 *>(memoryAddress); |
|
85 |
*pMemory = KTestValue1; |
|
86 |
test(KTestValue1 == *pMemory); |
|
87 |
} |
|
88 |
else |
|
89 |
{ |
|
90 |
test.Printf(_L("Memory Address not available from HAL\n")); |
|
91 |
} |
|
92 |
||
93 |
// Second basic test. Use the HAL to fetch a handle |
|
94 |
// to the display memory. |
|
95 |
// Check that the handle is not zero. |
|
96 |
// Get the base-address of the chunk. |
|
97 |
// Write this base address with a new value. |
|
98 |
// Read with the chunk base address to see that teh new value is there. |
|
99 |
// Read the memory address from the above test and check that it changed |
|
100 |
// to the new value. |
|
101 |
// Note that the memory address from above test MAY NOT BE SET - so |
|
102 |
// check to see if it's non-zero first. |
|
103 |
||
104 |
test.Next(_L("Checking Display Handle")); |
|
105 |
TInt handle = 0; |
|
106 |
volatile TUint32 *pChunkBase = 0; |
|
107 |
RChunk chunk; |
|
108 |
ret = HAL::Get(aScreenID, HALData::EDisplayMemoryHandle, handle); |
|
109 |
test ((KErrNone == ret || KErrNotSupported == ret)); |
|
110 |
if (KErrNone == ret) |
|
111 |
{ |
|
112 |
// Handle should not be zero. |
|
113 |
test(0 != handle); |
|
114 |
ret = chunk.SetReturnedHandle(handle); |
|
115 |
test(KErrNone == ret); |
|
116 |
||
117 |
pChunkBase = reinterpret_cast<TUint32 *>(chunk.Base()); |
|
118 |
*pChunkBase = KTestValue2; |
|
119 |
test(KTestValue2 == *pChunkBase); |
|
120 |
// We should see the new value through the pMemory pointer! |
|
121 |
if (pMemory) |
|
122 |
{ |
|
123 |
test(KTestValue2 == *pMemory); |
|
124 |
} |
|
80
597aaf25e343
Revision: 201008
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
125 |
// print it after test as this will corrupt memory buffer |
597aaf25e343
Revision: 201008
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
126 |
test.Printf(_L("Display Memory Address = %08x\n"), reinterpret_cast<TUint>(pChunkBase)); |
0 | 127 |
} |
128 |
else |
|
129 |
{ |
|
130 |
test.Printf(_L("Memory Handle not available from HAL - no point in further testing\n")); |
|
131 |
return; |
|
132 |
} |
|
133 |
||
134 |
||
135 |
// Check that we can write to more than the first bit of memory. |
|
136 |
test.Next(_L("Check that we can write to \"all\" of the memory")); |
|
137 |
// First, find the mode with the biggest number of bits per pixel: |
|
138 |
TInt totalModes; |
|
139 |
ret = HAL::Get(aScreenID, HAL::EDisplayNumModes, totalModes); |
|
140 |
test (KErrNone == ret); |
|
141 |
TInt biggestMode = 0; |
|
142 |
TInt maxBitsPerPixel = 0; |
|
143 |
for(TInt mode = 0; mode < totalModes; mode++) |
|
144 |
{ |
|
145 |
TInt bitsPerPixel = mode; |
|
146 |
ret = HAL::Get(aScreenID, HAL::EDisplayBitsPerPixel, bitsPerPixel); |
|
147 |
test (KErrNone == ret); |
|
148 |
if (bitsPerPixel > maxBitsPerPixel) |
|
149 |
{ |
|
150 |
maxBitsPerPixel = bitsPerPixel; |
|
151 |
biggestMode = mode; |
|
152 |
} |
|
153 |
} |
|
154 |
||
155 |
TInt offsetToFirstPixel = biggestMode; |
|
156 |
ret = HAL::Get(aScreenID, HALData::EDisplayOffsetToFirstPixel, offsetToFirstPixel); |
|
157 |
test(KErrNone == ret); |
|
158 |
||
159 |
TInt stride = biggestMode; |
|
160 |
ret = HAL::Get(aScreenID, HALData::EDisplayOffsetBetweenLines, stride); |
|
161 |
test(KErrNone == ret); |
|
162 |
||
163 |
TInt yPixels = biggestMode; |
|
164 |
ret = HAL::Get(aScreenID, HALData::EDisplayYPixels, yPixels); |
|
165 |
test(KErrNone == ret); |
|
166 |
||
167 |
// Note this is no attempt to be precise. xPixels is not |
|
168 |
TUint maxByte = offsetToFirstPixel + stride * yPixels - sizeof(TUint32); |
|
169 |
||
170 |
volatile TUint32 *memPtr = reinterpret_cast<volatile TUint32 *>(reinterpret_cast<volatile TUint8 *>(pChunkBase) + maxByte); |
|
171 |
*memPtr = KTestValue1; |
|
172 |
test(KTestValue1 == *memPtr); |
|
173 |
||
174 |
||
175 |
// Ask for a second handle and see that this also points to the same bit of memory. |
|
176 |
test.Next(_L("Checking Display Handle second time")); |
|
177 |
volatile TUint32 *pChunkBase2 = 0; |
|
178 |
ret = HAL::Get(aScreenID, HALData::EDisplayMemoryHandle, handle); |
|
179 |
test ((KErrNone == ret || KErrNotSupported == ret)); |
|
180 |
if (KErrNone == ret) |
|
181 |
{ |
|
182 |
// Handle should not be zero! |
|
183 |
test(0 != handle); |
|
184 |
RChunk chunk2; |
|
185 |
ret = chunk2.SetReturnedHandle(handle); |
|
186 |
test(KErrNone == ret); |
|
187 |
||
188 |
pChunkBase2 = reinterpret_cast<TUint32 *>(chunk2.Base()); |
|
189 |
test(KTestValue2 == *pChunkBase2); |
|
190 |
*pChunkBase2 = KTestValue3; |
|
191 |
test(KTestValue3 == *pChunkBase2); |
|
80
597aaf25e343
Revision: 201008
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
192 |
// print it after test as this will corrupt memory buffer |
597aaf25e343
Revision: 201008
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
193 |
test.Printf(_L("Display Memory Address = %08x\n"), reinterpret_cast<TUint>(pChunkBase)); |
0 | 194 |
chunk2.Close(); |
195 |
} |
|
196 |
||
197 |
test.Next(_L("Checking Display Handle using second process")); |
|
198 |
||
199 |
// Create a process, let it find the handle of the memory, then read it, and write it. |
|
200 |
// Check that the value we have is the new value: KTestValue3. |
|
201 |
_LIT(KProcName, "t_videomemprocess.exe"); |
|
202 |
RProcess process; |
|
203 |
||
204 |
ret = process.Create(KProcName, KNullDesC); |
|
205 |
test(KErrNone == ret); |
|
206 |
||
207 |
TRequestStatus procStatus; |
|
208 |
process.Logon(procStatus); |
|
209 |
process.SetParameter(12, aScreenID); |
|
210 |
process.Resume(); |
|
211 |
User::WaitForRequest(procStatus); |
|
212 |
||
213 |
test.Next(_L("Checking that second process updated video memory")); |
|
214 |
// Check that we got the new value. |
|
215 |
test(KTestValue4 == *pChunkBase); |
|
216 |
||
217 |
chunk.Close(); |
|
218 |
||
219 |
#ifdef __WINS__ |
|
220 |
displayChannel.Close(); |
|
221 |
#endif |
|
222 |
||
223 |
// Now for some negative tests: Attempt to get a handle for a closes display. |
|
224 |
test.Next(_L("Negative test: Check that we CAN NOT use closed screen")); |
|
225 |
ret = HAL::Get(aScreenID, HALData::EDisplayMemoryHandle, handle); |
|
226 |
test (KErrNone != ret); |
|
227 |
} |
|
228 |
||
229 |
||
230 |
||
231 |
LOCAL_C void NegativeTests(TInt aMaxScreens) |
|
232 |
{ |
|
233 |
TInt handle; |
|
234 |
TInt ret; |
|
235 |
// Another few negative tests: Try invalid screen numbers. |
|
236 |
test.Next(_L("Negative tests: Invalid screen ID's")); |
|
237 |
ret = HAL::Get(aMaxScreens, HALData::EDisplayMemoryHandle, handle); |
|
238 |
test (KErrNone != ret); |
|
239 |
||
240 |
ret = HAL::Get(aMaxScreens+1, HALData::EDisplayMemoryHandle, handle); |
|
241 |
test (KErrNone != ret); |
|
242 |
||
243 |
ret = HAL::Get(4718, HALData::EDisplayMemoryHandle, handle); |
|
244 |
test (KErrNone != ret); |
|
245 |
||
246 |
ret = HAL::Get(-1, HALData::EDisplayMemoryHandle, handle); |
|
247 |
test (KErrNone != ret); |
|
248 |
} |
|
249 |
||
250 |
||
251 |
||
252 |
GLDEF_C TInt E32Main() |
|
253 |
// |
|
254 |
// |
|
255 |
{ |
|
256 |
||
257 |
test.Title(); |
|
258 |
// |
|
259 |
#if defined(__EPOC32__) && defined(__CPU_X86) |
|
260 |
test.Printf(_L("Doesn't run on X86\n")); |
|
261 |
#else |
|
262 |
||
263 |
test.Start(_L("Testing Video Memory HAL interfaces")); |
|
264 |
||
265 |
TInt screens = 0; |
|
266 |
TInt ret=HAL::Get(HAL::EDisplayNumberOfScreens, screens); |
|
267 |
test((KErrNone == ret)); |
|
268 |
// We expect that there is at least ONE screen. |
|
269 |
test((screens > 0)); |
|
270 |
||
271 |
for(TInt i=0;i<screens;i++) |
|
272 |
{ |
|
273 |
RunTestsForScreen(i); |
|
274 |
} |
|
275 |
||
276 |
NegativeTests(screens); |
|
277 |
#endif |
|
278 |
||
279 |
return KErrNone; |
|
280 |
} |