|
1 // Copyright (c) 2007-2010 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 "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 // Tests for manual execution. |
|
15 |
|
16 /** |
|
17 @file |
|
18 @test |
|
19 @internalComponent - Graphics Resource API Conformance Test Suite |
|
20 */ |
|
21 |
|
22 #include "tsggenericmanual.h" |
|
23 |
|
24 CTSgGenericManual::CTSgGenericManual(TBool aConformanceTests) : |
|
25 CTSgTestStepBase(aConformanceTests) |
|
26 { |
|
27 INFO_PRINTF1(_L("Graphics resource component test - Generic Manual Tests.\r\n")); |
|
28 } |
|
29 |
|
30 CTSgGenericManual::~CTSgGenericManual() |
|
31 { |
|
32 iSecondProcess.Close(); |
|
33 iMsgQ.Close(); |
|
34 } |
|
35 |
|
36 /** |
|
37 This is intented to be used for TestStressResourceLeakL (GRAPHICS-RESOURCE-0050) test. |
|
38 It creates images until the memory full situation. The images are kept in the passed RArray of RSgImage. |
|
39 The returned error code is expected to be either KErrNoMemory or KErrNoGraphicsMemory. |
|
40 Optionally, it opens and closes a duplicate handle to each image in the same process and in another process. |
|
41 */ |
|
42 TInt CTSgGenericManual::CreateImages(const TSgImageInfo& aInfo, RArray<RSgImage>& aTestImages, TBool aDuplicate) |
|
43 { |
|
44 TInt err = KErrNone; |
|
45 while(err == KErrNone) |
|
46 { |
|
47 RSgImage image; |
|
48 err = image.Create(aInfo); |
|
49 if(err == KErrNone) |
|
50 { |
|
51 err = aTestImages.Append(image); |
|
52 if (err != KErrNone) |
|
53 { |
|
54 image.Close(); |
|
55 return err; |
|
56 } |
|
57 if (aDuplicate) |
|
58 { |
|
59 RSgImage image2; |
|
60 err = image2.Open(image.Id()); |
|
61 if (err != KErrNone) |
|
62 { |
|
63 return err; |
|
64 } |
|
65 // send the image ID to the second process and wait until the |
|
66 // second process has opened and closed a handle to the image |
|
67 TRequestStatus status; |
|
68 iSecondProcess.Rendezvous(status); |
|
69 iMsgQ.SendBlocking(image.Id()); |
|
70 User::WaitForRequest(status); |
|
71 image2.Close(); |
|
72 err = status.Int(); |
|
73 } |
|
74 } |
|
75 } |
|
76 return err; |
|
77 } |
|
78 |
|
79 void CTSgGenericManual::DestroyImages(RArray<RSgImage>& aTestImages) |
|
80 { |
|
81 TInt count = aTestImages.Count(); |
|
82 for(TInt i=0; i<count; ++i) |
|
83 { |
|
84 aTestImages[i].Close(); |
|
85 } |
|
86 aTestImages.Reset(); |
|
87 } |
|
88 |
|
89 /** |
|
90 @leave Gets system wide error code |
|
91 @return TVerdict code |
|
92 */ |
|
93 TVerdict CTSgGenericManual::doTestStepL() |
|
94 { |
|
95 SetTestStepID(_L("GRAPHICS-RESOURCE-0050")); |
|
96 INFO_PRINTF1(_L("RSgImage generic resource leak stress test.\r\n")); |
|
97 TestStressResourceLeakL(); |
|
98 RecordTestResultL(); |
|
99 |
|
100 return TestStepResult(); |
|
101 } |
|
102 |
|
103 /** |
|
104 @SYMTestCaseID GRAPHICS-RESOURCE-0050 |
|
105 @SYMTestCaseDesc RSgImage exhaustive and resource leak test |
|
106 @SYMPREQ PREQ2637 |
|
107 @SYMFssID RSgImage::Create(const TSgImageInfo&, const TAny*, TInt) |
|
108 RSgImage::Open(TSgDrawableId) |
|
109 RSgImage::Close() |
|
110 @SYMTestPriority Medium |
|
111 @SYMTestType CT |
|
112 @SYMTestPurpose To ensure no resource leaks while creating and destroying RSgImage multiple times |
|
113 @SYMTestActions Create images until it returns no memory error. Close the created images and |
|
114 create as many images as possible until memory is full. Test the number of images |
|
115 created and also for each iteration the number of images created to be the same. |
|
116 @SYMTestExpectedResults There should be no panics or leaves. |
|
117 */ |
|
118 void CTSgGenericManual::TestStressResourceLeakL() |
|
119 { |
|
120 TestOpenDriverL(); |
|
121 _LIT(KSection, "TestStressResourceLeak"); |
|
122 TInt numIterations; |
|
123 if (!GetIntFromConfig(KSection, _L("NumIterations"), numIterations)) |
|
124 { |
|
125 numIterations = 2; |
|
126 } |
|
127 TInt tolerance; |
|
128 if (!GetIntFromConfig(KSection, _L("Tolerance"), tolerance)) |
|
129 { |
|
130 tolerance = -1; |
|
131 } |
|
132 TInt width; |
|
133 if (!GetIntFromConfig(KSection, _L("ImageWidth"), width)) |
|
134 { |
|
135 width = 1; |
|
136 } |
|
137 TInt height; |
|
138 if (!GetIntFromConfig(KSection, _L("ImageHeight"), height)) |
|
139 { |
|
140 height = 1; |
|
141 } |
|
142 TSgImageInfo info; |
|
143 info.iPixelFormat = EUidPixelFormatRGB_565; |
|
144 info.iSizeInPixels = TSize(width, height); |
|
145 info.iUsage = ESgUsageBitOpenVgImage; |
|
146 TBool duplicate; |
|
147 if (!GetBoolFromConfig(KSection, _L("DuplicateHandle"), duplicate)) |
|
148 { |
|
149 duplicate = EFalse; |
|
150 } |
|
151 if (duplicate) |
|
152 { |
|
153 User::LeaveIfError(iMsgQ.CreateGlobal(KSgTestMultiprocessMsgQ, 1)); |
|
154 _LIT(KProcessName, "tgraphicsresourcemanualsecondprocess.exe"); |
|
155 User::LeaveIfError(iSecondProcess.Create(KProcessName, KNullDesC)); |
|
156 iSecondProcess.Resume(); |
|
157 } |
|
158 |
|
159 RArray<RSgImage> testImages; |
|
160 |
|
161 TInt count(0); |
|
162 TInt err = KErrNone; |
|
163 for (TInt i = 0; i < numIterations && err == KErrNone; ++i) |
|
164 { |
|
165 err = CreateImages(info, testImages, duplicate); |
|
166 TInt thisCount = testImages.Count(); |
|
167 DestroyImages(testImages); |
|
168 |
|
169 if (err == KErrNoMemory || err == KErrNoGraphicsMemory) |
|
170 { |
|
171 err = KErrNone; |
|
172 } |
|
173 else if (err != KErrNone) |
|
174 { |
|
175 WARN_PRINTF2(_L("Create images error [%d]"), err); |
|
176 SetTestStepResult(ETestSuiteError); |
|
177 } |
|
178 |
|
179 if (i == 0) |
|
180 { |
|
181 count = thisCount; |
|
182 } |
|
183 else |
|
184 { |
|
185 if (count != thisCount) |
|
186 { |
|
187 INFO_PRINTF4(_L("Mismatch @ iteration %d: initial %d, now %d"), i, count, thisCount); |
|
188 } |
|
189 if (tolerance >= 0) |
|
190 { |
|
191 TEST(Abs(count - thisCount) <= tolerance); |
|
192 } |
|
193 } |
|
194 } |
|
195 |
|
196 INFO_PRINTF2(_L("Last iteration: %d images created\r\n"), count); |
|
197 if (duplicate) |
|
198 { |
|
199 // send a null ID to tell the second process to kill itself |
|
200 // and wait until the second process terminates |
|
201 TRequestStatus status; |
|
202 iSecondProcess.Logon(status); |
|
203 iMsgQ.SendBlocking(KSgNullDrawableId); |
|
204 User::WaitForRequest(status); |
|
205 iMsgQ.Close(); |
|
206 iSecondProcess.Close(); |
|
207 } |
|
208 TestCloseDriver(); |
|
209 } |
|
210 |