|
1 // Copyright (c) 1997-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 // e32test\system\t_nanowait.cpp |
|
15 // Overview: |
|
16 // Test Kernal::NanoWait() against the FastCounter. |
|
17 // API Information: |
|
18 // NTimer |
|
19 // Details: |
|
20 // - Start one 100 msec NanoWait delay and verify that the |
|
21 // delay time is correct. |
|
22 // Platforms/Drives/Compatibility: |
|
23 // All. |
|
24 // Assumptions/Requirement/Pre-requisites: |
|
25 // Failures and causes: |
|
26 // Base Port information: |
|
27 // |
|
28 // |
|
29 |
|
30 #include <e32test.h> |
|
31 #include <e32uid.h> |
|
32 #include <e32hal.h> |
|
33 #include <hal.h> |
|
34 #include "d_nanowait.h" |
|
35 |
|
36 RTest test(_L("t_nanowait")); |
|
37 RNanoWait nanowait; |
|
38 |
|
39 TBool PauseOnError = 0; |
|
40 #define GETCH() (PauseOnError&&test.Getch()) |
|
41 |
|
42 #define TEST(c) ((void)((c)||(test.Printf(_L("Failed at line %d\n"),__LINE__),GETCH(),test(0),0))) |
|
43 #define CHECK(c) ((void)(((c)==0)||(test.Printf(_L("Error %d at line %d\n"),(c),__LINE__),GETCH(),test(0),0))) |
|
44 #ifdef __WINS__ |
|
45 #define TESTTIME(v,min,max) test.Printf(_L("Expected range [%d,%d]\n"),min,max+1) |
|
46 #else |
|
47 #define TESTTIME(v,min,max) TEST(v>=min && v<max) |
|
48 #endif |
|
49 |
|
50 const TPtrC KLddFileName=_L("D_NANOWAIT.LDD"); |
|
51 |
|
52 GLDEF_C TInt E32Main() |
|
53 // |
|
54 // Test NanoWait() delays |
|
55 // |
|
56 { |
|
57 |
|
58 |
|
59 // To use in command line |
|
60 TBool pause = EFalse; |
|
61 TBuf<256> cmdline; |
|
62 User::CommandLine(cmdline); |
|
63 if( cmdline == _L("-p")) |
|
64 { |
|
65 pause = ETrue; |
|
66 } |
|
67 |
|
68 |
|
69 test.Title(); |
|
70 |
|
71 test.Start(_L("Load D_NanoWait.LDD")); |
|
72 TInt r=User::LoadLogicalDevice(KLddFileName); |
|
73 TEST(r==KErrNone || r==KErrAlreadyExists); |
|
74 |
|
75 test.Next(_L("Test NanoWait delay")); |
|
76 r=nanowait.Open(); |
|
77 CHECK(r); |
|
78 |
|
79 TInt requested = 100000000; // nsec = 100 msec |
|
80 TUint32 startTick; |
|
81 TUint32 endTick; |
|
82 |
|
83 TInt nanokernel_tick_period; |
|
84 HAL::Get(HAL::ENanoTickPeriod, nanokernel_tick_period ); |
|
85 nanokernel_tick_period *= 1000; // convert from micro sec to nsec |
|
86 |
|
87 |
|
88 test.Printf(_L("Test parameters: total requested:%d nsec\n"), requested); |
|
89 |
|
90 startTick = User::NTickCount(); |
|
91 r=nanowait.StartNanoWait(1, requested); |
|
92 endTick = User::NTickCount(); |
|
93 |
|
94 startTick *= nanokernel_tick_period; // in nsec |
|
95 endTick *= nanokernel_tick_period; // in nsec |
|
96 |
|
97 TInt measured = endTick-startTick; |
|
98 TInt diff = measured - requested; |
|
99 test.Printf(_L("Requested delay:%10d nsec\n"), requested); |
|
100 test.Printf(_L("Measured delay :%10d nsec\n"), measured); |
|
101 test.Printf(_L("Difference :%10d nsec\n"), diff); |
|
102 |
|
103 |
|
104 test.End(); |
|
105 if( pause ) |
|
106 { |
|
107 test.Printf(_L("Press any key\n")); |
|
108 test.Getch(); |
|
109 } |
|
110 |
|
111 return(KErrNone); |
|
112 } |
|
113 |