|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "TestAppStep.h" |
|
19 |
|
20 |
|
21 CTestAppStep1::~CTestAppStep1() |
|
22 /** |
|
23 * Destructor |
|
24 */ |
|
25 { |
|
26 } |
|
27 |
|
28 CTestAppStep1::CTestAppStep1() |
|
29 /** |
|
30 * Constructor |
|
31 */ |
|
32 { |
|
33 // Call base class method to set up the human readable name for logging |
|
34 SetTestStepName(KSampleStep1); |
|
35 } |
|
36 |
|
37 TVerdict CTestAppStep1::doTestStepPreambleL() |
|
38 /** |
|
39 * @return - TVerdict code |
|
40 */ |
|
41 { |
|
42 SetTestStepResult(EPass); |
|
43 return TestStepResult(); |
|
44 } |
|
45 |
|
46 TVerdict CTestAppStep1::doTestStepL() |
|
47 /** |
|
48 * @return - TVerdict code |
|
49 * Smoke test step for a techview application. |
|
50 * Retrieves an exe name and corresponding uid from the config file. |
|
51 * Runs the exe. Delays for 20 secs. Checks that the exe is still running. |
|
52 */ |
|
53 { |
|
54 INFO_PRINTF1(_L("In Test Step CTestAppStep1")); |
|
55 SetTestStepResult(EFail); |
|
56 |
|
57 // Get the name of the app to run from the .ini configuration file. |
|
58 TPtrC exeToRun; |
|
59 _LIT(KExeName, "exename"); |
|
60 GetStringFromConfig(ConfigSection(),KExeName,exeToRun); |
|
61 INFO_PRINTF2(_L("The exe to run is %S"), &exeToRun); |
|
62 |
|
63 // Create a new process to run the executable in |
|
64 RProcess testProcess; |
|
65 if(testProcess.Create(exeToRun, KNullDesC()) == KErrNone) |
|
66 {testProcess.Resume();} |
|
67 else |
|
68 {return TestStepResult();} |
|
69 |
|
70 // Retrieve the UID of the app in order to check that it is running. |
|
71 TInt uidValue; |
|
72 _LIT(KUidKey, "uid"); |
|
73 if (!GetHexFromConfig(ConfigSection(), KUidKey, uidValue)) |
|
74 { |
|
75 ERR_PRINTF1(_L("Cannot read UID from config section.")); |
|
76 return TestStepResult(); |
|
77 } |
|
78 TUid exeUid; |
|
79 exeUid.iUid = uidValue; |
|
80 |
|
81 // In order to test this test code the process can be forced to panic |
|
82 // _LIT(KTestPanic, "test panic"); |
|
83 // testProcess.Panic(KTestPanic, 123); |
|
84 |
|
85 // Make sure app has stayed up for at least 20 secs |
|
86 User::After(2000000); |
|
87 INFO_PRINTF2(_L("Check that %S is still running after at least 20 seconds"), &exeToRun); |
|
88 |
|
89 // Loop through each process (match against default of *) |
|
90 TFindProcess findProcess; |
|
91 TFullName fullName; |
|
92 |
|
93 |
|
94 while((findProcess.Next(fullName) == KErrNone)) //&& (TestStepResult() == EFail)) |
|
95 { |
|
96 RProcess process; |
|
97 TInt ret=KErrNone; |
|
98 TInt count=0; |
|
99 |
|
100 // Open a handle to the process |
|
101 do |
|
102 { |
|
103 //INFO_PRINTF2(_L("process running is %S"), &fullName); |
|
104 count++; |
|
105 ret=process.Open(findProcess); |
|
106 if (ret!=KErrNone) |
|
107 { |
|
108 User::After(200000); |
|
109 } |
|
110 }while (ret!=KErrNone && count<=10); |
|
111 |
|
112 if (ret!=KErrNone) |
|
113 { |
|
114 User::Leave(ret); |
|
115 } |
|
116 |
|
117 // Extract any panic characteristics |
|
118 TUidType uid = process.Type(); |
|
119 TExitType exitType = process.ExitType(); |
|
120 TExitCategoryName exitCategory = process.ExitCategory(); |
|
121 TInt exitReason = process.ExitReason(); |
|
122 process.Close(); |
|
123 |
|
124 // If the uid being searched for is found and is running set the test step result to |
|
125 // pass. |
|
126 if(uid[2] == exeUid) |
|
127 { |
|
128 if (exitType == EExitPending) |
|
129 { |
|
130 INFO_PRINTF2(_L("A running process has been found with UID 0x%x"), exeUid ); |
|
131 SetTestStepResult(EPass); |
|
132 } |
|
133 else { |
|
134 if (exitType == EExitPanic) //print for debugging purposes |
|
135 { |
|
136 INFO_PRINTF2(_L("The process with UID 0x%x has exited due to a panic"), exeUid ); |
|
137 INFO_PRINTF3(_L("The exit Reason is %d, The exit category is \"%S\""), exitReason, &exitCategory); |
|
138 } |
|
139 } |
|
140 } // uid[2] == exeUid |
|
141 } // while |
|
142 |
|
143 // clean up |
|
144 testProcess.Kill(KErrNone); |
|
145 testProcess.Close(); |
|
146 |
|
147 return TestStepResult(); |
|
148 } |
|
149 |
|
150 TVerdict CTestAppStep1::doTestStepPostambleL() |
|
151 /** |
|
152 * @return - TVerdict code |
|
153 * Override of base class virtual |
|
154 */ |
|
155 { |
|
156 return TestStepResult(); |
|
157 } |