os/kernelhwsrv/kerneltest/e32test/device/t_tldd.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) 1998-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
// e32test\device\t_tldd.cpp
sl@0
    15
// Overview:
sl@0
    16
// Test device driver loading and unloading and
sl@0
    17
// the RBusLogicalChannel hook functionality.
sl@0
    18
// API Information:
sl@0
    19
// RBusLogicalChannel, DLogicalChannel, Kern::InstallLogicalDevice.
sl@0
    20
// Details:
sl@0
    21
// - Test loading the test logical device driver "D_LDD" and creating a logical
sl@0
    22
// channel.
sl@0
    23
// - Test initialisation of LDD data and bss sections
sl@0
    24
// - Test passing data to driver and back, and storing it in data/bss/heap
sl@0
    25
// areas
sl@0
    26
// - Test contructors were called for driver global data
sl@0
    27
// - Test functionality of Kern::InstallLogicalDevice by asking the test LDD
sl@0
    28
// to create a second device. Check this device works, and check it goes
sl@0
    29
// away when freed.
sl@0
    30
// - Check the return value as KErrInUse when the LDD close method is called 
sl@0
    31
// before closing the handle.
sl@0
    32
// - Close the handle and unload the device, verify success.
sl@0
    33
// - Check that no memory is leaked on the kernel heap
sl@0
    34
// - Load the logical device driver again and verify that the global variables
sl@0
    35
// and bss have been reinitialized.
sl@0
    36
// - Close the handle and unload the device, verify success.
sl@0
    37
// - Test User::LoadLogicalDevice and User::FreeLogicalDevice APIs, including
sl@0
    38
// free whilst in use and load whilst already loaded
sl@0
    39
// - On hardware, repeat all tests with the "D_LDD_RAM" device driver.
sl@0
    40
// - Check the return value is KErrNotSupported when trying to load invalid 
sl@0
    41
// logical device driver.
sl@0
    42
// Platforms/Drives/Compatibility:
sl@0
    43
// All.
sl@0
    44
// Assumptions/Requirement/Pre-requisites:
sl@0
    45
// Failures and causes:
sl@0
    46
// Base Port information:
sl@0
    47
// 
sl@0
    48
//
sl@0
    49
sl@0
    50
#include <e32test.h>
sl@0
    51
#include <e32hal.h>
sl@0
    52
#include <e32def.h>
sl@0
    53
#include <e32def_private.h>
sl@0
    54
#include "d_ldd.h"
sl@0
    55
sl@0
    56
_LIT(KLddFileName, "D_LDD.LDD");
sl@0
    57
_LIT(KLddFileNameBadUid, "D_LDDNS.LDD");
sl@0
    58
sl@0
    59
#ifdef __EPOC32__
sl@0
    60
_LIT(KLddFileNameRam, "D_LDD_RAM.LDD");
sl@0
    61
#endif
sl@0
    62
sl@0
    63
GLDEF_D RLddTest ldd;
sl@0
    64
GLDEF_D RTest test(_L("LDD tests"));
sl@0
    65
sl@0
    66
