|
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 // f32test\demandpaging\t_paginginfo.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 #include <e32test.h> |
|
19 |
|
20 RTest test(_L("t_paginginfo")); |
|
21 |
|
22 #include <e32rom.h> |
|
23 #include <u32hal.h> |
|
24 #include <f32file.h> |
|
25 #include <f32dbg.h> |
|
26 #include "testdefs.h" |
|
27 #include <hal.h> |
|
28 |
|
29 |
|
30 TInt DriveNumber=-1; // Parameter - Which drive? -1 = autodetect. |
|
31 TInt locDriveNumber; |
|
32 |
|
33 TBusLocalDrive Drive; |
|
34 TBool DisplayStats = ETrue; |
|
35 TBool ManualTest = EFalse; |
|
36 |
|
37 TInt findDataPagingDrive() |
|
38 /** |
|
39 Find the drive containing a swap partition. |
|
40 |
|
41 @return Local drive identifier. |
|
42 */ |
|
43 { |
|
44 TInt drive = KErrNotFound; |
|
45 |
|
46 test.Printf(_L("Searching for data paging drive:\n")); |
|
47 |
|
48 for(TInt i = 0; i < KMaxLocalDrives && drive < 0; ++i) |
|
49 { |
|
50 RLocalDrive d; |
|
51 TBool change = EFalse; |
|
52 |
|
53 if(d.Connect(i, change) == KErrNone) |
|
54 { |
|
55 test.Printf(_L("Connected to local drive %d\n"), i); |
|
56 TLocalDriveCapsV4 dc; |
|
57 TPckg<TLocalDriveCapsV4> capsPack(dc); |
|
58 |
|
59 if(d.Caps(capsPack) == KErrNone) |
|
60 { |
|
61 if ((dc.iMediaAtt & KMediaAttPageable) && |
|
62 (dc.iPartitionType == KPartitionTypePagedData)) |
|
63 { |
|
64 test.Printf(_L("Found swap partition on local drive %d\n"), i); |
|
65 drive = i; |
|
66 |
|
67 TPageDeviceInfo pageDeviceInfo; |
|
68 |
|
69 TPtr8 pageDeviceInfoBuf((TUint8*) &pageDeviceInfo, sizeof(pageDeviceInfo)); |
|
70 pageDeviceInfoBuf.FillZ(); |
|
71 |
|
72 TInt r = d.QueryDevice(RLocalDrive::EQueryPageDeviceInfo, pageDeviceInfoBuf); |
|
73 |
|
74 test.Printf(_L("EQueryPageDeviceInfo on local drive %d returned %d\n"), i, r); |
|
75 } |
|
76 } |
|
77 d.Close(); |
|
78 } |
|
79 } |
|
80 return drive; |
|
81 } |
|
82 |
|
83 |
|
84 |
|
85 void DisplayPageDeviceInfo(TInt aDataPagingDrive) |
|
86 { |
|
87 test.Printf(_L("Stats: \n")); |
|
88 |
|
89 SMediaPagingInfo info; |
|
90 TInt r = UserSvr::HalFunction(EHalGroupMedia,EMediaHalGetPagingInfo,(TAny*) aDataPagingDrive, &info); |
|
91 test.Printf(_L("HAL: EMediaHalGetPagingInfo returned %d\n"), r); |
|
92 if (r == KErrNone) |
|
93 { |
|
94 test.Printf(_L("iRomPageInCount %d\n"), info.iRomPageInCount); |
|
95 test.Printf(_L("iCodePageInCount %d\n"), info.iCodePageInCount); |
|
96 test.Printf(_L("iDataPageInCount %d\n"), info.iDataPageInCount); |
|
97 test.Printf(_L("iDataPageOutCount %d\n"), info.iDataPageOutCount); |
|
98 test.Printf(_L("iDataPageOutBackgroundCount %d\n"), info.iDataPageOutBackgroundCount); |
|
99 } |
|
100 |
|
101 |
|
102 RLocalDrive d; |
|
103 TBool change = EFalse; |
|
104 r = d.Connect(aDataPagingDrive, change); |
|
105 test (r == KErrNone); |
|
106 |
|
107 TPageDeviceInfo pageDeviceInfo; |
|
108 TPtr8 pageDeviceInfoBuf((TUint8*) &pageDeviceInfo, sizeof(pageDeviceInfo)); |
|
109 pageDeviceInfoBuf.FillZ(); |
|
110 r = d.QueryDevice(RLocalDrive::EQueryPageDeviceInfo, pageDeviceInfoBuf); |
|
111 test (r == KErrNone || r == KErrNotSupported); |
|
112 |
|
113 d.Close(); |
|
114 test.Printf(_L("iReservoirBlockCount %d\n"), pageDeviceInfo.iReservoirBlockCount); |
|
115 test.Printf(_L("iBadBlockCount %d\n"), pageDeviceInfo.iBadBlockCount); |
|
116 |
|
117 } |
|
118 |
|
119 // |
|
120 // The gubbins that starts all the tests |
|
121 // |
|
122 // ParseCommandLine reads the arguments and sets globals accordingly. |
|
123 // |
|
124 |
|
125 void ParseCommandLine() |
|
126 { |
|
127 TBuf<32> args; |
|
128 User::CommandLine(args); |
|
129 TLex lex(args); |
|
130 |
|
131 FOREVER |
|
132 { |
|
133 |
|
134 TPtrC token=lex.NextToken(); |
|
135 if(token.Length()!=0) |
|
136 { |
|
137 if ((token.Length()==2) && (token[1]==':')) |
|
138 DriveNumber=User::UpperCase(token[0])-'A'; |
|
139 else if (token.Length()==1) |
|
140 { |
|
141 TChar driveLetter = User::UpperCase(token[0]); |
|
142 if ((driveLetter>='A') && (driveLetter<='Z')) |
|
143 DriveNumber=driveLetter - (TChar) 'A'; |
|
144 else |
|
145 test.Printf(_L("Unknown argument '%S' was ignored.\n"), &token); |
|
146 } |
|
147 else if ((token==_L("help")) || (token==_L("-h")) || (token==_L("-?"))) |
|
148 { |
|
149 test.Printf(_L("\nUsage: t_paginginfo [enable] [disable] [stats]\n\n")); |
|
150 test.Getch(); |
|
151 } |
|
152 else if (token==_L("stats")) |
|
153 { |
|
154 DisplayStats = ETrue; |
|
155 } |
|
156 else if (token==_L("-m")) |
|
157 { |
|
158 ManualTest = ETrue; |
|
159 } |
|
160 else |
|
161 test.Printf(_L("Unknown argument '%S' was ignored.\n"), &token); |
|
162 } |
|
163 else |
|
164 break; |
|
165 |
|
166 } |
|
167 } |
|
168 |
|
169 // |
|
170 // E32Main |
|
171 // |
|
172 |
|
173 TInt E32Main() |
|
174 { |
|
175 test.Title(); |
|
176 |
|
177 test.Start(_L("Check that the rom is paged")); |
|
178 |
|
179 TRomHeader* romHeader = (TRomHeader*)UserSvr::RomHeaderAddress(); |
|
180 |
|
181 if (romHeader->iPageableRomStart==NULL) |
|
182 { |
|
183 test.Printf(_L("Test ROM is not paged - test skipped!\r\n")); |
|
184 test.End(); |
|
185 return 0; |
|
186 } |
|
187 ParseCommandLine(); |
|
188 |
|
189 TInt dataPagingDrive = findDataPagingDrive(); |
|
190 if (dataPagingDrive == KErrNotFound) |
|
191 { |
|
192 test.Printf(_L("Swap partition not found - test skipped!\r\n")); |
|
193 test.End(); |
|
194 return 0; |
|
195 } |
|
196 |
|
197 |
|
198 |
|
199 if (DisplayStats) |
|
200 { |
|
201 DisplayPageDeviceInfo(dataPagingDrive); |
|
202 |
|
203 if (ManualTest) |
|
204 test.Getch(); |
|
205 |
|
206 test.End(); |
|
207 return 0; |
|
208 } |
|
209 |
|
210 |
|
211 |
|
212 test.End(); |
|
213 return 0; |
|
214 } |
|
215 |
|
216 |