Update contrib.
1 // Copyright (c) 1998-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\device\t_tldd.cpp
16 // Test device driver loading and unloading and
17 // the RBusLogicalChannel hook functionality.
19 // RBusLogicalChannel, DLogicalChannel, Kern::InstallLogicalDevice.
21 // - Test loading the test logical device driver "D_LDD" and creating a logical
23 // - Test initialisation of LDD data and bss sections
24 // - Test passing data to driver and back, and storing it in data/bss/heap
26 // - Test contructors were called for driver global data
27 // - Test functionality of Kern::InstallLogicalDevice by asking the test LDD
28 // to create a second device. Check this device works, and check it goes
30 // - Check the return value as KErrInUse when the LDD close method is called
31 // before closing the handle.
32 // - Close the handle and unload the device, verify success.
33 // - Check that no memory is leaked on the kernel heap
34 // - Load the logical device driver again and verify that the global variables
35 // and bss have been reinitialized.
36 // - Close the handle and unload the device, verify success.
37 // - Test User::LoadLogicalDevice and User::FreeLogicalDevice APIs, including
38 // free whilst in use and load whilst already loaded
39 // - On hardware, repeat all tests with the "D_LDD_RAM" device driver.
40 // - Check the return value is KErrNotSupported when trying to load invalid
41 // logical device driver.
42 // Platforms/Drives/Compatibility:
44 // Assumptions/Requirement/Pre-requisites:
45 // Failures and causes:
46 // Base Port information:
53 #include <e32def_private.h>
56 _LIT(KLddFileName, "D_LDD.LDD");
57 _LIT(KLddFileNameBadUid, "D_LDDNS.LDD");
60 _LIT(KLddFileNameRam, "D_LDD_RAM.LDD");
64 GLDEF_D RTest test(_L("LDD tests"));
66 void DoTest(const TDesC& aLddFileName)
69 test.Start(_L("Loading LDD"));
71 // Need to load/unload before doing __KHEAP_MARK to ensure kernel's CodeChunk has been created
72 r=User::LoadLogicalDevice(aLddFileName);
73 test.Printf(_L("Returned %d\n"), r);
75 test.Next(_L("Unloading LDD"));
76 r = RLddTest::UnloadAndWait();
77 test.Printf(_L("Returned %d\n"), r);
79 test.Next(_L("Loading LDD"));
82 r=User::LoadLogicalDevice(aLddFileName);
83 test.Printf(_L("Returned %d\n"), r);
85 test.Next(_L("Opening device driver"));
86 test(ldd.Open()==KErrNone);
87 test.Next(_L("Test LDD global static function pointer"));
89 test.Printf(_L("%x\n"), r);
90 test.Next(_L("Test LDD global static data"));
92 test.Printf(_L("%x\n"), r);
95 test.Printf(_L("%x\n"), r);
98 test.Printf(_L("%x\n"), r);
101 test.Printf(_L("%x\n"), r);
104 test.Printf(_L("%x\n"), r);
106 test.Next(_L("Test LDD .bss"));
108 test.Printf(_L("%x\n"), r);
110 r=ldd.Test6(299792458);
111 test.Printf(_L("%x\n"), r);
114 test.Printf(_L("%x\n"), r);
116 test.Next(_L("Test global constructors"));
117 TUint32 v = ldd.Test7();
118 test.Printf(_L("iInt = %u\n"),v);
121 test.Printf(_L("Verify returned %d\n"), r);
125 test.Printf(_L("iInt = %u\n"),v);
128 test.Printf(_L("Verify returned %d\n"), r);
131 test.Next(_L("Test linked global static function pointer"));
133 test.Printf(_L("%x\n"), r);
134 test.Next(_L("Test linked global static data"));
136 test.Printf(_L("%x\n"), r);
139 test.Printf(_L("%x\n"), r);
142 test.Printf(_L("%x\n"), r);
145 test.Printf(_L("%x\n"), r);
148 test.Printf(_L("%x\n"), r);
150 test.Next(_L("Test linked .bss"));
152 test.Printf(_L("%x\n"), r);
154 r=ldd.LinkedTest6(299792458);
155 test.Printf(_L("%x\n"), r);
158 test.Printf(_L("%x\n"), r);
160 test.Next(_L("Test linked global constructors"));
161 v = ldd.LinkedTest7();
162 test.Printf(_L("iInt = %u\n"),v);
164 r = ldd.LinkedTest9();
165 test.Printf(_L("Verify returned %d\n"), r);
167 ldd.LinkedTest8(488);
168 v = ldd.LinkedTest7();
169 test.Printf(_L("iInt = %u\n"),v);
171 r = ldd.LinkedTest9();
172 test.Printf(_L("Verify returned %d\n"), r);
176 test.Next(_L("Test behaviour of Kern::InstallLogicalDevice"));
179 test(r==KErrNotFound);
180 r = ldd.TestKInstall();
185 r = User::FreeLogicalDevice(KKInstallLddName);
188 test(r==KErrNotFound);
190 test.Next(_L("Try to unload with open channel"));
194 r = RLddTest::UnloadAndWait();
195 test.Printf(_L("Returned %d\n"), r);
198 test.Next(_L("Close"));
200 test.Next(_L("Unload"));
201 r = RLddTest::UnloadAndWait();
202 test.Printf(_L("Returned %d\n"), r);
205 test.Next(_L("Reload"));
206 r=User::LoadLogicalDevice(aLddFileName);
207 test.Printf(_L("Returned %d\n"), r);
209 test.Next(_L("Open again"));
210 test(ldd.Open()==KErrNone);
212 test.Next(_L("Test data re-initialised"));
214 test.Printf(_L("%x\n"), r);
216 test.Next(_L("Test .bss reinitialised"));
218 test.Printf(_L("%x\n"), r);
221 test.Printf(_L("iInt = %u\n"),v);
224 test.Printf(_L("Verify returned %d\n"), r);
227 test.Next(_L("Test linked data re-initialised"));
229 test.Printf(_L("%x\n"), r);
231 test.Next(_L("Test linked .bss reinitialised"));
233 test.Printf(_L("%x\n"), r);
235 v = ldd.LinkedTest7();
236 test.Printf(_L("iInt = %u\n"),v);
238 r = ldd.LinkedTest9();
239 test.Printf(_L("Verify returned %d\n"), r);
244 test.Next(_L("Unload"));
245 r = RLddTest::Unload();
247 r=User::LoadLogicalDevice(aLddFileName);
249 r = RLddTest::UnloadAndWait();
250 test.Printf(_L("Returned %d\n"), r);
253 // Tests for User::LoadLogicalDevice and User::FreeLogicalDevice
255 test.Next(_L("Load Device"));
256 r=User::LoadLogicalDevice(aLddFileName);
258 test.Next(_L("Open Device"));
259 r=device.Open(KLddName);
261 test.Next(_L("Unload whilst in use"));
262 r = User::FreeLogicalDevice(KLddName);;
264 test.Next(_L("Close Device"));
266 test.Next(_L("Unload"));
267 r = User::FreeLogicalDevice(KLddName);;
270 test.Next(_L("Load Device"));
271 r=User::LoadLogicalDevice(aLddFileName);
273 test.Next(_L("Load Device again"));
274 r=User::LoadLogicalDevice(aLddFileName);
275 test(r==KErrAlreadyExists);
276 test.Next(_L("Unload"));
277 r = User::FreeLogicalDevice(KLddName);;
284 void DoTest2(const TDesC& aLddFileName)
286 test.Start(_L("Test repeated loading/unloading of RAM-based LDD"));
288 // This tests repeated loading and unloading works, and that it always
289 // re-loads the LDD code to the same address
292 for (TInt i = 0 ; i < 100 ; ++i)
294 test(User::LoadLogicalDevice(aLddFileName)==KErrNone);
295 test(ldd.Open()==KErrNone);
300 test(func==ldd.Test1());
303 test(User::FreeLogicalDevice(KLddName)==KErrNone);
308 GLDEF_C TInt E32Main()
310 // Test LDD static data
315 test.Start(_L("Test device driver loading and unloading"));
317 DoTest(KLddFileName);
319 DoTest(KLddFileNameRam);
320 DoTest2(KLddFileNameRam);
323 r=User::LoadLogicalDevice(KLddFileNameBadUid);
324 test(r==KErrNotSupported);