void DoTest(const TDesC& aLddFileName)
sl@0
    67
	{
sl@0
    68
	TInt r;
sl@0
    69
    test.Start(_L("Loading LDD"));
sl@0
    70
#ifdef __EPOC32__
sl@0
    71
	// Need to load/unload before doing __KHEAP_MARK to ensure kernel's CodeChunk has been created
sl@0
    72
	r=User::LoadLogicalDevice(aLddFileName);
sl@0
    73
	test.Printf(_L("Returned %d\n"), r);
sl@0
    74
    test(r==KErrNone);
sl@0
    75
    test.Next(_L("Unloading LDD"));
sl@0
    76
	r = RLddTest::UnloadAndWait();
sl@0
    77
	test.Printf(_L("Returned %d\n"), r);
sl@0
    78
	test(r==KErrNone);
sl@0
    79
    test.Next(_L("Loading LDD"));
sl@0
    80
#endif
sl@0
    81
	__KHEAP_MARK;
sl@0
    82
	r=User::LoadLogicalDevice(aLddFileName);
sl@0
    83
	test.Printf(_L("Returned %d\n"), r);
sl@0
    84
    test(r==KErrNone);
sl@0
    85
    test.Next(_L("Opening device driver"));
sl@0
    86
	test(ldd.Open()==KErrNone);
sl@0
    87
	test.Next(_L("Test LDD global static function pointer"));
sl@0
    88
	r=ldd.Test1();
sl@0
    89
	test.Printf(_L("%x\n"), r);
sl@0
    90
	test.Next(_L("Test LDD global static data"));
sl@0
    91
	r=ldd.Test2();
sl@0
    92
	test.Printf(_L("%x\n"), r);
sl@0
    93
	test(r==0x100);
sl@0
    94
	r=ldd.Test2();
sl@0
    95
	test.Printf(_L("%x\n"), r);
sl@0
    96
	test(r==0x101);
sl@0
    97
	r=ldd.Test2();
sl@0
    98
	test.Printf(_L("%x\n"), r);
sl@0
    99
	test(r==0x102);
sl@0
   100
	r=ldd.Test3();
sl@0
   101
	test.Printf(_L("%x\n"), r);
sl@0
   102
	test(r==0x103);
sl@0
   103
	r=ldd.Test3();
sl@0
   104
	test.Printf(_L("%x\n"), r);
sl@0
   105
	test(r==0x102);
sl@0
   106
	test.Next(_L("Test LDD .bss"));
sl@0
   107
	r=ldd.Test5();
sl@0
   108
	test.Printf(_L("%x\n"), r);
sl@0
   109
	test(r==0);
sl@0
   110
	r=ldd.Test6(299792458);
sl@0
   111
	test.Printf(_L("%x\n"), r);
sl@0
   112
	test(r==KErrNone);
sl@0
   113
	r=ldd.Test5();
sl@0
   114
	test.Printf(_L("%x\n"), r);
sl@0
   115
	test(r==299792458);
sl@0
   116
	test.Next(_L("Test global constructors"));
sl@0
   117
	TUint32 v = ldd.Test7();
sl@0
   118
	test.Printf(_L("iInt = %u\n"),v);
sl@0
   119
	test(v==487);
sl@0
   120
	r = ldd.Test9();
sl@0
   121
	test.Printf(_L("Verify returned %d\n"), r);
sl@0
   122
	test(r==KErrNone);
sl@0
   123
	ldd.Test8(488);
sl@0
   124
	v = ldd.Test7();
sl@0
   125
	test.Printf(_L("iInt = %u\n"),v);
sl@0
   126
	test(v==488);
sl@0
   127
	r = ldd.Test9();
sl@0
   128
	test.Printf(_L("Verify returned %d\n"), r);
sl@0
   129
	test(r==KErrNone);
sl@0
   130
sl@0
   131
	test.Next(_L("Test linked global static function pointer"));
sl@0
   132
	r=ldd.LinkedTest1();
sl@0
   133
	test.Printf(_L("%x\n"), r);
sl@0
   134
	test.Next(_L("Test linked global static data"));
sl@0
   135
	r=ldd.LinkedTest2();
sl@0
   136
	test.Printf(_L("%x\n"), r);
sl@0
   137
	test(r==0x100);
sl@0
   138
	r=ldd.LinkedTest2();
sl@0
   139
	test.Printf(_L("%x\n"), r);
sl@0
   140
	test(r==0x101);
sl@0
   141
	r=ldd.LinkedTest2();
sl@0
   142
	test.Printf(_L("%x\n"), r);
sl@0
   143
	test(r==0x102);
sl@0
   144
	r=ldd.LinkedTest3();
sl@0
   145
	test.Printf(_L("%x\n"), r);
sl@0
   146
	test(r==0x103);
sl@0
   147
	r=ldd.LinkedTest3();
sl@0
   148
	test.Printf(_L("%x\n"), r);
sl@0
   149
	test(r==0x102);
sl@0
   150
	test.Next(_L("Test linked .bss"));
sl@0
   151
	r=ldd.LinkedTest5();
sl@0
   152
	test.Printf(_L("%x\n"), r);
sl@0
   153
	test(r==0);
sl@0
   154
	r=ldd.LinkedTest6(299792458);
sl@0
   155
	test.Printf(_L("%x\n"), r);
sl@0
   156
	test(r==KErrNone);
sl@0
   157
	r=ldd.LinkedTest5();
sl@0
   158
	test.Printf(_L("%x\n"), r);
sl@0
   159
	test(r==299792458);
sl@0
   160
	test.Next(_L("Test linked global constructors"));
sl@0
   161
	v = ldd.LinkedTest7();
sl@0
   162
	test.Printf(_L("iInt = %u\n"),v);
sl@0
   163
	test(v==487);
sl@0
   164
	r = ldd.LinkedTest9();
sl@0
   165
	test.Printf(_L("Verify returned %d\n"), r);
sl@0
   166
	test(r==KErrNone);
sl@0
   167
	ldd.LinkedTest8(488);
sl@0
   168
	v = ldd.LinkedTest7();
sl@0
   169
	test.Printf(_L("iInt = %u\n"),v);
sl@0
   170
	test(v==488);
sl@0
   171
	r = ldd.LinkedTest9();
sl@0
   172
	test.Printf(_L("Verify returned %d\n"), r);
sl@0
   173
	test(r==KErrNone);
sl@0
   174
sl@0
   175
sl@0
   176
	test.Next(_L("Test behaviour of Kern::InstallLogicalDevice"));
sl@0
   177
	RKInstallTest ki;
sl@0
   178
	r = ki.Open();
sl@0
   179
	test(r==KErrNotFound);
sl@0
   180
	r = ldd.TestKInstall();
sl@0
   181
	test(r==KErrNone);
sl@0
   182
	r = ki.Open();
sl@0
   183
	test(r==KErrNone);
sl@0
   184
	ki.Close();
sl@0
   185
	r = User::FreeLogicalDevice(KKInstallLddName);
sl@0
   186
	test(r==KErrNone);
sl@0
   187
	r = ki.Open();
sl@0
   188
	test(r==KErrNotFound);
sl@0
   189
	
sl@0
   190
	test.Next(_L("Try to unload with open channel"));
sl@0
   191
	TInt i;
sl@0
   192
	for (i=0; i<10; ++i)
sl@0
   193
		{
sl@0
   194
		r = RLddTest::UnloadAndWait();
sl@0
   195
		test.Printf(_L("Returned %d\n"), r);
sl@0
   196
		test(r==KErrInUse);
sl@0
   197
		}
sl@0
   198
	test.Next(_L("Close"));
sl@0
   199
	ldd.Close();
sl@0
   200
	test.Next(_L("Unload"));
sl@0
   201
	r = RLddTest::UnloadAndWait();
sl@0
   202
	test.Printf(_L("Returned %d\n"), r);
sl@0
   203
	test(r==KErrNone);
sl@0
   204
	__KHEAP_MARKEND;
sl@0
   205
	test.Next(_L("Reload"));
sl@0
   206
	r=User::LoadLogicalDevice(aLddFileName);
sl@0
   207
	test.Printf(_L("Returned %d\n"), r);
sl@0
   208
    test(r==KErrNone);
sl@0
   209
	test.Next(_L("Open again"));
sl@0
   210
	test(ldd.Open()==KErrNone);
sl@0
   211
sl@0
   212
	test.Next(_L("Test data re-initialised"));
sl@0
   213
	r=ldd.Test4();
sl@0
   214
	test.Printf(_L("%x\n"), r);
sl@0
   215
	test(r==0x100);
sl@0
   216
	test.Next(_L("Test .bss reinitialised"));
sl@0
   217
	r=ldd.Test5();
sl@0
   218
	test.Printf(_L("%x\n"), r);
sl@0
   219
	test(r==0);
sl@0
   220
	v = ldd.Test7();
sl@0
   221
	test.Printf(_L("iInt = %u\n"),v);
sl@0
   222
	test(v==487);
sl@0
   223
	r = ldd.Test9();
sl@0
   224
	test.Printf(_L("Verify returned %d\n"), r);
sl@0
   225
	test(r==KErrNone);
sl@0
   226
	
sl@0
   227
	test.Next(_L("Test linked data re-initialised"));
sl@0
   228
	r=ldd.LinkedTest4();
sl@0
   229
	test.Printf(_L("%x\n"), r);
sl@0
   230
	test(r==0x100);
sl@0
   231
	test.Next(_L("Test linked .bss reinitialised"));
sl@0
   232
	r=ldd.LinkedTest5();
sl@0
   233
	test.Printf(_L("%x\n"), r);
sl@0
   234
	test(r==0);
sl@0
   235
	v = ldd.LinkedTest7();
sl@0
   236
	test.Printf(_L("iInt = %u\n"),v);
sl@0
   237
	test(v==487);
sl@0
   238
	r = ldd.LinkedTest9();
sl@0
   239
	test.Printf(_L("Verify returned %d\n"), r);
sl@0
   240
	test(r==KErrNone);
sl@0
   241
sl@0
   242
	ldd.Close();
sl@0
   243
sl@0
   244
	test.Next(_L("Unload"));
sl@0
   245
	r = RLddTest::Unload();
sl@0
   246
	test(r==KErrNone);
sl@0
   247
	r=User::LoadLogicalDevice(aLddFileName);
sl@0
   248
    test(r==KErrNone);
sl@0
   249
	r = RLddTest::UnloadAndWait();
sl@0
   250
	test.Printf(_L("Returned %d\n"), r);
sl@0
   251
	test(r==KErrNone);
sl@0
   252
sl@0
   253
	// Tests for User::LoadLogicalDevice and User::FreeLogicalDevice
sl@0
   254
	RDevice device;
sl@0
   255
	test.Next(_L("Load Device"));
sl@0
   256
	r=User::LoadLogicalDevice(aLddFileName);
sl@0
   257
    test(r==KErrNone);
sl@0
   258
	test.Next(_L("Open Device"));
sl@0
   259
	r=device.Open(KLddName);
sl@0
   260
    test(r==KErrNone);
sl@0
   261
	test.Next(_L("Unload whilst in use"));
sl@0
   262
	r = User::FreeLogicalDevice(KLddName);;
sl@0
   263
	test(r==KErrInUse);
sl@0
   264
	test.Next(_L("Close Device"));
sl@0
   265
	device.Close();
sl@0
   266
	test.Next(_L("Unload"));
sl@0
   267
	r = User::FreeLogicalDevice(KLddName);;
sl@0
   268
	test(r==KErrNone);
sl@0
   269
sl@0
   270
	test.Next(_L("Load Device"));
sl@0
   271
	r=User::LoadLogicalDevice(aLddFileName);
sl@0
   272
    test(r==KErrNone);
sl@0
   273
	test.Next(_L("Load Device again"));
sl@0
   274
	r=User::LoadLogicalDevice(aLddFileName);
sl@0
   275
    test(r==KErrAlreadyExists);
sl@0
   276
	test.Next(_L("Unload"));
sl@0
   277
	r = User::FreeLogicalDevice(KLddName);;
sl@0
   278
	test(r==KErrNone);
sl@0
   279
	
sl@0
   280
	test.End();
sl@0
   281
	}
