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