|
1 // Copyright (c) 2007-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 "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 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 @test |
|
19 @internalComponent - Internal Symbian test code |
|
20 */ |
|
21 |
|
22 #include <startupproperties.h> |
|
23 #include <hal.h> |
|
24 |
|
25 #include "startsafe.h" |
|
26 #include "tstartsafe_procretry.h" |
|
27 #include "testapprvafterretry.h" |
|
28 #include "testapps.h" |
|
29 |
|
30 |
|
31 // KDontRvCount is defined in testapprvafterretry.h |
|
32 // the application will fail to rendezvous KDontRvCount times |
|
33 // but will then acquiesce and rendezvous with KErrNone |
|
34 const TInt KTries = KDontRvCount; |
|
35 const TInt KStartSafeRetryTestTimeout = 600; //400; |
|
36 |
|
37 |
|
38 /** |
|
39 Old Test CaseID APPFWK-STARTSAFE-0007 |
|
40 New Test CaseID DEVSRVS-SYSSTART-STARTSAFE-0007 |
|
41 */ |
|
42 |
|
43 TVerdict CAppFwkStartSafeTestStepProcRetry::doTestStepL( void ) |
|
44 { |
|
45 TInt threadHandles_Before; |
|
46 TInt processHandles_Before; |
|
47 TInt threadHandles_After; |
|
48 TInt processHandles_After; |
|
49 |
|
50 RThread().HandleCount(processHandles_Before, threadHandles_Before); |
|
51 |
|
52 CStartSafe *startSafe = CStartSafe::NewL(); |
|
53 CleanupStack::PushL( startSafe ); |
|
54 |
|
55 CStartupProperties *prop = CStartupProperties::NewL(); |
|
56 CleanupStack::PushL( prop ); |
|
57 |
|
58 // Write the retry number to a file to be read, updated |
|
59 // and eventually deleted by the test-app. |
|
60 RFs fs; |
|
61 CleanupClosePushL( fs ); |
|
62 |
|
63 RFileWriteStream writeStream; |
|
64 CleanupClosePushL( writeStream ); |
|
65 |
|
66 if( KErrNone != fs.Connect() |
|
67 || KErrNone != writeStream.Replace(fs, KDontRvCountFile, EFileWrite) ) |
|
68 { |
|
69 User::Leave( KErrCouldNotConnect ); |
|
70 } |
|
71 |
|
72 writeStream.WriteInt8L( KDontRvCount ); |
|
73 writeStream.CommitL(); |
|
74 |
|
75 CleanupStack::PopAndDestroy( 2, &fs ); |
|
76 |
|
77 |
|
78 prop->SetFileParamsL( KTestAppRvAfterRetry, KNullDesC ); |
|
79 prop->SetStartupType( EStartProcess ); |
|
80 prop->SetStartMethod( EWaitForStart ); |
|
81 prop->SetNoOfRetries( KDontRvCount ); |
|
82 prop->SetTimeout( KStartSafeRetryTestTimeout ); |
|
83 |
|
84 RProcess proc; |
|
85 CleanupClosePushL( proc ); |
|
86 TInt tried = 0; |
|
87 TInt nTicksInMicroseconds = 0; |
|
88 HAL::Get( HAL::ENanoTickPeriod, nTicksInMicroseconds ); |
|
89 INFO_PRINTF2( _L("System nano-ticks in uSec = %d"), nTicksInMicroseconds ); |
|
90 |
|
91 TUint nTicks = User::NTickCount(); |
|
92 |
|
93 INFO_PRINTF1( _L("Launch the reluctant app (rendezvous after retry)")); |
|
94 TRAPD( err, startSafe->StartL(*prop, proc, tried) ); |
|
95 |
|
96 nTicks = ( User::NTickCount() - nTicks ); |
|
97 INFO_PRINTF2( _L("milliseconds after = %d"), nTicks * (nTicksInMicroseconds / 1000) ); |
|
98 |
|
99 |
|
100 // Ensure that the process's name is that of the test-app. |
|
101 TPtrC procNamePtr = proc.FileName().Right( KTestAppRvAfterRetry().Length() ); |
|
102 TInt nameComparison = procNamePtr.Compare( KTestAppRvAfterRetry() ); |
|
103 |
|
104 |
|
105 if ( (KTries !=tried) || (KErrNone != err) || (0 != nameComparison) ) |
|
106 { |
|
107 SetTestStepResult( EFail ); |
|
108 ERR_PRINTF4( _L("Test failed. Retries %d. StartL error code %d Process name \"%S\""), tried, err, &procNamePtr ); |
|
109 } |
|
110 else |
|
111 { |
|
112 SetTestStepResult( EPass ); |
|
113 INFO_PRINTF2( _L("Test passed. test-app Process launched after %d unsuccessful tries"), tried ); |
|
114 } |
|
115 |
|
116 |
|
117 // Dispose of the test-app. |
|
118 if( 0 == nameComparison ) |
|
119 { |
|
120 proc.Kill( KErrNone ); |
|
121 } |
|
122 |
|
123 CleanupStack::PopAndDestroy( 3, startSafe ); |
|
124 RThread().HandleCount(processHandles_After, threadHandles_After); |
|
125 TEST(processHandles_After == processHandles_Before); |
|
126 TEST(threadHandles_After == threadHandles_Before); |
|
127 |
|
128 return TestStepResult(); |
|
129 } |
|
130 |
|
131 |
|
132 |
|
133 CAppFwkStartSafeTestStepProcRetry::CAppFwkStartSafeTestStepProcRetry() |
|
134 { |
|
135 SetTestStepName(KCTestCaseProcRetry); |
|
136 } |