sl@0
   282
sl@0
   283
sl@0
   284
void DoTest2(const TDesC& aLddFileName)
sl@0
   285
	{
sl@0
   286
    test.Start(_L("Test repeated loading/unloading of RAM-based LDD"));
sl@0
   287
sl@0
   288
	// This tests repeated loading and unloading works, and that it always
sl@0
   289
	// re-loads the LDD code to the same address
sl@0
   290
	
sl@0
   291
	TInt func = 0;
sl@0
   292
	for (TInt i = 0 ; i < 100 ; ++i)
sl@0
   293
		{
sl@0
   294
		test(User::LoadLogicalDevice(aLddFileName)==KErrNone);
sl@0
   295
		test(ldd.Open()==KErrNone);
sl@0
   296
sl@0
   297
		if (i == 0)
sl@0
   298
			func=ldd.Test1();
sl@0
   299
		else	
sl@0
   300
			test(func==ldd.Test1());
sl@0
   301
		
sl@0
   302
		ldd.Close();
sl@0
   303
		test(User::FreeLogicalDevice(KLddName)==KErrNone);
sl@0
   304
		}
sl@0
   305
	test.End();
sl@0
   306
	}
sl@0
   307
sl@0
   308
GLDEF_C TInt E32Main()
sl@0
   309
//
sl@0
   310
// Test LDD static data
sl@0
   311
//
sl@0
   312
    {
sl@0
   313
	TInt r;
sl@0
   314
	test.Title();
sl@0
   315
	test.Start(_L("Test device driver loading and unloading"));
sl@0
   316
sl@0
   317
	DoTest(KLddFileName);
sl@0
   318
#ifdef __EPOC32__
sl@0
   319
	DoTest(KLddFileNameRam);
sl@0
   320
	DoTest2(KLddFileNameRam);
sl@0
   321
#endif
sl@0
   322
sl@0
   323
	r=User::LoadLogicalDevice(KLddFileNameBadUid);
sl@0
   324
	test(r==KErrNotSupported);
sl@0
   325
sl@0
   326
    test.End();
sl@0
   327
	return(KErrNone);
sl@0
   328
    }
sl@0
   329