Update contrib.
1 // Copyright (c) 2002-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.
17 #include "t_property.h"
19 _LIT(KTestName,"t_stress_property");
21 RTest test(KTestName);
23 const TInt32 KUidPropTestCategoryValue = 0x101f75b8;
24 const TUid KPropTestCategory = { KUidPropTestCategoryValue };
26 #define TEST_TIME 36000 //10 hours
28 #define TEST_ERROR(rl,rr) { if((TInt)rl!=(TInt)rr) { ExitThread(rl, rr, __LINE__); return KErrGeneral; } }
30 TBool volatile StopAndExit = EFalse;
33 LOCAL_D void ExitThread(TInt rl, TInt rr, TInt aLine)
35 test.Printf(_L("Test '%S' failed at line %d; Expected value=%d Actual value=%d; \n"), &KTestName, aLine, rr, rl);
37 //delete if it's not deleted, to wake up subscribing threads waiting for events on this property
38 RProperty::Delete(KPropTestCategory,0);
41 LOCAL_D TInt LowPriorityThread1(TAny* /*aParameter*/)
47 TInt r=prop.Attach(KPropTestCategory,0);
48 TEST_ERROR(r,KErrNone);
52 buffer.SetLength(length);
53 buffer[0]=(TUint8)(length%256);
54 buffer[length-1]=(TUint8)((length-1)%256);
59 if(r!=KErrArgument && r!=KErrNotFound)
61 //if it's not of type EInt and defined
62 TEST_ERROR(r,KErrNone);
64 User::AfterHighRes(0);
70 LOCAL_D TInt LowPriorityThread2(TAny* /*aParameter*/)
75 TInt r=prop.Attach(KPropTestCategory,0);
76 TEST_ERROR(r,KErrNone);
81 if(r!=KErrArgument && r!=KErrNotFound)
83 //if it's not of type EInt and defined
84 TEST_ERROR(r,KErrNone);
85 TInt length=buffer.Length();
88 TEST_ERROR(buffer[0],length%256);
89 TEST_ERROR(buffer[length-1],(length-1)%256);
96 LOCAL_D TInt MediumPriorityThread(TAny* /*aParameter*/)
101 TInt r=prop.Attach(KPropTestCategory,0);
102 TEST_ERROR(r,KErrNone);
104 TRequestStatus status;
108 prop.Subscribe(status);
110 User::WaitForRequest(status);
113 if(status.Int() != KErrNotFound)
115 //property is defined
116 TEST_ERROR(status.Int(),KErrNone);
121 TEST_ERROR(r,KErrNone);
122 TInt length=buffer.Length();
125 TEST_ERROR(buffer[0],length%256);
126 TEST_ERROR(buffer[length-1],(length-1)%256);
135 LOCAL_D TInt HighPriorityThread(TAny* /*aParameter*/)
138 TInt type=RProperty::EInt;
144 User::AfterHighRes(1000); //wait for 1ms
146 // test.Printf(_L("Deleting property\r\n"));
147 r=RProperty::Delete(KPropTestCategory,0);
148 TEST_ERROR(r,KErrNone);
150 // test.Printf(_L("Defining property\r\n"));
151 r=RProperty::Define(KPropTestCategory,0,type, KPassPolicy, KPassPolicy);
152 TEST_ERROR(r,KErrNone);
154 type=(type+1)%RProperty::ETypeLimit;
156 if(1000 == ++iteration)
158 //check if we should exit
159 TTimeIntervalSeconds timeTaken;
162 TInt r = time.SecondsFrom(startTime, timeTaken);
163 TEST_ERROR(r,KErrNone);
165 if(timeTaken.Int() >= TEST_TIME)
170 //delete if it's not deleted, to wake up subscribing threads waiting for events on this property
171 RProperty::Delete(KPropTestCategory,0);
182 GLDEF_C TInt E32Main()
185 test.Start(_L("Stress test using multiple threads accessing the same property"));
187 startTime.HomeTime();
188 TInt r=RProperty::Define(KPropTestCategory,0,RProperty::EInt, KPassPolicy, KPassPolicy);
191 TRequestStatus status1;
192 TRequestStatus status2;
193 TRequestStatus status3;
194 TRequestStatus status4;
200 r = t1.Create(KNullDesC, LowPriorityThread1, 0x2000, NULL, 0);
202 t1.SetPriority(EPriorityLess);
205 r = t2.Create(KNullDesC, LowPriorityThread2, 0x2000, NULL, 0);
207 t2.SetPriority(EPriorityLess);
210 r = t3.Create(KNullDesC, MediumPriorityThread, 0x2000, NULL, 0);
212 t3.SetPriority(EPriorityNormal);
215 r = t4.Create(KNullDesC, HighPriorityThread, 0x2000, NULL, 0);
217 t4.SetPriority(EPriorityMore);
220 TBool jit = User::JustInTime();
221 User::SetJustInTime(EFalse);
228 User::WaitForRequest(status1);
229 User::WaitForRequest(status2);
230 User::WaitForRequest(status3);
231 User::WaitForRequest(status4);
233 User::SetJustInTime(jit);
235 test(status1 == KErrNone);
236 test(status2 == KErrNone);
237 test(status3 == KErrNone);
238 test(status4 == KErrNone);
240 TTimeIntervalSeconds timeTaken;
243 r = time.SecondsFrom(startTime, timeTaken);
245 TInt totalTime = timeTaken.Int();
247 TInt seconds = totalTime % 60;
248 TInt minutes = (totalTime / 60) % 60;
249 TInt hours = totalTime / 3600;
251 test.Printf(_L("Time taken since test started: %d:%d:%d\r\n"),
252 hours, minutes, seconds);